From 5d712a59635c194dcdda8f450bae1f651d9e7b79 Mon Sep 17 00:00:00 2001 From: dusk Date: Mon, 28 Apr 2025 21:07:28 +0000 Subject: [PATCH] feat(wolumonde): perses dashboard as code with go --- .gitignore | 1 + deploy.nu | 2 ++ shells/dash.nu | 19 +++++++++++++++++++ shells/default.nix | 7 +++++++ hosts/wolumonde/default.nix | 5 ++++- pkgs-set/pkgs/percli.nix | 8 ++++---- hosts/wolumonde/modules/nginx.nix | 20 ++++++++++++++------ hosts/wolumonde/modules/pds.nix | 22 ++++++++++++++++++++++ hosts/wolumonde/modules/perses.nix | 37 ++++++++++++++++++++++++------------- hosts/wolumonde/modules/perses/dashboards/.gitignore | 2 ++ hosts/wolumonde/modules/perses/dashboards/go.mod | 28 ++++++++++++++++++++++++++++ hosts/wolumonde/modules/perses/dashboards/go.sum | 45 +++++++++++++++++++++++++++++++++++++++++++++ hosts/wolumonde/modules/perses/dashboards/wolumonde.go | 192 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hosts/wolumonde/modules/perses/provision/1-private-infra.yaml | 3 +++ hosts/wolumonde/modules/perses/provision/10-victoria.yaml | 12 ------------ hosts/wolumonde/modules/perses/provision/4-victoria.yaml | 12 ++++++++++++ hosts/wolumonde/modules/perses/provision/5-funny.yaml | 11 +++++++++++ hosts/wolumonde/modules/perses/provision/6-guest-role.yaml | 12 ++++++++++++ hosts/wolumonde/modules/perses/provision/7-funny-bind-role.yaml | 8 ++++++++ hosts/wolumonde/modules/perses/provision/90-wolumonde.yaml | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 20 file(s) changed, 637 insertion(s)(+), 36 deletion(s)(-) diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ ssh_key secrets/deploy-webhook.nu +# dnscontrol creds.json diff --git a/deploy.nu b/deploy.nu --- a/deploy.nu +++ b/deploy.nu @@ -5,6 +5,8 @@ path add /nix/var/nix/profiles/default/bin +cd $env.FLAKE + # load webhook secrets rage -d -i ./ssh_key ./secrets/deployWebhook.age | from toml | load-env diff --git a/shells/dash.nu b/shells/dash.nu new file mode 100644 --- /dev/null +++ b/shells/dash.nu @@ -0,0 +1,19 @@ +def "main build" [file: path] { + percli dac build -f ($file | path basename) + glob ./built/* + | enumerate + | each { + |f| mv -f $f.item ( + $env.PWD + | path join .. provision ( + $f.item + | path basename + | str replace "_output.yaml" ".yaml" + | $"9($f.index)-($in)" + ) + ) + } + rm ./built +} + +def main [] {} \ No newline at end of file diff --git a/shells/default.nix b/shells/default.nix --- a/shells/default.nix +++ b/shells/default.nix @@ -20,6 +20,7 @@ }; commit = pkgs.writers.writeNuBin "commit" ../commit.nu; deploy = pkgs.writers.writeNuBin "deploy" ../deploy.nu; + dash = pkgs.writers.writeNuBin "dash" ./dash.nu; in { default = mkNakedShell { @@ -31,8 +32,14 @@ treefmt rage nh + percli + go + gopls + # golangci-lint + # golangci-lint-langserver ]) ++ [ + dash agenix-wrapped commit deploy diff --git a/hosts/wolumonde/default.nix b/hosts/wolumonde/default.nix --- a/hosts/wolumonde/default.nix +++ b/hosts/wolumonde/default.nix @@ -10,7 +10,10 @@ # inputs.nixtopo.nixosModules.default ] ++ (tlib.importFolder (toString ./modules)); - environment.systemPackages = [ pkgs.magic-wormhole-rs ]; + environment.systemPackages = with pkgs; [ + magic-wormhole-rs + systemctl-tui + ]; boot.tmp.cleanOnBoot = true; zramSwap.enable = true; diff --git a/pkgs-set/pkgs/percli.nix b/pkgs-set/pkgs/percli.nix --- a/pkgs-set/pkgs/percli.nix +++ b/pkgs-set/pkgs/percli.nix @@ -5,21 +5,21 @@ }: let pname = "percli"; - version = "0.51.0-beta.1"; + version = "0.50.3"; src = fetchFromGitHub { owner = "perses"; repo = "perses"; tag = "v${version}"; - hash = "sha256-tub9W9ZOv1CDaZb/4JPg98HhfBqpVDSBQ6GNR8fBJ1Y="; + hash = "sha256-E8PTPit9QLPMlLvdx8rbw0BwC+ZqSMTHdfPJ4aE4dsw="; }; in buildGoModule { inherit pname version src; - CGO_ENABLED = 0; + env.CGO_ENABLED = 0; subPackages = [ "cmd/percli" ]; - vendorHash = "sha256-2qtyEIzMu3UIDbsqhpAJDVYr7WGmE6H3ngN74HaON04="; + vendorHash = "sha256-yUqV6pBl6tyE4f4tBVN0DwgVFey+1btVpK7eiMKkwIY="; } diff --git a/hosts/wolumonde/modules/nginx.nix b/hosts/wolumonde/modules/nginx.nix --- a/hosts/wolumonde/modules/nginx.nix +++ b/hosts/wolumonde/modules/nginx.nix @@ -31,7 +31,7 @@ '"req.headers.id":"$request_id",' '"req.headers.referer":"$http_referer",' '"req.headers.user-agent":"$http_user_agent",' - '"responseTime":$request_time' + '"requestTime":$request_time' '}'; access_log /var/log/nginx/access.log json_logs; ''; @@ -89,6 +89,13 @@ parser = "nginx_json"; } ]; + filters = [ + { + name = "modify"; + match = "logs.nginx"; + Add = [ "name nginx" ]; + } + ]; }; }; @@ -103,19 +110,20 @@ rules = [ { record = "nginx_request_count"; - expr = "* | stats count() as requests"; + expr = "name:nginx | stats count(*) as req"; } { record = "nginx_2xx_count"; - expr = ''* | res.statusCode:~"2.." | stats count() as successes''; + expr = ''name:nginx | res.statusCode:~"2.." | stats count(*) as success''; } { record = "nginx_5xx_count"; - expr = ''* | res.statusCode:~"5.." | stats count() as errors''; + expr = ''name:nginx | res.statusCode:~"5.." | stats count(*) as error''; } { - record = "nginx_request_latency_avg"; - expr = "* | stats avg(responseTime) as avg_latency"; + record = "nginx_request_latency"; + # filter out subscribeRepos requests because they are long polling http L + expr = "name:nginx | filter req.url:!/xrpc/com.atproto.sync.subscribeRepos | stats avg(requestTime) avg, quantile(0.5, requestTime) p50, quantile(0.9, requestTime) p90, quantile(0.99, requestTime) p99"; } ]; } diff --git a/hosts/wolumonde/modules/pds.nix b/hosts/wolumonde/modules/pds.nix --- a/hosts/wolumonde/modules/pds.nix +++ b/hosts/wolumonde/modules/pds.nix @@ -73,6 +73,28 @@ }; }; + services.vmalert.rules.groups = [ + { + name = "pds-logs"; + type = "vlogs"; + interval = "1m"; + rules = [ + { + record = "pds_request_count"; + expr = "name:pds | stats count(*) as requests"; + } + { + record = "pds_5xx_count"; + expr = ''name:pds | res.statusCode:~"5.." | stats count(*) as errors''; + } + { + record = "pds_response_latency"; + expr = "name:pds | stats avg(responseTime) avg, quantile(0.5, responseTime) p50, quantile(0.9, responseTime) p90, quantile(0.99, responseTime) p99"; + } + ]; + } + ]; + # virtualisation = { # podman = { # enable = true; diff --git a/hosts/wolumonde/modules/perses.nix b/hosts/wolumonde/modules/perses.nix --- a/hosts/wolumonde/modules/perses.nix +++ b/hosts/wolumonde/modules/perses.nix @@ -4,6 +4,28 @@ port = 7412; user = "perses"; + provisionFolder = "provisioning"; + + persesConfig = { + database.file = { + folder = "/perses"; + extension = "json"; + }; + provisioning.folders = [ "/perses/${provisionFolder}" ]; + security = { + enable_auth = true; + authentication = { + providers.enable_native = true; + disable_sign_up = true; + }; + cookie = { + same_site = "strict"; + secure = true; + }; + }; + }; + persesConfigYaml = pkgs.writers.writeYAML "config.yaml" persesConfig; + persesImage = pkgs.dockerTools.pullImage { imageName = "docker.io/persesdev/perses"; imageDigest = "sha256:7d4647ce31841f67c2361bd10ea344de1edd7fbf65711c75805a5aacdc7735d0"; @@ -16,7 +38,7 @@ contents = [ pkgs.curl ]; config.Entrypoint = [ "/bin/perses" ]; config.Cmd = [ - "--config=/etc/perses/config.yaml" + "--config=${persesConfigYaml}" "--log.level=info" "--web.listen-address=:${toString port}" # "--log.method-trace" @@ -32,7 +54,6 @@ persesEnv = config.virtualisation.oci-containers.containers.perses.environment; secrets = config.age.secrets; - provisionFolder = "provisioning"; in { environment.systemPackages = [ pkgs.percli ]; @@ -79,18 +100,8 @@ sdnotify = "healthy"; }; environmentFiles = [ secrets.persesSecret.path ]; - environment = { - PERSES_SECURITY_AUTHENTICATION_PROVIDERS_ENABLE_NATIVE = "true"; - PERSES_SECURITY_AUTHENTICATION_DISABLE_SIGN_UP = "true"; - PERSES_SECURITY_ENABLE_AUTH = "true"; - PERSES_SECURITY_COOKIE_SAME_SITE = "strict"; - PERSES_SECURITY_COOKIE_SECURE = "true"; - PERSES_PROVISIONING_FOLDERS_0 = "/perses/${provisionFolder}"; - # PERSES_PROVISIONING_INTERVAL = "1m"; - # PERSES_AUTHORIZATION_GUEST_PERMISSIONS_ACTIONS = "read"; - }; volumes = [ - "/var/lib/perses:/perses" + "/var/lib/perses:${persesConfig.database.file.folder}" ]; extraOptions = [ "--network=host" diff --git a/hosts/wolumonde/modules/perses/dashboards/.gitignore b/hosts/wolumonde/modules/perses/dashboards/.gitignore new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/dashboards/.gitignore @@ -0,0 +1,2 @@ +# folder used to store the results of the `percli dac build` command +built diff --git a/hosts/wolumonde/modules/perses/dashboards/go.mod b/hosts/wolumonde/modules/perses/dashboards/go.mod new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/dashboards/go.mod @@ -0,0 +1,28 @@ +module dash + +go 1.24.2 + +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/go-jose/go-jose/v4 v4.0.5 // indirect + github.com/jpillora/backoff v1.0.0 // indirect + github.com/muhlemmer/gu v0.3.1 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect + github.com/perses/perses v0.50.3 // indirect + github.com/prometheus/client_golang v1.20.5 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.63.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect + github.com/zitadel/oidc/v3 v3.36.1 // indirect + github.com/zitadel/schema v1.3.0 // indirect + golang.org/x/crypto v0.36.0 // indirect + golang.org/x/net v0.35.0 // indirect + golang.org/x/oauth2 v0.28.0 // indirect + golang.org/x/sys v0.31.0 // indirect + golang.org/x/text v0.23.0 // indirect + google.golang.org/protobuf v1.36.5 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/hosts/wolumonde/modules/perses/dashboards/go.sum b/hosts/wolumonde/modules/perses/dashboards/go.sum new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/dashboards/go.sum @@ -0,0 +1,45 @@ +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE= +github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/muhlemmer/gu v0.3.1 h1:7EAqmFrW7n3hETvuAdmFmn4hS8W+z3LgKtrnow+YzNM= +github.com/muhlemmer/gu v0.3.1/go.mod h1:YHtHR+gxM+bKEIIs7Hmi9sPT3ZDUvTN/i88wQpZkrdM= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/perses/perses v0.50.3 h1:BHlU9qkCFCUSP4HP5p9GwophWcxm5Vnu6Fsrx8Fb/+w= +github.com/perses/perses v0.50.3/go.mod h1:oqfHLOrXERvEqECShqXPjHXqVukQxcoaaTM6ySRF7hU= +github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y= +github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.63.0 h1:YR/EIY1o3mEFP/kZCD7iDMnLPlGyuU2Gb3HIcXnA98k= +github.com/prometheus/common v0.63.0/go.mod h1:VVFF/fBIoToEnWRVkYoXEkq3R3paCoxG9PXP74SnV18= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= +github.com/zitadel/oidc/v3 v3.36.1 h1:1AT1NqKKEqAwx4GmKJZ9fYkWH2WIn/VKMfQ46nBtRf0= +github.com/zitadel/oidc/v3 v3.36.1/go.mod h1:dApGZLvWZTHRuxmcbQlW5d2XVjVYR3vGOdq536igmTs= +github.com/zitadel/schema v1.3.0 h1:kQ9W9tvIwZICCKWcMvCEweXET1OcOyGEuFbHs4o5kg0= +github.com/zitadel/schema v1.3.0/go.mod h1:NptN6mkBDFvERUCvZHlvWmmME+gmZ44xzwRXwhzsbtc= +golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34= +golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc= +golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= +golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= +golang.org/x/oauth2 v0.28.0 h1:CrgCKl8PPAVtLnU3c+EDw6x11699EWlsDeWNWKdIOkc= +golang.org/x/oauth2 v0.28.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8= +golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= +golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= +golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= +google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= +google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/hosts/wolumonde/modules/perses/dashboards/wolumonde.go b/hosts/wolumonde/modules/perses/dashboards/wolumonde.go new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/dashboards/wolumonde.go @@ -0,0 +1,192 @@ +package main + +import ( + "flag" + "time" + + "github.com/perses/perses/go-sdk" + "github.com/perses/perses/go-sdk/common" + dash "github.com/perses/perses/go-sdk/dashboard" + "github.com/perses/perses/go-sdk/panel" + panels "github.com/perses/perses/go-sdk/panel-group" + "github.com/perses/perses/go-sdk/panel/bar" + "github.com/perses/perses/go-sdk/prometheus/query" + + timeSeries "github.com/perses/perses/go-sdk/panel/time-series" + // promDs "github.com/perses/perses/go-sdk/prometheus/datasource" +) + +func main() { + flag.Parse() + exec := sdk.NewExec() + var loadPanel = panels.AddPanel("load over 5 min", + timeSeries.Chart(), + panel.AddQuery( + query.PromQL( + "node_load5", + query.SeriesNameFormat("load"), + ), + ), + ) + var memoryPanel = panels.AddPanel("memory usage", + timeSeries.Chart( + timeSeries.WithYAxis( + timeSeries.YAxis{ + Format: &common.Format{ + Unit: "bytes", + }, + Max: 4000000000, + }, + ), + ), + panel.AddQuery( + query.PromQL( + "node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes", + query.SeriesNameFormat("current memory usage"), + ), + ), + ) + var resPanels = dash.AddPanelGroup("resource usage", + panels.PanelsPerLine(4), + loadPanel, memoryPanel, + ) + + var nginxPanel = panels.AddPanel("nginx requests / min", + timeSeries.Chart( + timeSeries.WithQuerySettings( + []timeSeries.QuerySettingsItem{ + { + QueryIndex: 0, + ColorMode: timeSeries.FixedMode, + ColorValue: "#FF0000", + }, + }, + ), + timeSeries.WithYAxis( + timeSeries.YAxis{ + Format: &common.Format{ + Unit: "decimal", + }, + }, + ), + ), + panel.AddQuery( + query.PromQL( + "nginx_5xx_count", + query.SeriesNameFormat("5xx errors"), + ), + ), + panel.AddQuery( + query.PromQL( + "nginx_request_count", + query.SeriesNameFormat("requests"), + ), + ), + ) + + var nginxLatencyPanel = panels.AddPanel("nginx latency / min", + timeSeries.Chart( + timeSeries.WithYAxis( + timeSeries.YAxis{ + Format: &common.Format{ + Unit: "seconds", + }, + Max: 1.0, + }, + ), + ), + panel.AddQuery( + query.PromQL( + "nginx_request_latency", + query.SeriesNameFormat("{{stats_result}}"), + ), + ), + ) + + var nginxPanels = dash.AddPanelGroup("nginx metrics", + panels.PanelsPerLine(3), + nginxPanel, + nginxLatencyPanel, + ) + + var pdsPanel = panels.AddPanel("pds requests / min", + timeSeries.Chart( + timeSeries.WithQuerySettings( + []timeSeries.QuerySettingsItem{ + { + QueryIndex: 0, + ColorMode: timeSeries.FixedMode, + ColorValue: "#FF0000", + }, + }, + ), + timeSeries.WithYAxis( + timeSeries.YAxis{ + Format: &common.Format{ + Unit: "decimal", + }, + }, + ), + ), + panel.AddQuery( + query.PromQL( + "pds_5xx_count", + query.SeriesNameFormat("5xx errors"), + ), + ), + panel.AddQuery( + query.PromQL( + "pds_request_count", + query.SeriesNameFormat("requests"), + ), + ), + ) + + var pdsLatencyPanel = panels.AddPanel("pds latency / min", + timeSeries.Chart( + timeSeries.WithYAxis( + timeSeries.YAxis{ + Format: &common.Format{ + Unit: "milliseconds", + }, + Max: 1000, + }, + ), + ), + panel.AddQuery( + query.PromQL( + "pds_response_latency", + query.SeriesNameFormat("{{stats_result}}"), + ), + ), + ) + + var pdsPanels = dash.AddPanelGroup("pds metrics", + panels.PanelsPerLine(3), + pdsPanel, + pdsLatencyPanel, + ) + + var anubisForgejoPanel = panels.AddPanel("anubis policy actions", + bar.Chart(), + panel.AddQuery( + query.PromQL( + "anubis_policy_results", + query.SeriesNameFormat("{{action}}: {{rule}}"), + ), + ), + ) + + var forgejoPanels = dash.AddPanelGroup("forgejo", + panels.PanelsPerLine(3), + anubisForgejoPanel, + ) + + builder, buildErr := dash.New("wolumonde", + dash.ProjectName("private-infra"), + dash.Duration(30*time.Minute), + dash.RefreshInterval(time.Minute), + resPanels, nginxPanels, pdsPanels, forgejoPanels, + ) + exec.BuildDashboard(builder, buildErr) +} diff --git a/hosts/wolumonde/modules/perses/provision/1-private-infra.yaml b/hosts/wolumonde/modules/perses/provision/1-private-infra.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/1-private-infra.yaml @@ -0,0 +1,3 @@ +kind: Project +metadata: + name: private-infra diff --git a/hosts/wolumonde/modules/perses/provision/10-victoria.yaml b/hosts/wolumonde/modules/perses/provision/10-victoria.yaml deleted file mode 100644 --- a/hosts/wolumonde/modules/perses/provision/10-victoria.yaml +++ /dev/null @@ -1,12 +0,0 @@ -- kind: GlobalDatasource - metadata: - name: victoria - spec: - default: true - plugin: - kind: PrometheusDatasource - spec: - proxy: - kind: HTTPProxy - spec: - url: http://localhost:8428 diff --git a/hosts/wolumonde/modules/perses/provision/4-victoria.yaml b/hosts/wolumonde/modules/perses/provision/4-victoria.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/4-victoria.yaml @@ -0,0 +1,12 @@ +- kind: GlobalDatasource + metadata: + name: victoria + spec: + default: true + plugin: + kind: PrometheusDatasource + spec: + proxy: + kind: HTTPProxy + spec: + url: http://localhost:8428 diff --git a/hosts/wolumonde/modules/perses/provision/5-funny.yaml b/hosts/wolumonde/modules/perses/provision/5-funny.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/5-funny.yaml @@ -0,0 +1,11 @@ +{ + "kind": "User", + "metadata": { + "name": "cat" + }, + "spec": { + "nativeProvider": { + "password": "ziplocballs" + } + } +} diff --git a/hosts/wolumonde/modules/perses/provision/6-guest-role.yaml b/hosts/wolumonde/modules/perses/provision/6-guest-role.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/6-guest-role.yaml @@ -0,0 +1,12 @@ +- kind: GlobalRole + metadata: + name: guest + spec: + permissions: + - actions: + - 'read' + scopes: + - 'Dashboard' + - 'Project' + - 'Datasource' + - 'GlobalDatasource' diff --git a/hosts/wolumonde/modules/perses/provision/7-funny-bind-role.yaml b/hosts/wolumonde/modules/perses/provision/7-funny-bind-role.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/7-funny-bind-role.yaml @@ -0,0 +1,8 @@ +- kind: GlobalRoleBinding + metadata: + name: cat + spec: + role: guest + subjects: + - kind: User + name: cat diff --git a/hosts/wolumonde/modules/perses/provision/90-wolumonde.yaml b/hosts/wolumonde/modules/perses/provision/90-wolumonde.yaml new file mode 100644 --- /dev/null +++ b/hosts/wolumonde/modules/perses/provision/90-wolumonde.yaml @@ -0,0 +1,227 @@ +kind: Dashboard +metadata: + name: wolumonde + createdAt: 0001-01-01T00:00:00Z + updatedAt: 0001-01-01T00:00:00Z + version: 0 + project: private-infra +spec: + panels: + "0_0": + kind: Panel + spec: + display: + name: load over 5 min + plugin: + kind: TimeSeriesChart + spec: {} + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: node_load5 + seriesNameFormat: load + "0_1": + kind: Panel + spec: + display: + name: memory usage + plugin: + kind: TimeSeriesChart + spec: + yAxis: + format: + unit: bytes + max: 4e+09 + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes + seriesNameFormat: current memory usage + "1_0": + kind: Panel + spec: + display: + name: nginx requests / min + plugin: + kind: TimeSeriesChart + spec: + yAxis: + format: + unit: decimal + querySettings: + - queryIndex: 0 + colorMode: fixed + colorValue: '#FF0000' + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: nginx_5xx_count + seriesNameFormat: 5xx errors + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: nginx_request_count + seriesNameFormat: requests + "1_1": + kind: Panel + spec: + display: + name: nginx latency / min + plugin: + kind: TimeSeriesChart + spec: + yAxis: + format: + unit: seconds + max: 1 + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: nginx_request_latency + seriesNameFormat: '{{stats_result}}' + "2_0": + kind: Panel + spec: + display: + name: pds requests / min + plugin: + kind: TimeSeriesChart + spec: + yAxis: + format: + unit: decimal + querySettings: + - queryIndex: 0 + colorMode: fixed + colorValue: '#FF0000' + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: pds_5xx_count + seriesNameFormat: 5xx errors + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: pds_request_count + seriesNameFormat: requests + "2_1": + kind: Panel + spec: + display: + name: pds latency / min + plugin: + kind: TimeSeriesChart + spec: + yAxis: + format: + unit: milliseconds + max: 1000 + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: pds_response_latency + seriesNameFormat: '{{stats_result}}' + "3_0": + kind: Panel + spec: + display: + name: anubis policy actions + plugin: + kind: BarChart + spec: + calculation: last + queries: + - kind: TimeSeriesQuery + spec: + plugin: + kind: PrometheusTimeSeriesQuery + spec: + query: anubis_policy_results + seriesNameFormat: '{{action}}: {{rule}}' + layouts: + - kind: Grid + spec: + display: + title: resource usage + items: + - x: 0 + "y": 0 + width: 6 + height: 6 + content: + $ref: '#/spec/panels/0_0' + - x: 6 + "y": 0 + width: 6 + height: 6 + content: + $ref: '#/spec/panels/0_1' + - kind: Grid + spec: + display: + title: nginx metrics + items: + - x: 0 + "y": 0 + width: 8 + height: 6 + content: + $ref: '#/spec/panels/1_0' + - x: 8 + "y": 0 + width: 8 + height: 6 + content: + $ref: '#/spec/panels/1_1' + - kind: Grid + spec: + display: + title: pds metrics + items: + - x: 0 + "y": 0 + width: 8 + height: 6 + content: + $ref: '#/spec/panels/2_0' + - x: 8 + "y": 0 + width: 8 + height: 6 + content: + $ref: '#/spec/panels/2_1' + - kind: Grid + spec: + display: + title: forgejo + items: + - x: 0 + "y": 0 + width: 8 + height: 6 + content: + $ref: '#/spec/panels/3_0' + duration: 30m + refreshInterval: 1m -- tangled.sh