16 May 2024 08:24 PM
Hello. I want to see database queries via custom metric if its possible. Anyone has an idea for how to achieve it?
Solved! Go to Solution.
16 May 2024 11:03 PM - edited 16 May 2024 11:17 PM
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 ( https://docs.dynatrace.com/docs/shortlink/sql-datasource) and a very good video so you can learn how to do it ( https://youtu.be/t9kHPKL9yKY?si=14TdHzlQQMoVLZ3g).
---------------------------------------------------------------------------------------
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);
}
I hope it's helpful 💪