@@ -54,6 +54,12 @@ MetricFamily::MetricFamily(
5454 .Help (description)
5555 .Register (*registry));
5656 break ;
57+ case TRITONSERVER_METRIC_KIND_HISTOGRAM:
58+ family_ = reinterpret_cast <void *>(&prometheus::BuildHistogram ()
59+ .Name (name)
60+ .Help (description)
61+ .Register (*registry));
62+ break ;
5763 default :
5864 throw std::invalid_argument (
5965 " Unsupported kind passed to MetricFamily constructor." );
@@ -63,7 +69,9 @@ MetricFamily::MetricFamily(
6369}
6470
6571void *
66- MetricFamily::Add (std::map<std::string, std::string> label_map, Metric* metric)
72+ MetricFamily::Add (
73+ std::map<std::string, std::string> label_map, Metric* metric,
74+ const std::vector<double >* buckets)
6775{
6876 void * prom_metric = nullptr ;
6977 switch (kind_) {
@@ -81,6 +89,17 @@ MetricFamily::Add(std::map<std::string, std::string> label_map, Metric* metric)
8189 prom_metric = reinterpret_cast <void *>(gauge_ptr);
8290 break ;
8391 }
92+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
93+ if (buckets == nullptr ) {
94+ throw std::invalid_argument (
95+ " Histogram must be constructed with bucket boundaries." );
96+ }
97+ auto histogram_family_ptr =
98+ reinterpret_cast <prometheus::Family<prometheus::Histogram>*>(family_);
99+ auto histogram_ptr = &histogram_family_ptr->Add (label_map, *buckets);
100+ prom_metric = reinterpret_cast <void *>(histogram_ptr);
101+ break ;
102+ }
84103 default :
85104 throw std::invalid_argument (
86105 " Unsupported family kind passed to Metric constructor." );
@@ -134,6 +153,14 @@ MetricFamily::Remove(void* prom_metric, Metric* metric)
134153 gauge_family_ptr->Remove (gauge_ptr);
135154 break ;
136155 }
156+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
157+ auto histogram_family_ptr =
158+ reinterpret_cast <prometheus::Family<prometheus::Histogram>*>(family_);
159+ auto histogram_ptr =
160+ reinterpret_cast <prometheus::Histogram*>(prom_metric);
161+ histogram_family_ptr->Remove (histogram_ptr);
162+ break ;
163+ }
137164 default :
138165 // Invalid kind should be caught in constructor
139166 LOG_ERROR << " Unsupported kind in Metric destructor." ;
@@ -169,7 +196,8 @@ MetricFamily::~MetricFamily()
169196//
170197Metric::Metric (
171198 TRITONSERVER_MetricFamily* family,
172- std::vector<const InferenceParameter*> labels)
199+ std::vector<const InferenceParameter*> labels,
200+ const std::vector<double >* buckets)
173201{
174202 family_ = reinterpret_cast <MetricFamily*>(family);
175203 kind_ = family_->Kind ();
@@ -188,7 +216,7 @@ Metric::Metric(
188216 std::string (reinterpret_cast <const char *>(param->ValuePointer ()));
189217 }
190218
191- metric_ = family_->Add (label_map, this );
219+ metric_ = family_->Add (label_map, this , buckets );
192220}
193221
194222Metric::~Metric ()
@@ -235,6 +263,11 @@ Metric::Value(double* value)
235263 *value = gauge_ptr->Value ();
236264 break ;
237265 }
266+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
267+ return TRITONSERVER_ErrorNew (
268+ TRITONSERVER_ERROR_UNSUPPORTED,
269+ " TRITONSERVER_METRIC_KIND_HISTOGRAM does not support Value" );
270+ }
238271 default :
239272 return TRITONSERVER_ErrorNew (
240273 TRITONSERVER_ERROR_UNSUPPORTED,
@@ -279,6 +312,11 @@ Metric::Increment(double value)
279312 }
280313 break ;
281314 }
315+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
316+ return TRITONSERVER_ErrorNew (
317+ TRITONSERVER_ERROR_UNSUPPORTED,
318+ " TRITONSERVER_METRIC_KIND_HISTOGRAM does not support Increment" );
319+ }
282320 default :
283321 return TRITONSERVER_ErrorNew (
284322 TRITONSERVER_ERROR_UNSUPPORTED,
@@ -308,6 +346,45 @@ Metric::Set(double value)
308346 gauge_ptr->Set (value);
309347 break ;
310348 }
349+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
350+ return TRITONSERVER_ErrorNew (
351+ TRITONSERVER_ERROR_UNSUPPORTED,
352+ " TRITONSERVER_METRIC_KIND_HISTOGRAM does not support Set" );
353+ }
354+ default :
355+ return TRITONSERVER_ErrorNew (
356+ TRITONSERVER_ERROR_UNSUPPORTED,
357+ " Unsupported TRITONSERVER_MetricKind" );
358+ }
359+
360+ return nullptr ; // Success
361+ }
362+
363+ TRITONSERVER_Error*
364+ Metric::Observe (double value)
365+ {
366+ if (metric_ == nullptr ) {
367+ return TRITONSERVER_ErrorNew (
368+ TRITONSERVER_ERROR_INTERNAL,
369+ " Could not set metric value. Metric has been invalidated." );
370+ }
371+
372+ switch (kind_) {
373+ case TRITONSERVER_METRIC_KIND_COUNTER: {
374+ return TRITONSERVER_ErrorNew (
375+ TRITONSERVER_ERROR_UNSUPPORTED,
376+ " TRITONSERVER_METRIC_KIND_COUNTER does not support Observe" );
377+ }
378+ case TRITONSERVER_METRIC_KIND_GAUGE: {
379+ return TRITONSERVER_ErrorNew (
380+ TRITONSERVER_ERROR_UNSUPPORTED,
381+ " TRITONSERVER_METRIC_KIND_GAUGE does not support Observe" );
382+ }
383+ case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
384+ auto histogram_ptr = reinterpret_cast <prometheus::Histogram*>(metric_);
385+ histogram_ptr->Observe (value);
386+ break ;
387+ }
311388 default :
312389 return TRITONSERVER_ErrorNew (
313390 TRITONSERVER_ERROR_UNSUPPORTED,
0 commit comments