cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Use "If" based on the variable

wellpplava
Contributor

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.

1 REPLY 1

Cameron-Leong
Dynatrace Helper
Dynatrace Helper

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;
}

CameronLeong_2-1723583082635.pngCameronLeong_3-1723583084963.png

 

Featured Posts