Unverified Commit ed22fbec authored by K900's avatar K900 Committed by GitHub
Browse files

pgscv: init package + module (#386064)

parents 4b65b859 80b437df
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -962,6 +962,7 @@
  ./services/monitoring/opentelemetry-collector.nix
  ./services/monitoring/osquery.nix
  ./services/monitoring/parsedmarc.nix
  ./services/monitoring/pgscv.nix
  ./services/monitoring/prometheus/alertmanager-gotify-bridge.nix
  ./services/monitoring/prometheus/alertmanager-irc-relay.nix
  ./services/monitoring/prometheus/alertmanager-webhook-logger.nix
+75 −0
Original line number Diff line number Diff line
{
  config,
  lib,
  pkgs,
  utils,
  ...
}:

let
  inherit (lib)
    mkEnableOption
    mkIf
    mkOption
    mkPackageOption
    types
    ;

  cfg = config.services.pgscv;

  settingsFormat = pkgs.formats.yaml { };
  configFile = settingsFormat.generate "config.yaml" cfg.settings;
in
{
  options.services.pgscv = {
    enable = mkEnableOption "pgSCV, a PostgreSQL ecosystem metrics collector";

    package = mkPackageOption pkgs "pgscv" { };

    logLevel = mkOption {
      type = types.enum [
        "debug"
        "info"
        "warn"
        "error"
      ];
      default = "info";
      description = "Log level for pgSCV.";
    };

    settings = mkOption {
      type = settingsFormat.type;
      default = { };
      description = ''
        Configuration for pgSCV, in YAML format.

        See [configuration reference](https://github.com/cherts/pgscv/wiki/Configuration-settings-reference).
      '';
    };
  };

  config = mkIf cfg.enable {
    systemd.services.pgscv = {
      description = "pgSCV - PostgreSQL ecosystem metrics collector";
      wantedBy = [ "multi-user.target" ];
      requires = [ "network-online.target" ];
      after = [ "network-online.target" ];
      path = [ pkgs.glibc ]; # shells out to getconf

      serviceConfig = {
        User = "postgres";
        Group = "postgres";
        ExecStart = utils.escapeSystemdExecArgs [
          (lib.getExe cfg.package)
          "--log-level=${cfg.logLevel}"
          "--config-file=${configFile}"
        ];
        KillMode = "control-group";
        TimeoutSec = 5;
        Restart = "on-failure";
        RestartSec = 10;
        OOMScoreAdjust = 1000;
      };
    };
  };
}
+43 −0
Original line number Diff line number Diff line
{
  lib,
  buildGoModule,
  fetchFromGitHub,
}:

buildGoModule rec {
  pname = "pgscv";
  version = "0.13.0";

  src = fetchFromGitHub {
    owner = "CHERTS";
    repo = "pgscv";
    tag = "v${version}";
    hash = "sha256-6qhJZHyVtEI4+pqi0dgagDC2RaISV9g/ygrezJO57Sk=";
  };

  vendorHash = "sha256-KahDpLwk+6KXaIfvjr7+nkFuEV4Dw3pyshkJ5XUEdUg=";

  ldflags = [
    "-X=main.appName=pgscv"
    "-X=main.gitTag=${src.tag}"
    "-X=main.gitCommit=${src.tag}"
    "-X=main.gitBranch=${src.tag}"
  ];

  # tests rely on a pretty complex Postgres setup
  doCheck = false;

  postInstall = ''
    mv $out/bin/{cmd,pgscv}
  '';

  meta = {
    description = "PgSCV is a PostgreSQL ecosystem metrics collector";
    homepage = "https://github.com/CHERTS/pgscv/";
    changelog = "https://github.com/CHERTS/pgscv/releases/${version}";
    license = lib.licenses.bsd3;
    platforms = lib.platforms.linux;
    maintainers = with lib.maintainers; [ k900 ];
    mainProgram = "pgscv";
  };
}