Logz.io has a comprehensive API that allows you to send and query logs or metrics easily. Now, that process is getting even easier for infrastructure monitoring. Logz.io has added support for the open source grafana API. In other words, you can use the OSS grafana’s integration within Logz.io.

The open source grafana API is composed of many supported HTTP APIs that the frontend of OSS grafana uses to manage dashboards and dashboard versions, alerts, send snapshots, manage folders and make annotations. The way we at Logz.io connect to that integration is by attaching the Logz.io API Gateway to one the six supported grafana HTTP API endpoints:

  • Alerting
  • Annotations
  • Dashboard
  • Dashboard versions
  • Folder/dashboard search
  • Snapshot

Simply call the API with a GET request after authenticating your Logz.io X-API-TOKEN:

GET /v1/grafana/api/{GRAFANA_API_URL}

Before you do anything else, you’ll need to create your X-API-TOKEN (or your key) to ship into your Logz.io account.

On your Logz.io Operations dashboard, make sure you are on the Metrics UI. Then hit the cog for Settings (⚙). Go to Tools, then Manage Tokens.

On the MANAGE TOKENS page, select the third option on the menu below the title which reads __API tokens__. Then select + New API Token. To use the API in Logz.io, you’ll need this token.

From there, place it in your API request. On OSS grafana, this is usually written as Authorization bearer <<token>>.

Examples

The following offer some examples of things you can do with the grafana API in the Logz.io API Gateway. Included are the basic versions of requests, their cURL counterparts, and some longer examples.

Dashboard API

The Dashboard API can do many things. You can either update an existing dashboard or generate a new one. Additionally, you can retrieve or delete dashboards, get tags, or move to the home dashboard:

Dashboard APIRequest FormatcURL Example
Create DashboardPOST /api/dashboards/dbcurl POST http://api.logz.io/v1/api/dashboards/db
Get Dashboard by uidGET /api/dashboards/uid/:uidcurl GET http://api.logz.io/v1/api/dashboards/uid/:uid
Delete dashboard by uidDELETE /api/dashboards/uid/:uidcurl DELETE http://api.logz.io/v1/api/dashboards/uid/:uid
Home DashboardGET /api/dashboards/homecurl GET http://api.logz.io/v1/api/dashboards/home
TagsGET /api/dashboards/tags HTTP/1.1

In order to create a dashboard, you’ll need to include your desired parameters for the dash itself. Define this in the body of the API.

Alerting API & Alerting Notifications API

Querying parameters for the Alerting API include: dashboardTag, dashboardQuery, panelId, dashboardId, query, folderId, limit, and state(ALL, ok, paused, alerting, pending, no_data).

Alerting APIRequest FormatcURL Example
Get alert by idGET /api/alerts/:idcurl GET http://api.logz.io/v1/api/alerts/id
Pause alert by idPOST /api/alerts/:id/pausecurl POST http://api.logz.io/v1/api/alerts/id/pause
Get list of alertsGET /api/alert-notificationscurl GET http://api.logz.io/v1/api/alert-notifications
Get list of alerts by idGET /api/alert-notifications/lookupcurl GET http://api.logz.io/v1/api/alert-notifications/lookup
Fetch notification by uidGET /api/alert-notifications/uid/:uidcurl GET http://api.logz.io/v1/api/alert-notifications/uid/:uid
Fetch notification by idGET /api/alert-notifications/:idcurl GET http://api.logz.io/v1/api/alert-notifications/:id
Test an alertGET /api/alert-notifications/testcurl GET http://api.logz.io/v1/api/alert-notifications/test
POST 'https://api.logz.io/v1/grafana/api/dashboards/db' \

--header 'x-api-token: 9c4fdb5e-****-****-****-15c8d2637828'
Accept: application/json
Content-Type: application/json
Authorization: Bearer 50m3rand0mb3ar3rnum43r{
  "uid": "new-alert-notification", //optional
  "name": "new alert notification",  //required
  "type":  "email", //required
  }
}

Annotations

The Annotations API rolled out with the annotation feature itself. They are filtered by tag once you’ve saved and configured them, in one of the given relational databases: postgres, mysql, or sqlite.

This particular grafana API uses the following query parameters (all of which are optional); to and from (for date and time in milliseconds), tags (for annotations not restricted to a specific panel or dash), type, userId, panelId, dashboardId, alertId, and limit.

This particular grafana API uses the following query parameters (all of which are optional); to and from (for date and time in milliseconds), tags (for annotations not restricted to a specific panel or dash), dashboardTag, dashboardQuery, panelId, dashboardId, query, folderId, state, and limit.

AnnotationsRequest FormatcURL Example
Create annotationPOST /api/annotationscurl GET http://api.logz.io/v1/api/annotations
Update annotationPUT /api/annotations/:idcurl PUT http://api.logz.io/v1/api/annotations/:id
Path annotationPATCH /api/annotations/:idcurl PATCH http://api.logz.io/v1/api/annotations/:id
Delete annotationDELETE /api/annotations/:idcurl DELETE http://api.logz.io/v1/api/annotations/:id

Examples:

Convert your dates to milliseconds and input your search limit. If you want to search for specific tags, you can search for multiple. Input the specific tag where it says <<tag_1>> and <<tag_2>>.

GET /api/annotations?from=1597743821000&to=1603014221000&tags=<<tag_1>>&tags=<<tag_2>>&limit=400

Folder/Dashboard Search API

This API lets you search through folders and/or dashboards using the following query parameters: query, page, tag, limit, type (as in dash-folder or dash-db), starred, and either folderIds or dashboardIds.

Search APIRequest FormatcURL Example
Get alert by idGET /api/alerts/:idcurl GET http://api.logz.io/v1/api/alerts/:id
Pause alert by idPOST /api/alerts/:id/pausecurl POST http://api.logz.io/v1/api/alerts/:id/pause

Snapshot API

Versions of the snapshot feature are available in most UI consoles for major DevOps tools. OSS grafana is no different — get a snapshot of a specific chart or dashboard straight out of your UI for reports or for sending.

Snapshot APIRequest FormatcURL Format
Create new snapshotPOST /api/snapshotscurl POST http://api.logz.io/v1/api//snapshots
Get a list of snapshotsGET /api/dashboard/snapshotscurl GET http://api.logz.io/v1/api/dashboard/snapshots
delete Snapshot by deleteKeyGET /api/snapshots-delete/:deleteKeycurl GET http://api.logz.io/v1/api/snapshots-delete/:deleteKey
delete snapshot by keyDELETE /api/snapshots/:keycurl DELETE http://api.logz.io/v1/api/snapshots/:key
get snapshot by keyGET /api/snapshots/:keycurl GET http://api.logz.io/v1/api/snapshots/:key

Conclusion

With this ability, it will be easier to call data within Logz.io Infrastructure Monitoring. For more information on Logz.io Infrastructure Monitoring, check out

Get started for free

Completely free for 14 days, no strings attached.