grafana tweaks

This commit is contained in:
Reid 2026-04-20 16:04:18 -07:00
parent 3291b8ae04
commit f1cd1e461f
Signed by: reidlab
GPG key ID: DAF5EAF6665839FD

View file

@ -10,13 +10,9 @@ in {
type = types.str; type = types.str;
default = "grafana.reidlab.pink"; default = "grafana.reidlab.pink";
}; };
orgId = mkOption { grafanaSocket = mkOption {
type = types.int; type = types.str;
default = 1; default = "/run/grafana/grafana.sock";
};
grafanaPort = mkOption {
type = types.int;
default = 3000;
}; };
alloyPort = mkOption { alloyPort = mkOption {
type = types.int; type = types.int;
@ -43,8 +39,8 @@ in {
settings = { settings = {
server = { server = {
domain = cfg.domain; domain = cfg.domain;
http_port = cfg.grafanaPort; protocol = "socket";
http_addr = "127.0.0.1"; socket = cfg.grafanaSocket;
}; };
database.type = "sqlite3"; # TODO: use postgres? database.type = "sqlite3"; # TODO: use postgres?
# use default secret key # use default secret key
@ -53,9 +49,9 @@ in {
}; };
provision.datasources.settings = { provision.datasources.settings = {
prune = true; # delete datasources if not in provision file
datasources = [ datasources = [
{ {
orgId = cfg.orgId;
name = "Prometheus"; name = "Prometheus";
type = "prometheus"; type = "prometheus";
url = "http://127.0.0.1:${toString cfg.prometheusPort}"; url = "http://127.0.0.1:${toString cfg.prometheusPort}";
@ -63,23 +59,12 @@ in {
isDefault = true; isDefault = true;
} }
{ {
orgId = cfg.orgId;
name = "Loki"; name = "Loki";
type = "loki"; type = "loki";
url = "http://127.0.0.1:${toString cfg.lokiPort}"; url = "http://127.0.0.1:${toString cfg.lokiPort}";
uid = "loki"; uid = "loki";
} }
]; ];
deleteDatasources = [
{
orgId = cfg.orgId;
name = "Prometheus";
}
{
orgId = cfg.orgId;
name = "Loki";
}
];
}; };
}; };
@ -89,6 +74,7 @@ in {
ports = { ports = {
node = mkPort 0; node = mkPort 0;
nginx = mkPort 1; nginx = mkPort 1;
smartctl = mkPort 2;
}; };
in { in {
enable = true; enable = true;
@ -105,6 +91,10 @@ in {
enable = true; enable = true;
port = ports.nginx; port = ports.nginx;
}; };
smartctl = {
enable = true;
port = ports.smartctl;
};
}; };
scrapeConfigs = let scrapeConfigs = let
@ -126,6 +116,13 @@ in {
labels = commonLabels; labels = commonLabels;
}]; }];
} }
{
job_name = "smartctl";
static_configs = [{
targets = [ "127.0.0.1:${toString ports.smartctl}" ];
labels = commonLabels;
}];
}
]; ];
}; };
@ -241,12 +238,15 @@ in {
''; '';
}; };
# fix unix sockets
systemd.services.nginx.serviceConfig.SupplementaryGroups = [ "grafana" ];
services.nginx.statusPage = true; services.nginx.statusPage = true;
services.nginx.virtualHosts."${cfg.domain}" = { services.nginx.virtualHosts."${cfg.domain}" = {
forceSSL = true; forceSSL = true;
enableACME = true; enableACME = true;
locations."/" = { locations."/" = {
proxyPass = "http://127.0.0.1:${toString cfg.grafanaPort}"; proxyPass = "http://unix:${cfg.grafanaSocket}";
proxyWebsockets = true; proxyWebsockets = true;
}; };
locations."= /robots.txt" = { locations."= /robots.txt" = {