github.com/netdata/go.d.plugin@v0.58.1/pkg/prometheus/metric_family.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package prometheus
     4  
     5  import (
     6  	"github.com/prometheus/prometheus/model/labels"
     7  	"github.com/prometheus/prometheus/model/textparse"
     8  )
     9  
    10  type (
    11  	MetricFamilies map[string]*MetricFamily
    12  
    13  	MetricFamily struct {
    14  		name    string
    15  		help    string
    16  		typ     textparse.MetricType
    17  		metrics []Metric
    18  	}
    19  	Metric struct {
    20  		labels    []labels.Label
    21  		gauge     *Gauge
    22  		counter   *Counter
    23  		summary   *Summary
    24  		histogram *Histogram
    25  		untyped   *Untyped
    26  	}
    27  	Gauge struct {
    28  		value float64
    29  	}
    30  	Counter struct {
    31  		value float64
    32  	}
    33  	Summary struct {
    34  		sum       float64
    35  		count     float64
    36  		quantiles []Quantile
    37  	}
    38  	Quantile struct {
    39  		quantile float64
    40  		value    float64
    41  	}
    42  	Histogram struct {
    43  		sum     float64
    44  		count   float64
    45  		buckets []Bucket
    46  	}
    47  	Bucket struct {
    48  		upperBound      float64
    49  		cumulativeCount float64
    50  	}
    51  	Untyped struct {
    52  		value float64
    53  	}
    54  )
    55  
    56  func (mfs MetricFamilies) Len() int {
    57  	return len(mfs)
    58  }
    59  
    60  func (mfs MetricFamilies) Get(name string) *MetricFamily {
    61  	return (mfs)[name]
    62  }
    63  
    64  func (mfs MetricFamilies) GetGauge(name string) *MetricFamily {
    65  	return mfs.get(name, textparse.MetricTypeGauge)
    66  }
    67  
    68  func (mfs MetricFamilies) GetCounter(name string) *MetricFamily {
    69  	return mfs.get(name, textparse.MetricTypeCounter)
    70  }
    71  
    72  func (mfs MetricFamilies) GetSummary(name string) *MetricFamily {
    73  	return mfs.get(name, textparse.MetricTypeSummary)
    74  }
    75  
    76  func (mfs MetricFamilies) GetHistogram(name string) *MetricFamily {
    77  	return mfs.get(name, textparse.MetricTypeHistogram)
    78  }
    79  
    80  func (mfs MetricFamilies) get(name string, typ textparse.MetricType) *MetricFamily {
    81  	mf := mfs.Get(name)
    82  	if mf == nil || mf.typ != typ {
    83  		return nil
    84  	}
    85  	return mf
    86  }
    87  
    88  func (mf *MetricFamily) Name() string               { return mf.name }
    89  func (mf *MetricFamily) Help() string               { return mf.help }
    90  func (mf *MetricFamily) Type() textparse.MetricType { return mf.typ }
    91  func (mf *MetricFamily) Metrics() []Metric          { return mf.metrics }
    92  
    93  func (m *Metric) Labels() labels.Labels { return m.labels }
    94  func (m *Metric) Gauge() *Gauge         { return m.gauge }
    95  func (m *Metric) Counter() *Counter     { return m.counter }
    96  func (m *Metric) Summary() *Summary     { return m.summary }
    97  func (m *Metric) Histogram() *Histogram { return m.histogram }
    98  func (m *Metric) Untyped() *Untyped     { return m.untyped }
    99  
   100  func (g Gauge) Value() float64   { return g.value }
   101  func (c Counter) Value() float64 { return c.value }
   102  func (u Untyped) Value() float64 { return u.value }
   103  
   104  func (s Summary) Count() float64        { return s.count }
   105  func (s Summary) Sum() float64          { return s.sum }
   106  func (s Summary) Quantiles() []Quantile { return s.quantiles }
   107  
   108  func (q Quantile) Quantile() float64 { return q.quantile }
   109  func (q Quantile) Value() float64    { return q.value }
   110  
   111  func (h Histogram) Count() float64    { return h.count }
   112  func (h Histogram) Sum() float64      { return h.sum }
   113  func (h Histogram) Buckets() []Bucket { return h.buckets }
   114  
   115  func (b Bucket) UpperBound() float64      { return b.upperBound }
   116  func (b Bucket) CumulativeCount() float64 { return b.cumulativeCount }