2014-05-27 22:54:43 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.influxdb;
|
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
configOptions = recursiveUpdate {
|
|
|
|
meta = {
|
|
|
|
bind-address = ":8088";
|
|
|
|
commit-timeout = "50ms";
|
|
|
|
dir = "${cfg.dataDir}/meta";
|
|
|
|
election-timeout = "1s";
|
|
|
|
heartbeat-timeout = "1s";
|
|
|
|
hostname = "localhost";
|
|
|
|
leader-lease-timeout = "500ms";
|
|
|
|
retention-autocreate = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
data = {
|
|
|
|
dir = "${cfg.dataDir}/data";
|
|
|
|
wal-dir = "${cfg.dataDir}/wal";
|
|
|
|
max-wal-size = 104857600;
|
|
|
|
wal-enable-logging = true;
|
|
|
|
wal-flush-interval = "10m";
|
|
|
|
wal-partition-flush-delay = "2s";
|
|
|
|
};
|
|
|
|
|
|
|
|
cluster = {
|
|
|
|
shard-writer-timeout = "5s";
|
|
|
|
write-timeout = "5s";
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
retention = {
|
|
|
|
enabled = true;
|
|
|
|
check-interval = "30m";
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
http = {
|
|
|
|
enabled = true;
|
|
|
|
auth-enabled = false;
|
|
|
|
bind-address = ":8086";
|
|
|
|
https-enabled = false;
|
|
|
|
log-enabled = true;
|
|
|
|
pprof-enabled = false;
|
|
|
|
write-tracing = false;
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
monitor = {
|
|
|
|
store-enabled = false;
|
|
|
|
store-database = "_internal";
|
|
|
|
store-interval = "10s";
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
admin = {
|
|
|
|
enabled = true;
|
|
|
|
bind-address = ":8083";
|
|
|
|
https-enabled = false;
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
graphite = [{
|
|
|
|
enabled = false;
|
|
|
|
}];
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
udp = [{
|
|
|
|
enabled = false;
|
|
|
|
}];
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2016-09-16 22:06:16 +02:00
|
|
|
collectd = [{
|
2015-11-16 12:59:30 +01:00
|
|
|
enabled = false;
|
2017-08-11 03:47:54 +02:00
|
|
|
typesdb = "${pkgs.collectd-data}/share/collectd/types.db";
|
2015-11-16 12:59:30 +01:00
|
|
|
database = "collectd_db";
|
2017-08-06 14:49:22 +02:00
|
|
|
bind-address = ":25826";
|
2016-09-16 22:06:16 +02:00
|
|
|
}];
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2016-09-16 22:06:16 +02:00
|
|
|
opentsdb = [{
|
2015-11-16 12:59:30 +01:00
|
|
|
enabled = false;
|
2016-09-16 22:06:16 +02:00
|
|
|
}];
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
continuous_queries = {
|
|
|
|
enabled = true;
|
|
|
|
log-enabled = true;
|
|
|
|
recompute-previous-n = 2;
|
|
|
|
recompute-no-older-than = "10m";
|
|
|
|
compute-runs-per-interval = 10;
|
|
|
|
compute-no-more-than = "2m";
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
|
2015-11-16 12:59:30 +01:00
|
|
|
hinted-handoff = {
|
|
|
|
enabled = true;
|
|
|
|
dir = "${cfg.dataDir}/hh";
|
|
|
|
max-size = 1073741824;
|
|
|
|
max-age = "168h";
|
|
|
|
retry-rate-limit = 0;
|
|
|
|
retry-interval = "1s";
|
|
|
|
};
|
|
|
|
} cfg.extraConfig;
|
|
|
|
|
|
|
|
configFile = pkgs.runCommand "config.toml" {
|
|
|
|
buildInputs = [ pkgs.remarshal ];
|
2018-11-08 11:59:03 +01:00
|
|
|
preferLocalBuild = true;
|
2015-11-16 12:59:30 +01:00
|
|
|
} ''
|
|
|
|
remarshal -if json -of toml \
|
|
|
|
< ${pkgs.writeText "config.json" (builtins.toJSON configOptions)} \
|
|
|
|
> $out
|
2014-05-27 22:54:43 +02:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.influxdb = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable the influxdb server";
|
2015-06-15 18:10:26 +02:00
|
|
|
type = types.bool;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.influxdb;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.influxdb";
|
2014-05-27 22:54:43 +02:00
|
|
|
description = "Which influxdb derivation to use";
|
|
|
|
type = types.package;
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "influxdb";
|
|
|
|
description = "User account under which influxdb runs";
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "influxdb";
|
|
|
|
description = "Group under which influxdb runs";
|
2019-08-08 22:48:27 +02:00
|
|
|
type = types.str;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/db/influxdb";
|
|
|
|
description = "Data directory for influxd data files.";
|
|
|
|
type = types.path;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
2015-11-16 12:59:30 +01:00
|
|
|
default = {};
|
2014-05-27 22:54:43 +02:00
|
|
|
description = "Extra configuration options for influxdb";
|
2015-11-16 12:59:30 +01:00
|
|
|
type = types.attrs;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.influxdb.enable {
|
|
|
|
|
2019-03-18 02:37:45 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0770 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
|
|
|
|
2014-05-27 22:54:43 +02:00
|
|
|
systemd.services.influxdb = {
|
|
|
|
description = "InfluxDB Server";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 20:11:02 +02:00
|
|
|
after = [ "network.target" ];
|
2014-05-27 22:54:43 +02:00
|
|
|
serviceConfig = {
|
2015-11-16 12:59:30 +01:00
|
|
|
ExecStart = ''${cfg.package}/bin/influxd -config "${configFile}"'';
|
2019-03-18 02:37:45 +01:00
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
2017-09-24 16:37:17 +02:00
|
|
|
postStart =
|
|
|
|
let
|
|
|
|
scheme = if configOptions.http.https-enabled then "-k https" else "http";
|
|
|
|
bindAddr = (ba: if hasPrefix ":" ba then "127.0.0.1${ba}" else "${ba}")(toString configOptions.http.bind-address);
|
|
|
|
in
|
|
|
|
mkBefore ''
|
|
|
|
until ${pkgs.curl.bin}/bin/curl -s -o /dev/null ${scheme}://${bindAddr}/ping; do
|
|
|
|
sleep 1;
|
|
|
|
done
|
|
|
|
'';
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == "influxdb") {
|
|
|
|
influxdb = {
|
|
|
|
uid = config.ids.uids.influxdb;
|
2021-08-08 14:00:00 +02:00
|
|
|
group = "influxdb";
|
2019-09-14 19:51:29 +02:00
|
|
|
description = "Influxdb daemon user";
|
|
|
|
};
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups = optionalAttrs (cfg.group == "influxdb") {
|
|
|
|
influxdb.gid = config.ids.gids.influxdb;
|
2014-05-27 22:54:43 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|