at 17.09-beta 1.9 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.prometheus.jsonExporter; 7in { 8 options = { 9 services.prometheus.jsonExporter = { 10 enable = mkEnableOption "prometheus JSON exporter"; 11 12 url = mkOption { 13 type = types.str; 14 description = '' 15 URL to scrape JSON from. 16 ''; 17 }; 18 19 configFile = mkOption { 20 type = types.path; 21 description = '' 22 Path to configuration file. 23 ''; 24 }; 25 26 port = mkOption { 27 type = types.int; 28 default = 7979; 29 description = '' 30 Port to listen on. 31 ''; 32 }; 33 34 extraFlags = mkOption { 35 type = types.listOf types.str; 36 default = []; 37 description = '' 38 Extra commandline options when launching the JSON exporter. 39 ''; 40 }; 41 42 openFirewall = mkOption { 43 type = types.bool; 44 default = false; 45 description = '' 46 Open port in firewall for incoming connections. 47 ''; 48 }; 49 }; 50 }; 51 52 config = mkIf cfg.enable { 53 networking.firewall.allowedTCPPorts = optional cfg.openFirewall cfg.port; 54 55 systemd.services.prometheus-json-exporter = { 56 description = "Prometheus exporter for JSON over HTTP"; 57 unitConfig.Documentation = "https://github.com/kawamuray/prometheus-json-exporter"; 58 wantedBy = [ "multi-user.target" ]; 59 serviceConfig = { 60 User = "nobody"; 61 Restart = "always"; 62 PrivateTmp = true; 63 WorkingDirectory = /tmp; 64 ExecStart = '' 65 ${pkgs.prometheus-json-exporter}/bin/prometheus-json-exporter \ 66 --port ${toString cfg.port} \ 67 ${cfg.url} ${cfg.configFile} \ 68 ${concatStringsSep " \\\n " cfg.extraFlags} 69 ''; 70 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 71 }; 72 }; 73 }; 74}