Use same user for both prometheus 1 and 2. Use StateDirectory.

This commit is contained in:
Jean-Baptiste Giraudeau 2019-03-22 23:24:56 +01:00
parent 5ae25922b5
commit 0333d877c2
No known key found for this signature in database
GPG Key ID: E96EF57FD501B961
2 changed files with 9 additions and 33 deletions

View File

@ -339,7 +339,6 @@
rss2email = 312; rss2email = 312;
cockroachdb = 313; cockroachdb = 313;
zoneminder = 314; zoneminder = 314;
prometheus2 = 315;
# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
@ -639,7 +638,6 @@
rss2email = 312; rss2email = 312;
cockroachdb = 313; cockroachdb = 313;
zoneminder = 314; zoneminder = 314;
prometheus2 = 315;
# When adding a gid, make sure it doesn't match an existing # When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal # uid. Users and groups with the same name should have equal

View File

@ -52,7 +52,7 @@ let
in promtoolCheck "check-config" "prometheus.yml" yml; in promtoolCheck "check-config" "prometheus.yml" yml;
cmdlineArgs = cfg.extraFlags ++ [ cmdlineArgs = cfg.extraFlags ++ [
"-storage.local.path=${cfg.dataDir}/metrics" "-storage.local.path=/var/lib/prometheus/metrics"
"-config.file=${prometheusYml}" "-config.file=${prometheusYml}"
"-web.listen-address=${cfg.listenAddress}" "-web.listen-address=${cfg.listenAddress}"
"-alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}" "-alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}"
@ -86,7 +86,7 @@ let
in prom2toolCheck "check config" "prometheus.yml" yml; in prom2toolCheck "check config" "prometheus.yml" yml;
cmdlineArgs2 = cfg2.extraFlags ++ [ cmdlineArgs2 = cfg2.extraFlags ++ [
"--storage.tsdb.path=${cfg2.dataDir}/data/" "--storage.tsdb.path=/var/lib/prometheus2/data/"
"--config.file=${prometheus2Yml}" "--config.file=${prometheus2Yml}"
"--web.listen-address=${cfg2.listenAddress}" "--web.listen-address=${cfg2.listenAddress}"
"--alertmanager.notification-queue-capacity=${toString cfg2.alertmanagerNotificationQueueCapacity}" "--alertmanager.notification-queue-capacity=${toString cfg2.alertmanagerNotificationQueueCapacity}"
@ -446,14 +446,6 @@ in {
''; '';
}; };
dataDir = mkOption {
type = types.path;
default = "/var/lib/prometheus";
description = ''
Directory to store Prometheus metrics data.
'';
};
extraFlags = mkOption { extraFlags = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [];
@ -568,14 +560,6 @@ in {
''; '';
}; };
dataDir = mkOption {
type = types.path;
default = "/var/lib/prometheus2";
description = ''
Directory to store Prometheus 2 metrics data.
'';
};
extraFlags = mkOption { extraFlags = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = []; default = [];
@ -666,15 +650,15 @@ in {
}; };
config = mkMerge [ config = mkMerge [
(mkIf cfg.enable { (mkIf (cfg.enable || cfg2.enable) {
users.groups.${promGroup}.gid = config.ids.gids.prometheus; users.groups.${promGroup}.gid = config.ids.gids.prometheus;
users.users.${promUser} = { users.users.${promUser} = {
description = "Prometheus daemon user"; description = "Prometheus daemon user";
uid = config.ids.uids.prometheus; uid = config.ids.uids.prometheus;
group = promGroup; group = promGroup;
home = cfg.dataDir;
createHome = true;
}; };
})
(mkIf cfg.enable {
systemd.services.prometheus = { systemd.services.prometheus = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network.target" ]; after = [ "network.target" ];
@ -686,19 +670,12 @@ in {
serviceConfig = { serviceConfig = {
User = promUser; User = promUser;
Restart = "always"; Restart = "always";
WorkingDirectory = cfg.dataDir; WorkingDirectory = /var/lib/prometheus;
StateDirectory = "prometheus";
}; };
}; };
}) })
(mkIf cfg2.enable { (mkIf cfg2.enable {
users.groups.${promGroup}.gid = config.ids.gids.prometheus2;
users.users.${promUser} = {
description = "Prometheus2 daemon user";
uid = config.ids.uids.prometheus2;
group = promGroup;
home = cfg2.dataDir;
createHome = true;
};
systemd.services.prometheus2 = { systemd.services.prometheus2 = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
after = [ "network.target" ]; after = [ "network.target" ];
@ -710,7 +687,8 @@ in {
serviceConfig = { serviceConfig = {
User = promUser; User = promUser;
Restart = "always"; Restart = "always";
WorkingDirectory = cfg2.dataDir; WorkingDirectory = /var/lib/prometheus2;
StateDirectory = "prometheus2";
}; };
}; };
}) })