prometheus-idrac-exporter: init at unstable-2023-06-29

This commit is contained in:
codec 2023-07-25 03:26:35 +02:00
parent 15e852ae82
commit 47db2bfffb
6 changed files with 232 additions and 1 deletions

View file

@ -36,6 +36,7 @@ let
"fastly"
"fritzbox"
"graphite"
"idrac"
"influxdb"
"ipmi"
"json"
@ -318,6 +319,14 @@ in
message = ''
Scaphandre needs 'intel_rapl_common' kernel module to be enabled. Please add it in 'boot.kernelModules'.
'';
} {
assertion = cfg.idrac.enable -> (
(cfg.idrac.configurationPath == null) != (cfg.idrac.configuration == null)
);
message = ''
Please ensure you have either `services.prometheus.exporters.idrac.configuration'
or `services.prometheus.exporters.idrac.configurationPath' set!
'';
} ] ++ (flip map (attrNames exporterOpts) (exporter: {
assertion = cfg.${exporter}.firewallFilter != null -> cfg.${exporter}.openFirewall;
message = ''
@ -325,7 +334,12 @@ in
`openFirewall' is set to `true'!
'';
})) ++ config.services.prometheus.exporters.assertions;
warnings = config.services.prometheus.exporters.warnings;
warnings = [(mkIf (config.services.prometheus.exporters.idrac.enable && config.services.prometheus.exporters.idrac.configurationPath != null) ''
Configuration file in `services.prometheus.exporters.idrac.configurationPath` may override
`services.prometheus.exporters.idrac.listenAddress` and/or `services.prometheus.exporters.idrac.port`.
Consider using `services.prometheus.exporters.idrac.configuration` instead.
''
)] ++ config.services.prometheus.exporters.warnings;
}] ++ [(mkIf config.services.minio.enable {
services.prometheus.exporters.minio.minioAddress = mkDefault "http://localhost:9000";
services.prometheus.exporters.minio.minioAccessKey = mkDefault config.services.minio.accessKey;

View file

@ -0,0 +1,69 @@
{ config, lib, pkgs, options }:
with lib;
let
cfg = config.services.prometheus.exporters.idrac;
configFile = if cfg.configurationPath != null
then cfg.configurationPath
else pkgs.writeText "idrac.yml" (builtins.toJSON cfg.configuration);
in
{
port = 9348;
extraOpts = {
configurationPath = mkOption {
type = with types; nullOr path;
default = null;
example = "/etc/prometheus-idrac-exporter/idrac.yml";
description = lib.mdDoc ''
Path to the service's config file. This path can either be a computed path in /nix/store or a path in the local filesystem.
The config file should NOT be stored in /nix/store as it will contain passwords and/or keys in plain text.
Mutually exclusive with `configuration` option.
Configuration reference: https://github.com/mrlhansen/idrac_exporter/#configuration
'';
};
configuration = mkOption {
type = types.nullOr types.attrs;
description = lib.mdDoc ''
Configuration for iDRAC exporter, as a nix attribute set.
Configuration reference: https://github.com/mrlhansen/idrac_exporter/#configuration
Mutually exclusive with `configurationPath` option.
'';
default = null;
example = {
timeout = 10;
retries = 1;
hosts = {
default = {
username = "username";
password = "password";
};
};
metrics = {
system = true;
sensors = true;
power = true;
sel = true;
storage = true;
memory = true;
};
};
};
};
serviceOpts = {
serviceConfig = {
LoadCredential = "configFile:${configFile}";
ExecStart = "${pkgs.prometheus-idrac-exporter}/bin/idrac_exporter -config %d/configFile";
Environment = [
"IDRAC_EXPORTER_LISTEN_ADDRESS=${cfg.listenAddress}"
"IDRAC_EXPORTER_LISTEN_PORT=${toString cfg.port}"
];
};
};
}

View file

@ -307,6 +307,23 @@ let
'';
};
idrac = {
exporterConfig = {
enable = true;
port = 9348;
configuration = {
hosts = {
default = { username = "username"; password = "password"; };
};
};
};
exporterTest = ''
wait_for_unit("prometheus-idrac-exporter.service")
wait_for_open_port(9348)
wait_until_succeeds("curl localhost:9348")
'';
};
influxdb = {
exporterConfig = {
enable = true;

View file

@ -0,0 +1,30 @@
{ lib, buildGoModule, fetchFromGitHub, nixosTests }:
buildGoModule rec {
pname = "idrac_exporter";
version = "unstable-2023-06-29";
src = fetchFromGitHub {
owner = "mrlhansen";
repo = "idrac_exporter";
rev = "3b311e0e6d602fb0938267287f425f341fbf11da";
sha256 = "sha256-N8wSjQE25TCXg/+JTsvQk3fjTBgfXTiSGHwZWFDmFKc=";
};
vendorHash = "sha256-iNV4VrdQONq7LXwAc6AaUROHy8TmmloUAL8EmuPtF/o=";
patches = [ ./idrac-exporter/config-from-environment.patch ];
ldflags = [ "-s" "-w" ];
doCheck = true;
passthru.tests = { inherit (nixosTests.prometheus-exporters) idrac; };
meta = with lib; {
inherit (src.meta) homepage;
description = "Simple iDRAC exporter for Prometheus";
license = licenses.mit;
maintainers = with maintainers; [ codec ];
};
}

View file

@ -0,0 +1,100 @@
diff --git a/internal/config/config.go b/internal/config/config.go
index ba8f066..1c801cd 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -2,8 +2,11 @@ package config
import (
"encoding/base64"
+ "fmt"
"os"
+ "strconv"
"sync"
+
"github.com/mrlhansen/idrac_exporter/internal/logging"
"gopkg.in/yaml.v2"
)
@@ -17,9 +20,9 @@ type HostConfig struct {
type RootConfig struct {
mutex sync.Mutex
- Address string `yaml:"address"`
- Port uint `yaml:"port"`
- MetricsPrefix string `yaml:"metrics_prefix"`
+ Address string `yaml:"address"`
+ Port uint `yaml:"port"`
+ MetricsPrefix string `yaml:"metrics_prefix"`
Collect struct {
System bool `yaml:"system"`
Sensors bool `yaml:"sensors"`
@@ -28,9 +31,29 @@ type RootConfig struct {
Storage bool `yaml:"storage"`
Memory bool `yaml:"memory"`
} `yaml:"metrics"`
- Timeout uint `yaml:"timeout"`
- Retries uint `yaml:"retries"`
- Hosts map[string]*HostConfig `yaml:"hosts"`
+ Timeout uint `yaml:"timeout"`
+ Retries uint `yaml:"retries"`
+ Hosts map[string]*HostConfig `yaml:"hosts"`
+}
+
+func getEnv(envvar string, defvalue string) string {
+ value := os.Getenv(envvar)
+ if len(value) == 0 {
+ return defvalue
+ }
+ return value
+}
+
+func getEnvUint(envvar string, defvalue uint) uint {
+ value, err := strconv.Atoi(getEnv(envvar, fmt.Sprint(defvalue)))
+ if err != nil {
+ logging.Fatalf("Failed parse integer value: %s", err)
+ }
+ if value == 0 {
+ return defvalue
+ }
+
+ return uint(value)
}
func (config *RootConfig) GetHostCfg(target string) *HostConfig {
@@ -70,29 +93,29 @@ func ReadConfigFile(fileName string) {
}
if Config.Address == "" {
- Config.Address = "0.0.0.0"
+ Config.Address = getEnv("IDRAC_EXPORTER_LISTEN_ADDRESS", "0.0.0.0")
}
if Config.Port == 0 {
- Config.Port = 9348
+ Config.Port = getEnvUint("IDRAC_EXPORTER_LISTEN_PORT", 9348)
}
if Config.Timeout == 0 {
- Config.Timeout = 10
+ Config.Timeout = getEnvUint("IDRAC_EXPORTER_TIMEOUT", 10)
}
if Config.Retries == 0 {
- Config.Retries = 1
+ Config.Retries = getEnvUint("IDRAC_EXPORTER_RETRIES", 1)
+ }
+
+ if Config.MetricsPrefix == "" {
+ Config.MetricsPrefix = getEnv("IDRAC_EXPORTER_PREFIX", "idrac")
}
if len(Config.Hosts) == 0 {
parseError("missing section", "hosts")
}
- if Config.MetricsPrefix == "" {
- Config.MetricsPrefix = "idrac"
- }
-
for k, v := range Config.Hosts {
if v.Username == "" {
parseError("missing username for host", k)

View file

@ -26823,6 +26823,7 @@ with pkgs;
prometheus-gitlab-ci-pipelines-exporter = callPackage ../servers/monitoring/prometheus/gitlab-ci-pipelines-exporter.nix { };
prometheus-graphite-exporter = callPackage ../servers/monitoring/prometheus/graphite-exporter.nix { };
prometheus-haproxy-exporter = callPackage ../servers/monitoring/prometheus/haproxy-exporter.nix { };
prometheus-idrac-exporter = callPackage ../servers/monitoring/prometheus/idrac-exporter.nix { };
prometheus-influxdb-exporter = callPackage ../servers/monitoring/prometheus/influxdb-exporter.nix { };
prometheus-ipmi-exporter = callPackage ../servers/monitoring/prometheus/ipmi-exporter.nix { };
prometheus-jitsi-exporter = callPackage ../servers/monitoring/prometheus/jitsi-exporter.nix { };