nix-config/hosts/grafana/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

123 lines
3.5 KiB
Nix
Raw Normal View History

2022-12-04 08:53:28 +01:00
{ config, pkgs, ... }:
2019-01-17 23:45:26 +01:00
{
2022-06-18 02:09:33 +02:00
microvm.mem = 4096;
2022-12-21 19:43:47 +01:00
c3d2.deployment.server = "server10";
2022-12-19 23:36:57 +01:00
environment.systemPackages = with pkgs; [ influxdb ];
2019-01-17 23:45:26 +01:00
2022-12-19 23:36:57 +01:00
networking = {
firewall = {
# influxdb
allowedTCPPorts = [ 8086 ];
2022-12-19 23:36:57 +01:00
# collectd
allowedUDPPorts = [ 25826 ];
};
2022-12-19 23:36:57 +01:00
hostName = "grafana";
2019-01-17 23:45:26 +01:00
};
2022-12-19 23:36:57 +01:00
services = {
grafana = {
enable = true;
2022-10-27 21:35:39 +02:00
2022-12-19 23:36:57 +01:00
provision = {
enable = true;
# curl https://root:SECRET@grafana.hq.c3d2.de/api/datasources | jq > hosts/grafana/datasources.json
datasources.settings.datasources = map
(datasource: {
inherit (datasource) name type access orgId url password user database isDefault jsonData;
})
(with builtins; fromJSON (readFile ./datasources.json));
dashboards.settings.providers = [{
settings = {
apiVersion = 1;
providers = [{
name = "c3d2";
}];
};
# for id in `curl https://root:SECRET@grafana.hq.c3d2.de/api/search | jq -j 'map(.uid) | join(" ")'`; do curl https://root:SECRET@grafana.hq.c3d2.de/api/dashboards/uid/$id | jq .dashboard > hosts/grafana/dashboards/$id.json;done
options.path = ./dashboards;
}];
2022-10-27 21:35:39 +02:00
};
2022-12-19 23:36:57 +01:00
settings = {
"auth.anonymous" = {
enabled = false;
org_name = "Chaos";
};
security = {
admin_password = "$__file{${config.sops.secrets."grafana/admin-password".path}}";
secret_key = "$__file{${config.sops.secrets."grafana/secret-key".path}}";
};
server.domain = "grafana.hq.c3d2.de";
users.allow_sign_up = false;
2022-10-27 21:35:39 +02:00
};
};
2022-12-19 23:36:57 +01:00
influxdb =
let
collectdTypes = pkgs.runCommand "collectd-types" { } ''
mkdir -p $out/share/collectd
cat ${pkgs.collectd-data}/share/collectd/types.db >> $out/share/collectd/types.db
echo "stations value:GAUGE:0:U" >> $out/share/collectd/types.db
'';
in
{
enable = true;
extraConfig = {
logging.level = "debug";
collectd = [{
enabled = true;
database = "collectd";
typesdb = "${collectdTypes}/share/collectd/types.db";
# create retention policy "30d" on collectd duration 30d replication 1 default
retention-policy = "30d";
}];
2022-03-29 00:01:28 +02:00
};
2022-12-19 23:36:57 +01:00
};
nginx = {
enable = true;
virtualHosts = {
"grafana.hq.c3d2.de" = {
default = true;
enableACME = true;
forceSSL = true;
locations = { "/".proxyPass = "http://localhost:3000/"; };
};
};
2022-03-29 00:01:28 +02:00
};
2022-12-19 23:36:57 +01:00
};
2019-01-17 23:45:26 +01:00
2022-10-27 21:35:39 +02:00
sops = {
defaultSopsFile = ./secrets.yaml;
secrets = {
"grafana/admin-password" = {
group = config.systemd.services.grafana.serviceConfig.User;
owner = config.systemd.services.grafana.serviceConfig.User;
};
"grafana/secret-key" = {
group = config.systemd.services.grafana.serviceConfig.User;
owner = config.systemd.services.grafana.serviceConfig.User;
};
};
};
2022-12-19 23:36:57 +01:00
systemd.services =
builtins.foldl'
(services: service:
services // {
"${service}".serviceConfig = {
RestartSec = 60;
Restart = "always";
};
}
)
{ } [ "grafana" "influxdb" ]
// {
# work around our slow storage that can't keep up
influxdb.serviceConfig.LimitNOFILE = "1048576:1048576";
influxdb.serviceConfig.TimeoutStartSec = "infinity";
};
2022-10-27 21:35:39 +02:00
system.stateVersion = "22.05";
2019-01-17 23:45:26 +01:00
}