git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #96679 from midchildan/add-mackerel

mackerel-agent: init at 0.69.3

commit5dee9b5699d1b9f591fe7f94c4e481d8ecef49c5 authorKevin Cox <kevincox@kevincox.ca> dateWed 11 Nov 2020, 06:59 (6 years ago) parente46d2ee921a66e
4 files changed+156
nixos/modules/module-list.nix+1 nixos/modules/services/monitoring/mackerel-agent.nix+111 pkgs/servers/monitoring/mackerel-agent/default.nix+42 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -542,6 +542,7 @@
542542 ./services/monitoring/kapacitor.nix
543543 ./services/monitoring/loki.nix
544544 ./services/monitoring/longview.nix
545+ ./services/monitoring/mackerel-agent.nix
545546 ./services/monitoring/monit.nix
546547 ./services/monitoring/munin.nix
547548 ./services/monitoring/nagios.nix
nixos/modules/services/monitoring/mackerel-agent.nixnew file+111
@@ -0,0 +1,111 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.mackerel-agent;
7+ settingsFmt = pkgs.formats.toml {};
8+in {
9+ options.services.mackerel-agent = {
10+ enable = mkEnableOption "mackerel.io agent";
11+
12+ # the upstream package runs as root, but doesn't seem to be strictly
13+ # necessary for basic functionality
14+ runAsRoot = mkEnableOption "Whether to run as root.";
15+
16+ autoRetirement = mkEnableOption ''
17+ Whether to automatically retire the host upon OS shutdown.
18+ '';
19+
20+ apiKeyFile = mkOption {
21+ type = types.path;
22+ default = "";
23+ example = "/run/keys/mackerel-api-key";
24+ description = ''
25+ Path to file containing the Mackerel API key. The file should contain a
26+ single line of the following form:
27+
28+ <literallayout>apikey = "EXAMPLE_API_KEY"</literallayout>
29+ '';
30+ };
31+
32+ settings = mkOption {
33+ description = ''
34+ Options for mackerel-agent.conf.
35+
36+ Documentation:
37+ <link xlink:href="https://mackerel.io/docs/entry/spec/agent"/>
38+ '';
39+
40+ default = {};
41+ example = {
42+ verbose = false;
43+ silent = false;
44+ };
45+
46+ type = types.submodule {
47+ freeformType = settingsFmt.type;
48+
49+ options.host_status = {
50+ on_start = mkOption {
51+ type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
52+ description = "Host status after agent startup.";
53+ default = "working";
54+ };
55+ on_stop = mkOption {
56+ type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
57+ description = "Host status after agent shutdown.";
58+ default = "poweroff";
59+ };
60+ };
61+
62+ options.diagnostic =
63+ mkEnableOption "Collect memory usage for the agent itself";
64+ };
65+ };
66+ };
67+
68+ config = mkIf cfg.enable {
69+ environment.systemPackages = with pkgs; [ mackerel-agent ];
70+
71+ environment.etc = {
72+ "mackerel-agent/mackerel-agent.conf".source =
73+ settingsFmt.generate "mackerel-agent.conf" cfg.settings;
74+ "mackerel-agent/conf.d/api-key.conf".source = cfg.apiKeyFile;
75+ };
76+
77+ services.mackerel-agent.settings = {
78+ root = mkDefault "/var/lib/mackerel-agent";
79+ pidfile = mkDefault "/run/mackerel-agent/mackerel-agent.pid";
80+
81+ # conf.d stores the symlink to cfg.apiKeyFile
82+ include = mkDefault "/etc/mackerel-agent/conf.d/*.conf";
83+ };
84+
85+ # upstream service file in https://git.io/JUt4Q
86+ systemd.services.mackerel-agent = {
87+ description = "mackerel.io agent";
88+ after = [ "network-online.target" "nss-lookup.target" ];
89+ wantedBy = [ "multi-user.target" ];
90+ environment = {
91+ MACKEREL_PLUGIN_WORKDIR = mkDefault "%C/mackerel-agent";
92+ };
93+ serviceConfig = {
94+ DynamicUser = !cfg.runAsRoot;
95+ PrivateTmp = mkDefault true;
96+ CacheDirectory = "mackerel-agent";
97+ ConfigurationDirectory = "mackerel-agent";
98+ RuntimeDirectory = "mackerel-agent";
99+ StateDirectory = "mackerel-agent";
100+ ExecStart = "${pkgs.mackerel-agent}/bin/mackerel-agent supervise";
101+ ExecStopPost = mkIf cfg.autoRetirement "${pkg.mackerel-agent}/bin/mackerel-agent retire -force";
102+ ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
103+ LimitNOFILE = mkDefault 65536;
104+ LimitNPROC = mkDefault 65536;
105+ };
106+ restartTriggers = [
107+ config.environment.etc."mackerel-agent/mackerel-agent.conf".source
108+ ];
109+ };
110+ };
111+}
pkgs/servers/monitoring/mackerel-agent/default.nixnew file+42
@@ -0,0 +1,42 @@
1+{ stdenv, lib, buildGoModule, fetchFromGitHub, makeWrapper, iproute, nettools }:
2+
3+buildGoModule rec {
4+ pname = "mackerel-agent";
5+ version = "0.69.3";
6+
7+ src = fetchFromGitHub {
8+ owner = "mackerelio";
9+ repo = pname;
10+ rev = "v${version}";
11+ sha256 = "0jkvqqzk6wyjsdsmn2l2cdw8pjqzswlqb9p492czhgrfy065lrqp";
12+ };
13+
14+ nativeBuildInputs = [ makeWrapper ];
15+ checkInputs = lib.optionals (!stdenv.isDarwin) [ nettools ];
16+ buildInputs = lib.optionals (!stdenv.isDarwin) [ iproute ];
17+
18+ vendorSha256 = "0kjky2mhs6dapnr4xpjpnbibp6y8r320igddplynsfsp8vwrfp7m";
19+
20+ subPackages = [ "." ];
21+
22+ buildFlagsArray = ''
23+ -ldflags=
24+ -X=main.version=${version}
25+ -X=main.gitcommit=v${version}
26+ '';
27+
28+ postInstall = ''
29+ wrapProgram $out/bin/mackerel-agent \
30+ --prefix PATH : "${lib.makeBinPath buildInputs}"
31+ '';
32+
33+ doCheck = true;
34+
35+ meta = with lib; {
36+ description = "System monitoring service for mackerel.io";
37+ homepage = "https://github.com/mackerelio/mackerel-agent";
38+ license = licenses.asl20;
39+ maintainers = with maintainers; [ midchildan ];
40+ platforms = platforms.all;
41+ };
42+}
pkgs/top-level/all-packages.nix+2
@@ -16872,6 +16872,8 @@ in
1687216872
1687316873 labelImg = callPackage ../applications/science/machine-learning/labelimg { };
1687416874
16875+ mackerel-agent = callPackage ../servers/monitoring/mackerel-agent { };
16876+
1687516877 mailman = callPackage ../servers/mail/mailman/wrapped.nix { };
1687616878
1687716879 mailman-rss = callPackage ../development/python-modules/mailman-rss { };