-
Notifications
You must be signed in to change notification settings - Fork 4
/
metrics.go
51 lines (44 loc) · 1.07 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
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
const namespace = "facebook_"
// Metrics implements the prometheus.Metrics interface and
// exposes gitea metrics for prometheus
type Metrics struct {
ReceiveCount *prometheus.Desc
SendCount *prometheus.Desc
}
// NewMetrics returns a new Metrics with all prometheus.Desc initialized
func NewMetrics() Metrics {
return Metrics{
ReceiveCount: prometheus.NewDesc(
namespace+"receive_count",
"Number of receive count",
nil, nil,
),
SendCount: prometheus.NewDesc(
namespace+"send_count",
"Number of send count",
nil, nil,
),
}
}
// Describe returns all possible prometheus.Desc
func (c Metrics) Describe(ch chan<- *prometheus.Desc) {
ch <- c.ReceiveCount
ch <- c.SendCount
}
// Collect returns the metrics with values
func (c Metrics) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.ReceiveCount,
prometheus.GaugeValue,
float64(ReceiveCount),
)
ch <- prometheus.MustNewConstMetric(
c.SendCount,
prometheus.GaugeValue,
float64(SendCount),
)
}