From bae2d4a74d8b45074e8309314840979fe461d64d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Reinst=C3=A4dtler?= Date: Sun, 6 Jun 2021 20:26:08 +0200 Subject: [PATCH] add custom collector for mampf TODO: caching --- MONITORING.md | 8 ++++++-- docker/development/prometheus.yml | 24 ++++++++++++++++++++++++ lib/collectors/mampf_collector.rb | 25 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 docker/development/prometheus.yml create mode 100644 lib/collectors/mampf_collector.rb diff --git a/MONITORING.md b/MONITORING.md index 9477a5b4c..4d52ac8e7 100644 --- a/MONITORING.md +++ b/MONITORING.md @@ -3,7 +3,7 @@ ## Getting started (development mode): Setting up prometheus & grafana 0. Start prometheus_exporter in the mampf container -`sudo docker-compose exec mampf prometheus_exporter -b 0.0.0.0` +`sudo docker-compose exec mampf prometheus_exporter -b 0.0.0.0 -a lib/collectors/mampf_collector.rb ` 1. Setup prometheus in development ```sh @@ -27,4 +27,8 @@ grafana/grafana 3. Now visit localhost:2345 and configure the datasource (`prometheus:9090`) 4. Setup the dashboard, interisting metrics: - `rate(ruby_collector_sessions_total[5m])` - - `rate(ruby_http_requests_total[5m])` \ No newline at end of file + - `rate(ruby_http_requests_total[5m])` + - `ruby_user_count`: Number of users in the DB + - `ruby_uploaded_medium_count`: Number of Media + - `ruby_tag_count`: Number of Tags + - `ruby_submissions_count`: Number of Submissions diff --git a/docker/development/prometheus.yml b/docker/development/prometheus.yml new file mode 100644 index 000000000..8c83ab935 --- /dev/null +++ b/docker/development/prometheus.yml @@ -0,0 +1,24 @@ +global: + scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. + evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. + # scrape_timeout is set to the global default (10s). + +# Alertmanager configuration + +# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'mampf' + + # Override the global default and scrape targets from this job every 5 seconds. + scrape_interval: 5s + scrape_timeout: 5s + + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + + static_configs: + - targets: ['mampf:9394'] \ No newline at end of file diff --git a/lib/collectors/mampf_collector.rb b/lib/collectors/mampf_collector.rb new file mode 100644 index 000000000..544b9a023 --- /dev/null +++ b/lib/collectors/mampf_collector.rb @@ -0,0 +1,25 @@ +unless defined? Rails + require File.expand_path("../../../config/environment", __FILE__) +end +class MampfCollector < PrometheusExporter::Server::TypeCollector + def initialize + end + + def collect(obj) + end + def type + "mampf" + end + + def metrics + user_count_gauge = PrometheusExporter::Metric::Gauge.new('user_count', 'number of users in the app') + user_count_gauge.observe User.count + medium_count_gauge = PrometheusExporter::Metric::Gauge.new('uploaded_medium_count', 'number of media') + medium_count_gauge.observe Medium.count + tag_count_gauge = PrometheusExporter::Metric::Gauge.new('tag_count', 'number of tags') + tag_count_gauge.observe Tag.count + submissions_count_gauge = PrometheusExporter::Metric::Gauge.new('submissions_count', 'number of submissions') + submissions_count_gauge.observe Submission.count + [user_count_gauge, medium_count_gauge,tag_count_gauge, submissions_count_gauge] + end + end \ No newline at end of file