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

Cumulative Sum - DQL

davidrodriguez
Dynatrace Enthusiast
Dynatrace Enthusiast

Is it possible to plot a cumulative sum in DQL? 

Let's take for example a graph that shows the count of a metric for the given time. How could we add a second line in the graph, that shows the cumulative sum of the previous metric? 

For the first metric (M1) we would see, for each data point a value (M1V1). On the other hand, for the cumulative metric (M2), we would see a sum of all the values previous to that data point.

M2V5 = M1V1 + ... + M1V4

 

Would this be possible? Thank you in advance

 

4 REPLIES 4

kauanschumacher
Newcomer

Any news?
My company is migrating from DataDog to Dynatrace, and we have so many dashboards to migrate. Some dashboards uses the "cumulative sum" to create linear growth charts to identify system flow anomallies

The cumulative sum it is so useful to resolve this problem...

 

Someone can help us?

kauanschumacher
Newcomer

@davidrodriguez maybe i found a workaround to do that!

In my use case, I need count logs by a message pattern and do a cummulative summarize to have a linear growth chart...

To do that I change my chart to "code chart" and implement the query using "@dynatrace-sdk" + response manipulation


See this example, and check if helps you

 

 

/*
* This function will run in the DYNATRACE JavaScript runtime.
* For information visit https://dt-url.net/functions-help
*/
import { queryExecutionClient } from '@dynatrace-sdk/client-query';

export default async function () {
  const env = $Environment;
  const from = $dt_timeframe_from;
  const to = $dt_timeframe_to;
  
  const timeout = 60;
  const query = `
    fetch logs, from:"${from}", to:"${to}"
    | filter dt.host_group.id == "${env}"
    | parse content, "JSON:contentjson"
    | filter contains(contentjson[message], "TradeCreationRequested") or 
             contains(contentjson[messageTemplate], "Trade created") or 
    | summarize Requested = countIf(contains(contentjson[message], "TradeCreationRequested")), 
                Created = countIf(contains(contentjson[messageTemplate], "Trade created")), 
                by: delta = bin(timestamp,10m)
    | sort delta desc
  `;
  
  const response = await queryExecutionClient.queryExecute({ body: { query, requestTimeoutMilliseconds: timeout * 1000, fetchTimeoutSeconds: timeout  } });
  response.logs = null;
  for (let i = 0; i < response.result.records.length; i++) 
  {
    response.result.records[i].Requested = response.result.records.filter((_, index) => index >= i).reduce((a, b) => a + (b.Requested * 1), 0);
    response.result.records[i].Created = response.result.records.filter((_, index) => index >= i).reduce((a, b) => a + (b.Created * 1), 0);
  }
  
  return response.result
}

 

sinisa_zubic
Dynatrace Champion
Dynatrace Champion

hi @davidrodriguez 

 

With the just released function arrayMovingSum it is no possible to create cumulative sum timeseries. some example from discover dynatrace

fetch bizevents
| filter event.type == "com.easytrade.deposit.start"
| makeTimeseries deposits = sum(amount), bins:60
| fieldsAdd deposits_cumulative=arrayMovingSum(deposits,60)

sinisa_zubic_0-1705072654513.png

 

Best,
Sini

check out an example on our playground environment. 

zietho_0-1713168715483.png

Featured Posts