mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-03-23 22:28:28 +01:00
Compare commits
No commits in common. "3b37a4c4de743d312f8a6e9050dd7bff7975f99e" and "7a6b17fb367246c953edc36a8b8e33504363e4e3" have entirely different histories.
3b37a4c4de
...
7a6b17fb36
6 changed files with 144 additions and 78 deletions
|
|
@ -50,6 +50,11 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
domain = "grafana.${privateDomain}";
|
domain = "grafana.${privateDomain}";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
victoriametrics = {
|
||||||
|
enable = true;
|
||||||
|
domain = "metrics.${privateDomain}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,10 +72,7 @@ in
|
||||||
http.addr = "localhost:${toString cfg.ntfyBridgePort}";
|
http.addr = "localhost:${toString cfg.ntfyBridgePort}";
|
||||||
ntfy = {
|
ntfy = {
|
||||||
baseurl = "https://ntfy.sh";
|
baseurl = "https://ntfy.sh";
|
||||||
notification = {
|
notification.topic = "splitleaf";
|
||||||
topic = "splitleaf";
|
|
||||||
priority = "default";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
{
|
{ config, lib, ... }:
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
allHosts,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
let
|
||||||
cfg = config.custom.services.alloy;
|
cfg = config.custom.services.alloy;
|
||||||
in
|
in
|
||||||
|
|
@ -18,6 +13,10 @@ in
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
default = 12345;
|
default = 12345;
|
||||||
};
|
};
|
||||||
|
metricsEndpoint = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
default = "https://metrics.${config.custom.networking.overlay.domain}/prometheus/api/v1/write";
|
||||||
|
};
|
||||||
collect.metrics = {
|
collect.metrics = {
|
||||||
system = lib.mkEnableOption "" // {
|
system = lib.mkEnableOption "" // {
|
||||||
default = true;
|
default = true;
|
||||||
|
|
@ -48,30 +47,19 @@ in
|
||||||
|
|
||||||
environment.etc =
|
environment.etc =
|
||||||
let
|
let
|
||||||
anyIsTrue = attrs: attrs |> lib.attrValues |> lib.any lib.id;
|
isTrue = x: x;
|
||||||
|
anyIsTrue = attrs: attrs |> lib.attrValues |> lib.any isTrue;
|
||||||
prometheusEndpoints =
|
|
||||||
allHosts
|
|
||||||
|> lib.attrValues
|
|
||||||
|> lib.filter (host: host.config.custom.services.prometheus.enable)
|
|
||||||
|> lib.map (host: "https://${host.config.custom.services.prometheus.domain}/api/v1/write");
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
"alloy/metrics-endpoint.alloy" = {
|
"alloy/metrics-endpoint.alloy" = {
|
||||||
enable = cfg.collect.metrics |> anyIsTrue;
|
enable = cfg.collect.metrics |> anyIsTrue;
|
||||||
text =
|
text = ''
|
||||||
prometheusEndpoints
|
|
||||||
|> lib.map (url: ''
|
|
||||||
endpoint {
|
|
||||||
url = "${url}"
|
|
||||||
}
|
|
||||||
'')
|
|
||||||
|> lib.concatLines
|
|
||||||
|> (endpoints: ''
|
|
||||||
prometheus.remote_write "default" {
|
prometheus.remote_write "default" {
|
||||||
${endpoints}
|
endpoint {
|
||||||
|
url = "${cfg.metricsEndpoint}"
|
||||||
}
|
}
|
||||||
'');
|
}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
"alloy/system-metrics.alloy" = {
|
"alloy/system-metrics.alloy" = {
|
||||||
enable = cfg.collect.metrics.system;
|
enable = cfg.collect.metrics.system;
|
||||||
|
|
@ -97,7 +85,7 @@ in
|
||||||
instance = constants.hostname,
|
instance = constants.hostname,
|
||||||
}]
|
}]
|
||||||
forward_to = [prometheus.remote_write.default.receiver]
|
forward_to = [prometheus.remote_write.default.receiver]
|
||||||
scrape_interval = "30s"
|
scrape_interval = "15s"
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,6 @@ in
|
||||||
inherit (cfg) port;
|
inherit (cfg) port;
|
||||||
webExternalUrl = "https://${cfg.domain}";
|
webExternalUrl = "https://${cfg.domain}";
|
||||||
|
|
||||||
extraFlags = [ "--web.enable-remote-write-receiver" ];
|
|
||||||
globalConfig = {
|
globalConfig = {
|
||||||
scrape_interval = "30s";
|
scrape_interval = "30s";
|
||||||
external_labels.monitor = "global";
|
external_labels.monitor = "global";
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,10 @@
|
||||||
config,
|
config,
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
allHosts,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
cfg = config.custom.web-services.grafana;
|
cfg = config.custom.web-services.grafana;
|
||||||
|
|
||||||
prometheusDomains =
|
|
||||||
allHosts
|
|
||||||
|> lib.attrValues
|
|
||||||
|> lib.map (host: host.config.custom.services.prometheus)
|
|
||||||
|> lib.filter (prometheus: prometheus.enable)
|
|
||||||
|> lib.map (prometheus: prometheus.domain);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.custom.web-services.grafana = {
|
options.custom.web-services.grafana = {
|
||||||
|
|
@ -26,18 +18,34 @@ in
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
default = 3000;
|
default = 3000;
|
||||||
};
|
};
|
||||||
datasources.prometheus = {
|
datasources = {
|
||||||
|
prometheus = {
|
||||||
enable = lib.mkEnableOption "" // {
|
enable = lib.mkEnableOption "" // {
|
||||||
default = prometheusDomains != [ ];
|
default = config.custom.web-services.victoriametrics.enable;
|
||||||
};
|
};
|
||||||
url = lib.mkOption {
|
url = lib.mkOption {
|
||||||
type = lib.types.nonEmptyStr;
|
type = lib.types.nonEmptyStr;
|
||||||
default = "https://metrics.${config.custom.networking.overlay.fqdn}";
|
default = "https://${config.custom.web-services.victoriametrics.domain}";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
dashboards.nodeExporter.enable = lib.mkEnableOption "" // {
|
victoriametrics = {
|
||||||
|
enable = lib.mkEnableOption "" // {
|
||||||
|
default = config.custom.web-services.victoriametrics.enable;
|
||||||
|
};
|
||||||
|
url = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
default = "https://${config.custom.web-services.victoriametrics.domain}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
dashboards = {
|
||||||
|
nodeExporter.enable = lib.mkEnableOption "" // {
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
victoriametrics.enable = lib.mkEnableOption "" // {
|
||||||
|
default = config.custom.web-services.victoriametrics.enable;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
|
@ -73,23 +81,40 @@ in
|
||||||
|
|
||||||
datasources.settings = {
|
datasources.settings = {
|
||||||
prune = true;
|
prune = true;
|
||||||
datasources = lib.optional cfg.datasources.prometheus.enable {
|
datasources = [
|
||||||
|
(lib.mkIf cfg.datasources.prometheus.enable {
|
||||||
name = "Prometheus";
|
name = "Prometheus";
|
||||||
type = "prometheus";
|
type = "prometheus";
|
||||||
inherit (cfg.datasources.prometheus) url;
|
inherit (cfg.datasources.prometheus) url;
|
||||||
isDefault = true;
|
isDefault = true;
|
||||||
jsonData = {
|
jsonData = {
|
||||||
prometheusType = "Prometheus";
|
prometheusType = "Prometheus";
|
||||||
prometheusVersion = "3.7.2";
|
prometheusVersion = "2.50.0";
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
})
|
||||||
|
(lib.mkIf cfg.datasources.victoriametrics.enable {
|
||||||
|
name = "VictoriaMetrics";
|
||||||
|
type = "victoriametrics-metrics-datasource";
|
||||||
|
inherit (cfg.datasources.victoriametrics) url;
|
||||||
|
isDefault = false;
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declarativePlugins =
|
||||||
|
let
|
||||||
|
plugins = pkgs.grafanaPlugins;
|
||||||
|
in
|
||||||
|
[
|
||||||
|
(lib.optional cfg.datasources.victoriametrics.enable plugins.victoriametrics-metrics-datasource)
|
||||||
|
]
|
||||||
|
|> lib.concatLists;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
environment.etc = {
|
||||||
# https://grafana.com/grafana/dashboards/1860-node-exporter-full/
|
# https://grafana.com/grafana/dashboards/1860-node-exporter-full/
|
||||||
environment.etc."grafana-dashboards/node-exporter-full.json" = {
|
"grafana-dashboards/node-exporter-full.json" = {
|
||||||
enable = cfg.dashboards.nodeExporter.enable;
|
enable = cfg.dashboards.nodeExporter.enable;
|
||||||
source = pkgs.fetchurl {
|
source = pkgs.fetchurl {
|
||||||
name = "node-exporter-full.json";
|
name = "node-exporter-full.json";
|
||||||
|
|
@ -97,21 +122,24 @@ in
|
||||||
hash = "sha256-EywgxEayjwNIGDvSmA/S56Ld49qrTSbIYFpeEXBJlTs=";
|
hash = "sha256-EywgxEayjwNIGDvSmA/S56Ld49qrTSbIYFpeEXBJlTs=";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
# https://grafana.com/grafana/dashboards/10229-victoriametrics-single-node/
|
||||||
custom.services.caddy = {
|
"grafana-dashboards/victoriametrics-single-node-patched.json" = {
|
||||||
virtualHosts.${cfg.domain}.port = cfg.port;
|
enable = cfg.dashboards.victoriametrics.enable;
|
||||||
|
source =
|
||||||
virtualHosts."metrics.${config.custom.networking.overlay.fqdn}".extraConfig =
|
pkgs.fetchurl {
|
||||||
let
|
name = "victoriametrics-single-node.json";
|
||||||
upstreams = prometheusDomains |> lib.map (domain: "https://${domain}") |> lib.concatStringsSep " ";
|
url = "https://grafana.com/api/dashboards/10229/revisions/41/download";
|
||||||
in
|
hash = "sha256-mwtah8A2w81WZjf5bUXoTJfS1R9UX+tua2PiDrBKJCQ=";
|
||||||
|
}
|
||||||
|
|> (
|
||||||
|
src:
|
||||||
|
pkgs.runCommand "victoriametrics-single-node-patched.json" { buildInputs = [ pkgs.gnused ]; } ''
|
||||||
|
sed 's/victoriametrics-logs-//g' ${src} > $out
|
||||||
''
|
''
|
||||||
reverse_proxy ${upstreams} {
|
);
|
||||||
header_up Host {upstream_hostport}
|
|
||||||
lb_policy first
|
|
||||||
health_uri /api/v1/status/buildinfo
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
custom.services.caddy.virtualHosts.${cfg.domain}.port = cfg.port;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
modules/nixos/web-services/victoriametrics.nix
Normal file
49
modules/nixos/web-services/victoriametrics.nix
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
{ config, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.custom.web-services.victoriametrics;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.custom.web-services.victoriametrics = {
|
||||||
|
enable = lib.mkEnableOption "";
|
||||||
|
domain = lib.mkOption {
|
||||||
|
type = lib.types.nonEmptyStr;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 8428;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
users = {
|
||||||
|
users.victoriametrics = {
|
||||||
|
isSystemUser = true;
|
||||||
|
group = config.users.groups.victoriametrics.name;
|
||||||
|
};
|
||||||
|
groups.victoriametrics = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.victoriametrics.serviceConfig = {
|
||||||
|
DynamicUser = lib.mkForce false;
|
||||||
|
User = config.users.users.victoriametrics.name;
|
||||||
|
Group = config.users.groups.victoriametrics.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
services.victoriametrics = {
|
||||||
|
enable = true;
|
||||||
|
listenAddress = "localhost:${toString cfg.port}";
|
||||||
|
extraOptions = [
|
||||||
|
"-selfScrapeInterval=15s"
|
||||||
|
"-selfScrapeJob=victoriametrics"
|
||||||
|
"-selfScrapeInstance=${config.networking.hostName}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
custom = {
|
||||||
|
services.caddy.virtualHosts.${cfg.domain}.port = cfg.port;
|
||||||
|
|
||||||
|
persistence.directories = [ "/var/lib/${config.services.victoriametrics.stateDir}" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue