From 9564a24c32db0c220477963c221fdf003f597223 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 17 Jun 2019 07:52:55 +0200 Subject: config collectd-base: send logs to wolf --- krebs/2configs/collectd-base.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/collectd-base.nix b/krebs/2configs/collectd-base.nix index 440f83fce..71a00be3a 100644 --- a/krebs/2configs/collectd-base.nix +++ b/krebs/2configs/collectd-base.nix @@ -9,7 +9,7 @@ let ModulePath "${collectd-connect-time}/lib/${python.libPrefix}/site-packages/" Import "collectd_connect_time" - target "localhost:22" "google.com" "google.de" "gum.r:22" "gum.krebsco.de" "heidi.shack:22" "10.42.0.1:22" "heise.de" "t-online.de" + target "localhost:22" "google.com" "google.de" "gum.r:22" "gum.krebsco.de" "10.42.0.1:22" "heise.de" "t-online.de" interval 10 @@ -18,7 +18,7 @@ let LoadPlugin write_graphite - Host "heidi.shack" + Host "wolf.r" Port "2003" Prefix "retiolum." EscapeCharacter "_" -- cgit v1.2.3 From 8225afec5b2e853d2e4eeae27adc5a39efcdae17 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 20 Jun 2019 22:21:56 +0200 Subject: wolf.r: init shack/prometheus config --- krebs/2configs/shack/prometheus/node.nix | 27 ++++ krebs/2configs/shack/prometheus/server.nix | 195 +++++++++++++++++++++++++++++ krebs/2configs/shack/prometheus/unifi.nix | 10 ++ 3 files changed, 232 insertions(+) create mode 100644 krebs/2configs/shack/prometheus/node.nix create mode 100644 krebs/2configs/shack/prometheus/server.nix create mode 100644 krebs/2configs/shack/prometheus/unifi.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/prometheus/node.nix b/krebs/2configs/shack/prometheus/node.nix new file mode 100644 index 000000000..5462464d5 --- /dev/null +++ b/krebs/2configs/shack/prometheus/node.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, ... }: +{ + networking.firewall.allowedTCPPorts = [ 9100 ]; + + services.prometheus.exporters.node = { + enable = true; + enabledCollectors = [ + "conntrack" + "diskstats" + "entropy" + "filefd" + "filesystem" + "loadavg" + "mdadm" + "meminfo" + "netdev" + "netstat" + "stat" + "time" + "vmstat" + "systemd" + "logind" + "interrupts" + "ksmd" + ]; + }; +} diff --git a/krebs/2configs/shack/prometheus/server.nix b/krebs/2configs/shack/prometheus/server.nix new file mode 100644 index 000000000..c936f2531 --- /dev/null +++ b/krebs/2configs/shack/prometheus/server.nix @@ -0,0 +1,195 @@ +{ pkgs, lib, config, ... }: +# from https://gist.github.com/globin/02496fd10a96a36f092a8e7ea0e6c7dd +{ + networking = { + firewall.allowedTCPPorts = [ + 3000 # grafana + 9090 # prometheus + 9093 # alertmanager + ]; + useDHCP = true; + }; + + services = { + prometheus = { + enable = true; + extraFlags = [ + "-storage.local.retention 8760h" + "-storage.local.series-file-shrink-ratio 0.3" + "-storage.local.memory-chunks 2097152" + "-storage.local.max-chunks-to-persist 1048576" + "-storage.local.index-cache-size.fingerprint-to-metric 2097152" + "-storage.local.index-cache-size.fingerprint-to-timerange 1048576" + "-storage.local.index-cache-size.label-name-to-label-values 2097152" + "-storage.local.index-cache-size.label-pair-to-fingerprints 41943040" + ]; + alertmanagerURL = [ "http://localhost:9093" ]; + rules = [ + '' + ALERT node_down + IF up == 0 + FOR 5m + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: Node is down.", + description = "{{$labels.alias}} has been down for more than 5 minutes." + } + ALERT node_systemd_service_failed + IF node_systemd_unit_state{state="failed"} == 1 + FOR 4m + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: Service {{$labels.name}} failed to start.", + description = "{{$labels.alias}} failed to (re)start service {{$labels.name}}." + } + ALERT node_filesystem_full_90percent + IF sort(node_filesystem_free{device!="ramfs"} < node_filesystem_size{device!="ramfs"} * 0.1) / 1024^3 + FOR 5m + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: Filesystem is running out of space soon.", + description = "{{$labels.alias}} device {{$labels.device}} on {{$labels.mountpoint}} got less than 10% space left on its filesystem." + } + ALERT node_filesystem_full_in_4h + IF predict_linear(node_filesystem_free{device!="ramfs"}[1h], 4*3600) <= 0 + FOR 5m + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: Filesystem is running out of space in 4 hours.", + description = "{{$labels.alias}} device {{$labels.device}} on {{$labels.mountpoint}} is running out of space of in approx. 4 hours" + } + ALERT node_filedescriptors_full_in_3h + IF predict_linear(node_filefd_allocated[1h], 3*3600) >= node_filefd_maximum + FOR 20m + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}} is running out of available file descriptors in 3 hours.", + description = "{{$labels.alias}} is running out of available file descriptors in approx. 3 hours" + } + ALERT node_load1_90percent + IF node_load1 / on(alias) count(node_cpu{mode="system"}) by (alias) >= 0.9 + FOR 1h + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: Running on high load.", + description = "{{$labels.alias}} is running with > 90% total load for at least 1h." + } + ALERT node_cpu_util_90percent + IF 100 - (avg by (alias) (irate(node_cpu{mode="idle"}[5m])) * 100) >= 90 + FOR 1h + LABELS { + severity="page" + } + ANNOTATIONS { + summary = "{{$labels.alias}}: High CPU utilization.", + description = "{{$labels.alias}} has total CPU utilization over 90% for at least 1h." + } + ALERT node_ram_using_90percent + IF node_memory_MemFree + node_memory_Buffers + node_memory_Cached < node_memory_MemTotal * 0.1 + FOR 30m + LABELS { + severity="page" + } + ANNOTATIONS { + summary="{{$labels.alias}}: Using lots of RAM.", + description="{{$labels.alias}} is using at least 90% of its RAM for at least 30 minutes now.", + } + '' + ]; + scrapeConfigs = [ + { + job_name = "node"; + scrape_interval = "10s"; + static_configs = [ + { + targets = [ + "localhost:9100" + ]; + labels = { + alias = "wolf.shack"; + }; + } + { + targets = [ + "localhost:9130" + ]; + labels = { + alias = "unifi.shack"; + }; + } + { + targets = [ + "10.42.22.184:9100" # puyak.shack + ]; + labels = { + alias = "puyak.shack"; + }; + } + { + targets = [ + "phenylbutazon.shack:9100" + ]; + labels = { + alias = "phenylbutazon.shack"; + }; + } + { + targets = [ + "ibuprofen.shack:9100" + ]; + labels = { + alias = "ibuprofen.shack"; + }; + } + ]; + } + ]; + alertmanager = { + enable = true; + listenAddress = "0.0.0.0"; + configuration = { + "global" = { + "smtp_smarthost" = "smtp.example.com:587"; + "smtp_from" = "alertmanager@example.com"; + }; + "route" = { + "group_by" = [ "alertname" "alias" ]; + "group_wait" = "30s"; + "group_interval" = "2m"; + "repeat_interval" = "4h"; + "receiver" = "team-admins"; + }; + "receivers" = [ + { + "name" = "team-admins"; + "email_configs" = [ + { + "to" = "devnull@example.com"; + "send_resolved" = true; + } + ]; + "webhook_configs" = [ + { + "url" = "https://example.com/prometheus-alerts"; + "send_resolved" = true; + } + ]; + } + ]; + }; + }; + }; + }; +} diff --git a/krebs/2configs/shack/prometheus/unifi.nix b/krebs/2configs/shack/prometheus/unifi.nix new file mode 100644 index 000000000..401ecb024 --- /dev/null +++ b/krebs/2configs/shack/prometheus/unifi.nix @@ -0,0 +1,10 @@ +{lib, ... }: +{ + services.prometheus.exporters.unifi = { + enable = true; + unifiAddress = "https://unifi.shack:8443/"; + unifiInsecure = true; + unifiUsername = "prometheus"; # needed manual login after setup to confirm the password + unifiPassword = lib.replaceChars ["\n"] [""] (builtins.readFile ); + }; +} -- cgit v1.2.3 From 19e25f58566866b7c5182ab0d26ff66cba2eeffd Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 7 Jul 2019 21:18:32 +0200 Subject: shack/gitlab-ci: enable graceful shutdown --- krebs/2configs/shack/gitlab-runner.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/gitlab-runner.nix b/krebs/2configs/shack/gitlab-runner.nix index 0fd06426a..f1bb94f37 100644 --- a/krebs/2configs/shack/gitlab-runner.nix +++ b/krebs/2configs/shack/gitlab-runner.nix @@ -13,9 +13,12 @@ in imports = [ "${runner-src}/gitlab-runner.nix" ]; - services.gitlab-runner2.enable = true; - ## registrationConfigurationFile contains: - # CI_SERVER_URL= - # REGISTRATION_TOKEN= - services.gitlab-runner2.registrationConfigFile = ; + services.gitlab-runner2 = { + enable = true; + ## registrationConfigurationFile contains: + # CI_SERVER_URL= + # REGISTRATION_TOKEN= + registrationConfigFile = ; + gracefulTermination = true; + }; } -- cgit v1.2.3 From 7ca133e90b565e0cd97fe447b3bd4872d11a22a8 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 8 Jul 2019 00:58:38 +0200 Subject: shack/gitlab-runner: do not restart service on change --- krebs/2configs/shack/gitlab-runner.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/gitlab-runner.nix b/krebs/2configs/shack/gitlab-runner.nix index f1bb94f37..501dc47ea 100644 --- a/krebs/2configs/shack/gitlab-runner.nix +++ b/krebs/2configs/shack/gitlab-runner.nix @@ -19,6 +19,7 @@ in # CI_SERVER_URL= # REGISTRATION_TOKEN= registrationConfigFile = ; - gracefulTermination = true; + #gracefulTermination = true; }; + systemd.services.gitlab-runner2.restartIfChanged = false; } -- cgit v1.2.3 From bb0bd75d7854b4612b9843729ab93a2c90cd69f5 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 11 Jul 2019 09:35:36 +0200 Subject: shack/muellshack: init --- krebs/2configs/shack/muellshack.nix | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 krebs/2configs/shack/muellshack.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/muellshack.nix b/krebs/2configs/shack/muellshack.nix new file mode 100644 index 000000000..3a8d1cd88 --- /dev/null +++ b/krebs/2configs/shack/muellshack.nix @@ -0,0 +1,42 @@ +{ config, lib, pkgs, ... }: + +let + pkg = pkgs.callPackage ( + pkgs.fetchgit { + url = "https://git.shackspace.de/rz/muellshack"; + rev = "d8a5e2d4c0a22804838675ac42b468299dcd9a76"; + sha256 = "0ff6q64dgdxmpszp94z100fdic175b1vvxn4crg8p0jcabzxsv0m"; + }) {}; + home = "/var/lib/muellshack"; + port = "8081"; +in { + users.users.muellshack = { + inherit home; + createHome = true; + }; + services.nginx.virtualHosts."muell.shack" = { + locations."/" = { + proxyPass = "http://localhost:${port}/muellshack/"; + }; + }; + services.nginx.virtualHosts."openhab.shack" = { + locations."/muellshack".proxyPass = "http://localhost:${port}"; + }; + systemd.services.muellshack = { + description = "muellshack"; + wantedBy = [ "multi-user.target" ]; + environment.PORT = port; + serviceConfig = { + User = "muellshack"; + # do not override the current storage fil + ExecStartPre = pkgs.writeDash "call-muell-pre" '' + cp -vf ${pkg}/share/static_muelldata.json ${home} + cp -vn ${pkg}/share/storage.json ${home} + ''; + WorkingDirectory = home; + ExecStart = "${pkg}/bin/muellshack"; + Restart = "always"; + PrivateTmp = true; + }; + }; +} -- cgit v1.2.3 From 9f27ddabacb1f163751d5ce45de0b972bb22aab3 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 11 Jul 2019 09:37:23 +0200 Subject: shack/gitlab-runner: docker.restartIfChanged = false --- krebs/2configs/shack/gitlab-runner.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/gitlab-runner.nix b/krebs/2configs/shack/gitlab-runner.nix index 501dc47ea..5f2ca02d9 100644 --- a/krebs/2configs/shack/gitlab-runner.nix +++ b/krebs/2configs/shack/gitlab-runner.nix @@ -6,10 +6,6 @@ let }; in { - systemd.services.gitlab-runner.path = [ - "/run/wrappers" # /run/wrappers/bin/su - "/" # /bin/sh - ]; imports = [ "${runner-src}/gitlab-runner.nix" ]; @@ -22,4 +18,5 @@ in #gracefulTermination = true; }; systemd.services.gitlab-runner2.restartIfChanged = false; + systemd.services.docker.restartIfChanged = false; } -- cgit v1.2.3 From 4dad3683f9acfa243b195e498af422b25bb9056e Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 11 Jul 2019 18:11:22 +0200 Subject: shack/muellshack: make storage.json writeable --- krebs/2configs/shack/muellshack.nix | 1 + 1 file changed, 1 insertion(+) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/muellshack.nix b/krebs/2configs/shack/muellshack.nix index 3a8d1cd88..928972140 100644 --- a/krebs/2configs/shack/muellshack.nix +++ b/krebs/2configs/shack/muellshack.nix @@ -32,6 +32,7 @@ in { ExecStartPre = pkgs.writeDash "call-muell-pre" '' cp -vf ${pkg}/share/static_muelldata.json ${home} cp -vn ${pkg}/share/storage.json ${home} + chmod 700 ${home}/storage.json ''; WorkingDirectory = home; ExecStart = "${pkg}/bin/muellshack"; -- cgit v1.2.3 From 31960101a75796c184d44264744da73d27f8cd78 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 11 Jul 2019 18:11:50 +0200 Subject: shack/node-light: init --- krebs/2configs/shack/node-light.nix | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 krebs/2configs/shack/node-light.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/node-light.nix b/krebs/2configs/shack/node-light.nix new file mode 100644 index 000000000..d7e9e90bb --- /dev/null +++ b/krebs/2configs/shack/node-light.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +let + pkg = pkgs.callPackage ( + pkgs.fetchgit { + url = "https://git.shackspace.de/rz/node-light.git"; + rev = "a32c782650c4cc0adf51250fe249167d7246c59b"; + sha256 = "0clvcp1m2ay0a9ibh7s21q7d9a6nam3497bysvc6mdygblks22qy"; + }) {}; + home = "/var/lib/node-light"; + port = "8082"; +in { + # receive response from light.shack / standby.shack + networking.firewall.allowedUDPPorts = [ 2342 ]; + users.users.node-light = { + inherit home; + createHome = true; + }; + services.nginx.virtualHosts."lounge.light.shack" = { + locations."/" = { + proxyPass = "http://localhost:${port}/lounge/"; + }; + }; + services.nginx.virtualHosts."power.light.shack" = { + locations."/" = { + proxyPass = "http://localhost:${port}/power/"; + }; + }; + + services.nginx.virtualHosts."openhab.shack" = { + serverAliases = [ "lightapi.shack" ]; + locations."/power".proxyPass = "http://localhost:${port}"; + locations."/lounge".proxyPass = "http://localhost:${port}"; + }; + systemd.services.node-light= { + description = "node-light"; + wantedBy = [ "multi-user.target" ]; + environment.PORT = port; + serviceConfig = { + User = "node-light"; + # do not override the current storage file + ExecStartPre = pkgs.writeDash "call-light-pre" '' + cp -vn ${pkg}/share/storage.json ${home} + chmod 700 ${home}/storage.json + + ''; + WorkingDirectory = home; + ExecStart = "${pkg}/bin/node-light"; + Restart = "always"; + PrivateTmp = true; + }; + }; +} -- cgit v1.2.3 From 80ed71e9b85ae06dea54ec1de7637ac9abd2a4aa Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 12 Jul 2019 17:20:54 +0200 Subject: shack/muell_mail: init --- krebs/2configs/shack/muell_mail.nix | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 krebs/2configs/shack/muell_mail.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/muell_mail.nix b/krebs/2configs/shack/muell_mail.nix new file mode 100644 index 000000000..732269c88 --- /dev/null +++ b/krebs/2configs/shack/muell_mail.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +let + pkg = pkgs.callPackage ( + pkgs.fetchgit { + url = "https://git.shackspace.de/rz/muell_mail"; + rev = "317370e3e98ce34da4ee615af7a80df7b519ab89"; + sha256 = "sha256:02mywm37n0v4icgy474wwkavb7vad93bvkigvz1cqn7fbg4ldc8k"; + }) {}; + home = "/var/lib/muell_mail"; + cfg = toString ; +in { + users.users.muell_mail = { + inherit home; + createHome = true; + }; + systemd.services.muell_mail = { + description = "muell_mail"; + wantedBy = [ "multi-user.target" ]; + environment.CONFIG = "${home}/muell_mail.js"; + serviceConfig = { + User = "muell_mail"; + ExecStartPre = pkgs.writeDash "muell_mail-pre" '' + install -D -omuell_mail -m700 ${cfg} ${home}/muell_mail.js + ''; + WorkingDirectory = home; + PermissionsStartOnly = true; + ExecStart = "${pkg}/bin/muell_mail"; + Restart = "always"; + PrivateTmp = true; + }; + }; +} -- cgit v1.2.3 From e767afa039b7441bd9709cdb9f4ce993cb2830cb Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 15 Jul 2019 09:58:20 +0200 Subject: shack/muell_mail,s3-power: update commits --- krebs/2configs/shack/muell_mail.nix | 4 ++-- krebs/2configs/shack/s3-power.nix | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 krebs/2configs/shack/s3-power.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/muell_mail.nix b/krebs/2configs/shack/muell_mail.nix index 732269c88..39d49918d 100644 --- a/krebs/2configs/shack/muell_mail.nix +++ b/krebs/2configs/shack/muell_mail.nix @@ -4,8 +4,8 @@ let pkg = pkgs.callPackage ( pkgs.fetchgit { url = "https://git.shackspace.de/rz/muell_mail"; - rev = "317370e3e98ce34da4ee615af7a80df7b519ab89"; - sha256 = "sha256:02mywm37n0v4icgy474wwkavb7vad93bvkigvz1cqn7fbg4ldc8k"; + rev = "861ec25ab22797d8961efb32e72d79e113aa9f0f"; + sha256 = "sha256:18cw95zbr7isv4cw80cbpd84n5z208fwh5390i6j10jkn398mjq2"; }) {}; home = "/var/lib/muell_mail"; cfg = toString ; diff --git a/krebs/2configs/shack/s3-power.nix b/krebs/2configs/shack/s3-power.nix new file mode 100644 index 000000000..f0648d00b --- /dev/null +++ b/krebs/2configs/shack/s3-power.nix @@ -0,0 +1,33 @@ +{ config, lib, pkgs, ... }: + +let + pkg = pkgs.callPackage ( + pkgs.fetchgit { + url = "https://git.shackspace.de/rz/s3-power"; + rev = "1a59f8e34924c8809d06895bd96c7f98d037026e"; + sha256 = "sha256:191625mg7n41852h1c0ay3492f29n7kxkab0kwczyp07xh5y25nn"; + }) {}; + home = "/var/lib/s3-power"; + cfg = toString ; +in { + users.users.s3_power = { + inherit home; + createHome = true; + }; + systemd.services.s3-power = { + description = "s3-power"; + wantedBy = [ "multi-user.target" ]; + environment.CONFIG = "${home}/s3-power.json"; + serviceConfig = { + User = "s3_power"; + ExecStartPre = pkgs.writeDash "s3-power-pre" '' + install -D -os3_power -m700 ${cfg} ${home}/s3-power.json + ''; + WorkingDirectory = home; + PermissionsStartOnly = true; + ExecStart = "${pkg}/bin/s3-power"; + Restart = "always"; + PrivateTmp = true; + }; + }; +} -- cgit v1.2.3 From 570af0025a1ff0e1346b7efcacf6eb00ebc7d4d6 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 16 Jul 2019 18:57:09 +0200 Subject: shack/muellshack,node-light: fix paths --- krebs/2configs/shack/muellshack.nix | 2 +- krebs/2configs/shack/node-light.nix | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/muellshack.nix b/krebs/2configs/shack/muellshack.nix index 928972140..1e6843bdf 100644 --- a/krebs/2configs/shack/muellshack.nix +++ b/krebs/2configs/shack/muellshack.nix @@ -20,7 +20,7 @@ in { }; }; services.nginx.virtualHosts."openhab.shack" = { - locations."/muellshack".proxyPass = "http://localhost:${port}"; + locations."/muellshack/".proxyPass = "http://localhost:${port}/muellshack/"; }; systemd.services.muellshack = { description = "muellshack"; diff --git a/krebs/2configs/shack/node-light.nix b/krebs/2configs/shack/node-light.nix index d7e9e90bb..63772f182 100644 --- a/krebs/2configs/shack/node-light.nix +++ b/krebs/2configs/shack/node-light.nix @@ -29,8 +29,8 @@ in { services.nginx.virtualHosts."openhab.shack" = { serverAliases = [ "lightapi.shack" ]; - locations."/power".proxyPass = "http://localhost:${port}"; - locations."/lounge".proxyPass = "http://localhost:${port}"; + locations."/power/".proxyPass = "http://localhost:${port}/power/"; + locations."/lounge/".proxyPass = "http://localhost:${port}/lounge/"; }; systemd.services.node-light= { description = "node-light"; -- cgit v1.2.3 From 64c0ea71430e4aeb0bfe385439c631b3c4d6b8f3 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 16 Jul 2019 19:47:49 +0200 Subject: shack/s3-power: use one-shot version --- krebs/2configs/shack/s3-power.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/s3-power.nix b/krebs/2configs/shack/s3-power.nix index f0648d00b..2b136478d 100644 --- a/krebs/2configs/shack/s3-power.nix +++ b/krebs/2configs/shack/s3-power.nix @@ -4,8 +4,8 @@ let pkg = pkgs.callPackage ( pkgs.fetchgit { url = "https://git.shackspace.de/rz/s3-power"; - rev = "1a59f8e34924c8809d06895bd96c7f98d037026e"; - sha256 = "sha256:191625mg7n41852h1c0ay3492f29n7kxkab0kwczyp07xh5y25nn"; + rev = "36df203a8fc1af02b08f60ab8d49c849b01e711f"; + sha256 = "sha256:0i05vllnfwj02sfpmg2m8hy0zq27kww9ampiaix6dl5wbyjlp51j"; }) {}; home = "/var/lib/s3-power"; cfg = toString ; @@ -15,10 +15,11 @@ in { createHome = true; }; systemd.services.s3-power = { + startAt = "daily"; description = "s3-power"; - wantedBy = [ "multi-user.target" ]; environment.CONFIG = "${home}/s3-power.json"; serviceConfig = { + Type = "oneshot"; User = "s3_power"; ExecStartPre = pkgs.writeDash "s3-power-pre" '' install -D -os3_power -m700 ${cfg} ${home}/s3-power.json @@ -26,7 +27,6 @@ in { WorkingDirectory = home; PermissionsStartOnly = true; ExecStart = "${pkg}/bin/s3-power"; - Restart = "always"; PrivateTmp = true; }; }; -- cgit v1.2.3 From c38f02c4d7a09cd8a1fd50b68f08338ae54a82bb Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 17 Jul 2019 00:53:56 +0200 Subject: shack/s3-power: update revision --- krebs/2configs/shack/mqtt.nix | 14 ++++++++++++++ krebs/2configs/shack/s3-power.nix | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 krebs/2configs/shack/mqtt.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/mqtt.nix b/krebs/2configs/shack/mqtt.nix new file mode 100644 index 000000000..5e7a1af7c --- /dev/null +++ b/krebs/2configs/shack/mqtt.nix @@ -0,0 +1,14 @@ +{ + network.firewall.allowedTCPPorts = [ 1883 ]; + network.firewall.allowedUDPPorts = [ 1883 ]; + services.mosquitto = { + enable = true; + host = "0.0.0.0"; + users = {}; + # TODO: secure that shit + aclExtraConf = '' + pattern readwrite /# + ''; + allowAnonymous = true; + }; +} diff --git a/krebs/2configs/shack/s3-power.nix b/krebs/2configs/shack/s3-power.nix index 2b136478d..40c42260f 100644 --- a/krebs/2configs/shack/s3-power.nix +++ b/krebs/2configs/shack/s3-power.nix @@ -4,8 +4,8 @@ let pkg = pkgs.callPackage ( pkgs.fetchgit { url = "https://git.shackspace.de/rz/s3-power"; - rev = "36df203a8fc1af02b08f60ab8d49c849b01e711f"; - sha256 = "sha256:0i05vllnfwj02sfpmg2m8hy0zq27kww9ampiaix6dl5wbyjlp51j"; + rev = "b2b87b56bb40d714dbbecd1285566870b256aec4"; + sha256 = "sha256:02wikwf3rgkkggwbwqisdvhlwd38w5pw011xhwvhnj114s3rynan"; }) {}; home = "/var/lib/s3-power"; cfg = toString ; -- cgit v1.2.3 From 35837fd8d6df7d3fe4797fbc478fb2ccd0581bcb Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 17 Jul 2019 10:43:12 +0200 Subject: shack/powerraw: init --- krebs/2configs/shack/powerraw.nix | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 krebs/2configs/shack/powerraw.nix (limited to 'krebs/2configs') diff --git a/krebs/2configs/shack/powerraw.nix b/krebs/2configs/shack/powerraw.nix new file mode 100644 index 000000000..9b957b783 --- /dev/null +++ b/krebs/2configs/shack/powerraw.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: +# Replacement for powerraw.shack pollin box +# Requires usb-serial device on host +# Requires mqtt available at mqtt.shack +# Requires hostname powerraw.shack +let + pkg = pkgs.python3.pkgs.callPackage ( + pkgs.fetchgit { + url = "https://git.shackspace.de/rz/powermeter.git"; + rev = "96609f0d632e0732afa768ddd7b3f8841ca37c1b"; + sha256 = "sha256:0wfpm3ik5r081qv2crmpjwylgg2v8ximq347qh0fzq1rwv0dqbnn"; + }) {}; +in { + # receive response from light.shack / standby.shack + networking.firewall.allowedUDPPorts = [ 11111 ]; + users.users.powermeter = { + extraGroups = [ "dialout" ]; + }; + + systemd.services.powermeter-serial2mqtt = { + description = "powerraw Serial -> mqtt"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "powermeter"; + ExecStart = "${pkg}/bin/powermeter-serial2mqtt"; + Restart = "always"; + PrivateTmp = true; + }; + }; + + systemd.services.powermeter-mqtt2socket = { + description = "powerraw mqtt -> raw socket 11111"; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "powermeter"; + ExecStart = "${pkg}/bin/powermeter-mqtt2socket"; + Restart = "always"; + PrivateTmp = true; + }; + }; +} -- cgit v1.2.3 From 8e0c6fc8c5a4d76f6485ee317dc91d5cfffe70f6 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 17 Jul 2019 10:55:36 +0200 Subject: shack/mqtt: update permissions --- krebs/2configs/default.nix | 7 +++++++ krebs/2configs/shack/mqtt.nix | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'krebs/2configs') diff --git a/krebs/2configs/default.nix b/krebs/2configs/default.nix index fafcd72c3..8771c0e1d 100644 --- a/krebs/2configs/default.nix +++ b/krebs/2configs/default.nix @@ -34,6 +34,13 @@ with import ; rxvt_unicode.terminfo ]; + i18n = { + consoleKeyMap = "us"; + defaultLocale = lib.mkForce "C"; + }; + + + programs.ssh.startAgent = false; services.openssh = { diff --git a/krebs/2configs/shack/mqtt.nix b/krebs/2configs/shack/mqtt.nix index 5e7a1af7c..8e5438db2 100644 --- a/krebs/2configs/shack/mqtt.nix +++ b/krebs/2configs/shack/mqtt.nix @@ -1,13 +1,13 @@ { - network.firewall.allowedTCPPorts = [ 1883 ]; - network.firewall.allowedUDPPorts = [ 1883 ]; + networking.firewall.allowedTCPPorts = [ 1883 ]; + networking.firewall.allowedUDPPorts = [ 1883 ]; services.mosquitto = { enable = true; host = "0.0.0.0"; users = {}; # TODO: secure that shit aclExtraConf = '' - pattern readwrite /# + pattern readwrite # ''; allowAnonymous = true; }; -- cgit v1.2.3 From a45066902735f72a945f7b2d8c76c6d35e4a69bd Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 17 Jul 2019 13:55:33 +0200 Subject: shack/powerraw: send stats to influx as well --- krebs/2configs/shack/powerraw.nix | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'krebs/2configs') 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)); } -- cgit v1.2.3