59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
// known high signals, we will set these to zero after.
|
|
// key is uuid:role
|
|
knownHighSwitches = map[string]prometheus.Labels{} // tima was here
|
|
|
|
switchGauge *prometheus.GaugeVec = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
|
Namespace: "plapkit",
|
|
Name: "switches",
|
|
}, []string{"system", "member", "member_display"})
|
|
|
|
messageCounter *prometheus.CounterVec = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "plapkit",
|
|
Name: "messages",
|
|
}, []string{"system", "member", "member_display"})
|
|
)
|
|
|
|
func clearHighSwitches() {
|
|
for _, labels := range knownHighSwitches {
|
|
switchGauge.With(labels).Set(0)
|
|
}
|
|
}
|
|
|
|
func promCountSwitches(systemID string, members []*PluralKitMember) {
|
|
clearHighSwitches()
|
|
|
|
for idx, member := range members {
|
|
labels := prometheus.Labels{
|
|
"system": systemID,
|
|
"member": member.UUID,
|
|
"member_display": member.Name,
|
|
}
|
|
|
|
gv := 1.0
|
|
if idx != 0 {
|
|
gv = -1.0
|
|
}
|
|
switchGauge.With(labels).Set(gv)
|
|
knownHighSwitches[member.UUID] = labels
|
|
}
|
|
}
|
|
|
|
func promCountMessage(h HookPayload) {
|
|
member, ok := h.Data["member"].(map[string]interface{})
|
|
if !ok {
|
|
log.Println("[promCountMessage] failed to get member from data")
|
|
return
|
|
}
|
|
|
|
messageCounter.WithLabelValues(h.SystemID, member["uuid"].(string), member["name"].(string)).Inc()
|
|
}
|