app-exporter/apps/metrics.go

66 lines
2.6 KiB
Go
Raw Normal View History

2024-10-31 20:42:28 +01:00
package apps
import (
"github.com/prometheus/client_golang/prometheus"
)
type Metrics struct {
Cubebackup prometheus.GaugeVec
Forgejo prometheus.GaugeVec
ForgejoRunner prometheus.GaugeVec
Grafana prometheus.GaugeVec
2024-11-15 14:20:05 +01:00
Minio prometheus.GaugeVec
2024-10-31 20:42:28 +01:00
Nextcloud prometheus.GaugeVec
Odoo prometheus.GaugeVec
Postgres prometheus.GaugeVec
Vaultwarden prometheus.GaugeVec
2024-11-15 16:47:30 +01:00
Version prometheus.GaugeVec
2024-10-31 20:42:28 +01:00
}
func NewMetrics(reg prometheus.Registerer) *Metrics {
metrics := &Metrics{
Cubebackup: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "cubebackup", Help: ""}, []string{"version"}),
Forgejo: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "forgejo", Help: ""}, []string{"version"}),
ForgejoRunner: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "forgejo_runner", Help: ""}, []string{"version"}),
Grafana: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "grafana", Help: ""}, []string{"version"}),
2024-11-15 14:20:05 +01:00
Minio: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "minio", Help: ""}, []string{"version"}),
2024-10-31 20:42:28 +01:00
Nextcloud: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "nextcloud", Help: ""}, []string{"version"}),
Odoo: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "odoo", Help: ""}, []string{"version", "version_date"}),
Postgres: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "postgres", Help: ""}, []string{"version"}),
Vaultwarden: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "app", Subsystem: "version", Name: "vaultwarden", Help: ""}, []string{"version"}),
2024-11-15 16:47:30 +01:00
Version: *prometheus.NewGaugeVec(prometheus.GaugeOpts{Namespace: "appexporter", Name: "version", Help: "The version of this exporter"}, []string{"version"}),
2024-10-31 20:42:28 +01:00
}
reg.MustRegister(
metrics.Cubebackup,
metrics.Forgejo,
metrics.ForgejoRunner,
metrics.Grafana,
2024-11-15 14:20:05 +01:00
metrics.Minio,
2024-10-31 20:42:28 +01:00
metrics.Nextcloud,
metrics.Odoo,
metrics.Postgres,
metrics.Vaultwarden,
2024-11-15 16:47:30 +01:00
metrics.Version,
2024-10-31 20:42:28 +01:00
)
return metrics
}
// Reset all metrics
//
2024-11-15 16:47:30 +01:00
// Reset all except app-exporter version
//
2024-10-31 20:42:28 +01:00
// This should be called on every loop iteration.
func (m *Metrics) Reset() {
m.Cubebackup.Reset()
m.Forgejo.Reset()
m.ForgejoRunner.Reset()
m.Grafana.Reset()
2024-11-15 14:20:05 +01:00
m.Minio.Reset()
2024-10-31 20:42:28 +01:00
m.Nextcloud.Reset()
m.Odoo.Reset()
m.Postgres.Reset()
m.Vaultwarden.Reset()
}