nixpkgs/nixos/modules/services/monitoring/bosun.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 lines
3.7 KiB
Nix
Raw Permalink Normal View History

2014-11-20 14:49:45 +00:00
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.bosun;
configFile = pkgs.writeText "bosun.conf" ''
${lib.optionalString (cfg.opentsdbHost != null) "tsdbHost = ${cfg.opentsdbHost}"}
${lib.optionalString (cfg.influxHost != null) "influxHost = ${cfg.influxHost}"}
2014-11-20 14:49:45 +00:00
httpListen = ${cfg.listenAddress}
stateFile = ${cfg.stateFile}
2015-11-16 14:08:10 +01:00
ledisDir = ${cfg.ledisDir}
checkFrequency = ${cfg.checkFrequency}
2014-11-20 14:56:49 +00:00
${cfg.extraConfig}
2014-11-20 14:49:45 +00:00
'';
in
{
options = {
services.bosun = {
enable = lib.mkEnableOption "bosun";
2014-11-20 14:49:45 +00:00
package = lib.mkPackageOption pkgs "bosun" { };
2014-11-20 14:49:45 +00:00
user = lib.mkOption {
type = lib.types.str;
2014-11-20 14:49:45 +00:00
default = "bosun";
description = ''
User account under which bosun runs.
'';
};
group = lib.mkOption {
type = lib.types.str;
2014-11-20 14:49:45 +00:00
default = "bosun";
description = ''
Group account under which bosun runs.
'';
};
opentsdbHost = lib.mkOption {
type = lib.types.nullOr lib.types.str;
2014-11-20 14:49:45 +00:00
default = "localhost:4242";
description = ''
Host and port of the OpenTSDB database that stores bosun data.
2015-11-16 14:08:10 +01:00
To disable opentsdb you can pass null as parameter.
'';
};
influxHost = lib.mkOption {
type = lib.types.nullOr lib.types.str;
2015-11-16 14:08:10 +01:00
default = null;
example = "localhost:8086";
description = ''
Host and port of the influxdb database.
2014-11-20 14:49:45 +00:00
'';
};
listenAddress = lib.mkOption {
type = lib.types.str;
2014-11-20 14:49:45 +00:00
default = ":8070";
description = ''
The host address and port that bosun's web interface will listen on.
'';
};
stateFile = lib.mkOption {
type = lib.types.path;
2014-11-20 14:49:45 +00:00
default = "/var/lib/bosun/bosun.state";
description = ''
Path to bosun's state file.
'';
};
ledisDir = lib.mkOption {
type = lib.types.path;
2015-11-16 14:08:10 +01:00
default = "/var/lib/bosun/ledis_data";
description = ''
Path to bosun's ledis data dir
'';
};
checkFrequency = lib.mkOption {
type = lib.types.str;
default = "5m";
description = ''
Bosun's check frequency
'';
};
extraConfig = lib.mkOption {
type = lib.types.lines;
2014-11-20 14:56:49 +00:00
default = "";
description = ''
Extra configuration options for Bosun. You should describe your
desired templates, alerts, macros, etc through this configuration
option.
A detailed description of the supported syntax can be found at-spi2-atk
<https://bosun.org/configuration.html>
2014-11-20 14:56:49 +00:00
'';
};
2014-11-20 14:49:45 +00:00
};
};
config = lib.mkIf cfg.enable {
2015-11-16 14:08:10 +01:00
2014-11-20 14:49:45 +00:00
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"
mkdir -p "${cfg.ledisDir}";
2014-11-20 14:49:45 +00:00
if [ "$(id -u)" = 0 ]; then
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}"
chown ${cfg.user}:${cfg.group} "${cfg.stateFile}.tmp"
chown ${cfg.user}:${cfg.group} "${cfg.ledisDir}"
2014-11-20 14:49:45 +00:00
fi
'';
2014-11-20 14:49:45 +00:00
serviceConfig = {
PermissionsStartOnly = true;
User = cfg.user;
Group = cfg.group;
ExecStart = ''
${cfg.package}/bin/bosun -c ${configFile}
2014-11-20 14:49:45 +00:00
'';
};
};
users.users.bosun = {
2014-11-20 14:49:45 +00:00
description = "bosun user";
group = "bosun";
uid = config.ids.uids.bosun;
};
users.groups.bosun.gid = config.ids.gids.bosun;
2014-11-20 14:49:45 +00:00
};
}