A helper function to redirect Grafana drill down links into Instana
The purpose of this function is to extend the Instana plugin for Grafana and add a new feature - drill down from a Grafana graph to the Instana object dashboard.
The current problem is that an Instana dashboard URL requires the snapshotId of the object, which is not known by Grafana. The timeseries Grafana collects from Instana only has the object name (FQDN in the case of hosts).
Note that as of October 2021, this function only works on entities of type
entity.host
andentity.python.app
An example of a dashboard URL is https://<instanaHostURL>/#/physical/dashboard?snapshotId=<snapshotId>
After setting up the Grafana plugin for Instana (per https://grafana.com/grafana/plugins/instana-datasource/) you can create Grafana dashboards which show information about hosts monitored by Instana.
You can now edit your widget to add a drill down link:
Scroll to the bottom of the sidebar and click "Add link" in Data links.
What we would like to do now is add a link in the format of https://<instanaHostURL>/#/physical/dashboard?snapshotId=<snapshotId>
But as you can see, snapshotId
is not one of the available fields:
The solution is to create a helper function which will recieve the Series Name
(in the case of hosts this is the FQDN), translate that to the most recent snapshotId and redirect the browser to the Instana server.
The code shared in this repository does this.
The solution assumes that it will receive 3 parameters:
- instanaURL - the base URL of the Instana backend (
https://myInstanaserver
) - instanaAPIToken - the API token to query the Instana REST API (highly recommended you use a token with limited and read-only access)
- fqdn - the FQDN of the host you want to view in Instana
The rest of this document will explain how to use this code as an IBM Cloud Function:
- Login to
https://cloud.ibm.com/functions/actions
and create a new action by clicking "Create" - Create an entity of type "Action"
- Create an action with the Python runtime and give it whatever name you want.
- Paste the content of the file (
redirectInstana.py
) into the online editor and save the file.
- In the "Parameters" tab, add the
instanaURL
andinstanaAPIToken
values and save.
- In the "Endpoints" tab, click the "Enable as Web Action" checkbox and save. Note/record the value of the public HTTP endpoint
At this point you can test your function by running the command line instruction:
curl https://<thePublicFunctionEndpoint>.json?fqdn=<Hostname.domain>
and getting, as a result something like this:
{
"headers": {
"location": "https://<instanaServer>/#/physical/dashboard?snapshotId=<snapshotId>"
},
"statusCode": 302
}%
Note that the suffix
.json
was added to the function to display the HTTP response in your CLI window. This is not necessary in a browser.
If you enter the function in your browser (with or without the .json
suffix), you will be redirected to the same location.
Returning to the Grafana dashboard, you can now create a drill down link which will call the function in a new browser tab and open the Instana dashboard on the host.
For a VM/host use the format:
https://<endpoint>/redirectInstana?fqdn==${__series.name}
For a Python application use the format:
https://<endpoint>/redirectInstana?plugin=python&python_name=${__series.name}