Merge pull request #125573 from Flakebi/prometheus-script-exporter

prometheus-script-exporter: init at 1.2.0
This commit is contained in:
Luke Granger-Brown 2021-06-07 01:59:41 +01:00 committed by GitHub
commit 91fb672b21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 109 additions and 0 deletions

View File

@ -56,6 +56,7 @@ let
"redis"
"rspamd"
"rtl_433"
"script"
"snmp"
"smokeping"
"sql"

View File

@ -0,0 +1,64 @@
{ config, lib, pkgs, options }:
with lib;
let
cfg = config.services.prometheus.exporters.script;
configFile = pkgs.writeText "script-exporter.yaml" (builtins.toJSON cfg.settings);
in
{
port = 9172;
extraOpts = {
settings.scripts = mkOption {
type = with types; listOf (submodule {
options = {
name = mkOption {
type = str;
example = "sleep";
description = "Name of the script.";
};
script = mkOption {
type = str;
example = "sleep 5";
description = "Shell script to execute when metrics are requested.";
};
timeout = mkOption {
type = nullOr int;
default = null;
example = 60;
description = "Optional timeout for the script in seconds.";
};
};
});
example = literalExample ''
{
scripts = [
{ name = "sleep"; script = "sleep 5"; }
];
}
'';
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/adhocteam/script_exporter#sample-configuration" />
'';
};
};
serviceOpts = {
serviceConfig = {
ExecStart = ''
${pkgs.prometheus-script-exporter}/bin/script_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--config.file ${configFile} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
NoNewPrivileges = true;
ProtectHome = true;
ProtectSystem = "strict";
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectControlGroups = true;
};
};
}

View File

@ -964,6 +964,24 @@ let
'';
};
script = {
exporterConfig = {
enable = true;
settings.scripts = [
{ name = "success"; script = "sleep 1"; }
];
};
exporterTest = ''
wait_for_unit("prometheus-script-exporter.service")
wait_for_open_port(9172)
wait_until_succeeds(
"curl -sSf 'localhost:9172/probe?name=success' | grep -q '{}'".format(
'script_success{script="success"} 1'
)
)
'';
};
smokeping = {
exporterConfig = {
enable = true;

View File

@ -0,0 +1,25 @@
{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
buildGoModule rec {
pname = "script_exporter";
version = "1.2.0";
src = fetchFromGitHub {
owner = "adhocteam";
repo = pname;
rev = "v${version}";
sha256 = "t/xgRalcHxEcT1peU1ePJUItD02rQdfz1uWpXDBo6C0=";
};
vendorSha256 = "Hs1SNpC+t1OCcoF3FBgpVGkhR97ulq6zYhi8BQlgfVc=";
passthru.tests = { inherit (nixosTests.prometheus-exporters) script; };
meta = with lib; {
description = "Shell script prometheus exporter";
homepage = "https://github.com/adhocteam/script_exporter";
license = licenses.mit;
maintainers = with maintainers; [ Flakebi ];
platforms = platforms.linux;
};
}

View File

@ -19735,6 +19735,7 @@ in
prometheus-redis-exporter = callPackage ../servers/monitoring/prometheus/redis-exporter.nix { };
prometheus-rabbitmq-exporter = callPackage ../servers/monitoring/prometheus/rabbitmq-exporter.nix { };
prometheus-rtl_433-exporter = callPackage ../servers/monitoring/prometheus/rtl_433-exporter.nix { };
prometheus-script-exporter = callPackage ../servers/monitoring/prometheus/script-exporter.nix { };
prometheus-smokeping-prober = callPackage ../servers/monitoring/prometheus/smokeping-prober.nix { };
prometheus-snmp-exporter = callPackage ../servers/monitoring/prometheus/snmp-exporter.nix { };
prometheus-statsd-exporter = callPackage ../servers/monitoring/prometheus/statsd-exporter.nix { };