I'm trying to setup http_request_duration_seconds metric the same as provides prometheus-net
.NET implementation somehow adds dimensions like namespace, service, pod, and code that could be used in Grafana:
// ...
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${datasource}"
},
"exemplar": true,
"expr": "sum(rate(http_request_duration_seconds_count{namespace=\"$namespace\", service=~\"$service\", pod=~\"$pod\"}[$interval])) by (code)",
"interval": "",
"legendFormat": "{{ code }}",
"queryType": "randomWalk",
"refId": "A"
}
],
"title": "Requests per second",
"type": "timeseries"
// ...
It seems like I could extract these values from context. I've read the article related to k8s and TorchServe and didn't find anything related to my problem.
A piece of code related to the metric:
http_request_duration_seconds_count = self.metrics.get_metric(
metric_name='http_request_duration_seconds',
metric_type=MetricTypes.HISTOGRAM)
start = time.monotonic()
request = data[0]
dataset = self.preprocess(request)
inferenced = self.inference(dataset)
result = self.postprocess(inferenced)
http_request_duration_seconds_count.add_or_update(
value=time.monotonic() - start,
# dimension_values=['namespace_name', 'service_service', 'pod_name']
)
emit_metrics(self.metrics.store)