forked from mirrors/nixpkgs
nixos: add prometheus_nginxlog_exporter module + test
This commit is contained in:
parent
ce7608d6e7
commit
65fd031277
|
@ -37,6 +37,7 @@ let
|
|||
"modemmanager"
|
||||
"nextcloud"
|
||||
"nginx"
|
||||
"nginxlog"
|
||||
"node"
|
||||
"openvpn"
|
||||
"postfix"
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
{ config, lib, pkgs, options }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.prometheus.exporters.nginxlog;
|
||||
in {
|
||||
port = 9117;
|
||||
extraOpts = {
|
||||
settings = mkOption {
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
description = ''
|
||||
All settings of nginxlog expressed as an Nix attrset.
|
||||
|
||||
Check the official documentation for the corresponding YAML
|
||||
settings that can all be used here: https://github.com/martin-helmich/prometheus-nginxlog-exporter
|
||||
|
||||
The `listen` object is already generated by `port`, `listenAddress` and `metricsEndpoint` and
|
||||
will be merged with the value of `settings` before writting it as JSON.
|
||||
'';
|
||||
};
|
||||
|
||||
metricsEndpoint = mkOption {
|
||||
type = types.str;
|
||||
default = "/metrics";
|
||||
description = ''
|
||||
Path under which to expose metrics.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
serviceOpts = let
|
||||
listenConfig = {
|
||||
listen = {
|
||||
port = cfg.port;
|
||||
address = cfg.listenAddress;
|
||||
metrics_endpoint = cfg.metricsEndpoint;
|
||||
};
|
||||
};
|
||||
completeConfig = pkgs.writeText "nginxlog-exporter.yaml" (builtins.toJSON (lib.recursiveUpdate listenConfig cfg.settings));
|
||||
in {
|
||||
serviceConfig = {
|
||||
ExecStart = ''
|
||||
${pkgs.prometheus-nginxlog-exporter}/bin/prometheus-nginxlog-exporter -config-file ${completeConfig}
|
||||
'';
|
||||
Restart="always";
|
||||
ProtectSystem="full";
|
||||
};
|
||||
};
|
||||
}
|
|
@ -444,6 +444,67 @@ let
|
|||
'';
|
||||
};
|
||||
|
||||
nginxlog = {
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
group = "nginx";
|
||||
settings = {
|
||||
namespaces = [
|
||||
{
|
||||
name = "filelogger";
|
||||
source = {
|
||||
files = [ "/var/log/nginx/filelogger.access.log" ];
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "syslogger";
|
||||
source = {
|
||||
syslog = {
|
||||
listen_address = "udp://127.0.0.1:10000";
|
||||
format = "rfc3164";
|
||||
tags = ["nginx"];
|
||||
};
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
metricProvider = {
|
||||
services.nginx = {
|
||||
enable = true;
|
||||
httpConfig = ''
|
||||
server {
|
||||
listen 80;
|
||||
server_name filelogger.local;
|
||||
access_log /var/log/nginx/filelogger.access.log;
|
||||
}
|
||||
server {
|
||||
listen 81;
|
||||
server_name syslogger.local;
|
||||
access_log syslog:server=127.0.0.1:10000,tag=nginx,severity=info;
|
||||
}
|
||||
'';
|
||||
};
|
||||
};
|
||||
exporterTest = ''
|
||||
wait_for_unit("nginx.service")
|
||||
wait_for_unit("prometheus-nginxlog-exporter.service")
|
||||
wait_for_open_port(9117)
|
||||
wait_for_open_port(80)
|
||||
wait_for_open_port(81)
|
||||
succeed("curl http://localhost")
|
||||
execute("sleep 1")
|
||||
succeed(
|
||||
"curl -sSf http://localhost:9117/metrics | grep 'filelogger_http_response_count_total' | grep -q 1"
|
||||
)
|
||||
succeed("curl http://localhost:81")
|
||||
execute("sleep 1")
|
||||
succeed(
|
||||
"curl -sSf http://localhost:9117/metrics | grep 'syslogger_http_response_count_total' | grep -q 1"
|
||||
)
|
||||
'';
|
||||
};
|
||||
|
||||
node = {
|
||||
exporterConfig = {
|
||||
enable = true;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ stdenv, buildGoModule, fetchFromGitHub }:
|
||||
{ stdenv, buildGoModule, fetchFromGitHub, nixosTests }:
|
||||
|
||||
buildGoModule rec {
|
||||
pname = "nginxlog_exporter";
|
||||
|
@ -17,6 +17,8 @@ buildGoModule rec {
|
|||
|
||||
runVend = true;
|
||||
|
||||
passthru.tests = { inherit (nixosTests.prometheus-exporters) nginxlog; };
|
||||
|
||||
meta = with stdenv.lib; {
|
||||
description = "Export metrics from Nginx access log files to Prometheus";
|
||||
homepage = "https://github.com/martin-helmich/prometheus-nginxlog-exporter";
|
||||
|
|
Loading…
Reference in a new issue