discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
528 stars 155 forks source link

Custom quantile for pre-defined metrics, example #134

Open mvasilenko opened 3 years ago

mvasilenko commented 3 years ago

Hi,

I'm trying to add custom quantile for pre-defined metrics the code:

on_worker_boot do
   ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
  if ENV.fetch('PROMETHEUS_ENABLED', 'false') == 'true'
    require 'prometheus_exporter/client'
    require 'prometheus_exporter/metric'
    require 'prometheus_exporter/instrumentation'

    client = PrometheusExporter::Client.new(host: 'localhost', port:9394)
    PrometheusExporter::Client.default = client

    PrometheusExporter::Instrumentation::Process.start(type: 'puma_worker')

    PrometheusExporter::Instrumentation::ActiveRecord.start(
        custom_labels: { type: 'active_record' },
        config_labels: [:database, :host]
    )
  end
end

In the README there are examples for custom metrics - https://github.com/discourse/prometheus_exporter/blob/master/README.md#custom-quantiles-and-buckets

How can I add quantiles for pre-defined metrics, like response time, i.e. override this constant and add 95 percentile:

DEFAULT_QUANTILES = [0.99, 0.9, 0.5, 0.1, 0.01]

Thank you

SamSaffron commented 3 years ago

Changing the default is not cleanly overridable, you would have to redefine the constant. Open to a PR here that makes changing defaults cleaner.