14 Nov 2023 09:18 AM - last edited on 15 Nov 2023 08:15 AM by MaciejNeumann
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
Solved! Go to Solution.
02 Jan 2024 05:44 PM - edited 02 Jan 2024 05:48 PM
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?
02 Jan 2024 06:58 PM - edited 02 Jan 2024 06:59 PM
@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
}
12 Jan 2024 03:18 PM
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)
Best,
Sini
15 Apr 2024 09:12 AM - edited 15 Apr 2024 09:13 AM
check out an example on our playground environment.