summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorJaka Hudoklin <jakahudoklin@gmail.com>2014-05-27 22:54:43 +0200
committerJaka Hudoklin <jakahudoklin@gmail.com>2014-05-27 22:56:36 +0200
commit66456c07989282f63a8425cc3a4554a79f1b6709 (patch)
treee1b9acd00daefac7897f79d0f1246a1922fd10f6 /nixos
parent6bfb25b9e870ef080120108e2b1a94ace725a015 (diff)
downloadnixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar.gz
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar.bz2
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar.lz
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar.xz
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.tar.zst
nixpkgs-66456c07989282f63a8425cc3a4554a79f1b6709.zip
nixos: add influxdb module
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/databases/influxdb.nix241
-rw-r--r--nixos/release.nix1
-rw-r--r--nixos/tests/influxdb.nix34
5 files changed, 279 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index 13ec502047d..db50a010e7d 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -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!
 
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 0737da71923..c1b55cb5550 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -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
diff --git a/nixos/modules/services/databases/influxdb.nix b/nixos/modules/services/databases/influxdb.nix
new file mode 100644
index 00000000000..61fe96d5d64
--- /dev/null
+++ b/nixos/modules/services/databases/influxdb.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;
+    };
+  };
+
+}
diff --git a/nixos/release.nix b/nixos/release.nix
index 06749966cbb..e5eadb57fe6 100644
--- a/nixos/release.nix
+++ b/nixos/release.nix
@@ -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 {};
diff --git a/nixos/tests/influxdb.nix b/nixos/tests/influxdb.nix
new file mode 100644
index 00000000000..278b264170f
--- /dev/null
+++ b/nixos/tests/influxdb.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
+    ~);
+  '';
+}