<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Grail Aggregation Function Percentiles in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/245387#M879</link>
    <description>&lt;P&gt;For any late-comers to the thread, you can read up on timeseries percentile in the &lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/commands/metric-commands" target="_blank"&gt;Dynatrace Docs&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 13 May 2024 06:49:15 GMT</pubDate>
    <dc:creator>nickvogt</dc:creator>
    <dc:date>2024-05-13T06:49:15Z</dc:date>
    <item>
      <title>Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237281#M689</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;
&lt;P&gt;I have found that there are no PERCENTILES as aggregation functions in GRAIL. We have min, max, sum, avg, count and countIf.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregOReilly_0-1708019330159.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/17639i292CA08D28C4CA8B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregOReilly_0-1708019330159.png" alt="GregOReilly_0-1708019330159.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Any plans to add percentile? Some of my customers only work with percentiles and the previous dashboards could support a percentile.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 08:23:20 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237281#M689</guid>
      <dc:creator>GregOReilly</dc:creator>
      <dc:date>2024-03-01T08:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237600#M690</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I understand that, as of now, direct support for retrieving the 90th percentile timeseries data might not be available. However, I remember plans are underway to introduce this functionality. In the meantime, you can use JavaScript along with APIs to query metrics, specifically targeting the 90th percentile. Below, I've shared my optimized JavaScript code for efficiently calculating the 90th percentile response time.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { metricsClient } from "@dynatrace-sdk/client-classic-environment-v2";

/**
 * Fetches metric data based on a provided query and time range.
 * @param {string} query - The metric query selector.
 * @param {string} from - The start time for the query in ISO format.
 * @param {string} to - The end time for the query in ISO format.
 * @returns The queried metric data.
 */
async function fetchMetrics(query: string, from: string, to: string) {
  const response = await metricsClient.query({
    acceptType: 'application/json; charset=utf-8', 
    from,
    to,
    metricSelector: query
  });
  return response.result;
}

/**
 * Main function to calculate and return the 90th percentile response time for a specific service.
 * @returns {Promise&amp;lt;{response time percentil 90: number}&amp;gt;} - The 90th percentile response time in seconds.
 */
export default async function() {
  const from = new Date('2023-11-01T00:00:00Z');
  const to = new Date('2024-02-20T00:00:00Z');
  const serviceId = "SERVICE-XXXXXXXXXXXX";

  // Prepare time range for the query.
  const fromRequest = from.toISOString().slice(0, 19);
  const toRequest = to.toISOString().slice(0, 19);

  // Construct query for the 90th percentile of response time.
  const responseTimeQuery = `builtin:service.response.time:filter(and(or(in("dt.entity.service",entitySelector("type(service),entityId(~"${serviceId}~")"))))):splitBy():fold(percentile(90))`;
  const responseMetrics = await fetchMetrics(responseTimeQuery, fromRequest, toRequest);
  
  // Extract the 90th percentile response time in seconds.
  const responseTimePercentile90 = responseMetrics[0].data[0].values[0] / 1000;
  
  return { "response time percentil 90": responseTimePercentile90 };
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoseRomero_0-1708473881726.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/17722i710315C959DF3055/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoseRomero_0-1708473881726.png" alt="JoseRomero_0-1708473881726.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 00:10:08 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237600#M690</guid>
      <dc:creator>JoseRomero</dc:creator>
      <dc:date>2024-02-21T00:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237642#M691</link>
      <description>&lt;P&gt;Percentiles are important for any customer or user, because averages really only skim the surface of what is happening. T&lt;SPAN&gt;&lt;SPAN class=""&gt;he problem with this solution(not just becaause its javascript, not everyone knows it) is that it is service-based... I need something that does the same for metrics obtained from logs... to be specific, &amp;nbsp;timeseries data parsed out from fetched log data. Or are you saying, no need to cut metrics, use this approach using raw log data?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregOReilly_0-1708505091683.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/17737iB001EDD2C1AC6ED7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregOReilly_0-1708505091683.png" alt="GregOReilly_0-1708505091683.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;if I understand correctly, this code simply does an old school data fetch from dynatrace and (potentially) displays it. It doesnt actually implement a percentile based data-crunch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 08:47:43 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/237642#M691</guid>
      <dc:creator>GregOReilly</dc:creator>
      <dc:date>2024-02-21T08:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/238463#M692</link>
      <description>&lt;P&gt;I too am in need of `percentile` in `makeTimeseries` command, and after reading &lt;A href="https://docs.dynatrace.com/docs/platform/davis-ai/basics/percentiles-for-analyzing-performance" target="_blank" rel="noopener"&gt;https://docs.dynatrace.com/docs/platform/davis-ai/basics/percentiles-for-analyzing-performance&lt;/A&gt; I was surprised there weren't more aggregation functions available!&amp;nbsp; &lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/aggregation-functions" target="_blank" rel="noopener"&gt;https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/functions/aggregation-functions&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Can we vote somewhere to request this?&amp;nbsp; Is it a technical limitation there aren't more aggregation commands available in `makeTimeseries`?&lt;/P&gt;&lt;P&gt;It would also be good to label this with "aggregation", "makeTimeseries", etc.&lt;/P&gt;&lt;P&gt;Edit: in October 2023 Fabrice said&amp;nbsp;"we're going to have percentile very soon", WRT to the grail &lt;FONT face="andale mono,times"&gt;timeseries&lt;/FONT&gt; command - &lt;A href="https://community.dynatrace.com/t5/Videos/A-Practical-Guide-to-DQL-for-Metrics/td-p/225776" target="_blank"&gt;https://community.dynatrace.com/t5/Videos/A-Practical-Guide-to-DQL-for-Metrics/td-p/225776&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Mar 2024 22:54:58 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/238463#M692</guid>
      <dc:creator>asharpe</dc:creator>
      <dc:date>2024-03-11T22:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/238595#M693</link>
      <description>&lt;P&gt;I'm using this approximation, though the accuracy is sensitive to the interval in the &lt;FONT face="andale mono,times"&gt;bin()&lt;/FONT&gt; call and that calculated by the &lt;FONT face="andale mono,times"&gt;makeTimeseries()&lt;/FONT&gt; call.&amp;nbsp; You also seem to need the field as a number, not a string.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;fetch logs
| summarize _90 = percentile(field, 90), by: { timestamp = bin(timestamp, 1m) }
| makeTimeseries avg(_90)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to get the time span from the dashboard into a query so if you use this in a dash, you'll need to remember that the accuracy might be quite poor depending on the intervals.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 21:56:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/238595#M693</guid>
      <dc:creator>asharpe</dc:creator>
      <dc:date>2024-03-01T21:56:53Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/240072#M734</link>
      <description>&lt;P&gt;Today we have noticed that the documentation page was updated (this is cool, but annoying as we dont know what updated). In this case we can see percentiles have appeared:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregOReilly_0-1710520212269.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/18315iBD00D17CA9F26A6C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregOReilly_0-1710520212269.png" alt="GregOReilly_0-1710520212269.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, we tried this in our env....we hit a bug&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregOReilly_1-1710520245347.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/18316i70BE9EF9D781E4B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregOReilly_1-1710520245347.png" alt="GregOReilly_1-1710520245347.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2024 16:30:53 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/240072#M734</guid>
      <dc:creator>GregOReilly</dc:creator>
      <dc:date>2024-03-15T16:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/240096#M736</link>
      <description>&lt;P&gt;This is promising!&lt;/P&gt;&lt;P&gt;I feel like it's equal chance a bug in the docs or a bug in the code.&amp;nbsp; The docs first say that percentile() is available as an aggregation function, but the immediately following bullet list doesn't include it.&amp;nbsp; The next portion says that percentile is a parameter, but doesn't say to which function (it's not listed in any of the function synopsis).&lt;/P&gt;&lt;P&gt;This leads me to think the percentile parameter is only available on the percentile function, but I haven't tried yet.&lt;/P&gt;&lt;P&gt;Thanks for the heads up, I'll give it a go shortly!&lt;/P&gt;</description>
      <pubDate>Sat, 16 Mar 2024 08:50:01 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/240096#M736</guid>
      <dc:creator>asharpe</dc:creator>
      <dc:date>2024-03-16T08:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/242704#M820</link>
      <description>&lt;P&gt;Yesterday i used the percentiles and its working. Please check now.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 08:17:10 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/242704#M820</guid>
      <dc:creator>selva</dc:creator>
      <dc:date>2024-04-16T08:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/242709#M821</link>
      <description>&lt;P&gt;Great news, just tried and its working for me now too!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="GregOReilly_0-1713257802019.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/18910i2474C246C5AE3BB7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="GregOReilly_0-1713257802019.png" alt="GregOReilly_0-1713257802019.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 08:57:25 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/242709#M821</guid>
      <dc:creator>GregOReilly</dc:creator>
      <dc:date>2024-04-16T08:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/245387#M879</link>
      <description>&lt;P&gt;For any late-comers to the thread, you can read up on timeseries percentile in the &lt;A href="https://docs.dynatrace.com/docs/platform/grail/dynatrace-query-language/commands/metric-commands" target="_blank"&gt;Dynatrace Docs&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 13 May 2024 06:49:15 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/245387#M879</guid>
      <dc:creator>nickvogt</dc:creator>
      <dc:date>2024-05-13T06:49:15Z</dc:date>
    </item>
    <item>
      <title>Re: Grail Aggregation Function Percentiles</title>
      <link>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/260000#M1350</link>
      <description>&lt;P&gt;I tried the example in the Dynatrace Docs:&amp;nbsp;&lt;A href="https://docs.dynatrace.com/docs/shortlink/aggregation-functions#percentile" target="_blank"&gt;https://docs.dynatrace.com/docs/shortlink/aggregation-functions#percentile&lt;/A&gt;. Percentile 100 shouldn't be&amp;nbsp;3201 ?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="elodie_lam_0-1729511660312.png" style="width: 400px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/23899i2701CA295A3CAAD7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="elodie_lam_0-1729511660312.png" alt="elodie_lam_0-1729511660312.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Oct 2024 11:56:30 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Grail-Aggregation-Function-Percentiles/m-p/260000#M1350</guid>
      <dc:creator>elodie_lam</dc:creator>
      <dc:date>2024-10-21T11:56:30Z</dc:date>
    </item>
  </channel>
</rss>

