Skip to content
Snippets Groups Projects
megacli2prom.nix 1.51 KiB
Newer Older
  • Learn to ignore specific revisions
  • # MegaCli to Prometheus text format exporter
    #
    # Scope: Gets data from MegaRAID compatible storage controllers and mogrifies
    #        to Prometheus text format, saves to a temp file, to later be scraped
    #        by the node exporter.
    # 
    # Usage: Import this to every server with a MegaRAID card that you want to
    #        include in the central monitoring system
    #
    # See https://nixos.org/manual/nixos/stable/#module-services-prometheus-exporters
    
    { config, lib, ourpkgs }:
    
    let
      cfg = config.services.private-storage.monitoring.megacli2prom;
    
    in {
      options.services.private-storage.monitoring.megacli2prom = {
        enable = lib.mkEnableOption "MegaCli2Prom metrics gathering service";
        outFile = lib.mkOption {
          type = lib.types.path;
          description = "Where to store the temporary file for node exporter to scrape?";
          default = /run/prometheus-node-exporter/megacli.prom
        };
        interval = lib.mkOption {
          type = lib.types.str;
          description = ''
            How often to do it?
            See https://www.freedesktop.org/software/systemd/man/systemd.time.html#Calendar%20Events
          '';
          default = "hourly";
        };
      };
    
      config =
        lib.mkIf cfg.enable {
    
          environment.systemPackages = [ ourpkgs.megacli2prom ];
    
          systemd.services.megacli2prom = {
            enable = true;
            description = "MegaCli2Prom metrics gathering service";
            wantedBy = [ "multi-user.target" ];
            startAt = cfg.interval;
            script = "${ourpkgs.megacli2prom}/bin/megacli2prom > ${cfg.outFile}";
          };
      };
    }