Добавил обновление метрик (наверно)
This commit is contained in:
parent
d858e881e8
commit
583a9e9cdf
2 changed files with 17 additions and 5 deletions
1
go.mod
1
go.mod
|
@ -11,6 +11,7 @@ require gopkg.in/yaml.v3 v3.0.1
|
|||
require (
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/klauspost/compress v1.17.9 // indirect
|
||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.62.0 // indirect
|
||||
|
|
21
main.go
21
main.go
|
@ -6,6 +6,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"pleroma_stats_exporter/config"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
@ -58,16 +59,26 @@ func unmJson(jsonString string) map[string]any {
|
|||
return decodedJson
|
||||
}
|
||||
|
||||
func main() {
|
||||
confFile := config.UnmYamlConfig("config.yaml")
|
||||
|
||||
reg := prometheus.NewRegistry()
|
||||
instanceMetrics := SetMetricsOpts(reg)
|
||||
func updateMetrics(instanceMetrics *metrics, confFile config.InstanceVars) {
|
||||
instanceStat := unmJson(getJson("https://" + confFile.Target.Instance + "/api/v1/instance"))["stats"]
|
||||
instanceCount := instanceStat.(map[string]interface{})
|
||||
userFollowers := unmJson(getJson("https://" + confFile.Target.Instance + "/api/v1/accounts/" + confFile.Target.UserID))["followers_count"]
|
||||
instanceMetrics.InstancesCount.Set(instanceCount["domain_count"].(float64))
|
||||
instanceMetrics.FollowersCount.Set(userFollowers.(float64))
|
||||
}
|
||||
|
||||
func main() {
|
||||
confFile := config.UnmYamlConfig("config.yaml")
|
||||
|
||||
reg := prometheus.NewRegistry()
|
||||
instanceMetrics := SetMetricsOpts(reg)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
updateMetrics(instanceMetrics, confFile)
|
||||
time.Sleep(5 * time.Minute)
|
||||
}
|
||||
}()
|
||||
|
||||
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
|
||||
log.Fatal(http.ListenAndServe(confFile.Exporter.Listen+":"+confFile.Exporter.Port, nil))
|
||||
|
|
Loading…
Add table
Reference in a new issue