-
Notifications
You must be signed in to change notification settings - Fork 325
/
metrics.go
56 lines (45 loc) · 1.49 KB
/
metrics.go
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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package exporter
import (
"io"
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/prometheus/client_golang/prometheus"
)
var (
eventsExportedTotal = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Name: "events_exported_total",
Help: "Total number of events exported",
})
eventsExportedBytesTotal = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Name: "events_exported_bytes_total",
Help: "Number of bytes exported for events",
})
eventsExportTimestamp = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: consts.MetricsNamespace,
Name: "events_last_exported_timestamp",
Help: "Timestamp of the most recent event to be exported",
})
)
func InitMetrics(registry *prometheus.Registry) {
registry.MustRegister(eventsExportedTotal)
registry.MustRegister(eventsExportedBytesTotal)
registry.MustRegister(eventsExportTimestamp)
}
func newExportedBytesCounterWriter(w io.Writer, c prometheus.Counter) io.Writer {
return byteCounterWriter{Writer: w, bytesWritten: c}
}
type byteCounterWriter struct {
io.Writer
bytesWritten prometheus.Counter
}
func (w byteCounterWriter) Write(p []byte) (int, error) {
n, err := w.Writer.Write(p)
w.bytesWritten.Add(float64(n))
return n, err
}
func NewExportedBytesTotalWriter(w io.Writer) io.Writer {
return newExportedBytesCounterWriter(w, eventsExportedBytesTotal)
}