2019-06-16 19:59:06 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2018-11-01 20:52:17 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.kapacitor;
|
|
|
|
|
|
|
|
kapacitorConf = pkgs.writeTextFile {
|
|
|
|
name = "kapacitord.conf";
|
|
|
|
text = ''
|
|
|
|
hostname="${config.networking.hostName}"
|
|
|
|
data_dir="${cfg.dataDir}"
|
|
|
|
|
|
|
|
[http]
|
|
|
|
bind-address = "${cfg.bind}:${toString cfg.port}"
|
|
|
|
log-enabled = false
|
|
|
|
auth-enabled = false
|
|
|
|
|
|
|
|
[task]
|
|
|
|
dir = "${cfg.dataDir}/tasks"
|
|
|
|
snapshot-interval = "${cfg.taskSnapshotInterval}"
|
|
|
|
|
|
|
|
[replay]
|
|
|
|
dir = "${cfg.dataDir}/replay"
|
|
|
|
|
|
|
|
[storage]
|
|
|
|
boltdb = "${cfg.dataDir}/kapacitor.db"
|
|
|
|
|
|
|
|
${optionalString (cfg.loadDirectory != null) ''
|
|
|
|
[load]
|
|
|
|
enabled = true
|
|
|
|
dir = "${cfg.loadDirectory}"
|
|
|
|
''}
|
|
|
|
|
|
|
|
${optionalString (cfg.defaultDatabase.enable) ''
|
|
|
|
[[influxdb]]
|
|
|
|
name = "default"
|
|
|
|
enabled = true
|
|
|
|
default = true
|
|
|
|
urls = [ "${cfg.defaultDatabase.url}" ]
|
|
|
|
username = "${cfg.defaultDatabase.username}"
|
|
|
|
password = "${cfg.defaultDatabase.password}"
|
|
|
|
''}
|
|
|
|
|
2018-11-08 21:34:23 +00:00
|
|
|
${optionalString (cfg.alerta.enable) ''
|
|
|
|
[alerta]
|
|
|
|
enabled = true
|
|
|
|
url = "${cfg.alerta.url}"
|
|
|
|
token = "${cfg.alerta.token}"
|
|
|
|
environment = "${cfg.alerta.environment}"
|
|
|
|
origin = "${cfg.alerta.origin}"
|
|
|
|
''}
|
|
|
|
|
2018-11-01 20:52:17 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.kapacitor = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "kapacitor";
|
2018-11-01 20:52:17 +00:00
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
2021-10-05 10:48:43 +00:00
|
|
|
default = "/var/lib/kapacitor";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Location where Kapacitor stores its state";
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2022-11-30 16:15:00 +00:00
|
|
|
type = types.port;
|
2018-11-01 20:52:17 +00:00
|
|
|
default = 9092;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Port of Kapacitor";
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bind = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2021-10-03 16:06:03 +00:00
|
|
|
example = "0.0.0.0";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Address to bind to. The default is to bind to all addresses";
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "These lines go into kapacitord.conf verbatim.";
|
2018-11-01 20:52:17 +00:00
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "kapacitor";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "User account under which Kapacitor runs";
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "kapacitor";
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Group under which Kapacitor runs";
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
taskSnapshotInterval = mkOption {
|
|
|
|
type = types.str;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Specifies how often to snapshot the task state (in InfluxDB time units)";
|
2018-11-01 20:52:17 +00:00
|
|
|
default = "1m0s";
|
|
|
|
};
|
|
|
|
|
|
|
|
loadDirectory = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Directory where to load services from, such as tasks, templates and handlers (or null to disable service loading on startup)";
|
2018-11-01 20:52:17 +00:00
|
|
|
default = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultDatabase = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "kapacitor.defaultDatabase";
|
2018-11-01 20:52:17 +00:00
|
|
|
|
|
|
|
url = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The URL to an InfluxDB server that serves as the default database";
|
2018-11-01 20:52:17 +00:00
|
|
|
example = "http://localhost:8086";
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
username = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The username to connect to the remote InfluxDB server";
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
password = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The password to connect to the remote InfluxDB server";
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
};
|
2018-11-08 21:34:23 +00:00
|
|
|
|
|
|
|
alerta = {
|
2024-04-13 12:54:15 +00:00
|
|
|
enable = mkEnableOption "kapacitor alerta integration";
|
2018-11-08 21:34:23 +00:00
|
|
|
|
|
|
|
url = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "The URL to the Alerta REST API";
|
2018-11-08 21:34:23 +00:00
|
|
|
default = "http://localhost:5000";
|
2019-08-08 20:48:27 +00:00
|
|
|
type = types.str;
|
2018-11-08 21:34:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
token = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Default Alerta authentication token";
|
2018-11-08 21:34:23 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
environment = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Default Alerta environment";
|
2018-11-08 21:34:23 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "Production";
|
|
|
|
};
|
|
|
|
|
|
|
|
origin = mkOption {
|
2024-04-13 12:54:15 +00:00
|
|
|
description = "Default origin of alert";
|
2018-11-08 21:34:23 +00:00
|
|
|
type = types.str;
|
|
|
|
default = "kapacitor";
|
|
|
|
};
|
|
|
|
};
|
2018-11-01 20:52:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
environment.systemPackages = [ pkgs.kapacitor ];
|
|
|
|
|
2024-01-11 21:10:18 +00:00
|
|
|
systemd.tmpfiles.settings."10-kapacitor".${cfg.dataDir}.d = {
|
|
|
|
inherit (cfg) user group;
|
|
|
|
};
|
2019-02-24 17:39:56 +00:00
|
|
|
|
2018-11-01 20:52:17 +00:00
|
|
|
systemd.services.kapacitor = {
|
|
|
|
description = "Kapacitor Real-Time Stream Processing Engine";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "networking.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.kapacitor}/bin/kapacitord -config ${kapacitorConf}";
|
|
|
|
User = "kapacitor";
|
|
|
|
Group = "kapacitor";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.kapacitor = {
|
|
|
|
uid = config.ids.uids.kapacitor;
|
|
|
|
description = "Kapacitor user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups.kapacitor = {
|
|
|
|
gid = config.ids.gids.kapacitor;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|