builder.h 704 B

1234567891011121314151617181920212223242526272829303132333435
  1. #pragma once
  2. #include <string>
  3. #include <map>
  4. #include "registry.h"
  5. namespace prometheus {
  6. template <typename CustomMetric>
  7. class Builder {
  8. Family::Labels labels_;
  9. std::string name_;
  10. std::string help_;
  11. public:
  12. Builder& Labels(const std::map<const std::string, const std::string>& labels) {
  13. labels_ = labels;
  14. return *this;
  15. }
  16. Builder& Name(const std::string& name) {
  17. name_ = name;
  18. return *this;
  19. }
  20. Builder& Help(const std::string& help) {
  21. help_ = help;
  22. return *this;
  23. }
  24. CustomFamily<CustomMetric>& Register(Registry& registry) {
  25. return registry.Add<CustomFamily<CustomMetric>>(name_, help_, labels_);
  26. }
  27. };
  28. }