13 Aug 2024 04:25 PM
Hello!
Is it possible to use multiple metrics in Dashboard v3 based on the variable selected in the dashboard?
For example, Store Variable
If == "Store X"
timeseries max(metric A
Store Y, metric b....
Basically, we have two architectures, an old one and a new one. We would like to include them in the same dashboard, by changing the variable for a store, the metric will also change.
Solved! Go to Solution.
13 Aug 2024 10:05 PM
Hello,
You can do this with a very simple code tile. In the example below, CPU usage is used if the variable is "true", and memory usage is used if the variable is "false".
/*
* This function will run in the Dynatrace JavaScript runtime.
* For more information, visit https://dt-url.net/functions-help
*/
import { queryExecutionClient } from '@dynatrace-sdk/client-query';
export default async function () {
const timeout = 60;
let query
if($Variable == "true"){
query = 'timeseries avg(dt.host.cpu.usage), by: { host.name } | limit 5';
}
else{
query = 'timeseries avg(dt.host.memory.usage), by: { host.name } | limit 5';
}
const response = await queryExecutionClient.queryExecute({ body: { query, requestTimeoutMilliseconds: timeout * 1000, fetchTimeoutSeconds: timeout } });
return response.result;
}