client_metric.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <cstdint>
  3. #include <string>
  4. #include <tuple>
  5. #include <vector>
  6. namespace prometheus {
  7. // ñòðóêòóðà, â êîòîðóþ êîïèðóþòñÿ çíà÷åíèÿ ìåòðèê ïåðåä èõ ñåðèàëèçàöèåé
  8. struct ClientMetric {
  9. // Label
  10. struct Label {
  11. std::string name;
  12. std::string value;
  13. Label(const std::string name_, const std::string value_) : name(name_), value(value_) {}
  14. bool operator<(const Label& rhs) const {
  15. return std::tie(name, value) < std::tie(rhs.name, rhs.value);
  16. }
  17. bool operator==(const Label& rhs) const {
  18. return std::tie(name, value) == std::tie(rhs.name, rhs.value);
  19. }
  20. };
  21. std::vector<Label> label;
  22. // Counter
  23. struct Counter {
  24. double value = 0.0;
  25. };
  26. Counter counter;
  27. // Gauge
  28. struct Gauge {
  29. double value = 0.0;
  30. };
  31. Gauge gauge;
  32. // Summary
  33. struct Quantile {
  34. double quantile = 0.0;
  35. double value = 0.0;
  36. };
  37. struct Summary {
  38. std::uint64_t sample_count = 0;
  39. double sample_sum = 0.0;
  40. std::vector<Quantile> quantile;
  41. };
  42. Summary summary;
  43. // Histogram
  44. struct Bucket {
  45. std::uint64_t cumulative_count = 0;
  46. double upper_bound = 0.0;
  47. };
  48. struct Histogram {
  49. std::uint64_t sample_count = 0;
  50. double sample_sum = 0.0;
  51. std::vector<Bucket> bucket;
  52. };
  53. Histogram histogram;
  54. // Untyped
  55. struct Untyped {
  56. double value = 0;
  57. };
  58. Untyped untyped;
  59. // Timestamp
  60. std::int64_t timestamp_ms = 0;
  61. };
  62. } // namespace prometheus