+ for (const Histogram &histogram : histograms) {
+ ss << "# TYPE nageru_" << histogram.name << " histogram\n";
+
+ int64_t sum = 0, count = 0;
+ for (size_t i = 0; i < histogram.num_elements; ++i) {
+ char buf[16];
+ snprintf(buf, sizeof(buf), "%lu", i);
+ vector<pair<string, string>> labels = histogram.labels;
+ labels.emplace_back("le", buf);
+
+ int64_t val = histogram.location_int64[i].load();
+ sum += i * val;
+ count += val;
+ ss << serialize_name(histogram.name + "_bucket", labels) << " " << count << "\n";
+ }
+
+ ss << serialize_name(histogram.name + "_sum", histogram.labels) << " " << sum << "\n";
+ ss << serialize_name(histogram.name + "_count", histogram.labels) << " " << count << "\n";
+ }