Excecute SQL Queries within Dynatrace for easy query result Metrics
- Marco Critti

- 17 hours ago
- 4 min read
LEVEL | Advanced |
What is it about?
Dynatrace offers many ways to ingest metrics. One of them is using simple SQL queries to collect basic metrics that you can visualize in a Dynatrace dashboard or use to count values and trigger alerts when a defined threshold is reached.
This guide shows you step by step how to build such an extension.
What's included
In this section of the documentation you will find a brief description of:
Prerequisites for extension 2.0
Step by Step guide
further links
Prerequisites
You need Visual Studio Code
Install the Dynatrace Extensions extension

https://marketplace.visualstudio.com/items?itemName=DynatracePlatformExtensions.dynatrace-extensions
You need a Access Token, you can choose therefore the Extension Development template.

You will need a Access Token. In Dynatrace go to Access Tokens and generate a new one using the Extension Development template.
Step by step guide
STEP 1
You choose a folder to develop, then you have to


Go to the extension
Add environment ( here you use the Dynatrace tenant URL and the token generated before in Prerequisites
Initialize workspace
STEP 2
To initialize the workspace you can also use the command > Dynatrace extensions: Initialize workspace ( i.e. after you used open folder... to start a new project)

Next you choose the schema version which also means the ActiveGate needs to be at least at the same Version or higher. You can change this also later in the YAML File
STEP 3

STEP 4

You will be asked about using existing Certificates or to generate new ones. You can also copy certificated to the folder if you like to use existing ones.The path looks like this:
Windows
C:\Users\{User}\AppData\Roaming\Code\User\workspaceStorage\{ProjectGUID}\DynatracePlatformExtensions.dynatrace-extensions\certificates
i.e.
C:\Users\marcocritti\AppData\Roaming\Code\User\workspaceStorage\9aa5416375b159722d2f828154782dba\DynatracePlatformExtensions.dynatrace-extensions\certificates
MAC
/Users/{User}/Library/Application Support/Code/User/workspaceStorage/{ProjectGUID}/DynatracePlatformExtensions.dynatrace-extensions/certificates/
i.e.
/Users/marcocritti/Library/Application Support/Code/User/workspaceStorage/352982e62777b7ed5acd625df9644944/DynatracePlatformExtensions.dynatrace-extensions/certificates/

STEP 5

You will then choose what project you want to start. You can look into every in your tenant existing Extension with Download an Extension. For a new extension you should go with YAML Extension.
STEP 6

This is how your starting point will look.
STEP 7
If you look for your certificates you may also browse in your Visual Code Settings under Settings > Workspace > Extensions > Dynatrace Extensions > Certificates

Alternatively Settings > User > Extensions > Dynatrace Extensions > Certificates
STEP 8
Our example is a simple SQL Query:

The Count we take as the metric called feedback and APP_SOURCE as the dimension appsource / appsource name. The feedback2 and source_name are the same thing, but put there for illustration of feature sets, featuresets allow you in the end to choose which metrics you want:

Oracle Dynatrace Extension Expand source
STEP 9

After you have your code you have to build and upload the extension.With >dynatrace extensions you get an overview over all commands.
To Build we use >Dynatrace extensions. Build
STEP 10

In case you opted for the option Use existing Certificates in Step 4, and you didnt copy any to the specified path and didnt have any generated you can do so now either of these steps to sign your extension.
STEP 11

Either activate your extension in Dynatrace itself or over Visual Studio Code.

STEP 12
You will be asked to open Dynatrace where you will be redirected to your Extension

In the next stepp you can add a monitoring configuration
STEP 13

In the first step of adding a configuration for your extension you have to define to which ActiveGate it should be deployed, you have to choose Environmental ActiveGates which have Extension 2.0 enabled.
Make sure your root certificate (ca.pem see STEP 4) is copied to those ActiveGates.
Sign Extensions
Remote extensions
Upload your root certificate to each ActiveGate host within the ActiveGate group selected for running your extensions
Save the root.pem certificate file in the following location:
Linux:
<CONFIG>/remotepluginmodule/agent/conf/certificates/ (default: /var/lib/dynatrace/remotepluginmodule/agent/conf/certificates/)
Windows:
%PROGRAMDATA%\dynatrace\remotepluginmodule\agent\conf\certificates
STEP 14

In this step you fill out all Information to connect to your DB. You can use User/Password or as well Vault credentials which is also User/Password but you can share it in the environment without exposing the values.
STEP 15
In the next step you can define Attributes, which I didnt use in my examples and then the final step is to give your configuration a name and activate it.

Here you would also have the FeatureSets to choose which metric you want ( see step 8). In this case here I removed all feature sets to see what's going on with the groups we define in the YAML. As far as I can observe you will never see those groups in the UI, you just need to have them there to have a valid YAML. You can also Use the shown JSON file to automate the whole process via API.
STEP 16
Afterwards you will see your configuration and its status:

If you click on the status you will be redirected o the respective Log View. From there you would also see if there is an issue with your extension.
STEP 17
You will see your results in the DataExplorer.Be aware that you need the permissions in your Management Zone otherwise you will not be able to see it even if you created it.

If you cant see the metric it might be that you have access only to specific management zones. In such a case create a Dimensional rule for METRIC where METRIC_KEY equals your new Metric .
STEP 18
Here all steps needed in an overview:





Comments