prometheus
This commit is contained in:
parent
c30492cfde
commit
ab6a7352a1
5 changed files with 93 additions and 8 deletions
39
hosts/hackens-org/modules/mqtt2prometheus/default.nix
Normal file
39
hosts/hackens-org/modules/mqtt2prometheus/default.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.mqtt2prometheus;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.services.mqtt2prometheus = {
|
||||||
|
enable = lib.mkEnableOption "Enable mqtt2Prometheus";
|
||||||
|
package = lib.mkOption {
|
||||||
|
type = lib.types.package;
|
||||||
|
description = "Which mqtt2prometheus package to use";
|
||||||
|
};
|
||||||
|
listenAddress = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "127.0.0.1";
|
||||||
|
description = "listen address for HTTP server used to expose metrics";
|
||||||
|
};
|
||||||
|
listenPort = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 9641;
|
||||||
|
description = "HTTP port used to expose metrics";
|
||||||
|
};
|
||||||
|
config = lib.mkOption { # à nixifier
|
||||||
|
type = lib.types.path;
|
||||||
|
description = "Path to config file";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
systemd.services."mqtt2prometheus" = {
|
||||||
|
enable = true;
|
||||||
|
description = "MQTT client which exposes metrics for prometheus monitoring software";
|
||||||
|
after = [ "network.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart = "${cfg.package}/bin/mqtt2prometheus -config ${cfg.config} -listen-address ${cfg.listenAddress} -listen-port ${toString cfg.listenPort}";
|
||||||
|
Restart = "always";
|
||||||
|
};
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
{ pkgs, ... }:
|
||||||
|
pkgs.buildGoModule rec {
|
||||||
|
pname = "mqtt2prometheus";
|
||||||
|
version = "0.1.6";
|
||||||
|
src = pkgs.fetchFromGitHub {
|
||||||
|
owner = "hikhvar";
|
||||||
|
repo = "mqtt2prometheus";
|
||||||
|
rev = "v${version}";
|
||||||
|
sha256 = "0dz5mrwm231g45i8rbmvaza8bm6cr4jg5vc87h41vnm7xsx815g7";
|
||||||
|
};
|
||||||
|
vendorSha256 = "1fyzij7cakhd6x2hf3rvvslvvxmfmlp881x5rz2qwm04spa18cp4";
|
||||||
|
postInstall = ''
|
||||||
|
mv $out/bin/cmd $out/bin/mqtt2prometheus
|
||||||
|
'';
|
||||||
|
}
|
23
hosts/hackens-org/prometheus/config.yaml
Normal file
23
hosts/hackens-org/prometheus/config.yaml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
mqtt:
|
||||||
|
# The MQTT broker to connect to
|
||||||
|
server: tcp://new.hackens.org:1883
|
||||||
|
# The Topic path to subscribe to. Be aware that you have to specify the wildcard, if you want to follow topics for multiple sensors.
|
||||||
|
topic_path: kfet/open
|
||||||
|
# The MQTT QoS level
|
||||||
|
qos: 0
|
||||||
|
metric_per_topic_config:
|
||||||
|
metric_name_regex: "(?P<deviceid>.*)/(?P<metricname>.*)"
|
||||||
|
cache:
|
||||||
|
# Timeout. Each received metric will be presented for this time if no update is send via MQTT.
|
||||||
|
# Set the timeout to -1 to disable the deletion of metrics from the cache. The exporter presents the ingest timestamp
|
||||||
|
# to prometheus.
|
||||||
|
timeout: 24h
|
||||||
|
metrics:
|
||||||
|
# The name of the metric in prometheus
|
||||||
|
- prom_name: keft_open
|
||||||
|
# The name of the metric in a MQTT JSON message
|
||||||
|
mqtt_name: open
|
||||||
|
# The prometheus help text for this metric
|
||||||
|
help: K-Fêt opening state
|
||||||
|
# The prometheus type for this metric. Valid values are: "gauge" and "counter"
|
||||||
|
type: gauge
|
|
@ -1,23 +1,28 @@
|
||||||
{ pkgs, lib, config, ... }:
|
{ pkgs, lib, config, ... }:
|
||||||
{
|
{
|
||||||
networking.firewall.allowedTCPPorts = [ 9090 # prometheus ];
|
imports = [ ../modules/mqtt2prometheus ];
|
||||||
|
networking.firewall.allowedTCPPorts = [ 9090 ];
|
||||||
services = {
|
services = {
|
||||||
prometheus = {
|
prometheus = {
|
||||||
enable = true;
|
enable = true;
|
||||||
scrapeConfigs = [
|
scrapeConfigs = [
|
||||||
{
|
{
|
||||||
job_name = "node";
|
job_name = "mqtt_listener";
|
||||||
scrape_interval = "10s";
|
scrape_interval = "120s";
|
||||||
static_configs = [
|
static_configs = [
|
||||||
{
|
{
|
||||||
targets = [
|
targets = [
|
||||||
"localhost:9100"
|
"localhost:9641"
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
mqtt2prometheus = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.callPackage (import ./mqtt2prometheus.nix) { };
|
||||||
|
config = ./config.yaml;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
pkgs.buildGoModule {
|
pkgs.buildGoModule rec {
|
||||||
pname = "mqtt2prometheus";
|
pname = "mqtt2prometheus";
|
||||||
version = "0.1.6";
|
version = "0.1.6";
|
||||||
src = pkgs.fetchFromGithub {
|
src = pkgs.fetchFromGitHub {
|
||||||
owner = "hikhvar";
|
owner = "hikhvar";
|
||||||
repo = "mqtt2prometheus";
|
repo = "mqtt2prometheus";
|
||||||
rev = "v${version}";
|
rev = "v${version}";
|
||||||
sha256 = "0dz5mrwm231g45i8rbmvaza8bm6cr4jg5vc87h41vnm7xsx815g7";
|
sha256 = "0dz5mrwm231g45i8rbmvaza8bm6cr4jg5vc87h41vnm7xsx815g7";
|
||||||
};
|
};
|
||||||
vendorSha256 = "";
|
vendorSha256 = "1fyzij7cakhd6x2hf3rvvslvvxmfmlp881x5rz2qwm04spa18cp4";
|
||||||
|
postInstall = ''
|
||||||
|
mv $out/bin/cmd $out/bin/mqtt2prometheus
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue