<?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 Creating Custom Metric For Database Queries in DQL</title>
    <link>https://community.dynatrace.com/t5/DQL/Creating-Custom-Metric-For-Database-Queries/m-p/245863#M900</link>
    <description>&lt;P&gt;Hello. I want to see database queries via custom metric if its possible. Anyone has an idea for how to achieve it?&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2024 19:24:55 GMT</pubDate>
    <dc:creator>kasdev</dc:creator>
    <dc:date>2024-05-16T19:24:55Z</dc:date>
    <item>
      <title>Creating Custom Metric For Database Queries</title>
      <link>https://community.dynatrace.com/t5/DQL/Creating-Custom-Metric-For-Database-Queries/m-p/245863#M900</link>
      <description>&lt;P&gt;Hello. I want to see database queries via custom metric if its possible. Anyone has an idea for how to achieve it?&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 19:24:55 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Creating-Custom-Metric-For-Database-Queries/m-p/245863#M900</guid>
      <dc:creator>kasdev</dc:creator>
      <dc:date>2024-05-16T19:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Creating Custom Metric For Database Queries</title>
      <link>https://community.dynatrace.com/t5/DQL/Creating-Custom-Metric-For-Database-Queries/m-p/245872#M903</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.dynatrace.com/t5/user/viewprofilepage/user-id/72156"&gt;@kasdev&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I think what you are looking for is this :&amp;nbsp;&lt;A href="https://community.dynatrace.com/t5/Extensions/Custom-extension-for-Databases/m-p/242363#M4293" target="_blank" rel="noopener"&gt;Solved: Custom extension for Databases - Dynatrace Community&lt;/A&gt;&amp;nbsp;&lt;BR /&gt;I suggest checking the link because it has many very good answers.&lt;BR /&gt;&lt;BR /&gt;But in summary what you need to do is create a metric from "custom database extension", choosing the database of your preference.&lt;BR /&gt;&lt;A href="https://www.dynatrace.com/hub/detail/custom-database-extension/" target="_blank" rel="noopener"&gt;Custom database extension monitoring &amp;amp; observability | Dynatrace Hub&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PierreGutierrez_0-1715896807041.png" style="width: 489px;"&gt;&lt;img src="https://community.dynatrace.com/t5/image/serverpage/image-id/19911iFD52024BDBB87045/image-dimensions/489x187?v=v2" width="489" height="187" role="button" title="PierreGutierrez_0-1715896807041.png" alt="PierreGutierrez_0-1715896807041.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Dynatrace provides you with documentation (&amp;nbsp;&lt;A href="https://docs.dynatrace.com/docs/shortlink/sql-datasourc" target="_blank" rel="noopener"&gt;https://docs.dynatrace.com/docs/shortlink/sql-datasourc&lt;/A&gt;e)&amp;nbsp; and a very good video so you can learn how to do it (&amp;nbsp;&lt;A href="https://youtu.be/t9kHPKL9yKY?si=14TdHzlQQMoVLZ3g" target="_blank" rel="nofollow noopener noreferrer"&gt;https://youtu.be/t9kHPKL9yKY?si=14TdHzlQQMoVLZ3g&lt;/A&gt;).&amp;nbsp;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;Once you get the metrics in dynatrace, you could exploit that information in Dashboard Generation 3:&lt;BR /&gt;I share an example code with you:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { metricsClient, monitoredEntitiesClient } from "@dynatrace-sdk/client-classic-environment-v2";


async function fetchMetrics(metricSelector, from,to) {
    const response = await metricsClient.query({
        acceptType: 'application/json; charset=utf-8',
        from: from,
        to: to,
        metricSelector: metricSelector
    });
    return response;
}


export default async function () {
  let sum = 0;
  let from = Date.parse(new Date($dt_timeframe_from)).toString();
  let to = Date.parse(new Date($dt_timeframe_to)).toString();
  
  let query_data = 'builtin:apps.other.keyUserActions.requestCount.os:splitBy("dt.entity.os"):sort(value(auto,descending)):limit(20)';
  let data = await fetchMetrics(query_data,from, to);
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;In JavaScript example : The query_data line, you have to replace it with the metric you have created&lt;/LI-SPOILER&gt;&lt;P&gt;&lt;BR /&gt;I hope it's helpful &lt;span class="lia-unicode-emoji" title=":flexed_biceps:"&gt;💪&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2024 22:17:24 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/DQL/Creating-Custom-Metric-For-Database-Queries/m-p/245872#M903</guid>
      <dc:creator>PierreGutierrez</dc:creator>
      <dc:date>2024-05-16T22:17:24Z</dc:date>
    </item>
  </channel>
</rss>

