rename metrics to match prometheus official naming conventions (#184)

rename metrics to match prometheus official naming conventions (#184)

  • Raise an error if the gauge metric name has _total suffix
  • rename metrics to match prometheus official naming conventions
  • documentation for renaming metrics to match prometheus official naming convention
  • add the prefix for resque metric names that were not described in README.md
  • rename metrics to match prometheus official naming conventions
  • add missing unicorn collector test
  • rename metrics to match prometheus official naming conventions
  • add missing tests for sidekiq que
diff --git a/CHANGELOG b/CHANGELOG
index 2f0eac6..0ed44d0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+1.0.0 - dd-mm-yyyy
+
+- Breaking change: rename metrics to match prometheus official naming conventions (See https://prometheus.io/docs/practices/naming/#metric-names)
+
 0.8.1 - 04-08-2021
 
 - FEATURE: swap from hardcoded STDERR to logger pattern (see README for details)
diff --git a/README.md b/README.md
index 69a1b32..6b032e5 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@ Prometheus Exporter allows you to aggregate custom metrics from multiple process
 To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/archive/2018/02/02/instrumenting-rails-with-prometheus) (it has pretty pictures!)
 
 * [Requirements](#requirements)
+* [Migrating from v0.x](#migrating-from-v0.x)
 * [Installation](#installation)
 * [Usage](#usage)
   * [Single process mode](#single-process-mode)
@@ -37,6 +38,12 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
 
 Minimum Ruby of version 2.5.0 is required, Ruby 2.4.0 is EOL as of 2020-04-05
 
+## Migrating from v0.x
+
+There are some major changes in v1.x from v0.x.
+
+- Some of metrics are renamed to match [prometheus official guide for metric names](https://prometheus.io/docs/practices/naming/#metric-names). (#184)
+
 ## Installation
 
 Add this line to your application's Gemfile:
@@ -425,7 +432,7 @@ This metric has a `job_name` label and a `queue` label.
 **PrometheusExporter::Instrumentation::SidekiqQueue**
 | Type  | Name                            | Description                  |
 | ---   | ---                             | ---                          |
-| Gauge | `sidekiq_queue_backlog_total`   | Size of the sidekiq queue    |
+| Gauge | `sidekiq_queue_backlog`         | Size of the sidekiq queue    |
 | Gauge | `sidekiq_queue_latency_seconds` | Latency of the sidekiq queue |
 
 Both metrics will have a `queue` label with the name of the queue.
@@ -529,15 +536,15 @@ end
 
 #### Metrics collected by Puma Instrumentation
 
-| Type  | Name                              | Description                                                 |
-| ---   | ---                               | ---                                                         |
-| Gauge | `puma_workers_total`              | Number of puma workers                                      |
-| Gauge | `puma_booted_workers_total`       | Number of puma workers booted                               |
-| Gauge | `puma_old_workers_total`          | Number of old puma workers                                  |
-| Gauge | `puma_running_threads_total`      | Number of puma threads currently running                    |
-| Gauge | `puma_request_backlog_total`      | Number of requests waiting to be processed by a puma thread |
-| Gauge | `puma_thread_pool_capacity_total` | Number of puma threads available at current scale           |
-| Gauge | `puma_max_threads_total`          | Number of puma threads at available at max scale            |
+| Type  | Name                        | Description                                                 |
+| ---   | ---                         | ---                                                         |
+| Gauge | `puma_workers`              | Number of puma workers                                      |
+| Gauge | `puma_booted_workers`       | Number of puma workers booted                               |
+| Gauge | `puma_old_workers`          | Number of old puma workers                                  |
+| Gauge | `puma_running_threads`      | Number of puma threads currently running                    |
+| Gauge | `puma_request_backlog`      | Number of requests waiting to be processed by a puma thread |
+| Gauge | `puma_thread_pool_capacity` | Number of puma threads available at current scale           |
+| Gauge | `puma_max_threads`          | Number of puma threads at available at max scale            |
 
 All metrics may have a `phase` label and all custom labels provided with the `labels` option.
 
@@ -554,14 +561,14 @@ PrometheusExporter::Instrumentation::Resque.start
 
 #### Metrics collected by Resque Instrumentation
 
-| Type  | Name                   | Description                            |
-| ---   | ---                    | ---                                    |
-| Gauge | `processed_jobs_total` | Total number of processed Resque jobs  |
-| Gauge | `failed_jobs_total`    | Total number of failed Resque jobs     |
-| Gauge | `pending_jobs_total`   | Total number of pending Resque jobs    |
-| Gauge | `queues_total`         | Total number of Resque queues          |
-| Gauge | `workers_total`        | Total number of Resque workers running |
-| Gauge | `working_total`        | Total number of Resque workers working |
+| Type  | Name                    | Description                            |
+| ---   | ---                     | ---                                    |
+| Gauge | `resque_processed_jobs` | Total number of processed Resque jobs  |
+| Gauge | `resque_failed_jobs`    | Total number of failed Resque jobs     |
+| Gauge | `resque_pending_jobs`   | Total number of pending Resque jobs    |
+| Gauge | `resque_queues`         | Total number of Resque queues          |
+| Gauge | `resque_workers`        | Total number of Resque workers running |
+| Gauge | `resque_working`        | Total number of Resque workers working |
 
 ### Unicorn process metrics
 
@@ -580,11 +587,11 @@ Note: You must install the `raindrops` gem in your `Gemfile` or locally.
 
 #### Metrics collected by Unicorn Instrumentation
 
-| Type  | Name                            | Description                                                    |
-| ---   | ---                             | ---                                                            |
-| Gauge | `unicorn_workers_total`         | Number of unicorn workers                                      |
-| Gauge | `unicorn_active_workers_total`  | Number of active unicorn workers                               |
-| Gauge | `unicorn_request_backlog_total` | Number of requests waiting to be processed by a unicorn worker |
+| Type  | Name                      | Description                                                    |
+| ---   | ---                       | ---                                                            |
+| Gauge | `unicorn_workers`         | Number of unicorn workers                                      |
+| Gauge | `unicorn_active_workers`  | Number of active unicorn workers                               |
+| Gauge | `unicorn_request_backlog` | Number of requests waiting to be processed by a unicorn worker |
 
 ### Custom type collectors
 
diff --git a/lib/prometheus_exporter/instrumentation/puma.rb b/lib/prometheus_exporter/instrumentation/puma.rb
index ede1d0d..ffecbba 100644
--- a/lib/prometheus_exporter/instrumentation/puma.rb
+++ b/lib/prometheus_exporter/instrumentation/puma.rb
@@ -46,9 +46,9 @@ module PrometheusExporter::Instrumentation
 
       if stats.key?("workers")
         metric[:phase] = stats["phase"]
-        metric[:workers_total] = stats["workers"]
-        metric[:booted_workers_total] = stats["booted_workers"]
-        metric[:old_workers_total] = stats["old_workers"]
+        metric[:workers] = stats["workers"]
+        metric[:booted_workers] = stats["booted_workers"]
+        metric[:old_workers] = stats["old_workers"]
 
         stats["worker_status"].each do |worker|
           next if worker["last_status"].empty?
@@ -62,15 +62,15 @@ module PrometheusExporter::Instrumentation
     private
 
     def collect_worker_status(metric, status)
-      metric[:request_backlog_total] ||= 0
-      metric[:running_threads_total] ||= 0
-      metric[:thread_pool_capacity_total] ||= 0
-      metric[:max_threads_total] ||= 0
+      metric[:request_backlog] ||= 0
+      metric[:running_threads] ||= 0
+      metric[:thread_pool_capacity] ||= 0
+      metric[:max_threads] ||= 0
 

[... diff too long, it was truncated ...]

GitHub sha: b3400567945731aecc6e54445ff1a6a29041bf30

This commit appears in #184 which was merged by SamSaffron.