You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
2.0 KiB

  1. package metrics
  2. import (
  3. "github.com/prometheus/client_golang/prometheus"
  4. )
  5. // Status is the status of a measurable metric (incoming commands, outgoing polls, etc)
  6. type Status string
  7. // Common status values
  8. const (
  9. StatusSuccess = "success"
  10. StatusFailure = "failure"
  11. )
  12. var (
  13. cmdCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
  14. Name: "goneb_pling_cmd_total",
  15. Help: "The number of incoming commands from matrix clients",
  16. }, []string{"cmd", "status"})
  17. configureServicesCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
  18. Name: "goneb_configure_services_total",
  19. Help: "The total number of configured services requests",
  20. }, []string{"service_type"})
  21. webhookCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
  22. Name: "goneb_webhook_total",
  23. Help: "The total number of recognised incoming webhook requests",
  24. }, []string{"service_type"})
  25. authSessionCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
  26. Name: "goneb_auth_session_total",
  27. Help: "The total number of successful /requestAuthSession requests",
  28. }, []string{"realm_type"})
  29. )
  30. // IncrementCommand increments the pling command counter
  31. func IncrementCommand(cmdName string, st Status) {
  32. cmdCounter.With(prometheus.Labels{"cmd": cmdName, "status": string(st)}).Inc()
  33. }
  34. // IncrementConfigureService increments the /configureService counter
  35. func IncrementConfigureService(serviceType string) {
  36. configureServicesCounter.With(prometheus.Labels{"service_type": serviceType}).Inc()
  37. }
  38. // IncrementWebhook increments the incoming webhook request counter
  39. func IncrementWebhook(serviceType string) {
  40. webhookCounter.With(prometheus.Labels{"service_type": serviceType}).Inc()
  41. }
  42. // IncrementAuthSession increments the /requestAuthSession request counter
  43. func IncrementAuthSession(realmType string) {
  44. authSessionCounter.With(prometheus.Labels{"realm_type": realmType}).Inc()
  45. }
  46. func init() {
  47. prometheus.MustRegister(cmdCounter)
  48. prometheus.MustRegister(configureServicesCounter)
  49. prometheus.MustRegister(webhookCounter)
  50. prometheus.MustRegister(authSessionCounter)
  51. }