2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.heartbeat;
|
|
|
|
|
|
|
|
heartbeatYml = pkgs.writeText "heartbeat.yml" ''
|
|
|
|
name: ${cfg.name}
|
|
|
|
tags: ${builtins.toJSON cfg.tags}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.heartbeat = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "heartbeat");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-08-12 12:06:08 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.heartbeat;
|
|
|
|
defaultText = literalExpression "pkgs.heartbeat";
|
|
|
|
example = literalExpression "pkgs.heartbeat7";
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
The heartbeat package to use.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "heartbeat";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Name of the beat";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Tags to place on the shipped log messages";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/heartbeat";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "The state directory. heartbeat's own logs and other data are stored here.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = ''
|
|
|
|
heartbeat.monitors:
|
|
|
|
- type: http
|
|
|
|
urls: ["http://localhost:9200"]
|
|
|
|
schedule: '@every 10s'
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Any other configuration options you want to add";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.stateDir}' - nobody nogroup - -"
|
|
|
|
];
|
|
|
|
|
|
|
|
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";
|
2022-08-12 12:06:08 +00:00
|
|
|
ExecStart = "${cfg.package}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\"";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|