Merge pull request 'prometheus' (#10) from prometheus into master
Reviewed-on: https://git.rz.ens.wtf/HackENS/hackens-org-configurations/pulls/10
This commit is contained in:
commit
63ee851b2d
5 changed files with 120 additions and 0 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
|
28
hosts/hackens-org/prometheus/default.nix
Normal file
28
hosts/hackens-org/prometheus/default.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{ pkgs, lib, config, ... }:
|
||||
{
|
||||
imports = [ ../modules/mqtt2prometheus ];
|
||||
networking.firewall.allowedTCPPorts = [ 9090 ];
|
||||
services = {
|
||||
prometheus = {
|
||||
enable = true;
|
||||
scrapeConfigs = [
|
||||
{
|
||||
job_name = "mqtt_listener";
|
||||
scrape_interval = "120s";
|
||||
static_configs = [
|
||||
{
|
||||
targets = [
|
||||
"localhost:9641"
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
mqtt2prometheus = {
|
||||
enable = true;
|
||||
package = pkgs.callPackage (import ./mqtt2prometheus.nix) { };
|
||||
config = ./config.yaml;
|
||||
};
|
||||
};
|
||||
}
|
15
hosts/hackens-org/prometheus/mqtt2prometheus.nix
Normal file
15
hosts/hackens-org/prometheus/mqtt2prometheus.nix
Normal file
|
@ -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
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue