From bf87b3460ac23d77f2585d247292f40616f59c4b Mon Sep 17 00:00:00 2001 From: stuebinm Date: Fri, 11 Nov 2022 23:19:34 +0100 Subject: chaski/tracktrain: add a grafana --- chaski/services/tracktrain.nix | 52 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/chaski/services/tracktrain.nix b/chaski/services/tracktrain.nix index 3d59806..5887f73 100644 --- a/chaski/services/tracktrain.nix +++ b/chaski/services/tracktrain.nix @@ -19,12 +19,62 @@ in proxyPass = "http://192.168.42.41:4000"; proxyWebsockets = true; }; + # don't expose prometheus endpoint + locations."/metrics".return = "404"; + enableACME = true; forceSSL = true; extraConfig = '' add_header 'Access-Control-Allow-Origin' '*' always; ''; }; + services.nginx.virtualHosts."tracktrain.ilztalbahn.eu" = { + locations."/api" = { + proxyPass = "http://192.168.42.41:4000"; + proxyWebsockets = true; + extraConfig = '' + add_header 'Access-Control-Allow-Origin' '*' always; + ''; + }; + locations."/metrics/" = { + proxyPass = "http://localhost:2342"; + proxyWebsockets = true; + extraConfig = '' + rewrite ^/metrics/(.*) /$1 break; + ''; + }; + enableACME = true; + forceSSL = true; + }; + + services.prometheus = { + enable = true; + port = 9001; + scrapeConfigs = [ { + job_name = "tracktrain"; + static_configs = [{ + targets = [ "192.168.42.41:4000" ]; + }]; + } ]; + }; + + services.grafana = { + enable = true; + domain = "tracktrain.ilztalbahn.eu"; + rootUrl = "%(protocol)s://%(domain)s:/metrics/"; + port = 2342; + addr = "0.0.0.0"; + extraOptions.serve_from_sub_path = "true"; + + provision = { + enable = true; + datasources = [ { + url = "http://localhost:9001"; + type = "prometheus"; + name = "prometheus"; + } ]; + }; + }; networking.firewall.allowedTCPPorts = [ 443 ]; @@ -56,7 +106,7 @@ in sed -i "s/^>=.*//g" *.cabal sed -i "s/>=.*//g" *.cabal ''; })) - }/bin/tracktrain --dbString="dbname=tracktrain user=tracktrain" --warp.port=4000 + }/bin/tracktrain --dbString="dbname=tracktrain user=tracktrain" --warp.port=4000 +RTS -T ''; startAt = "daily"; }; -- cgit v1.2.3