prom.go 802 B

1234567891011121314151617181920212223242526272829
  1. package utils
  2. import (
  3. "fmt"
  4. "github.com/710leo/urlooker/dataobj"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/prometheus/client_golang/prometheus/push"
  7. )
  8. func PushPromethues(addr string, itemsChecked []*dataobj.CheckResult, ip string) {
  9. addr = "http://" + addr
  10. for _, itemChecked := range itemsChecked {
  11. completionTime := prometheus.NewGauge(prometheus.GaugeOpts{
  12. Name: "urlooker_api_status",
  13. })
  14. completionTime.SetToCurrentTime()
  15. completionTime.Set(float64(itemChecked.Status))
  16. if err := push.New(addr, "urlooker").
  17. Collector(completionTime).
  18. Grouping("domain", itemChecked.Domain).
  19. Grouping("creator", itemChecked.Creator).
  20. Grouping("from", ip).
  21. Push(); err != nil {
  22. fmt.Println("Could not push completion time to Pushgateway:", err)
  23. }
  24. }
  25. }