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