Merge pull request #2777 from offlinehacker/nixos/influxdb/add
nixos: add influxdb module
This commit is contained in:
commit
e328471b8a
|
@ -132,6 +132,7 @@
|
|||
hydra = 122;
|
||||
spiped = 123;
|
||||
teamspeak = 124;
|
||||
influxdb = 125;
|
||||
|
||||
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
|
||||
|
||||
|
@ -238,6 +239,7 @@
|
|||
hydra = 122;
|
||||
spiped = 123;
|
||||
teamspeak = 124;
|
||||
influxdb = 125;
|
||||
|
||||
# When adding a gid, make sure it doesn't match an existing uid. And don't use gids above 399!
|
||||
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
./services/databases/postgresql.nix
|
||||
./services/databases/virtuoso.nix
|
||||
./services/databases/monetdb.nix
|
||||
./services/databases/influxdb.nix
|
||||
./services/desktops/accountservice.nix
|
||||
./services/desktops/geoclue2.nix
|
||||
./services/desktops/gnome3/at-spi2-core.nix
|
||||
|
|
|
@ -0,0 +1,241 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.influxdb;
|
||||
|
||||
influxdbConfig = pkgs.writeText "config.toml" ''
|
||||
bind-address = "${cfg.bindAddress}"
|
||||
|
||||
[logging]
|
||||
level = "info"
|
||||
file = "stdout"
|
||||
|
||||
[admin]
|
||||
port = ${toString cfg.adminPort}
|
||||
assets = "${pkgs.influxdb}/share/influxdb/admin"
|
||||
|
||||
[api]
|
||||
port = ${toString cfg.apiPort}
|
||||
${cfg.apiExtraConfig}
|
||||
|
||||
[input_plugins]
|
||||
${cfg.inputPluginsConfig}
|
||||
|
||||
[raft]
|
||||
dir = "${cfg.dataDir}/raft"
|
||||
${cfg.raftConfig}
|
||||
|
||||
[storage]
|
||||
dir = "${cfg.dataDir}/db"
|
||||
${cfg.storageConfig}
|
||||
|
||||
[cluster]
|
||||
${cfg.clusterConfig}
|
||||
|
||||
[sharding]
|
||||
${cfg.shardingConfig}
|
||||
|
||||
[wal]
|
||||
dir = "${cfg.dataDir}/wal"
|
||||
${cfg.walConfig}
|
||||
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
in
|
||||
{
|
||||
|
||||
###### interface
|
||||
|
||||
options = {
|
||||
|
||||
services.influxdb = {
|
||||
|
||||
enable = mkOption {
|
||||
default = false;
|
||||
description = "Whether to enable the influxdb server";
|
||||
type = types.uniq types.bool;
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
default = pkgs.influxdb;
|
||||
description = "Which influxdb derivation to use";
|
||||
type = types.package;
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
default = "influxdb";
|
||||
description = "User account under which influxdb runs";
|
||||
type = types.string;
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
default = "influxdb";
|
||||
description = "Group under which influxdb runs";
|
||||
type = types.string;
|
||||
};
|
||||
|
||||
dataDir = mkOption {
|
||||
default = "/var/db/influxdb";
|
||||
description = "Data directory for influxd data files.";
|
||||
type = types.path;
|
||||
};
|
||||
|
||||
bindAddress = mkOption {
|
||||
default = "127.0.0.1";
|
||||
description = "Address where influxdb listens";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
adminPort = mkOption {
|
||||
default = 8083;
|
||||
description = "The port where influxdb admin listens";
|
||||
type = types.int;
|
||||
};
|
||||
|
||||
apiPort = mkOption {
|
||||
default = 8086;
|
||||
description = "The port where influxdb api listens";
|
||||
type = types.int;
|
||||
};
|
||||
|
||||
apiExtraConfig = mkOption {
|
||||
default = ''
|
||||
read-timeout = "5s"
|
||||
'';
|
||||
description = "Extra influxdb api configuration";
|
||||
example = ''
|
||||
ssl-port = 8084
|
||||
ssl-cert = /path/to/cert.pem
|
||||
read-timeout = "5s"
|
||||
'';
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
inputPluginsConfig = mkOption {
|
||||
default = "";
|
||||
description = "Configuration of influxdb extra plugins";
|
||||
example = ''
|
||||
[input_plugins.graphite]
|
||||
enabled = true
|
||||
port = 2003
|
||||
database = "graphite"
|
||||
'';
|
||||
};
|
||||
|
||||
raftConfig = mkOption {
|
||||
default = ''
|
||||
port = 8090
|
||||
'';
|
||||
description = "Influxdb raft configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
storageConfig = mkOption {
|
||||
default = ''
|
||||
write-buffer-size = 10000
|
||||
'';
|
||||
description = "Influxdb raft configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
clusterConfig = mkOption {
|
||||
default = ''
|
||||
protobuf_port = 8099
|
||||
protobuf_timeout = "2s"
|
||||
protobuf_heartbeat = "200ms"
|
||||
protobuf_min_backoff = "1s"
|
||||
protobuf_max_backoff = "10s"
|
||||
|
||||
write-buffer-size = 10000
|
||||
max-response-buffer-size = 100
|
||||
|
||||
concurrent-shard-query-limit = 10
|
||||
'';
|
||||
description = "Influxdb cluster configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
leveldbConfig = mkOption {
|
||||
default = ''
|
||||
max-open-files = 40
|
||||
lru-cache-size = "200m"
|
||||
max-open-shards = 0
|
||||
point-batch-size = 100
|
||||
write-batch-size = 5000000
|
||||
'';
|
||||
description = "Influxdb leveldb configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
shardingConfig = mkOption {
|
||||
default = ''
|
||||
replication-factor = 1
|
||||
|
||||
[sharding.short-term]
|
||||
duration = "7d"
|
||||
split = 1
|
||||
|
||||
[sharding.long-term]
|
||||
duration = "30d"
|
||||
split = 1
|
||||
'';
|
||||
description = "Influxdb sharding configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
walConfig = mkOption {
|
||||
default = ''
|
||||
flush-after = 1000
|
||||
bookmark-after = 1000
|
||||
index-after = 1000
|
||||
requests-per-logfile = 10000
|
||||
'';
|
||||
description = "Influxdb write-ahead log configuration";
|
||||
type = types.lines;
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
default = "";
|
||||
description = "Extra configuration options for influxdb";
|
||||
type = types.string;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
###### implementation
|
||||
|
||||
config = mkIf config.services.influxdb.enable {
|
||||
|
||||
systemd.services.influxdb = {
|
||||
description = "InfluxDB Server";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-interfaces.target" ];
|
||||
serviceConfig = {
|
||||
ExecStart = ''${cfg.package}/bin/influxdb -config "${influxdbConfig}"'';
|
||||
User = "${cfg.user}";
|
||||
Group = "${cfg.group}";
|
||||
PermissionsStartOnly = true;
|
||||
};
|
||||
preStart = ''
|
||||
mkdir -m 0770 -p ${cfg.dataDir}
|
||||
if [ "$(id -u)" = 0 ]; then chown -R ${cfg.user}:${cfg.group} ${cfg.dataDir}; fi
|
||||
'';
|
||||
};
|
||||
|
||||
users.extraUsers = optional (cfg.user == "influxdb") {
|
||||
name = "influxdb";
|
||||
uid = config.ids.uids.influxdb;
|
||||
description = "Influxdb daemon user";
|
||||
};
|
||||
|
||||
users.extraGroups = optional (cfg.group == "influxdb") {
|
||||
name = "influxdb";
|
||||
gid = config.ids.gids.influxdb;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
|
@ -221,6 +221,7 @@ in rec {
|
|||
tests.installer.rebuildCD = forAllSystems (system: (import tests/installer.nix { inherit system; }).rebuildCD.test);
|
||||
tests.installer.separateBoot = forAllSystems (system: (import tests/installer.nix { inherit system; }).separateBoot.test);
|
||||
tests.installer.simple = forAllSystems (system: (import tests/installer.nix { inherit system; }).simple.test);
|
||||
tests.influxdb = callTest tests/influxdb.nix {};
|
||||
tests.ipv6 = callTest tests/ipv6.nix {};
|
||||
tests.jenkins = callTest tests/jenkins.nix {};
|
||||
tests.kde4 = callTest tests/kde4.nix {};
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
# This test runs influxdb and checks if influxdb is up and running
|
||||
|
||||
import ./make-test.nix {
|
||||
nodes = {
|
||||
one = { config, pkgs, ... }: {
|
||||
services.influxdb.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
startAll;
|
||||
|
||||
$one->waitForUnit("influxdb.service");
|
||||
|
||||
# Check if admin interface is avalible
|
||||
$one->waitUntilSucceeds("curl -f 127.0.0.1:8083");
|
||||
|
||||
# create database
|
||||
$one->succeed(q~
|
||||
curl -X POST 'http://localhost:8086/db?u=root&p=root' \
|
||||
-d '{"name": "test"}'
|
||||
~);
|
||||
|
||||
# write some points and run simple query
|
||||
$one->succeed(q~
|
||||
curl -X POST 'http://localhost:8086/db/test/series?u=root&p=root' \
|
||||
-d '[{"name":"foo","columns":["val"],"points":[[6666]]}]'
|
||||
~);
|
||||
$one->succeed(q~
|
||||
curl -G 'http://localhost:8086/db/test/series?u=root&p=root' \
|
||||
--data-urlencode 'q=select * from foo limit 1' | grep 6666
|
||||
~);
|
||||
'';
|
||||
}
|
Loading…
Reference in New Issue