73 lines
2.3 KiB
Nix
Raw Normal View History

2024-01-09 23:11:11 -05:00
# InfluxDB is a timeseries database similar to Prometheus. While
# VictoriaMetrics can also act as an InfluxDB, this version of it allows for
# infinite retention separate from our other metrics, which can be nice for
# recording health information, for example.
2024-04-20 09:42:06 -04:00
{ config, lib, ... }:
2025-01-20 22:35:40 -05:00
let
cfg = config.nmasur.presets.services.influxdb2;
in
2024-04-20 09:42:06 -04:00
{
2023-12-17 02:02:17 +00:00
2025-01-20 22:35:40 -05:00
options.nmasur.presets.services.influxdb2.enable =
lib.mkEnableOption "InfluxDB timeseries database";
config = lib.mkIf cfg.enable {
2023-12-17 02:02:17 +00:00
services.influxdb2 = {
2025-01-20 22:35:40 -05:00
enable = true;
2023-12-17 02:02:17 +00:00
provision = {
enable = true;
initialSetup = {
bucket = "default";
organization = "main";
passwordFile = config.secrets.influxdb2Password.dest;
retention = 0; # Keep data forever
tokenFile = config.secrets.influxdb2Token.dest;
username = "admin";
};
};
settings = { };
};
# Create credentials file for InfluxDB admin
secrets.influxdb2Password = lib.mkIf config.services.influxdb2.enable {
source = ../../../private/influxdb2-password.age;
dest = "${config.secretsDirectory}/influxdb2-password";
owner = "influxdb2";
group = "influxdb2";
permissions = "0440";
};
2024-04-20 09:42:06 -04:00
systemd.services.influxdb2Password-secret = lib.mkIf config.services.influxdb2.enable {
requiredBy = [ "influxdb2.service" ];
before = [ "influxdb2.service" ];
};
2023-12-17 02:02:17 +00:00
secrets.influxdb2Token = lib.mkIf config.services.influxdb2.enable {
source = ../../../private/influxdb2-token.age;
dest = "${config.secretsDirectory}/influxdb2-token";
owner = "influxdb2";
group = "influxdb2";
permissions = "0440";
};
2024-04-20 09:42:06 -04:00
systemd.services.influxdb2Token-secret = lib.mkIf config.services.influxdb2.enable {
requiredBy = [ "influxdb2.service" ];
before = [ "influxdb2.service" ];
};
2023-12-17 02:02:17 +00:00
2024-04-20 09:42:06 -04:00
caddy.routes = lib.mkIf config.services.influxdb2.enable [
{
match = [ { host = [ config.hostnames.influxdb ]; } ];
handle = [
{
handler = "reverse_proxy";
upstreams = [ { dial = "localhost:8086"; } ];
}
];
}
];
2023-12-17 02:02:17 +00:00
# Configure Cloudflare DNS to point to this machine
services.cloudflare-dyndns.domains = [ config.hostnames.influxdb ];
2023-12-17 02:02:17 +00:00
};
}