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

Creating Custom Metric For Database Queries


Hello. I want to see database queries via custom metric if its possible. Anyone has an idea for how to achieve it?


Dynatrace Pro
Dynatrace Pro

Hi @kasdev 

I think what you are looking for is this : Solved: Custom extension for Databases - Dynatrace Community 
I suggest checking the link because it has many very good answers.

But in summary what you need to do is create a metric from "custom database extension", choosing the database of your preference.
Custom database extension monitoring & observability | Dynatrace Hub


Dynatrace provides you with documentation (  and a very good video so you can learn how to do it ( 


Once you get the metrics in dynatrace, you could exploit that information in Dashboard Generation 3:
I share an example code with you:


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);


In JavaScript example : The query_data line, you have to replace it with the metric you have created

I hope it's helpful 💪

Pierre Gutierrez - LATAM ACE Consultant - Loving Cats! Loving Technology !

Featured Posts