nixpkgs/nixos/modules/services/logging/heartbeat.nix

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

76 lines
1.8 KiB
Nix
Raw Normal View History

2017-07-01 16:57:18 +00:00
{ config, lib, pkgs, ... }:
let
cfg = config.services.heartbeat;
heartbeatYml = pkgs.writeText "heartbeat.yml" ''
name: ${cfg.name}
tags: ${builtins.toJSON cfg.tags}
${cfg.extraConfig}
'';
in
{
options = {
services.heartbeat = {
enable = lib.mkEnableOption "heartbeat, uptime monitoring";
2017-07-01 16:57:18 +00:00
package = lib.mkPackageOption pkgs "heartbeat" {
example = "heartbeat7";
};
name = lib.mkOption {
type = lib.types.str;
2017-07-01 16:57:18 +00:00
default = "heartbeat";
description = "Name of the beat";
};
tags = lib.mkOption {
type = lib.types.listOf lib.types.str;
2017-07-01 16:57:18 +00:00
default = [];
description = "Tags to place on the shipped log messages";
};
stateDir = lib.mkOption {
type = lib.types.str;
2017-07-01 16:57:18 +00:00
default = "/var/lib/heartbeat";
description = "The state directory. heartbeat's own logs and other data are stored here.";
};
extraConfig = lib.mkOption {
type = lib.types.lines;
2017-07-01 16:57:18 +00:00
default = ''
heartbeat.monitors:
- type: http
urls: ["http://localhost:9200"]
schedule: '@every 10s'
'';
description = "Any other configuration options you want to add";
};
};
};
config = lib.mkIf cfg.enable {
2017-07-01 16:57:18 +00:00
systemd.tmpfiles.rules = [
"d '${cfg.stateDir}' - nobody nogroup - -"
];
2017-07-01 16:57:18 +00:00
systemd.services.heartbeat = with pkgs; {
description = "heartbeat log shipper";
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -p "${cfg.stateDir}"/{data,logs}
'';
serviceConfig = {
User = "nobody";
AmbientCapabilities = "cap_net_raw";
ExecStart = "${cfg.package}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\"";
2017-07-01 16:57:18 +00:00
};
};
};
}