Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

services.prometheus: refactor to modular prometheus exporters #73

Open
milahu opened this issue Aug 26, 2024 · 1 comment
Open

services.prometheus: refactor to modular prometheus exporters #73

milahu opened this issue Aug 26, 2024 · 1 comment

Comments

@milahu
Copy link
Owner

milahu commented Aug 26, 2024

currently im trying to add services.prometheus.exporters.qbittorrent
to fix Package request: prometheus-qbittorrent-exporter

actual

this requires
adding nixos/modules/services/monitoring/prometheus/exporters/qbittorrent.nix
patching nixos/modules/services/monitoring/prometheus/exporters.nix
disabling the module services/monitoring/prometheus/default.nix
importing prometheus/default.nix from the patched nixpkgs

{ config, pkgs, lib, modulesPath, inputs, ... }:

{
  # override nixos modules
  # https://stackoverflow.com/a/46407944/10440128
  # see also: nixos/modules/module-list.nix
  disabledModules = [

    # no. error: The option `services.prometheus.exporters.qbittorrent' does not exist.
    # override services.prometheus
    #"services/monitoring/prometheus/default.nix"

    # override services.prometheus.exporters
    "services/monitoring/prometheus/exporters.nix"
  ];

  imports = [
    ./hardware-configuration.nix

    # no. error: The option `services.prometheus.exporters.qbittorrent' does not exist.
    # override services.prometheus
    #./modules/services/monitoring/prometheus/default.nix

    # override services.prometheus.exporters
    ./modules/services/monitoring/prometheus/exporters.nix
  ];

expected

ideally this should work without patching prometheus/exporters.nix
only by adding prometheus/exporters/qbittorrent.nix to imports

/etc/nixos/configuration.nix

{ config, pkgs, lib, modulesPath, inputs, ... }:

{
  imports = [
    ./hardware-configuration.nix

    # TODO implement modular prometheus exporters
    # add services.prometheus.exporters.qbittorrent
    ./modules/services/monitoring/prometheus/exporters/qbittorrent.nix
  ];

  services.grafana = {
    enable = true;
    declarativePlugins = with pkgs.grafanaPlugins; [
      grafana-piechart-panel # for prometheus-qbittorrent-exporter
    ];
    settings = {
      # ...
    };
  };

  services.prometheus = {
    enable = true;
    port = 9001;
    # /var/lib/prometheus2/
    #retentionTime = "15d"; # default -> 80 MB
    retentionTime = "740d"; # 2 years -> 4 GB
    exporters = {
      node = {
        enable = true;
        enabledCollectors = [ "systemd" ];
        port = 9002;
      };
      qbittorrent = {
        enable = true;
        port = 9003;
        qbittorrentPort = 1952;
        package = pkgs.nur.repos.milahu.prometheus-qbittorrent-exporter;
      };
    };
    scrapeConfigs = [
      {
        job_name = "chrysalis";
        static_configs = [{
          targets = [
            "127.0.0.1:${toString config.services.prometheus.exporters.node.port}"
            "127.0.0.1:${toString config.services.prometheus.exporters.qbittorrent.port}"
          ];
        }];
      }
    ];
  };

possible solution

add a mkPrometheusExporter function
so prometheus/exporters/qbittorrent.nix looks like

{ lib
, mkPrometheusExporter
}:

mkPrometheusExporter {
  name = "qbittorrent";
  # ...
}

probably this would require
adding all prometheus exporters to nixos/modules/module-list.nix

keywords

  • decentralization of nixpkgs
  • modularization of nixpkgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@milahu and others