2024-04-07 02:07:26 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
ginprometheus "github.com/zsais/go-gin-prometheus"
|
|
|
|
ormMetric "gorm.io/plugin/prometheus"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
GaugeDomainCounts = prometheus.NewGauge(prometheus.GaugeOpts{
|
|
|
|
Namespace: "recoredui",
|
|
|
|
Subsystem: "domains",
|
|
|
|
Name: "count",
|
|
|
|
Help: "domains managed in reCoreD-UI",
|
|
|
|
})
|
|
|
|
|
|
|
|
GaugeRecordCounts = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
|
|
Namespace: "recoredui",
|
|
|
|
Subsystem: "records",
|
|
|
|
Name: "count",
|
|
|
|
Help: "records managed in reCoreD-UI, by domain",
|
|
|
|
}, []string{"domain"})
|
|
|
|
)
|
|
|
|
|
2024-04-09 08:28:18 +00:00
|
|
|
func RegisterMetrics() {
|
2024-04-07 02:07:26 +00:00
|
|
|
prometheus.MustRegister(GaugeDomainCounts, GaugeRecordCounts)
|
|
|
|
|
|
|
|
GormMetrics := ormMetric.New(ormMetric.Config{
|
|
|
|
DBName: "recored-ui",
|
|
|
|
MetricsCollector: []ormMetric.MetricsCollector{
|
|
|
|
&ormMetric.MySQL{
|
|
|
|
VariableNames: []string{"Threads_running"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}).Collectors
|
|
|
|
prometheus.MustRegister(GormMetrics...)
|
|
|
|
|
|
|
|
GinMetrics := ginprometheus.NewPrometheus("recoredui")
|
|
|
|
for _, v := range GinMetrics.MetricsList {
|
|
|
|
prometheus.MustRegister(v.MetricCollector)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-09 08:28:18 +00:00
|
|
|
func RefreshMetrics() error {
|
|
|
|
domainCounts, err := getDomainCounts()
|
2024-04-07 02:07:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
GaugeDomainCounts.Set(domainCounts)
|
|
|
|
|
2024-04-09 08:28:18 +00:00
|
|
|
recordCounts, err := getRecordCounts()
|
2024-04-07 02:07:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for domain, counts := range recordCounts {
|
|
|
|
GaugeRecordCounts.WithLabelValues(domain).Set(counts)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|