nixos/prometheus: add process exporter
This commit is contained in:
parent
0d70bbcda4
commit
5e5a3c39ed
|
@ -51,6 +51,7 @@ let
|
||||||
"pihole"
|
"pihole"
|
||||||
"postfix"
|
"postfix"
|
||||||
"postgres"
|
"postgres"
|
||||||
|
"process"
|
||||||
"py-air-control"
|
"py-air-control"
|
||||||
"redis"
|
"redis"
|
||||||
"rspamd"
|
"rspamd"
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
{ config, lib, pkgs, options }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.services.prometheus.exporters.process;
|
||||||
|
configFile = pkgs.writeText "process-exporter.yaml" (builtins.toJSON cfg.settings);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
port = 9256;
|
||||||
|
extraOpts = {
|
||||||
|
settings.process_names = mkOption {
|
||||||
|
type = types.listOf types.anything;
|
||||||
|
default = {};
|
||||||
|
example = literalExample ''
|
||||||
|
{
|
||||||
|
process_names = [
|
||||||
|
# Remove nix store path from process name
|
||||||
|
{ name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
|
||||||
|
];
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
All settings expressed as an Nix attrset.
|
||||||
|
|
||||||
|
Check the official documentation for the corresponding YAML
|
||||||
|
settings that can all be used here: <link xlink:href="https://github.com/ncabatoff/process-exporter" />
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
serviceOpts = {
|
||||||
|
serviceConfig = {
|
||||||
|
DynamicUser = false;
|
||||||
|
ExecStart = ''
|
||||||
|
${pkgs.prometheus-process-exporter}/bin/process-exporter \
|
||||||
|
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
|
||||||
|
--config.path ${configFile} \
|
||||||
|
${concatStringsSep " \\\n " cfg.extraFlags}
|
||||||
|
'';
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
ProtectHome = true;
|
||||||
|
ProtectSystem = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -864,6 +864,25 @@ let
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process = {
|
||||||
|
exporterConfig = {
|
||||||
|
enable = true;
|
||||||
|
settings.process_names = [
|
||||||
|
# Remove nix store path from process name
|
||||||
|
{ name = "{{.Matches.Wrapped}} {{ .Matches.Args }}"; cmdline = [ "^/nix/store[^ ]*/(?P<Wrapped>[^ /]*) (?P<Args>.*)" ]; }
|
||||||
|
];
|
||||||
|
};
|
||||||
|
exporterTest = ''
|
||||||
|
wait_for_unit("prometheus-process-exporter.service")
|
||||||
|
wait_for_open_port(9256)
|
||||||
|
wait_until_succeeds(
|
||||||
|
"curl -sSf localhost:9256/metrics | grep -q '{}'".format(
|
||||||
|
'namedprocess_namegroup_cpu_seconds_total{groupname="process-exporter '
|
||||||
|
)
|
||||||
|
)
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
py-air-control = {
|
py-air-control = {
|
||||||
nodeName = "py_air_control";
|
nodeName = "py_air_control";
|
||||||
exporterConfig = {
|
exporterConfig = {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{ lib, buildGoModule, fetchFromGitHub }:
|
{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
|
||||||
|
|
||||||
buildGoModule rec {
|
buildGoModule rec {
|
||||||
pname = "process-exporter";
|
pname = "process-exporter";
|
||||||
|
@ -19,6 +19,8 @@ buildGoModule rec {
|
||||||
|
|
||||||
doCheck = true;
|
doCheck = true;
|
||||||
|
|
||||||
|
passthru.tests = { inherit (nixosTests.prometheus-exporters) process; };
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "Prometheus exporter that mines /proc to report on selected processes";
|
description = "Prometheus exporter that mines /proc to report on selected processes";
|
||||||
homepage = "https://github.com/ncabatoff/process-exporter";
|
homepage = "https://github.com/ncabatoff/process-exporter";
|
||||||
|
|
Loading…
Reference in a new issue