Access Metrics via API
How to access your metric data in Asserts via the Grafana Prometheus api
Asserts ships with an embedded Grafana instance which allows you to explore your Asserts metrics as well as the metrics you expose to Asserts as described here.
In addition to exploring via the Grafana UI, you can also access them via api.
To do so you will need to create api credentials. You can either do this for your specific user account or create global credentials associated with your instance.
Creating Credentials
User Credentials
You can create API credentials for yourself as well as retrieve the instant and range query endpoints on the API Credentials page in the Your Settings section of the settings menu. Note that the urls are only visible to users with the proper permission.
Global Credentials
You can create global API credentials as well as retrieve the instant and range query endpoints on the API Credentials page in the Your Settings section of the settings menu.
Accessing Prometheus through Grafana
All calls to the embedded Grafana instance must be proxied through the Asserts api-server. This will give you the ability to set role level access per user within Asserts
Once you have your credentials, send your token & key as basic auth credentials to the Asserts api-server. See the Prometheus API documentation for details on calling their apis.
Sample Instant Query
Sample Instant Response
Formatting Metric Output
Formatting metric data into something like a CSV file will make it much more sharable if you're not consuming the metrics into code.
Instant Metrics to CSV Sample
Here is a small sample Python script to run a PromQL query and output the metrics, labels & values as CSV
Last updated