Unverified Commit 0840c28c authored by Nick Cao's avatar Nick Cao Committed by GitHub
Browse files

Merge pull request #268991 from undefined-moe/mongodb-exporter

add prometheus-mongodb-exporter
parents 3d5ad96d b46ec2c4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ let
    "mikrotik"
    "minio"
    "modemmanager"
    "mongodb"
    "mysqld"
    "nextcloud"
    "nginx"
+68 −0
Original line number Diff line number Diff line
{ config, lib, pkgs, options }:

with lib;

let
  cfg = config.services.prometheus.exporters.mongodb;
in
{
  port = 9216;
  extraOpts = {
    uri = mkOption {
      type = types.str;
      default = "mongodb://localhost:27017/test";
      example = "mongodb://localhost:27017/test";
      description = lib.mdDoc "MongoDB URI to connect to.";
    };
    collStats = mkOption {
      type = types.listOf types.str;
      default = [ ];
      example = [ "db1.coll1" "db2" ];
      description = lib.mdDoc ''
        List of comma separared databases.collections to get $collStats
      '';
    };
    indexStats = mkOption {
      type = types.listOf types.str;
      default = [ ];
      example = [ "db1.coll1" "db2" ];
      description = lib.mdDoc ''
        List of comma separared databases.collections to get $indexStats
      '';
    };
    collector = mkOption {
      type = types.listOf types.str;
      default = [ ];
      example = [ "diagnosticdata" "replicasetstatus" "dbstats" "topmetrics" "currentopmetrics" "indexstats" "dbstats" "profile" ];
      description = lib.mdDoc "Enabled collectors";
    };
    collectAll = mkOption {
      type = types.bool;
      default = false;
      description = lib.mdDoc ''
        Enable all collectors. Same as specifying all --collector.<name>
      '';
    };
    telemetryPath = mkOption {
      type = types.str;
      default = "/metrics";
      example = "/metrics";
      description = lib.mdDoc "Metrics expose path";
    };
  };
  serviceOpts = {
    serviceConfig = {
      RuntimeDirectory = "prometheus-mongodb-exporter";
      ExecStart = ''
        ${getExe pkgs.prometheus-mongodb-exporter} \
          --mongodb.uri=${cfg.uri}
          ${if cfg.collectAll then "--collect-all" else concatMapStringsSep " " (x: "--collect.${x}") cfg.collector} \
          --collector.collstats=${concatStringsSep "," cfg.collStats} \
          --collector.indexstats=${concatStringsSep "," cfg.indexStats} \
          --web.listen-address=${cfg.listenAddress}:${toString cfg.port} \
          --web.telemetry-path=${cfg.telemetryPath} \
          ${escapeShellArgs cfg.extraFlags}
      '';
    };
  };
}
+39 −0
Original line number Diff line number Diff line
{ lib, buildGoModule, fetchFromGitHub }:

buildGoModule rec {
  pname = "mongodb_exporter";
  version = "0.39.0";

  src = fetchFromGitHub {
    owner = "percona";
    repo = "mongodb_exporter";
    rev = "v${version}";
    hash = "sha256-QII93sd/Lh+m6S5HtDsOt2BUnqg+X8I24KoU+MAWWQU=";
  };

  vendorHash = "sha256-khNkh2LufCE3KdPYRCALz66X+Q1U+sTIILh4uDzhKiI=";

  ldflags = [
    "-s"
    "-w"
    "-X main.version=${version}"
    "-X main.commit=${src.rev}"
    "-X main.Branch=unknown"
    "-X main.buildDate=unknown"
  ];

  subPackages = [ "." ];

  # those check depends on docker;
  # nixpkgs doesn't have mongodb application available;
  doCheck = false;

  meta = with lib;
    {
      description = "A Prometheus exporter for MongoDB including sharding, replication and storage engines";
      homepage = "https://github.com/percona/mongodb_exporter";
      license = licenses.asl20;
      maintainers = with maintainers; [ undefined-moe ];
      mainProgram = "mongodb_exporter";
    };
}
+1 −0
Original line number Diff line number Diff line
@@ -27167,6 +27167,7 @@ with pkgs;
  prometheus-mikrotik-exporter = callPackage ../servers/monitoring/prometheus/mikrotik-exporter.nix { };
  prometheus-minio-exporter = callPackage ../servers/monitoring/prometheus/minio-exporter { };
  prometheus-modemmanager-exporter = callPackage ../servers/monitoring/prometheus/modemmanager-exporter.nix { };
  prometheus-mongodb-exporter = callPackage ../servers/monitoring/prometheus/mongodb-exporter.nix { };
  prometheus-mysqld-exporter = callPackage ../servers/monitoring/prometheus/mysqld-exporter.nix { };
  prometheus-nats-exporter = callPackage ../servers/monitoring/prometheus/nats-exporter.nix { };
  prometheus-nextcloud-exporter = callPackage ../servers/monitoring/prometheus/nextcloud-exporter.nix { };