mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 14:54:29 +01:00
prometheus-postgres-exporter: init at 0.5.1
This commit is contained in:
parent
a8d45e7fc3
commit
e4c60a1e42
5 changed files with 96 additions and 0 deletions
|
@ -32,6 +32,7 @@ let
|
|||
"nginx"
|
||||
"node"
|
||||
"postfix"
|
||||
"postgres"
|
||||
"snmp"
|
||||
"surfboard"
|
||||
"tor"
|
||||
|
|
|
@ -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}
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
|
@ -232,6 +232,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;
|
||||
|
|
24
pkgs/servers/monitoring/prometheus/postgres-exporter.nix
Normal file
24
pkgs/servers/monitoring/prometheus/postgres-exporter.nix
Normal 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 ];
|
||||
};
|
||||
}
|
|
@ -14808,6 +14808,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 {
|
||||
|
|
Loading…
Reference in a new issue