Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable create Summary #661

Open
ArkadySh opened this issue Oct 16, 2023 · 1 comment
Open

Unable create Summary #661

ArkadySh opened this issue Oct 16, 2023 · 1 comment

Comments

@ArkadySh
Copy link

ArkadySh commented Oct 16, 2023

Can you provide working example how create summary family ?

I tried to do something like this :

struct SummaryWithQuantiles {
		prometheus::Family<prometheus::Summary> family;
		std::vector<double> quantiles;

		// Constructor to initialize the family member
		SummaryWithQuantiles(const prometheus::Family<prometheus::Summary>& fam, const std::vector<double>& q)
			: family(fam), quantiles(q) {}
	};

	void PrometheusInterface::CreateSummary(const std::string& name, const std::string& help, const std::vector<double>& quantiles) {
		const std::chrono::milliseconds max_age(3600000);  // 1 hour
		const int age_buckets = 5;

		// Create the summary family
		auto summary_family = prometheus::BuildSummary()
			.Name(name)
			.Help(help)
			.MaxAge(max_age)
			.AgeBuckets(age_buckets)
			.Register(*mRegisterShPtr);

		// Create a custom structure to hold the summary family and quantiles
		SummaryWithQuantiles summaryWithQuantiles(summary_family, quantiles);

		// Store the summary with quantiles in the map
		mSummaries[name] = summaryWithQuantiles;
	}
		void PrometheusInterface::ObserveSummary(const std::string& name, double value, const std::map<std::string, std::string>& labels) {
		if (mSummaries.find(name) != mSummaries.end()) {
			auto& summaryWithQuantiles = mSummaries[name];
			for (double quantile : summaryWithQuantiles.quantiles) {
				summaryWithQuantiles.family.Add(labels).Quantile(quantile).Observe(value);
			}
		}
		else {
			LOG4CXX_ERROR(log4cxx::Logger::getLogger("PrometheusInterface"), Format("Summary metric %s was not created before, so it will not be observed!", name.c_str()));
		}
	}

but it is not compiled .

@medvel
Copy link

medvel commented Mar 25, 2024

There is a bug in summary.h:

Class Summary has to be declared as "class Summary : public Metric", not "class Summary : Metric".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants