about summary refs log tree commit diff
path: root/nixos/modules/services/monitoring/bosun.nix
diff options
context:
space:
mode:
authorOliver Charles <ollie@ocharles.org.uk>2014-11-20 14:49:45 +0000
committerOliver Charles <ollie@ocharles.org.uk>2014-11-24 14:40:47 +0000
commit891c262e9a90520070762389db3e97ca44c88ac3 (patch)
treef7745132de4f3c315b16e70acc02b8d9e58cc2cb /nixos/modules/services/monitoring/bosun.nix
parent2ed07c6cc1ce6c2e1c91f87630633dd92057e72b (diff)
Add a NixOS module to run bosun
Diffstat (limited to 'nixos/modules/services/monitoring/bosun.nix')
-rw-r--r--nixos/modules/services/monitoring/bosun.nix121
1 files changed, 121 insertions, 0 deletions
diff --git a/nixos/modules/services/monitoring/bosun.nix b/nixos/modules/services/monitoring/bosun.nix
new file mode 100644
index 0000000000000..90fa573e9cd1e
--- /dev/null
+++ b/nixos/modules/services/monitoring/bosun.nix
@@ -0,0 +1,121 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.bosun;
+
+  configFile = pkgs.writeText "bosun.conf" ''
+    tsdbHost = ${cfg.opentsdbHost}
+    httpListen = ${cfg.listenAddress}
+    stateFile = ${cfg.stateFile}
+    checkFrequency = 5m
+  '';
+
+in {
+
+  options = {
+
+    services.bosun = {
+
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = ''
+          Whether to run bosun.
+        '';
+      };
+
+      package = mkOption {
+        type = types.package;
+        default = pkgs.bosun;
+        example = literalExample "pkgs.bosun";
+        description = ''
+          bosun binary to use.
+        '';
+      };
+
+      user = mkOption {
+        type = types.string;
+        default = "bosun";
+        description = ''
+          User account under which bosun runs.
+        '';
+      };
+
+      group = mkOption {
+        type = types.string;
+        default = "bosun";
+        description = ''
+          Group account under which bosun runs.
+        '';
+      };
+
+      opentsdbHost = mkOption {
+        type = types.string;
+        default = "localhost:4242";
+        description = ''
+          Host and port of the OpenTSDB database that stores bosun data.
+        '';
+      };
+
+      listenAddress = mkOption {
+        type = types.string;
+        default = ":8070";
+        description = ''
+          The host address and port that bosun's web interface will listen on.
+        '';
+      };
+
+      stateFile = mkOption {
+        type = types.string;
+        default = "/var/lib/bosun/bosun.state";
+        description = ''
+          Path to bosun's state file.
+        '';
+      };
+
+    };
+
+  };
+
+  config = mkIf config.services.bosun.enable {
+
+
+    systemd.services.bosun = {
+      description = "bosun metrics collector (part of Bosun)";
+      wantedBy = [ "multi-user.target" ];
+
+      preStart =
+        ''
+        mkdir -p `dirname ${cfg.stateFile}`;
+        touch ${cfg.stateFile}
+        touch ${cfg.stateFile}.tmp
+
+        if [ "$(id -u)" = 0 ]; then
+          chown ${cfg.user}:${cfg.group} ${cfg.stateFile}
+          chown ${cfg.user}:${cfg.group} ${cfg.stateFile}.tmp
+        fi
+        '';
+
+      serviceConfig = {
+        PermissionsStartOnly = true;
+        User = cfg.user;
+        Group = cfg.group;
+        ExecStart = ''
+          ${cfg.package}/bin/bosun -c ${configFile}
+        '';
+      };
+    };
+
+    users.extraUsers.bosun = {
+      description = "bosun user";
+      group = "bosun";
+      uid = config.ids.uids.bosun;
+    };
+
+    users.extraGroups.bosun.gid = config.ids.gids.bosun;
+
+  };
+
+}