aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2023-01-08 11:08:52 +0100
committerKarel Kočí <cynerd@email.cz>2023-01-08 11:08:52 +0100
commit99c357915697b9d800523b2252850c758e2aae1d (patch)
treed296b94d4f4532f412554ce52f414bc77df67fce /nixos/modules
parente7abf8728a0fd0a77e6fa5803acd1b0c1e0682c6 (diff)
downloadnixos-personal-99c357915697b9d800523b2252850c758e2aae1d.tar.gz
nixos-personal-99c357915697b9d800523b2252850c758e2aae1d.tar.bz2
nixos-personal-99c357915697b9d800523b2252850c758e2aae1d.zip
nixos/monitoring: expand monitoring
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/desktop.nix2
-rw-r--r--nixos/modules/home-assistant.nix49
-rw-r--r--nixos/modules/hosts.nix2
-rw-r--r--nixos/modules/monitoring.nix61
4 files changed, 93 insertions, 21 deletions
diff --git a/nixos/modules/desktop.nix b/nixos/modules/desktop.nix
index 1f3ab71..27beb04 100644
--- a/nixos/modules/desktop.nix
+++ b/nixos/modules/desktop.nix
@@ -23,8 +23,6 @@ in {
};
config = mkIf cnf.enable {
- cynerd.hosts.enable = true;
-
programs.sway.enable = true;
programs.sway.wrapperFeatures.gtk = true;
programs.sway.extraPackages = with pkgs; [
diff --git a/nixos/modules/home-assistant.nix b/nixos/modules/home-assistant.nix
index 80c76b3..e4f2232 100644
--- a/nixos/modules/home-assistant.nix
+++ b/nixos/modules/home-assistant.nix
@@ -26,6 +26,10 @@ in {
acl = ["readwrite bigclown/#"];
passwordFile = "/run/secrets/mosquitto.bigclown.pass";
};
+ telegraf = {
+ acl = ["read bigclown/node/#"];
+ passwordFile = "/run/secrets/mosquitto.telegraf.pass";
+ };
homeassistant = {
acl = [
"readwrite bigclown/#"
@@ -51,6 +55,7 @@ in {
};
};
mqtt2influxdb = {
+ # TODO remove as we have telegraf
enable = true;
environmentFile = "/run/secrets/bigclown.env";
mqtt = {
@@ -128,6 +133,50 @@ in {
serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini";
};
+ services.telegraf.extraConfig = {
+ outputs.influxdb_v2 = [{
+ urls = ["http://errol:8086"];
+ token = "$INFLUX_TOKEN";
+ organization = "personal";
+ bucket = "bigclown";
+ tagpass.source = ["bigclown"];
+ }];
+ inputs.mqtt_consumer = let
+ consumer = data_type: topics: {
+ tags = { source = "bigclown"; };
+ servers = ["tcp://localhost:1883"];
+ topics = topics;
+ username = "telegraf";
+ password = "$MQTT_PASSWORD";
+ data_format = "value";
+ data_type = data_type;
+ topic_parsing = [{
+ topic = "bigclown/node/+/+/+/+";
+ measurement = "_/_/_/_/_/measurement";
+ tags = "_/_/device/field/_/_";
+ }];
+ };
+ in [
+ (consumer "float" [
+ "bigclown/node/+/battery/+/voltage"
+ "bigclown/node/+/thermometer/+/temperature"
+ "bigclown/node/+/hygrometer/+/relative-humidity"
+ "bigclown/node/+/lux-meter/+/illuminance"
+ "bigclown/node/+/barometer/+/pressure"
+ "bigclown/node/+/pir/+/event-count"
+ "bigclown/node/+/push-button/+/event-count"
+ ])
+ (consumer "boolean" [
+ "bigclown/node/+/flood-detector/+/alarm"
+ ])
+ ];
+ processors.pivot = [{
+ tag_key = "field";
+ value_key = "value";
+ tagpass.source = ["bigclown"];
+ }];
+ };
+
services.home-assistant = {
enable = false;
openFirewall = true;
diff --git a/nixos/modules/hosts.nix b/nixos/modules/hosts.nix
index e307619..ca9daa1 100644
--- a/nixos/modules/hosts.nix
+++ b/nixos/modules/hosts.nix
@@ -17,7 +17,7 @@ in {
cynerd.hosts = {
enable = mkOption {
type = types.bool;
- default = false;
+ default = true;
description = "Use my personal static hosts";
};
vpn = staticZoneOption;
diff --git a/nixos/modules/monitoring.nix b/nixos/modules/monitoring.nix
index 1f011dd..abeba2d 100644
--- a/nixos/modules/monitoring.nix
+++ b/nixos/modules/monitoring.nix
@@ -30,6 +30,7 @@ in {
config = mkMerge [
{ cynerd.monitoring.host = "errol"; }
+
(mkIf cnf.enable {
# Telegraf configuration
services.telegraf = {
@@ -37,44 +38,63 @@ in {
environmentFiles = ["/run/secrets/telegraf.env"];
extraConfig = {
agent = {};
- outputs.influxdb_v2 = {
+ outputs.influxdb_v2 = [{
urls = ["http://errol:8086"];
token = "$INFLUX_TOKEN";
organization = "personal";
bucket = "monitoring";
- };
+ tagdrop.source = ["bigclown"]; # See home-assistant.nix
+ }];
inputs = {
- cpu = {
+ cpu = [{
percpu = true;
totalcpu = true;
- };
- disk = {
+ }];
+ mem = [{}];
+ swap = [{}];
+ disk = [{
ignore_fs = [
"tmpfs" "devtmpfs" "devfs" "iso9660" "overlay" "aufs" "squashfs"
];
- };
- diskio = {};
- diskio = {};
- mem = {};
- net = {};
- processes = {};
- swap = {};
- system = {};
+ }];
+ diskio = [{}];
+ net = [{}];
+ system = [{}];
+ processes = [{}];
+ systemd_units = [{}];
+ wireguard = [{}];
} // (optionalAttrs cnf.hw {
- sensors = {};
- smart = {};
+ sensors = [{}];
+ smart = [{
+ path_smartctl = "${pkgs.smartmontools}/bin/smartctl";
+ use_sudo = true;
+ }];
+ wireless = [{}];
});
};
};
- # TODO probably add this to the upstream configuration
systemd.services.telegraf.path = with pkgs; [
+ "/run/wrappers"
] ++ (optionals cnf.hw [
- nvme-cli lm_sensors smartmontools
+ lm_sensors smartmontools nvme-cli
]);
+ security.sudo.extraRules = [
+ {
+ users = ["telegraf"];
+ commands = [{
+ command = "${pkgs.smartmontools}/bin/smartctl";
+ options = ["NOPASSWD"];
+ }];
+ }
+ ];
})
+
(mkIf isHost {
# InfluxDB
services.influxdb2.enable = mkIf isHost true;
+ services.telegraf.extraConfig.inputs.prometheus = {
+ urls = ["http://localhost:8086/metrics"];
+ };
# Grafana
services.grafana = mkIf isHost {
enable = true;
@@ -84,9 +104,14 @@ in {
admin_user = "cynerd";
admin_password = "$__file{/run/secrets/grafana.admin.pass}";
};
+ server = {
+ http_addr = "";
+ http_port = 3000;
+ };
};
};
-
+ networking.firewall.allowedTCPPorts = [8086 3000];
})
+
];
}