From 458fafa8fc9c83d9f0648e2758e8e0ddd45bc5ad Mon Sep 17 00:00:00 2001 From: Louis Blin <45168934+lbpdt@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:03:55 +0000 Subject: nixos/prometheus-exporters/artifactory: init at 1.9.0 Adds a Prometheus exporter to scrape metrics from the API of JFrog Artifactory instances. --- .../services/monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/artifactory.nix | 59 ++++++++++++++++++++++ nixos/tests/prometheus-exporters.nix | 15 ++++++ .../monitoring/prometheus/artifactory-exporter.nix | 36 +++++++++++++ pkgs/top-level/all-packages.nix | 1 + 5 files changed, 112 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/artifactory.nix create mode 100644 pkgs/servers/monitoring/prometheus/artifactory-exporter.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index 1fd85c66f84..474005c8928 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -22,6 +22,7 @@ let exporterOpts = genAttrs [ "apcupsd" + "artifactory" "bind" "bird" "blackbox" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/artifactory.nix b/nixos/modules/services/monitoring/prometheus/exporters/artifactory.nix new file mode 100644 index 00000000000..2adcecc728b --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/artifactory.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, options }: + +with lib; + +let + cfg = config.services.prometheus.exporters.artifactory; +in +{ + port = 9531; + extraOpts = { + scrapeUri = mkOption { + type = types.str; + default = "http://localhost:8081/artifactory"; + description = '' + URI on which to scrape JFrog Artifactory. + ''; + }; + + artiUsername = mkOption { + type = types.str; + description = '' + Username for authentication against JFrog Artifactory API. + ''; + }; + + artiPassword = mkOption { + type = types.str; + default = ""; + description = '' + Password for authentication against JFrog Artifactory API. + One of the password or access token needs to be set. + ''; + }; + + artiAccessToken = mkOption { + type = types.str; + default = ""; + description = '' + Access token for authentication against JFrog Artifactory API. + One of the password or access token needs to be set. + ''; + }; + }; + serviceOpts = { + serviceConfig = { + ExecStart = '' + ${pkgs.prometheus-artifactory-exporter}/bin/artifactory_exporter \ + --web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ + --artifactory.scrape-uri ${cfg.scrapeUri} \ + ${concatStringsSep " \\\n " cfg.extraFlags} + ''; + Environment = [ + "ARTI_USERNAME=${cfg.artiUsername}" + "ARTI_PASSWORD=${cfg.artiPassword}" + "ARTI_ACCESS_TOKEN=${cfg.artiAccessToken}" + ]; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index 89d17c9de8c..161762de723 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -75,6 +75,21 @@ let ''; }; + artifactory = { + exporterConfig = { + enable = true; + artiUsername = "artifactory-username"; + artiPassword = "artifactory-password"; + }; + exporterTest = '' + wait_for_unit("prometheus-artifactory-exporter.service") + wait_for_open_port(9531) + succeed( + "curl -sSf http://localhost:9531/metrics | grep -q 'artifactory_up'" + ) + ''; + }; + bind = { exporterConfig = { enable = true; diff --git a/pkgs/servers/monitoring/prometheus/artifactory-exporter.nix b/pkgs/servers/monitoring/prometheus/artifactory-exporter.nix new file mode 100644 index 00000000000..3aa1e18a9f1 --- /dev/null +++ b/pkgs/servers/monitoring/prometheus/artifactory-exporter.nix @@ -0,0 +1,36 @@ +{ lib, buildGoModule, fetchFromGitHub, nixosTests }: + +buildGoModule rec { + pname = "artifactory_exporter"; + version = "1.9.0"; + rev = "v${version}"; + + src = fetchFromGitHub { + owner = "peimanja"; + repo = pname; + rev = rev; + sha256 = "1zmkajg48i40jm624p2h03bwg7w28682yfcgk42ig3d50p8xwqc3"; + }; + + vendorSha256 = "1594bpfwhbjgayf4aacs7rfjxm4cnqz8iak8kpm1xzsm1cx1il17"; + + subPackages = [ "." ]; + + buildFlagsArray = '' + -ldflags= + -s -w + -X github.com/prometheus/common/version.Version=${version} + -X github.com/prometheus/common/version.Revision=${rev} + -X github.com/prometheus/common/version.Branch=master + -X github.com/prometheus/common/version.BuildDate=19700101-00:00:00 + ''; + + passthru.tests = { inherit (nixosTests.prometheus-exporters) artifactory; }; + + meta = with lib; { + description = "JFrog Artifactory Prometheus Exporter"; + homepage = "https://github.com/peimanja/artifactory_exporter"; + license = licenses.asl20; + maintainers = with maintainers; [ lbpdt ]; + }; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5c4eaa8e71a..509186ed9ac 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -18164,6 +18164,7 @@ in prometheus = callPackage ../servers/monitoring/prometheus { }; prometheus-alertmanager = callPackage ../servers/monitoring/prometheus/alertmanager.nix { }; prometheus-apcupsd-exporter = callPackage ../servers/monitoring/prometheus/apcupsd-exporter.nix { }; + prometheus-artifactory-exporter = callPackage ../servers/monitoring/prometheus/artifactory-exporter.nix { }; prometheus-aws-s3-exporter = callPackage ../servers/monitoring/prometheus/aws-s3-exporter.nix { }; prometheus-bind-exporter = callPackage ../servers/monitoring/prometheus/bind-exporter.nix { }; prometheus-bird-exporter = callPackage ../servers/monitoring/prometheus/bird-exporter.nix { }; -- cgit 1.4.1