Add prometheus co2 exporter

This commit is contained in:
Simon Bruder 2022-11-03 16:40:05 +01:00
parent c906e208e2
commit fd3bb4284b
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
8 changed files with 88 additions and 0 deletions

View file

@ -8,6 +8,7 @@
./services/media-backup.nix
./services/media.nix
./services/torrent.nix
./services/co2_exporter.nix
];
sbruder = {

View file

@ -0,0 +1,8 @@
{ config, ... }:
{
services.co2_exporter = {
enable = true;
listenAddress = "${config.sbruder.wireguard.home.address}:9672"; # uses port numer of unrelated co2 exporter to avoid 8080
};
}

View file

@ -98,6 +98,10 @@ in
job_name = "hcloud";
static_configs = mkStaticTarget config.services.hcloud_exporter.listenAddress;
}
{
job_name = "co2";
static_configs = mkStaticTarget "fuuko.vpn.sbruder.de:9672";
}
];
rules =

View file

@ -15,6 +15,9 @@
# TI-84+ SE
SUBSYSTEM=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="e008", MODE="0660", GROUP="users"
# TFA AIRCO2NTROL COACH (Holtek Semiconductor, Inc. USB-zyTemp)
SUBSYSTEMS=="usb", ATTRS{idVendor}=="04d9", ATTRS{idProduct}=="a052", MODE="0644"
'';
boot.kernelModules = [ "uinput" ];

View file

@ -0,0 +1,24 @@
{ lib, buildGoModule, fetchFromGitHub }:
buildGoModule rec {
pname = "co2_exporter";
version = "unstable-2022-11-03";
src = fetchFromGitHub {
owner = "sbruder"; # fork of am3os original version
repo = pname;
rev = "49ee376d257c0d92dcb819de6d67bb16d64b0339";
sha256 = "sha256-GJyIS6G0egSfk6LI38VqXg+E+WWQqJRmcvUU9Nk5MSo=";
};
subPackages = [ "." ];
vendorSha256 = "sha256-CMo6FBzw0/OMKEX12oNqhbF/0dRRFR6W3VRp+EU6Q68=";
oCheck = false; # no tests
meta = with lib; {
license = licenses.mit;
maintainer = with mainatiners; [ sbruder ];
};
}

View file

@ -0,0 +1,45 @@
{ config, lib, pkgs, ... }:
let
cfg = config.services.co2_exporter;
in
{
options.services.co2_exporter = {
enable = lib.mkEnableOption "co2 exporter";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.co2_exporter;
description = "The package to use for the exporter.";
};
device = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "The path to the co2 monitor device.";
};
listenAddress = lib.mkOption {
type = lib.types.str;
default = ":8080";
description = "The address to listen on";
example = "127.0.0.1:8080";
};
};
config = lib.mkIf cfg.enable {
systemd.services.co2_exporter = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
environment = {
CO2MONITOR_ADDRESS = cfg.listenAddress;
} // (lib.optionalAttrs (!isNull cfg.device) {
CO2MONITOR_DEVICE = cfg.device;
});
serviceConfig = {
ExecStart = "${cfg.package}/bin/co2_exporter";
Restart = "always";
# systemd-analyze --no-pager security co2_exporter.service
DynamicUser = true;
# FIXME
};
};
};
}

View file

@ -5,6 +5,8 @@ in
{
bwrap-helper = callPackage ./bwrap-helper { };
co2_exporter = callPackage ./co2_exporter { };
osu-lazer = callPackage ./osu-lazer { inherit (prev) osu-lazer; };
osu-lazer-sandbox = callPackage ./osu-lazer-sandbox { };

View file

@ -3,5 +3,6 @@
{
imports = [
./wordclock-dimmer/module.nix
./co2_exporter/module.nix
];
}