06 Feb 2025
08:05 PM
- last edited on
10 Feb 2025
12:26 PM
by
MaciejNeumann
Hello Community,
Is it possible to combine two metrics in an API call. They are not the same family.
builtin:containers.memory.limitBytes and builtin:kubernetes.workload.requests_memory
with the search key being the Kubernetes namespace.
(Otherwise, I can probably make two calls and then merge the results.)
Any ideas would be appreciated.
Thanks,
Lou
Solved! Go to Solution.
06 Feb 2025 08:45 PM
I think you should be able to get what you want one way or another. In the metrics get data points API call you can set metric selector in which you can specify multiple metric selectors (separated by commas) or you can do metric expressions (i.e simple arithmetic).
If you query for multiple selectors you will have the results separate in the response (but with 1 call) and if you use an expression (e.g. metricA + metricB) the data points returned will be the result. You'll want to make sure you are splitting by the same dimensions in each subselector.
e.g.
metricSelector: builtin:host.cpu.idle:splitBy("dt.entity.host") + builtin:host.cpu.system:splitBy("dt.entity.host")
Response:
{
"totalCount": 2,
"nextPageKey": null,
"resolution": "Inf",
"result": [
{
"metricId": "builtin:host.cpu.idle:splitBy(\"dt.entity.host\")+builtin:host.cpu.system:splitBy(\"dt.entity.host\")",
"dataPointCountRatio": 0.0000242,
"dimensionCountRatio": 0.00004,
"data": [
{
"dimensions": [
"HOST-5B4495AD33E8513B"
],
"dimensionMap": {
"dt.entity.host": "HOST-5B4495AD33E8513B"
},
"timestamps": [
1738874700000
],
"values": [
99.52119439623269
]
},
{
"dimensions": [
"HOST-561B1E07CB771F4B"
],
"dimensionMap": {
"dt.entity.host": "HOST-561B1E07CB771F4B"
},
"timestamps": [
1738874700000
],
"values": [
95.33600394990708
]
}
]
}
]
}