1{ config, lib, pkgs, options }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.exporters.nginx; 7in 8{ 9 port = 9113; 10 extraOpts = { 11 scrapeUri = mkOption { 12 type = types.str; 13 default = "http://localhost/nginx_status"; 14 description = lib.mdDoc '' 15 Address to access the nginx status page. 16 Can be enabled with services.nginx.statusPage = true. 17 ''; 18 }; 19 telemetryPath = mkOption { 20 type = types.str; 21 default = "/metrics"; 22 description = lib.mdDoc '' 23 Path under which to expose metrics. 24 ''; 25 }; 26 sslVerify = mkOption { 27 type = types.bool; 28 default = true; 29 description = lib.mdDoc '' 30 Whether to perform certificate verification for https. 31 ''; 32 }; 33 constLabels = mkOption { 34 type = types.listOf types.str; 35 default = []; 36 example = [ 37 "label1=value1" 38 "label2=value2" 39 ]; 40 description = lib.mdDoc '' 41 A list of constant labels that will be used in every metric. 42 ''; 43 }; 44 }; 45 serviceOpts = mkMerge ([{ 46 serviceConfig = { 47 ExecStart = '' 48 ${pkgs.prometheus-nginx-exporter}/bin/nginx-prometheus-exporter \ 49 --nginx.scrape-uri='${cfg.scrapeUri}' \ 50 --nginx.ssl-verify=${boolToString cfg.sslVerify} \ 51 --web.listen-address=${cfg.listenAddress}:${toString cfg.port} \ 52 --web.telemetry-path=${cfg.telemetryPath} \ 53 --prometheus.const-labels=${concatStringsSep "," cfg.constLabels} \ 54 ${concatStringsSep " \\\n " cfg.extraFlags} 55 ''; 56 }; 57 }] ++ [(mkIf config.services.nginx.enable { 58 after = [ "nginx.service" ]; 59 requires = [ "nginx.service" ]; 60 })]); 61 imports = [ 62 (mkRenamedOptionModule [ "telemetryEndpoint" ] [ "telemetryPath" ]) 63 (mkRemovedOptionModule [ "insecure" ] '' 64 This option was replaced by 'prometheus.exporters.nginx.sslVerify'. 65 '') 66 ({ options.warnings = options.warnings; options.assertions = options.assertions; }) 67 ]; 68}