prometheus-borg-exporter/metrics.go

58 lines
3 KiB
Go

package main
import (
"github.com/prometheus/client_golang/prometheus"
)
type Metrics struct {
ArchiveCount prometheus.GaugeVec
LastArchiveTime prometheus.GaugeVec
LastModified prometheus.GaugeVec
TotalChunks prometheus.GaugeVec
TotalCsize prometheus.GaugeVec
TotalSize prometheus.GaugeVec
TotalUniqueChunks prometheus.GaugeVec
UniqueCsize prometheus.GaugeVec
UniqueSize prometheus.GaugeVec
}
func NewMetrics(reg prometheus.Registerer) *Metrics {
metrics := &Metrics{
ArchiveCount: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "archive_count", Help: "Number of archive for this repository"}, []string{"repo_name"}),
LastArchiveTime: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "last_archive", Help: "UNIX timestamp of the last archive"}, []string{"repo_name"}),
LastModified: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "last_modified", Help: "Last modified UNIX timestamp"}, []string{"repo_name"}),
TotalChunks: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "total_chunks", Help: "Number of chunks"}, []string{"repo_name"}),
TotalCsize: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "total_csize", Help: "Total compressed and encrypted size of all chunks"}, []string{"repo_name"}),
TotalSize: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "total_size", Help: "Total uncompressed size of all chunks"}, []string{"repo_name"}),
TotalUniqueChunks: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "total_unique_chunks", Help: "Number of unique chunks"}, []string{"repo_name"}),
UniqueCsize: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "unique_csize", Help: "Compressed and encrypted size of all chunks"}, []string{"repo_name"}),
UniqueSize: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "borg", Subsystem: "repository", Name: "unique_size", Help: "Uncompressed size of all chunks"}, []string{"repo_name"}),
}
reg.MustRegister(metrics.ArchiveCount)
reg.MustRegister(metrics.LastArchiveTime)
reg.MustRegister(metrics.LastModified)
reg.MustRegister(metrics.TotalChunks)
reg.MustRegister(metrics.TotalCsize)
reg.MustRegister(metrics.TotalSize)
reg.MustRegister(metrics.TotalUniqueChunks)
reg.MustRegister(metrics.UniqueCsize)
reg.MustRegister(metrics.UniqueSize)
return metrics
}
// Reset all metrics
//
// This should be called on every loop iteration.
func (m *Metrics) Reset() {
m.ArchiveCount.Reset()
m.LastArchiveTime.Reset()
m.LastModified.Reset()
m.TotalChunks.Reset()
m.TotalCsize.Reset()
m.TotalSize.Reset()
m.TotalUniqueChunks.Reset()
m.UniqueCsize.Reset()
m.UniqueSize.Reset()
}