Metrics.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c)2013-2023 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2025-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. #include <prometheus/simpleapi.h>
  13. namespace prometheus {
  14. namespace simpleapi {
  15. std::shared_ptr<Registry> registry_ptr = std::make_shared<Registry>();
  16. Registry& registry = *registry_ptr;
  17. SaveToFile saver;
  18. }
  19. }
  20. namespace ZeroTier {
  21. namespace Metrics {
  22. // Packet Type Counts
  23. prometheus::simpleapi::counter_family_t packets
  24. { "zt_packet_incoming", "incoming packet type counts"};
  25. prometheus::simpleapi::counter_metric_t pkt_error
  26. { packets.Add({{"packet_type", "error"}}) };
  27. prometheus::simpleapi::counter_metric_t pkt_ack
  28. { packets.Add({{"packet_type", "ack"}}) };
  29. prometheus::simpleapi::counter_metric_t pkt_qos
  30. { packets.Add({{"packet_type", "qos"}}) };
  31. prometheus::simpleapi::counter_metric_t pkt_hello
  32. { packets.Add({{"packet_type", "hello"}}) };
  33. prometheus::simpleapi::counter_metric_t pkt_ok
  34. { packets.Add({{"packet_type", "ok"}}) };
  35. prometheus::simpleapi::counter_metric_t pkt_whois
  36. { packets.Add({{"packet_type", "whois"}}) };
  37. prometheus::simpleapi::counter_metric_t pkt_rendezvous
  38. { packets.Add({{"packet_type", "rendezvous"}}) };
  39. prometheus::simpleapi::counter_metric_t pkt_frame
  40. { packets.Add({{"packet_type", "frame"}}) };
  41. prometheus::simpleapi::counter_metric_t pkt_ext_frame
  42. { packets.Add({{"packet_type", "ext_frame"}}) };
  43. prometheus::simpleapi::counter_metric_t pkt_echo
  44. { packets.Add({{"packet_type", "echo"}}) };
  45. prometheus::simpleapi::counter_metric_t pkt_multicast_like
  46. { packets.Add({{"packet_type", "multicast_like"}}) };
  47. prometheus::simpleapi::counter_metric_t pkt_network_credentials
  48. { packets.Add({{"packet_type", "network_credentials"}}) };
  49. prometheus::simpleapi::counter_metric_t pkt_network_config_request
  50. { packets.Add({{"packet_type", "network_config_request"}}) };
  51. prometheus::simpleapi::counter_metric_t pkt_network_config
  52. { packets.Add({{"packet_type", "network_config"}}) };
  53. prometheus::simpleapi::counter_metric_t pkt_multicast_gather
  54. { packets.Add({{"packet_type", "multicast_gather"}}) };
  55. prometheus::simpleapi::counter_metric_t pkt_multicast_frame
  56. { packets.Add({{"packet_type", "multicast_frame"}}) };
  57. prometheus::simpleapi::counter_metric_t pkt_push_direct_paths
  58. { packets.Add({{"packet_type", "push_direct_paths"}}) };
  59. prometheus::simpleapi::counter_metric_t pkt_user_message
  60. { packets.Add({{"packet_type", "user_message"}}) };
  61. prometheus::simpleapi::counter_metric_t pkt_remote_trace
  62. { packets.Add({{"packet_type", "remote_trace"}}) };
  63. prometheus::simpleapi::counter_metric_t pkt_path_negotiation_request
  64. { packets.Add({{"packet_type", "path_negotiation_request"}}) };
  65. // Packet Error Counts
  66. prometheus::simpleapi::counter_family_t packet_errors
  67. { "zt_packet_incoming_error", "incoming packet errors"};
  68. prometheus::simpleapi::counter_metric_t pkt_error_obj_not_found
  69. { packet_errors.Add({{"error_type", "obj_not_found"}}) };
  70. prometheus::simpleapi::counter_metric_t pkt_error_unsupported_op
  71. { packet_errors.Add({{"error_type", "unsupported_operation"}}) };
  72. prometheus::simpleapi::counter_metric_t pkt_error_identity_collision
  73. { packet_errors.Add({{"error_type", "identity_collision"}}) };
  74. prometheus::simpleapi::counter_metric_t pkt_error_need_membership_cert
  75. { packet_errors.Add({{"error_type", "need_membership_certificate"}}) };
  76. prometheus::simpleapi::counter_metric_t pkt_error_network_access_denied
  77. { packet_errors.Add({{"error_type", "network_access_denied"}}) };
  78. prometheus::simpleapi::counter_metric_t pkt_error_unwanted_multicast
  79. { packet_errors.Add({{"error_type", "unwanted_multicast"}}) };
  80. prometheus::simpleapi::counter_metric_t pkt_error_authentication_required
  81. { packet_errors.Add({{"error_type", "authentication_required"}}) };
  82. // Data Sent/Received Metrics
  83. prometheus::simpleapi::counter_metric_t udp_send
  84. { "zt_udp_data_sent", "number of bytes ZeroTier has sent via UDP" };
  85. prometheus::simpleapi::counter_metric_t udp_recv
  86. { "zt_udp_data_recv", "number of bytes ZeroTier has received via UDP" };
  87. prometheus::simpleapi::counter_metric_t tcp_send
  88. { "zt_tcp_data_sent", "number of bytes ZeroTier has sent via TCP" };
  89. prometheus::simpleapi::counter_metric_t tcp_recv
  90. { "zt_tcp_data_recv", "number of bytes ZeroTier has received via TCP" };
  91. // General Controller Metrics
  92. prometheus::simpleapi::gauge_metric_t network_count
  93. {"controller_network_count", "number of networks the controller is serving"};
  94. prometheus::simpleapi::gauge_metric_t member_count
  95. {"controller_member_count", "number of network members the controller is serving"};
  96. prometheus::simpleapi::counter_metric_t network_changes
  97. {"controller_network_change_count", "number of times a network configuration is changed"};
  98. prometheus::simpleapi::counter_metric_t member_changes
  99. {"controller_member_change_count", "number of times a network member configuration is changed"};
  100. prometheus::simpleapi::counter_metric_t member_auths
  101. {"controller_member_auth_count", "number of network member auths"};
  102. prometheus::simpleapi::counter_metric_t member_deauths
  103. {"controller_member_deauth_count", "number of network member deauths"};
  104. #ifdef ZT_CONTROLLER_USE_LIBPQ
  105. // Central Controller Metrics
  106. prometheus::simpleapi::counter_metric_t pgsql_mem_notification
  107. { "controller_pgsql_member_notifications_received", "number of member change notifications received via pgsql NOTIFY" };
  108. prometheus::simpleapi::counter_metric_t pgsql_net_notification
  109. { "controller_pgsql_network_notifications_received", "number of network change notifications received via pgsql NOTIFY" };
  110. prometheus::simpleapi::counter_metric_t pgsql_node_checkin
  111. { "controller_pgsql_node_checkin_count", "number of node check-ins (pgsql)" };
  112. prometheus::simpleapi::counter_metric_t redis_mem_notification
  113. { "controller_redis_member_notifications_received", "number of member change notifications received via redis" };
  114. prometheus::simpleapi::counter_metric_t redis_net_notification
  115. { "controller_redis_network_notifications_received", "number of network change notifications received via redis" };
  116. prometheus::simpleapi::counter_metric_t redis_node_checkin
  117. { "controller_redis_node_checkin_count", "number of node check-ins (redis)" };
  118. // Central DB Pool Metrics
  119. prometheus::simpleapi::counter_metric_t conn_counter
  120. { "controller_pgsql_connections_created", "number of pgsql connections created"};
  121. prometheus::simpleapi::counter_metric_t max_pool_size
  122. { "controller_pgsql_max_conn_pool_size", "max connection pool size for postgres"};
  123. prometheus::simpleapi::counter_metric_t min_pool_size
  124. { "controller_pgsql_min_conn_pool_size", "minimum connection pool size for postgres" };
  125. prometheus::simpleapi::gauge_metric_t pool_avail
  126. { "controller_pgsql_available_conns", "number of available postgres connections" };
  127. prometheus::simpleapi::gauge_metric_t pool_in_use
  128. { "controller_pgsql_in_use_conns", "number of postgres database connections in use" };
  129. prometheus::simpleapi::counter_metric_t pool_errors
  130. { "controller_pgsql_connection_errors", "number of connection errors the connection pool has seen" };
  131. #endif
  132. }
  133. }