tetragon

Форк
0
/
bpfmetric.go 
47 строк · 1.3 Кб
1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright Authors of Tetragon
3

4
package metrics
5

6
import "github.com/prometheus/client_golang/prometheus"
7

8
// BPFMetric represents a metric read directly from a BPF map.
9
// It's intended to be used in custom collectors. The interface doesn't provide
10
// any validation, so it's up to the collector implementer to guarantee the
11
// metrics consistency.
12
type BPFMetric interface {
13
	Desc() *prometheus.Desc
14
	MustMetric(value float64, labelValues ...string) prometheus.Metric
15
}
16

17
type bpfCounter struct {
18
	desc *prometheus.Desc
19
}
20

21
func NewBPFCounter(desc *prometheus.Desc) BPFMetric {
22
	return &bpfCounter{desc: desc}
23
}
24

25
func (c *bpfCounter) Desc() *prometheus.Desc {
26
	return c.desc
27
}
28

29
func (c *bpfCounter) MustMetric(value float64, labelValues ...string) prometheus.Metric {
30
	return prometheus.MustNewConstMetric(c.desc, prometheus.CounterValue, value, labelValues...)
31
}
32

33
type bpfGauge struct {
34
	desc *prometheus.Desc
35
}
36

37
func NewBPFGauge(desc *prometheus.Desc) BPFMetric {
38
	return &bpfGauge{desc: desc}
39
}
40

41
func (g *bpfGauge) Desc() *prometheus.Desc {
42
	return g.desc
43
}
44

45
func (g *bpfGauge) MustMetric(value float64, labelValues ...string) prometheus.Metric {
46
	return prometheus.MustNewConstMetric(g.desc, prometheus.GaugeValue, value, labelValues...)
47
}
48

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.