diff options
author | makefu <github@syntax-fehler.de> | 2019-07-17 13:55:33 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2019-07-17 13:55:33 +0200 |
commit | a45066902735f72a945f7b2d8c76c6d35e4a69bd (patch) | |
tree | 97ca92935e1570ad5b844b97e42a386653678f55 /krebs/2configs | |
parent | 8e0c6fc8c5a4d76f6485ee317dc91d5cfffe70f6 (diff) |
shack/powerraw: send stats to influx as well
Diffstat (limited to 'krebs/2configs')
-rw-r--r-- | krebs/2configs/shack/powerraw.nix | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/krebs/2configs/shack/powerraw.nix b/krebs/2configs/shack/powerraw.nix index 9b957b783..af3f129c1 100644 --- a/krebs/2configs/shack/powerraw.nix +++ b/krebs/2configs/shack/powerraw.nix @@ -4,6 +4,7 @@ # Requires mqtt available at mqtt.shack # Requires hostname powerraw.shack let + influx-url = "http://influx.shack:8086"; pkg = pkgs.python3.pkgs.callPackage ( pkgs.fetchgit { url = "https://git.shackspace.de/rz/powermeter.git"; @@ -13,9 +14,7 @@ let in { # receive response from light.shack / standby.shack networking.firewall.allowedUDPPorts = [ 11111 ]; - users.users.powermeter = { - extraGroups = [ "dialout" ]; - }; + users.users.powermeter.extraGroups = [ "dialout" ]; systemd.services.powermeter-serial2mqtt = { description = "powerraw Serial -> mqtt"; @@ -38,4 +37,36 @@ in { PrivateTmp = true; }; }; + + services.telegraf = { + enable = true; + extraConfig = { + agent.debug = false; + outputs = { + influxdb = [{ + urls = [ influx-url ]; + database = "telegraf"; + }]; + }; + }; + }; + + services.telegraf.extraConfig.inputs.mqtt_consumer = let + genTopic = name: topic: tags: { + servers = [ "tcp://mqtt.shack:1883" ]; + qos = 0; + connection_timeout = "30s"; + topics = [ topic ]; + inherit tags; + persistent_session = false; + name_override = name; + data_format = "value"; + data_type = "float"; + }; + sensor = "total"; + types = [ "Voltage" "Current" "Power" ]; + phases = [ 1 2 3 ]; + in + [ (genTopic "Power consumed" "/power/${sensor}/consumed" { inherit sensor; }) ] ++ + (lib.flatten (map (type: (map (phase: (genTopic "Power" "/power/${sensor}/L${toString phase}/${type}" { inherit sensor phase type; }) ) phases)) types)); } |