DQL
Questions about Dynatrace Query Language
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Difference DQL Calculate diference of two timeseries metrics

Hi everyone,

I want to create a difference between two metrics over the time. For example to show the differnece between published and processed queue messages.
How to do this with DQL?

I tried to start with this command.

timeseries {publish_count = sum(dt.service.messaging.publish.count), receive_count = sum(dt.service.messaging.receive.count)}, by:{messaging.destination.name}
| fieldsAdd difference = publish_count - receive_count
| summarize by:{messaging.destination.name}, total_difference = sum(difference)

 

But this just return null.

 

Best regards,

Robert

2 REPLIES 2

MaximilianoML
Champion

Hello @robert_laurat,

timeseries returns arrays, so publish_count and receive_count are not single values.
Also, empty buckets are null unless you set default: 0.

Try this for the difference over time:

timeseries {
  publish_count = sum(dt.service.messaging.publish.count, default: 0),
  receive_count = sum(dt.service.messaging.receive.count, default: 0)
}, by: { messaging.destination.name }
| fieldsAdd difference = publish_count[] - receive_count[]

timeseries-robert.pngThat gives you a difference array for each destination, one value per time bucket. Dynatrace supports iterative array expressions like this with [].

 

 

 

 

I hope this helps you 😀

 

 

Max Lopes

Hi @MaximilianoML, the default:0  was the trick.

I also tried to explicitly set [] at the calculation, but without success.

 

Thanks,

Robert

Featured Posts