2017-01-09 16:09:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with builtins;
|
2023-06-10 10:50:53 +00:00
|
|
|
with lib;
|
2017-01-09 16:09:52 +00:00
|
|
|
|
|
|
|
let
|
2017-02-07 16:21:25 +00:00
|
|
|
cfg = config.krebs.kapacitor;
|
2017-01-09 16:09:52 +00:00
|
|
|
|
|
|
|
out = {
|
2017-02-07 16:21:25 +00:00
|
|
|
options.krebs.kapacitor = api;
|
2017-01-09 16:09:52 +00:00
|
|
|
config = mkIf cfg.enable imp;
|
|
|
|
};
|
|
|
|
|
2017-02-07 16:09:39 +00:00
|
|
|
configOptions = recursiveUpdate {
|
|
|
|
hostname = "localhost";
|
|
|
|
data_dir = cfg.dataDir;
|
|
|
|
http = {
|
|
|
|
bind-address = ":9092";
|
|
|
|
auth-enabled = false;
|
|
|
|
log-enabled = false;
|
|
|
|
gtgwrite-tracing = false;
|
|
|
|
pprof-enabled = false;
|
|
|
|
https-enabled = false;
|
|
|
|
https-certificate = "/etc/ssl/kapacitor.pem";
|
|
|
|
shutdown-timeout = "10s";
|
|
|
|
shared-secret = "";
|
|
|
|
};
|
|
|
|
|
|
|
|
replay ={
|
|
|
|
dir = "${cfg.dataDir}/replay";
|
|
|
|
};
|
|
|
|
|
|
|
|
storage = {
|
|
|
|
boltdb = "${cfg.dataDir}/kapacitor.db";
|
|
|
|
};
|
|
|
|
|
|
|
|
task = {
|
|
|
|
dir = "${cfg.dataDir}/tasks";
|
|
|
|
snapshot-interval = "1m0s";
|
|
|
|
};
|
|
|
|
|
|
|
|
influxdb = [{
|
|
|
|
enabled = true;
|
|
|
|
name = "default";
|
|
|
|
default = false;
|
|
|
|
urls = ["http://localhost:8086"];
|
|
|
|
username = "";
|
|
|
|
password = "";
|
|
|
|
ssl-ca = "";
|
|
|
|
ssl-cert = "";
|
|
|
|
ssl-key = "";
|
|
|
|
insecure-skip-verify = false;
|
|
|
|
timeout = "0s";
|
|
|
|
disable-subscriptions = false;
|
|
|
|
subscription-protocol = "http";
|
|
|
|
udp-bind = "";
|
|
|
|
udp-buffer = 1000;
|
|
|
|
udp-read-buffer = 0;
|
|
|
|
startup-timeout = "5m0s";
|
|
|
|
subscriptions-sync-interval = "1m0s";
|
|
|
|
influxdb.excluded-subscriptions = {
|
|
|
|
_kapacitor = ["autogen"];
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
|
|
|
|
logging = {
|
|
|
|
file = "STDERR";
|
|
|
|
level = "INFO";
|
|
|
|
};
|
|
|
|
|
|
|
|
deadman = {
|
|
|
|
interval = "10s";
|
|
|
|
id = "{{ .Group }}:NODE_NAME for task '{{ .TaskName }}'";
|
|
|
|
message = "{{ .ID }} is {{ if eq .Level \"OK\" }}alive{{ else }}dead{{ end }}: {{ index .Fields \"emitted\" | printf \"%0.3f\" }} points/INTERVAL.";
|
|
|
|
global = false;
|
|
|
|
};
|
|
|
|
} cfg.extraConfig;
|
|
|
|
|
2017-01-09 16:09:52 +00:00
|
|
|
api = {
|
|
|
|
enable = mkEnableOption "kapacitor";
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/kapacitor";
|
|
|
|
};
|
|
|
|
user = mkOption {
|
2017-02-07 16:09:39 +00:00
|
|
|
type = types.user;
|
|
|
|
default = {
|
|
|
|
name = "kapacitor";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
2017-01-09 16:09:52 +00:00
|
|
|
};
|
2017-02-07 16:09:39 +00:00
|
|
|
group = mkOption {
|
|
|
|
type = types.group;
|
|
|
|
default = {
|
|
|
|
name = "kapacitor";
|
|
|
|
};
|
2017-02-05 21:47:54 +00:00
|
|
|
};
|
2017-02-07 16:09:39 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.attrs;
|
2017-01-28 17:36:53 +00:00
|
|
|
default = {};
|
|
|
|
};
|
2017-02-07 16:09:39 +00:00
|
|
|
alarms = mkOption {
|
|
|
|
type = with types; attrsOf (submodule {
|
|
|
|
options = {
|
|
|
|
database = mkOption {
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
text = mkOption {
|
|
|
|
type = str;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = {};
|
2017-01-09 16:09:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-02-07 16:09:39 +00:00
|
|
|
configFile = pkgs.runCommand "kapacitor.toml" {} ''
|
|
|
|
${pkgs.remarshal}/bin/remarshal -if json -of toml \
|
|
|
|
< ${pkgs.writeText "kapacitor.json" (builtins.toJSON configOptions)} \
|
|
|
|
> $out
|
|
|
|
'';
|
2017-01-09 16:09:52 +00:00
|
|
|
|
|
|
|
imp = {
|
2017-02-07 16:09:39 +00:00
|
|
|
users = {
|
|
|
|
groups.${cfg.group.name} = {
|
|
|
|
inherit (cfg.group) name gid;
|
|
|
|
};
|
|
|
|
users.${cfg.user.name} = {
|
|
|
|
inherit (cfg.user) home name uid;
|
|
|
|
createHome = true;
|
|
|
|
group = cfg.group.name;
|
|
|
|
};
|
|
|
|
};
|
2017-01-09 16:09:52 +00:00
|
|
|
|
|
|
|
systemd.services.kapacitor = {
|
|
|
|
description = "kapacitor";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "always";
|
2017-02-07 16:09:39 +00:00
|
|
|
User = cfg.user.name;
|
2017-01-09 16:09:52 +00:00
|
|
|
ExecStart = "${pkgs.kapacitor}/bin/kapacitord -config ${configFile}";
|
|
|
|
};
|
|
|
|
};
|
2017-01-28 17:36:53 +00:00
|
|
|
|
|
|
|
systemd.services.kapacitor-alarms = {
|
|
|
|
description = "kapacitor-alarms";
|
|
|
|
after = [ "kapacitor.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
restartIfChanged = true;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
2017-02-07 16:09:39 +00:00
|
|
|
User = cfg.user.name;
|
2017-01-28 17:36:53 +00:00
|
|
|
ExecStart = pkgs.writeDash "add_alarms" ''
|
|
|
|
${pkgs.kapacitor}/bin/kapacitor delete tasks \*
|
|
|
|
${concatStrings (mapAttrsToList (name: alarm: ''
|
|
|
|
${pkgs.kapacitor}/bin/kapacitor define ${name} \
|
|
|
|
-type batch \
|
2017-02-07 16:09:39 +00:00
|
|
|
-tick ${pkgs.writeText "${name}.tick" alarm.text} \
|
|
|
|
-dbrp ${alarm.database}.default
|
2017-01-28 17:36:53 +00:00
|
|
|
${pkgs.kapacitor}/bin/kapacitor enable ${name}
|
|
|
|
'') cfg.alarms)}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2017-01-09 16:09:52 +00:00
|
|
|
};
|
|
|
|
in out
|