Skip to content

Commit

Permalink
add options for prometheus exporter ports
Browse files Browse the repository at this point in the history
  • Loading branch information
brainrake committed Oct 28, 2024
1 parent 8321c02 commit 7762b9d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
24 changes: 11 additions & 13 deletions modules/monitoring.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ in {
ports = mkOption {
type = with types; listOf port;
default = [
config.cardano.node.prometheusExporter.port
config.cardano.oura.prometheusExporter.port
config.services.blockfrost.settings.server.port
config.services.cardano-db-sync.explorerConfig.PrometheusPort
config.services.ogmios.port
config.services.prometheus.exporters.node.port
config.services.prometheus.exporters.nginx.port
config.services.prometheus.exporters.postgres.port
12798 # cardano-node
9186 # oura
];
description = ''
List of ports where prometheus exporters are exposed. This can be used to open ports in the firewall.
Expand Down Expand Up @@ -66,7 +66,7 @@ in {
}
{
job_name = "cardano-node";
static_configs = [{targets = map (target: "${target}:12798") cfg.targets;}];
static_configs = [{targets = map (target: "${target}:${builtins.toString config.cardano.node.prometheusExporter.port}") cfg.targets;}];
}
{
job_name = "kupo";
Expand All @@ -87,7 +87,7 @@ in {
}
{
job_name = "oura";
static_configs = [{targets = map (target: "${target}:9186") cfg.targets;}];
static_configs = [{targets = map (target: "${target}:${builtins.toString config.cardano.oura.prometheusExporter.port}") cfg.targets;}];
}
{
job_name = "postgres";
Expand Down Expand Up @@ -149,20 +149,18 @@ in {
};
})
(mkIf cfg.exporters.enable {
cardano.node.prometheusExporter.enable = true;
cardano.oura.prometheusExporter.enable = true;

services.blockfrost = mkIf config.services.bockfrost.enable or false {
settings.server.prometheusMetrics = true;
};

services.prometheus.exporters = {
node.enable = true;
nginx.enable = config.services.nginx.enable;
postgres.enable = config.services.postgresql.enable;
};
services.cardano-node = mkIf config.services.cardano-node.enable {
extraNodeConfig.hasPrometheus = ["0.0.0.0" 12798];
};
services.blockfrost = mkIf config.services.bockfrost.enable or false {
settings.server.prometheusMetrics = true;
};
services.oura.settings = mkIf config.services.oura.enable or false {
metrics.address = "0.0.0.0:9186";
};
})
(mkIf cfg.exporters.openFirewall {
networking.firewall.allowedTCPPorts = cfg.exporters.ports;
Expand Down
13 changes: 13 additions & 0 deletions modules/node.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ in {
type = lib.types.path;
default = "/etc/cardano-node/config.json";
};

prometheusExporter.enable =
lib.mkEnableOption "prometheus exporter";

prometheusExporter.port = lib.mkOption {
description = "Port where Prometheus exporter is exposed.";
type = lib.types.port;
default = 12798;
};
};

config = lib.mkIf cfg.enable {
Expand All @@ -44,6 +53,10 @@ in {
inherit (cfg) socketPath;
environment = config.cardano.network;

extraNodeConfig = lib.mkIf cfg.prometheusExporter.enable {
hasPrometheus = ["0.0.0.0" config.cardano.node.prometheusExporter.port];
};

# Listen on all interfaces.
hostAddr = lib.mkDefault "0.0.0.0";

Expand Down
15 changes: 12 additions & 3 deletions modules/oura.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ in {
enable =
lib.mkEnableOption "Oura"
// {default = config.cardano.enable or false;};

integrate =
lib.mkEnableOption ''
connect oura to local cardano-node via N2C
''
lib.mkEnableOption ''connect oura to local cardano-node via N2C''
// {default = config.cardano.node.enable or false;};

prometheusExporter.enable =
lib.mkEnableOption "prometheus exporter";

prometheusExporter.port = lib.mkOption {
description = "Port where Prometheus exporter is exposed.";
type = lib.types.port;
default = 9186;
};
};

config = lib.mkIf cfg.enable {
Expand All @@ -25,6 +33,7 @@ in {
address = ["Unix" config.cardano.node.socketPath];
magic = config.cardano.network;
};
metrics.address = lib.mkIf cfg.prometheusExporter.enable "0.0.0.0:${builtins.toString cfg.prometheusExporter.port}";
};
};

Expand Down

0 comments on commit 7762b9d

Please sign in to comment.