blob: c793bb073199c52cc8a94b303753450808db4dfb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.vmagent;
settingsFormat = pkgs.formats.json { };
in {
options.services.vmagent = {
enable = mkEnableOption (lib.mdDoc "vmagent");
user = mkOption {
default = "vmagent";
type = types.str;
description = lib.mdDoc ''
User account under which vmagent runs.
'';
};
group = mkOption {
type = types.str;
default = "vmagent";
description = lib.mdDoc ''
Group under which vmagent runs.
'';
};
package = mkOption {
default = pkgs.vmagent;
defaultText = lib.literalMD "pkgs.vmagent";
type = types.package;
description = lib.mdDoc ''
vmagent package to use.
'';
};
dataDir = mkOption {
type = types.str;
default = "/var/lib/vmagent";
description = lib.mdDoc ''
The directory where vmagent stores its data files.
'';
};
remoteWriteUrl = mkOption {
default = "http://localhost:8428/api/v1/write";
type = types.str;
description = lib.mdDoc ''
The storage endpoint such as VictoriaMetrics
'';
};
prometheusConfig = mkOption {
type = lib.types.submodule { freeformType = settingsFormat.type; };
description = lib.mdDoc ''
Config for prometheus style metrics
'';
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to open the firewall for the default ports.
'';
};
};
config = mkIf cfg.enable {
users.groups = mkIf (cfg.group == "vmagent") { vmagent = { }; };
users.users = mkIf (cfg.user == "vmagent") {
vmagent = {
group = cfg.group;
description = "vmagent daemon user";
home = cfg.dataDir;
isSystemUser = true;
};
};
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8429 ];
systemd.services.vmagent = let
prometheusConfig = settingsFormat.generate "prometheusConfig.yaml" cfg.prometheusConfig;
in {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "vmagent system service";
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Type = "simple";
Restart = "on-failure";
WorkingDirectory = cfg.dataDir;
ExecStart = "${cfg.package}/bin/vmagent -remoteWrite.url=${cfg.remoteWriteUrl} -promscrape.config=${prometheusConfig}";
};
};
systemd.tmpfiles.rules =
[ "d '${cfg.dataDir}' 0755 ${cfg.user} ${cfg.group} -" ];
};
}
|