lib/vmpooler/metrics/promstats.rb
def add_prometheus_metric(metric_spec, name, docstring)
        case metric_spec[:mtype]
        when M_COUNTER
          metric_class = Prometheus::Client::Counter
        when M_GAUGE
          metric_class = Prometheus::Client::Gauge
        when M_SUMMARY
          metric_class = Prometheus::Client::Summary
        when M_HISTOGRAM
          metric_class = Prometheus::Client::Histogram
        else
          raise("Unable to register metric #{name} with metric type #{metric_spec[:mtype]}")
        end

        if (metric_spec[:mtype] == M_HISTOGRAM) && (metric_spec.key? :buckets)
          prom_metric = metric_class.new(
            name.to_sym,
            docstring: docstring,
            labels: metric_spec[:param_labels] + [:vmpooler_instance],
            buckets: metric_spec[:buckets],
            preset_labels: { vmpooler_instance: @prefix }
          )
        else
          prom_metric = metric_class.new(
            name.to_sym,
            docstring: docstring,
            labels: metric_spec[:param_labels] + [:vmpooler_instance],
            preset_labels: { vmpooler_instance: @prefix }
          )
        end
        @prometheus.register(prom_metric)
      end
# Helper to add individual prom metric.
# Allow Histograms to specify the bucket size.
Helper to add individual prom metric.
Allow Histograms to specify the bucket size.
Helper to add individual prom metric . Allow Histograms to specify the bucket size .
def add_prometheus_metric(metric_spec, name, docstring)
        case metric_spec[:mtype]
        when M_COUNTER
          metric_class = Prometheus::Client::Counter
        when M_GAUGE
          metric_class = Prometheus::Client::Gauge
        when M_SUMMARY
          metric_class = Prometheus::Client::Summary
        when M_HISTOGRAM
          metric_class = Prometheus::Client::Histogram
        else
          raise("Unable to register metric #{name} with metric type #{metric_spec[:mtype]}")
        end
        if (metric_spec[:mtype] == M_HISTOGRAM) && (metric_spec.key? :buckets)
          prom_metric = metric_class.new(
            name.to_sym,
            docstring: docstring,
            labels: metric_spec[:param_labels] + [:vmpooler_instance],
            buckets: metric_spec[:buckets],
            preset_labels: { vmpooler_instance: @prefix }
          )
        else
          prom_metric = metric_class.new(
            name.to_sym,
            docstring: docstring,
            labels: metric_spec[:param_labels] + [:vmpooler_instance],
            preset_labels: { vmpooler_instance: @prefix }
          )
        end
        @prometheus.register(prom_metric)
      end
def add_prometheus_metric ( metric_spec , name , docstring ) case metric_spec [ :mtype ] when M_COUNTER metric_class = Prometheus :: Client :: Counter when M_GAUGE metric_class = Prometheus :: Client :: Gauge when M_SUMMARY metric_class = Prometheus :: Client :: Summary when M_HISTOGRAM metric_class = Prometheus :: Client :: Histogram else raise ( "Unable to register metric #{name} with metric type #{metric_spec[:mtype]}" ) end if ( metric_spec [ :mtype ] == M_HISTOGRAM ) && ( metric_spec . key? :buckets ) prom_metric = metric_class . new ( name . to_sym , docstring : docstring , labels : metric_spec [ :param_labels ] + [ :vmpooler_instance ] , buckets : metric_spec [ :buckets ] , preset_labels : { vmpooler_instance : @prefix } ) else prom_metric = metric_class . new ( name . to_sym , docstring : docstring , labels : metric_spec [ :param_labels ] + [ :vmpooler_instance ] , preset_labels : { vmpooler_instance : @prefix } ) end @prometheus . register ( prom_metric ) end
Helper to add individual prom metric.
Helper to add individual prom metric .
metric_spec
name
docstring