Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

prometheus.go 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package stats
  2. import (
  3. "time"
  4. "github.com/juju/errors"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/9seconds/mtg/config"
  7. )
  8. const prometheusPollTime = time.Second
  9. type prometheusExporter struct {
  10. connections *prometheus.GaugeVec
  11. traffic *prometheus.GaugeVec
  12. speed *prometheus.GaugeVec
  13. crashes prometheus.Gauge
  14. }
  15. func (p *prometheusExporter) run() {
  16. for range time.Tick(prometheusPollTime) {
  17. instance := GetStats()
  18. p.connections.WithLabelValues("abridged", "v4").Set(float64(instance.Connections.Abridged.IPv4))
  19. p.connections.WithLabelValues("abridged", "v6").Set(float64(instance.Connections.Abridged.IPv6))
  20. p.connections.WithLabelValues("intermediate", "v4").Set(float64(instance.Connections.Intermediate.IPv4))
  21. p.connections.WithLabelValues("intermediate", "v6").Set(float64(instance.Connections.Intermediate.IPv6))
  22. p.connections.WithLabelValues("secure", "v4").Set(float64(instance.Connections.Secure.IPv4))
  23. p.connections.WithLabelValues("secure", "v6").Set(float64(instance.Connections.Secure.IPv6))
  24. p.traffic.WithLabelValues("ingress").Set(float64(instance.Traffic.ingress))
  25. p.traffic.WithLabelValues("egress").Set(float64(instance.Traffic.egress))
  26. p.speed.WithLabelValues("ingress").Set(float64(instance.Speed.ingress))
  27. p.speed.WithLabelValues("egress").Set(float64(instance.Speed.egress))
  28. p.crashes.Set(float64(instance.Crashes))
  29. }
  30. }
  31. func newPrometheus(conf *config.Config) (*prometheusExporter, error) {
  32. connections := prometheus.NewGaugeVec(prometheus.GaugeOpts{
  33. Namespace: conf.Prometheus.Prefix,
  34. Name: "connections",
  35. Help: "Current number of connections to the proxy.",
  36. }, []string{"type", "protocol"})
  37. traffic := prometheus.NewGaugeVec(prometheus.GaugeOpts{
  38. Namespace: conf.Prometheus.Prefix,
  39. Name: "traffic",
  40. Help: "Traffic passed through the proxy in bytes.",
  41. }, []string{"direction"})
  42. speed := prometheus.NewGaugeVec(prometheus.GaugeOpts{
  43. Namespace: conf.Prometheus.Prefix,
  44. Name: "speed",
  45. Help: "Current throughput in bytes per second.",
  46. }, []string{"direction"})
  47. crashes := prometheus.NewGauge(prometheus.GaugeOpts{
  48. Namespace: conf.Prometheus.Prefix,
  49. Name: "crashes",
  50. Help: "How many crashes happened.",
  51. })
  52. if err := prometheus.Register(connections); err != nil {
  53. return nil, errors.Annotate(err, "Cannot register connections collector")
  54. }
  55. if err := prometheus.Register(traffic); err != nil {
  56. return nil, errors.Annotate(err, "cannot register traffic collector")
  57. }
  58. if err := prometheus.Register(speed); err != nil {
  59. return nil, errors.Annotate(err, "cannot register speed collector")
  60. }
  61. if err := prometheus.Register(crashes); err != nil {
  62. return nil, errors.Annotate(err, "cannot register crashes collector")
  63. }
  64. return &prometheusExporter{
  65. connections: connections,
  66. traffic: traffic,
  67. speed: speed,
  68. crashes: crashes,
  69. }, nil
  70. }