metrics.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package origin
  2. import (
  3. "github.com/cloudflare/cloudflared/connection"
  4. "github.com/prometheus/client_golang/prometheus"
  5. )
  6. // Metrics uses connection.MetricsNamespace(aka cloudflared) as namespace and connection.TunnelSubsystem
  7. // (tunnel) as subsystem to keep them consistent with the previous qualifier.
  8. var (
  9. totalRequests = prometheus.NewCounter(
  10. prometheus.CounterOpts{
  11. Namespace: connection.MetricsNamespace,
  12. Subsystem: connection.TunnelSubsystem,
  13. Name: "total_requests",
  14. Help: "Amount of requests proxied through all the tunnels",
  15. },
  16. )
  17. concurrentRequests = prometheus.NewGauge(
  18. prometheus.GaugeOpts{
  19. Namespace: connection.MetricsNamespace,
  20. Subsystem: connection.TunnelSubsystem,
  21. Name: "concurrent_requests_per_tunnel",
  22. Help: "Concurrent requests proxied through each tunnel",
  23. },
  24. )
  25. responseByCode = prometheus.NewCounterVec(
  26. prometheus.CounterOpts{
  27. Namespace: connection.MetricsNamespace,
  28. Subsystem: connection.TunnelSubsystem,
  29. Name: "response_by_code",
  30. Help: "Count of responses by HTTP status code",
  31. },
  32. []string{"status_code"},
  33. )
  34. requestErrors = prometheus.NewCounter(
  35. prometheus.CounterOpts{
  36. Namespace: connection.MetricsNamespace,
  37. Subsystem: connection.TunnelSubsystem,
  38. Name: "request_errors",
  39. Help: "Count of error proxying to origin",
  40. },
  41. )
  42. haConnections = prometheus.NewGauge(
  43. prometheus.GaugeOpts{
  44. Namespace: connection.MetricsNamespace,
  45. Subsystem: connection.TunnelSubsystem,
  46. Name: "ha_connections",
  47. Help: "Number of active ha connections",
  48. },
  49. )
  50. )
  51. func init() {
  52. prometheus.MustRegister(
  53. totalRequests,
  54. concurrentRequests,
  55. responseByCode,
  56. requestErrors,
  57. haConnections,
  58. )
  59. }
  60. func incrementRequests() {
  61. totalRequests.Inc()
  62. concurrentRequests.Inc()
  63. }
  64. func decrementConcurrentRequests() {
  65. concurrentRequests.Dec()
  66. }