dynamic_counters_wrapper.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include <library/cpp/monlib/dynamic_counters/counters.h>
  3. namespace NUnifiedAgent {
  4. class TDynamicCountersWrapper: public TAtomicRefCount<TDynamicCountersWrapper> {
  5. public:
  6. explicit TDynamicCountersWrapper(const TIntrusivePtr<NMonitoring::TDynamicCounters>& counters)
  7. : Counters(counters)
  8. {
  9. }
  10. NMonitoring::TDynamicCounters::TCounterPtr MakeCounterWithLabels(
  11. const std::vector<std::pair<TString, TString>>& labels,
  12. const char* name,
  13. bool derivative
  14. ) {
  15. auto ptr = Unwrap();
  16. for (const auto& p : labels) {
  17. ptr = ptr->GetSubgroup(p.first, p.second);
  18. }
  19. return ptr->GetCounter(name, derivative);
  20. }
  21. NMonitoring::THistogramPtr MakeHistogramWithLabels(
  22. const std::vector<std::pair<TString, TString>>& labels,
  23. const char* name,
  24. NMonitoring::IHistogramCollectorPtr hist
  25. ) {
  26. auto ptr = Unwrap();
  27. for (const auto& p : labels) {
  28. ptr = ptr->GetSubgroup(p.first, p.second);
  29. }
  30. return ptr->GetHistogram(name, std::move(hist));
  31. }
  32. virtual ~TDynamicCountersWrapper() = default;
  33. const TIntrusivePtr<NMonitoring::TDynamicCounters>& Unwrap() const {
  34. return Counters;
  35. }
  36. protected:
  37. NMonitoring::TDeprecatedCounter& GetCounter(const TString& value, bool derivative) {
  38. return *Counters->GetCounter(value, derivative);
  39. }
  40. private:
  41. TIntrusivePtr<NMonitoring::TDynamicCounters> Counters;
  42. };
  43. class TUpdatableCounters: public TDynamicCountersWrapper {
  44. public:
  45. using TDynamicCountersWrapper::TDynamicCountersWrapper;
  46. virtual void Update() = 0;
  47. };
  48. }