Merge pull request #65751 from mayflower/pkgs/prometheus-postgres-exporter

prometheus-postgres-exporter: init at 0.5.1
This commit is contained in:
WilliButz 2019-08-02 18:45:32 +02:00 committed by GitHub
commit c221f9fdf2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 0 deletions

View file

@ -33,6 +33,7 @@ let
"nginx"
"node"
"postfix"
"postgres"
"snmp"
"surfboard"
"tor"

View file

@ -0,0 +1,46 @@
{ config, lib, pkgs, options }:
with lib;
let
cfg = config.services.prometheus.exporters.postgres;
in
{
port = 9187;
extraOpts = {
telemetryPath = mkOption {
type = types.str;
default = "/metrics";
description = ''
Path under which to expose metrics.
'';
};
dataSourceName = mkOption {
type = types.str;
default = "user=postgres database=postgres host=/run/postgresql sslmode=disable";
example = "postgresql://username:password@localhost:5432/postgres?sslmode=disable";
description = ''
Accepts PostgreSQL URI form and key=value form arguments.
'';
};
runAsLocalSuperUser = mkOption {
type = types.bool;
default = false;
description = ''
Whether to run the exporter as the local 'postgres' super user.
'';
};
};
serviceOpts = {
environment.DATA_SOURCE_NAME = cfg.dataSourceName;
serviceConfig = {
User = mkIf cfg.runAsLocalSuperUser (mkForce "postgres");
ExecStart = ''
${pkgs.prometheus-postgres-exporter}/bin/postgres_exporter \
--web.listen-address ${cfg.listenAddress}:${toString cfg.port} \
--web.telemetry-path ${cfg.telemetryPath} \
${concatStringsSep " \\\n " cfg.extraFlags}
'';
};
};
}

View file

@ -274,6 +274,30 @@ let
'';
};
postgres = {
exporterConfig = {
enable = true;
runAsLocalSuperUser = true;
};
metricProvider = {
services.postgresql.enable = true;
};
exporterTest = ''
waitForUnit("prometheus-postgres-exporter.service");
waitForOpenPort(9187);
waitForUnit("postgresql.service");
succeed("curl -sSf http://localhost:9187/metrics | grep -q 'pg_exporter_last_scrape_error 0'");
succeed("curl -sSf http://localhost:9187/metrics | grep -q 'pg_up 1'");
systemctl("stop postgresql.service");
succeed("curl -sSf http://localhost:9187/metrics | grep -qv 'pg_exporter_last_scrape_error 0'");
succeed("curl -sSf http://localhost:9187/metrics | grep -q 'pg_up 0'");
systemctl("start postgresql.service");
waitForUnit("postgresql.service");
succeed("curl -sSf http://localhost:9187/metrics | grep -q 'pg_exporter_last_scrape_error 0'");
succeed("curl -sSf http://localhost:9187/metrics | grep -q 'pg_up 1'");
'';
};
snmp = {
exporterConfig = {
enable = true;

View file

@ -0,0 +1,24 @@
{ stdenv, buildGoPackage, fetchFromGitHub }:
with stdenv.lib;
buildGoPackage rec {
name = "postgres_exporter-${version}";
version = "0.5.1";
goPackagePath = "github.com/wrouesnel/postgres_exporter";
src = fetchFromGitHub {
owner = "wrouesnel";
repo = "postgres_exporter";
rev = "v${version}";
sha256 = "1awcqhiak56nrsaa49lkw6mcbrlm86ls14sp9v69h3a0brc1q7bn";
};
meta = {
inherit (src.meta) homepage;
description = "A Prometheus exporter for PostgreSQL";
license = licenses.asl20;
maintainers = with maintainers; [ fpletz ];
};
}

View file

@ -14806,6 +14806,7 @@ in
prometheus-node-exporter = callPackage ../servers/monitoring/prometheus/node-exporter.nix { };
prometheus-openvpn-exporter = callPackage ../servers/monitoring/prometheus/openvpn-exporter.nix { };
prometheus-postfix-exporter = callPackage ../servers/monitoring/prometheus/postfix-exporter.nix { };
prometheus-postgres-exporter = callPackage ../servers/monitoring/prometheus/postgres-exporter.nix { };
prometheus-pushgateway = callPackage ../servers/monitoring/prometheus/pushgateway.nix { };
prometheus-rabbitmq-exporter = callPackage ../servers/monitoring/prometheus/rabbitmq-exporter.nix { };
prometheus-snmp-exporter = callPackage ../servers/monitoring/prometheus/snmp-exporter.nix {