-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmetrics.go
79 lines (74 loc) · 2.46 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
)
func (b *backup) startMetricsServer() {
b.backupsTotal = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "backup",
Name: "backups_all_total",
Help: "The total number of backups attempted, including failures.",
})
b.backupsSuccessful = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "backup",
Name: "backups_successful_total",
Help: "The total number of backups that succeeded.",
})
b.backupsFailed = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "backup",
Name: "backups_failed_total",
Help: "The total number of backups that failed.",
})
b.backupDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_duration_milliseconds",
Help: "The duration of backups in milliseconds.",
})
b.filesNew = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_files_new",
Help: "Amount of new files.",
})
b.filesChanged = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_files_changed",
Help: "Amount of files with changes.",
})
b.filesUnmodified = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_files_unmodified",
Help: "Amount of files unmodified since last backup.",
})
b.filesProcessed = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_files_processed",
Help: "Total number of files scanned by the backup for changes.",
})
b.bytesAdded = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_added_bytes",
Help: "Total number of bytes added to the repository.",
})
b.bytesProcessed = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "backup",
Name: "backup_processed_bytes",
Help: "Total number of bytes scanned by the backup for changes",
})
prometheus.MustRegister(
b.backupsTotal,
b.backupsSuccessful,
b.backupsFailed,
b.backupDuration,
b.filesNew,
b.filesChanged,
b.filesUnmodified,
b.filesProcessed,
b.bytesAdded,
b.bytesProcessed,
)
http.Handle(b.PrometheusEndpoint, promhttp.Handler())
err := http.ListenAndServe(b.PrometheusAddress, nil)
logger.Fatal("metrics server closed", zap.Error(err))
}