This repo shows examples for how to use the Dynatrace API and Dynatrace custom devices for reporting.
Both examples use the queryDynatrace.lib
to call the Dynatrace API to gather metrics.
- Dynatrace problem count and user session counts are for the last 24 hours from the time script is run
- entity counts will be current for the time the script is run
- Install jquery utility -- Windows/Mac instructions or Linux
- copy as creds.sav as creds.json
- Fill in your Dynatrace values
{
"dynatraceUrl": "https://{your tenant}.live.dynatrace.com",
"dynatraceApiToken": "",
"relativeTimeframe": "day",
"managementZone": ""
}
NOTE: this example is the SaaS dynatrace URL. Other API URL formats include:
- https://{your-domain}/e/{your-environment-id}
- xyz123.dynatrace-managed.com
- relative time frame can be any of the values listed in the "_comment" lines in the file
- Managgement zone is null by default. Management zones are integers found in your dynatrace tenant URL when filtered on a management zone. The file inputParameters.lib will check the validity of a management zone before executing.
This example will generate a text report to the terminal that uses the Dynatrace API to gather metrics and display them in the terminal. It will also generate CVS output that you can copy-n-paste into Excel.
To run this example:
- Follow the instruction as described in the Prerequisites Setup section below
- run
./dynatraceReport.sh
NOTE: See "other files" section below for other files this script depends on
This example will gather the same metrics as the report example above, but will publish it into a Dynatrace Custom device.
Once in a custom device, you can use the Dynatace Web to view metrics or make a customer dashboard.
To run this example:
- Follow the instruction as described in the Prerequisites Setup section below
- run
./createCustomMetrics.sh
- This will create the metrics to store the report data - run
./addDeviceData.sh
- this script will first call the Dynatrace API to gather metrics and then publish then to the custom device. - within Dynatrace, in the left side menu navigate to: 'Technologies'. Then click on 'custom devices' and then click to view the new device
- It might take a minute for data to appear.
Option to collect dacal
- Run the
loopAddDeviceData.sh
script. This will call theaddDeviceData.sh
in a loop. See comments in this script for running it in the background. - You can also make a crontab entry to run the
addDeviceData.sh
script once a day. For example
# Run once a day at midnight
0 0 * * * cd <your path>/dt-api-reporting && ./addDeviceData.sh && echo "Crontab called addDeviceData @ "`date` >> addDeviceData.log
To remove this example:
- run
./deleteCustomMetrics.sh
- this will remove all the custom metrics - the custom Device will automatically be removed after a few days once the device has no metric data
- metrics.lib - this scripts provides a report that uses the Dynatrace API to gather metrics
- queryDynatrace.lib - this scripts provides a report that uses the Dynatrace API to gather metrics
- creds.sav - template you can copy as creds.json. Add your Dynatrace
- inputParameters.lib - creates epoch time in ms for relative time frame chosen and validates management zone