summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/pkg/prometheus/metric_family.go
blob: dde08801eae5c74d7aa5f21112de0af9d5878598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: GPL-3.0-or-later

package prometheus

import (
	"github.com/prometheus/common/model"
	"github.com/prometheus/prometheus/model/labels"
)

type (
	MetricFamilies map[string]*MetricFamily

	MetricFamily struct {
		name    string
		help    string
		typ     model.MetricType
		metrics []Metric
	}
	Metric struct {
		labels    []labels.Label
		gauge     *Gauge
		counter   *Counter
		summary   *Summary
		histogram *Histogram
		untyped   *Untyped
	}
	Gauge struct {
		value float64
	}
	Counter struct {
		value float64
	}
	Summary struct {
		sum       float64
		count     float64
		quantiles []Quantile
	}
	Quantile struct {
		quantile float64
		value    float64
	}
	Histogram struct {
		sum     float64
		count   float64
		buckets []Bucket
	}
	Bucket struct {
		upperBound      float64
		cumulativeCount float64
	}
	Untyped struct {
		value float64
	}
)

func (mfs MetricFamilies) Len() int {
	return len(mfs)
}

func (mfs MetricFamilies) Get(name string) *MetricFamily {
	return (mfs)[name]
}

func (mfs MetricFamilies) GetGauge(name string) *MetricFamily {
	return mfs.get(name, model.MetricTypeGauge)
}

func (mfs MetricFamilies) GetCounter(name string) *MetricFamily {
	return mfs.get(name, model.MetricTypeCounter)
}

func (mfs MetricFamilies) GetSummary(name string) *MetricFamily {
	return mfs.get(name, model.MetricTypeSummary)
}

func (mfs MetricFamilies) GetHistogram(name string) *MetricFamily {
	return mfs.get(name, model.MetricTypeHistogram)
}

func (mfs MetricFamilies) get(name string, typ model.MetricType) *MetricFamily {
	mf := mfs.Get(name)
	if mf == nil || mf.typ != typ {
		return nil
	}
	return mf
}

func (mf *MetricFamily) Name() string           { return mf.name }
func (mf *MetricFamily) Help() string           { return mf.help }
func (mf *MetricFamily) Type() model.MetricType { return mf.typ }
func (mf *MetricFamily) Metrics() []Metric      { return mf.metrics }

func (m *Metric) Labels() labels.Labels { return m.labels }
func (m *Metric) Gauge() *Gauge         { return m.gauge }
func (m *Metric) Counter() *Counter     { return m.counter }
func (m *Metric) Summary() *Summary     { return m.summary }
func (m *Metric) Histogram() *Histogram { return m.histogram }
func (m *Metric) Untyped() *Untyped     { return m.untyped }

func (g Gauge) Value() float64   { return g.value }
func (c Counter) Value() float64 { return c.value }
func (u Untyped) Value() float64 { return u.value }

func (s Summary) Count() float64        { return s.count }
func (s Summary) Sum() float64          { return s.sum }
func (s Summary) Quantiles() []Quantile { return s.quantiles }

func (q Quantile) Quantile() float64 { return q.quantile }
func (q Quantile) Value() float64    { return q.value }

func (h Histogram) Count() float64    { return h.count }
func (h Histogram) Sum() float64      { return h.sum }
func (h Histogram) Buckets() []Bucket { return h.buckets }

func (b Bucket) UpperBound() float64      { return b.upperBound }
func (b Bucket) CumulativeCount() float64 { return b.cumulativeCount }