From 25d8f4f28473cc4a2afa1a87b99441894fce64bf Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Wed, 30 Oct 2024 10:17:24 +0100 Subject: [PATCH 1/2] mod_prometheus: use 'declare' rather than 'new' for histogram and counter (#339) If a node crashes metrics might already be defined in prometheus and thus 'new' would crash. --- mod_prometheus/src/mod_prometheus.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod_prometheus/src/mod_prometheus.erl b/mod_prometheus/src/mod_prometheus.erl index 2e7f879b..03dab6cf 100644 --- a/mod_prometheus/src/mod_prometheus.erl +++ b/mod_prometheus/src/mod_prometheus.erl @@ -352,7 +352,7 @@ handle_histogram(Name, HName, HistogramOpts, Host, Action, State) -> InitArg = State#{name => HName, labels => LabelNames}, case Action of subscribe -> - prometheus_histogram:new( + prometheus_histogram:declare( [ {name, HName}, {buckets, maps:get(buckets, HistogramOpts, [1, 10, 100, 500, 750, 1000, 3000, 5000])}, @@ -377,7 +377,7 @@ handle_counter(Name, HName, CounterOpts, Host, Action, State) -> InitArg = State#{name => HName, labels => LabelNames}, case Action of subscribe -> - prometheus_counter:new( + prometheus_counter:declare( [{name, HName}, {help, maps:get(help, CounterOpts, "No help")}, {labels, LabelNames}] ), ?INFO_MSG("Created new Prometheus counter for ~p with labels ~p", [HName, LabelNames]), @@ -441,4 +441,4 @@ find_stanza_type([Arg | Args]) when is_tuple(Arg) -> find_stanza_type([_ | Args]) -> find_stanza_type(Args); find_stanza_type([]) -> - unknown. \ No newline at end of file + unknown. From 769dbf0f9459c90923c1115cef3a57527516e8b3 Mon Sep 17 00:00:00 2001 From: Stefan Strigler Date: Mon, 4 Nov 2024 08:18:33 +0000 Subject: [PATCH 2/2] don't loose data of docker containers --- mod_prometheus/example/docker-compose.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mod_prometheus/example/docker-compose.yml b/mod_prometheus/example/docker-compose.yml index afaf5ccc..47d5c728 100644 --- a/mod_prometheus/example/docker-compose.yml +++ b/mod_prometheus/example/docker-compose.yml @@ -3,17 +3,25 @@ version: '3.7' services: prometheus: - network_mode: "host" image: docker.io/prom/prometheus container_name: prometheus ports: - "9090:9090" volumes: + - prometheus-data:/prometheus - ./prometheus.yml:/etc/prometheus/prometheus.yml + restart: always grafana: - network_mode: "host" image: docker.io/grafana/grafana-enterprise container_name: grafana ports: - "3000:3000" + volumes: + - grafana-data:/var/lib/grafana + - ./grafana_defaults.ini:/usr/share/grafana/conf/defaults.ini + restart: always + +volumes: + prometheus-data: + grafana-data: