diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 2c63a19deb73..4d91e266d85b 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -168,6 +168,7 @@ hbase = 158; opentsdb = 159; scollector = 160; + bosun = 161; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! @@ -300,6 +301,7 @@ systemd-timesync = 154; liquidsoap = 155; scollector = 156; + bosun = 157; # 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 c6b44f590f88..3965dc3e53ef 100755 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -190,6 +190,7 @@ ./services/misc/uhub.nix ./services/misc/zookeeper.nix ./services/monitoring/apcupsd.nix + ./services/monitoring/bosun.nix ./services/monitoring/collectd.nix ./services/monitoring/dd-agent.nix ./services/monitoring/graphite.nix diff --git a/nixos/modules/services/monitoring/bosun.nix b/nixos/modules/services/monitoring/bosun.nix new file mode 100644 index 000000000000..90fa573e9cd1 --- /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; + + }; + +}