git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #27019 from fadenb/heartbeat_service

heartbeat service: init

commitc0086b8996b3e948a6b392b55763f07123e48fcc authorJoachim F <joachifm@users.noreply.github.com> dateSun 2 Jul 2017, 11:42 (9 years ago) parentd15e20f97e8422
2 files changed+74−1
nixos/modules/module-list.nix+2−1 nixos/modules/services/logging/heartbeat.nix+72
nixos/modules/module-list.nix+2−1
@@ -235,16 +235,17 @@
235235 ./services/hardware/udisks2.nix
236236 ./services/hardware/upower.nix
237237 ./services/hardware/thermald.nix
238+ ./services/logging/SystemdJournal2Gelf.nix
238239 ./services/logging/awstats.nix
239240 ./services/logging/fluentd.nix
240241 ./services/logging/graylog.nix
242+ ./services/logging/heartbeat.nix
241243 ./services/logging/journalbeat.nix
242244 ./services/logging/klogd.nix
243245 ./services/logging/logcheck.nix
244246 ./services/logging/logrotate.nix
245247 ./services/logging/logstash.nix
246248 ./services/logging/rsyslogd.nix
247− ./services/logging/SystemdJournal2Gelf.nix
248249 ./services/logging/syslog-ng.nix
249250 ./services/logging/syslogd.nix
250251 ./services/mail/dovecot.nix
nixos/modules/services/logging/heartbeat.nixnew file+72
@@ -0,0 +1,72 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.heartbeat;
7+
8+ heartbeatYml = pkgs.writeText "heartbeat.yml" ''
9+ name: ${cfg.name}
10+ tags: ${builtins.toJSON cfg.tags}
11+
12+ ${cfg.extraConfig}
13+ '';
14+
15+in
16+{
17+ options = {
18+
19+ services.heartbeat = {
20+
21+ enable = mkEnableOption "heartbeat";
22+
23+ name = mkOption {
24+ type = types.str;
25+ default = "heartbeat";
26+ description = "Name of the beat";
27+ };
28+
29+ tags = mkOption {
30+ type = types.listOf types.str;
31+ default = [];
32+ description = "Tags to place on the shipped log messages";
33+ };
34+
35+ stateDir = mkOption {
36+ type = types.str;
37+ default = "/var/lib/heartbeat";
38+ description = "The state directory. heartbeat's own logs and other data are stored here.";
39+ };
40+
41+ extraConfig = mkOption {
42+ type = types.lines;
43+ default = ''
44+ heartbeat.monitors:
45+ - type: http
46+ urls: ["http://localhost:9200"]
47+ schedule: '@every 10s'
48+ '';
49+ description = "Any other configuration options you want to add";
50+ };
51+
52+ };
53+ };
54+
55+ config = mkIf cfg.enable {
56+
57+ systemd.services.heartbeat = with pkgs; {
58+ description = "heartbeat log shipper";
59+ wantedBy = [ "multi-user.target" ];
60+ preStart = ''
61+ mkdir -p "${cfg.stateDir}"/{data,logs}
62+ chown nobody:nogroup "${cfg.stateDir}"/{data,logs}
63+ '';
64+ serviceConfig = {
65+ User = "nobody";
66+ PermissionsStartOnly = true;
67+ AmbientCapabilities = "cap_net_raw";
68+ ExecStart = "${pkgs.heartbeat}/bin/heartbeat -c \"${heartbeatYml}\" -path.data \"${cfg.stateDir}/data\" -path.logs \"${cfg.stateDir}/logs\"";
69+ };
70+ };
71+ };
72+}