mirror of https://github.com/grafana/grafana
prometheushacktoberfestmetricsmonitoringalertinggrafanagoinfluxdbmysqlpostgresanalyticsdata-visualizationdashboardbusiness-intelligenceelasticsearch
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
973 lines
25 KiB
973 lines
25 KiB
![]()
9 years ago
|
+++
|
||
![]()
3 years ago
|
aliases = ["/docs/grafana/latest/http_api/data_source/", "/docs/grafana/latest/http_api/datasource/"]
|
||
![]()
9 years ago
|
description = "Grafana Data source HTTP API"
|
||
|
keywords = ["grafana", "http", "documentation", "api", "data source"]
|
||
![]()
3 years ago
|
title = "Data source HTTP API "
|
||
![]()
9 years ago
|
+++
|
||
|
|
||
![]()
10 years ago
|
# Data source API
|
||
![]()
10 years ago
|
|
||
![]()
3 years ago
|
> If you are running Grafana Enterprise and have [Role-based access control]({{< relref "../../enterprise/access-control/_index.md" >}}) enabled, for some endpoints you would need to have relevant permissions.
|
||
![]()
4 years ago
|
> Refer to specific resources to understand what permissions are required.
|
||
|
|
||
![]()
6 years ago
|
## Get all data sources
|
||
![]()
10 years ago
|
|
||
|
`GET /api/datasources`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ---------------- | -------------- |
|
||
|
| datasources:read | datasources:\* |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
10 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
GET /api/datasources HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
10 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
[
|
||
![]()
6 years ago
|
{
|
||
|
"id": 1,
|
||
|
"orgId": 1,
|
||
![]()
5 years ago
|
"uid": "H8joYFVGz"
|
||
![]()
6 years ago
|
"name": "datasource_elastic",
|
||
|
"type": "elasticsearch",
|
||
|
"typeLogoUrl": "public/app/plugins/datasource/elasticsearch/img/elasticsearch.svg",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "grafana-dash",
|
||
|
"basicAuth": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {
|
||
|
"esVersion": 5,
|
||
|
"logLevelField": "",
|
||
|
"logMessageField": "",
|
||
|
"maxConcurrentShardRequests": 256,
|
||
|
"timeField": "@timestamp"
|
||
|
},
|
||
|
"readOnly": false
|
||
|
}
|
||
![]()
8 years ago
|
]
|
||
|
```
|
||
![]()
10 years ago
|
|
||
![]()
6 years ago
|
## Get a single data source by Id
|
||
![]()
10 years ago
|
|
||
|
`GET /api/datasources/:datasourceId`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ---------------- | ---------------------------------------------------------------------------- |
|
||
|
| datasources:read | datasources:\*<br>datasources:id:\*<br>datasources:id:1 (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
10 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
GET /api/datasources/1 HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
9 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
![]()
6 years ago
|
"id": 1,
|
||
![]()
5 years ago
|
"uid": "kLtEtcRGk",
|
||
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": false,
|
||
|
"basicAuthUser": "",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {
|
||
|
"graphiteType": "default",
|
||
|
"graphiteVersion": "1.1"
|
||
|
},
|
||
|
"secureJsonFields": {},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Get a single data source by UID
|
||
|
|
||
|
`GET /api/datasources/uid/:uid`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ---------------- | -------------------------------------------------------------------------------------- |
|
||
|
| datasources:read | datasources:\*<br>datasources:uid:\*<br>datasources:uid:kLtEtcRGk (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
5 years ago
|
**Example request:**
|
||
|
|
||
|
```http
|
||
|
GET /api/datasources/uid/kLtEtcRGk HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"id": 1,
|
||
|
"uid": "kLtEtcRGk",
|
||
![]()
6 years ago
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": false,
|
||
|
"basicAuthUser": "",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {
|
||
|
"graphiteType": "default",
|
||
|
"graphiteVersion": "1.1"
|
||
|
},
|
||
|
"secureJsonFields": {},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
![]()
8 years ago
|
}
|
||
|
```
|
||
![]()
9 years ago
|
|
||
![]()
9 years ago
|
## Get a single data source by Name
|
||
![]()
9 years ago
|
|
||
![]()
7 years ago
|
`GET /api/datasources/name/:name`
|
||
![]()
9 years ago
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ---------------- | ---------------------------------------------------------------------------------------------- |
|
||
|
| datasources:read | datasources:\*<br>datasources:name:\*<br>datasources:name:test_datasource (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
9 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
GET /api/datasources/name/test_datasource HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
10 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
![]()
6 years ago
|
"id": 1,
|
||
![]()
5 years ago
|
"uid": "kLtEtcRGk",
|
||
![]()
6 years ago
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": false,
|
||
|
"basicAuthUser": "",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {
|
||
|
"graphiteType": "default",
|
||
|
"graphiteVersion": "1.1"
|
||
|
},
|
||
|
"secureJsonFields": {},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
![]()
8 years ago
|
}
|
||
|
```
|
||
![]()
10 years ago
|
|
||
![]()
9 years ago
|
## Get data source Id by Name
|
||
|
|
||
|
`GET /api/datasources/id/:name`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ------------------- | ---------------------------------------------------------------------------------------------- |
|
||
![]()
4 years ago
|
| datasources.id:read | datasources:\*<br>datasources:name:\*<br>datasources:name:test_datasource (single data source) |
|
||
![]()
4 years ago
|
|
||
|
### Examples
|
||
|
|
||
![]()
9 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
GET /api/datasources/id/test_datasource HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
9 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
![]()
9 years ago
|
|
||
![]()
8 years ago
|
{
|
||
|
"id":1
|
||
|
}
|
||
|
```
|
||
![]()
9 years ago
|
|
||
![]()
6 years ago
|
## Create a data source
|
||
![]()
10 years ago
|
|
||
|
`POST /api/datasources`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ------------------ | ----- |
|
||
|
| datasources:create | n/a |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
8 years ago
|
**Example Graphite Request**:
|
||
![]()
10 years ago
|
|
||
![]()
8 years ago
|
```http
|
||
|
POST /api/datasources HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
|
||
|
{
|
||
|
"name":"test_datasource",
|
||
|
"type":"graphite",
|
||
|
"url":"http://mydatasource.com",
|
||
|
"access":"proxy",
|
||
|
"basicAuth":false
|
||
|
}
|
||
|
```
|
||
![]()
10 years ago
|
|
||
![]()
6 years ago
|
**Example Graphite Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"datasource": {
|
||
|
"id": 1,
|
||
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": false,
|
||
|
"basicAuthUser": "",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {},
|
||
|
"secureJsonFields": {},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
|
},
|
||
|
"id": 1,
|
||
|
"message": "Datasource added",
|
||
|
"name": "test_datasource"
|
||
|
}
|
||
|
```
|
||
|
|
||
![]()
5 years ago
|
> **Note:** By defining `password` and `basicAuthPassword` under `secureJsonData` Grafana encrypts them securely as an encrypted blob in the database. The response then lists the encrypted fields under `secureJsonFields`.
|
||
![]()
6 years ago
|
|
||
|
**Example Graphite Request with basic auth enabled**:
|
||
|
|
||
|
```http
|
||
|
POST /api/datasources HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
|
||
|
{
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"access": "proxy",
|
||
|
"basicAuth": true,
|
||
|
"basicAuthUser": "basicuser",
|
||
|
"secureJsonData": {
|
||
|
"basicAuthPassword": "basicpassword"
|
||
|
}
|
||
|
}
|
||
|
```
|
||
![]()
4 years ago
|
|
||
![]()
6 years ago
|
**Example Response with basic auth enabled**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"datasource": {
|
||
|
"id": 1,
|
||
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": true,
|
||
|
"basicAuthUser": "basicuser",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {},
|
||
|
"secureJsonFields": {
|
||
|
"basicAuthPassword": true
|
||
|
},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
|
},
|
||
|
"id": 102,
|
||
|
"message": "Datasource added",
|
||
|
"name": "test_datasource"
|
||
|
}
|
||
|
```
|
||
|
|
||
![]()
8 years ago
|
**Example CloudWatch Request**:
|
||
![]()
8 years ago
|
|
||
|
```http
|
||
|
POST /api/datasources HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
|
||
|
{
|
||
|
"name": "test_datasource",
|
||
|
"type": "cloudwatch",
|
||
|
"url": "http://monitoring.us-west-1.amazonaws.com",
|
||
|
"access": "proxy",
|
||
|
"jsonData": {
|
||
|
"authType": "keys",
|
||
|
"defaultRegion": "us-west-1"
|
||
|
},
|
||
|
"secureJsonData": {
|
||
![]()
7 years ago
|
"accessKey": "Ol4pIDpeKSA6XikgOl4p",
|
||
|
"secretKey": "dGVzdCBrZXkgYmxlYXNlIGRvbid0IHN0ZWFs"
|
||
![]()
8 years ago
|
}
|
||
![]()
8 years ago
|
}
|
||
|
```
|
||
![]()
10 years ago
|
|
||
![]()
10 years ago
|
## Update an existing data source
|
||
![]()
10 years ago
|
|
||
|
`PUT /api/datasources/:datasourceId`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ----------------- | ---------------------------------------------------------------------------- |
|
||
|
| datasources:write | datasources:\*<br>datasources:id:\*<br>datasources:id:1 (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
10 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
PUT /api/datasources/1 HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
|
||
|
{
|
||
|
"id":1,
|
||
|
"orgId":1,
|
||
|
"name":"test_datasource",
|
||
|
"type":"graphite",
|
||
|
"access":"proxy",
|
||
|
"url":"http://mydatasource.com",
|
||
|
"password":"",
|
||
|
"user":"",
|
||
|
"database":"",
|
||
|
"basicAuth":true,
|
||
|
"basicAuthUser":"basicuser",
|
||
![]()
6 years ago
|
"secureJsonData": {
|
||
|
"basicAuthPassword": "basicpassword"
|
||
|
},
|
||
![]()
8 years ago
|
"isDefault":false,
|
||
|
"jsonData":null
|
||
|
}
|
||
|
```
|
||
![]()
10 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
![]()
10 years ago
|
|
||
![]()
6 years ago
|
{
|
||
|
"datasource": {
|
||
|
"id": 1,
|
||
|
"orgId": 1,
|
||
|
"name": "test_datasource",
|
||
|
"type": "graphite",
|
||
|
"typeLogoUrl": "",
|
||
|
"access": "proxy",
|
||
|
"url": "http://mydatasource.com",
|
||
|
"password": "",
|
||
|
"user": "",
|
||
|
"database": "",
|
||
|
"basicAuth": true,
|
||
|
"basicAuthUser": "basicuser",
|
||
|
"basicAuthPassword": "",
|
||
|
"withCredentials": false,
|
||
|
"isDefault": false,
|
||
|
"jsonData": {},
|
||
|
"secureJsonFields": {
|
||
|
"basicAuthPassword": true
|
||
|
},
|
||
|
"version": 1,
|
||
|
"readOnly": false
|
||
|
},
|
||
|
"id": 102,
|
||
|
"message": "Datasource updated",
|
||
|
"name": "test_datasource"
|
||
|
}
|
||
![]()
8 years ago
|
```
|
||
![]()
10 years ago
|
|
||
![]()
5 years ago
|
> **Note:** Similar to [creating a data source](#create-a-data-source), `password` and `basicAuthPassword` should be defined under `secureJsonData` in order to be stored securely as an encrypted blob in the database. Then, the encrypted fields are listed under `secureJsonFields` section in the response.
|
||
![]()
6 years ago
|
|
||
![]()
8 years ago
|
## Delete an existing data source by id
|
||
![]()
10 years ago
|
|
||
|
`DELETE /api/datasources/:datasourceId`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ------------------ | ---------------------------------------------------------------------------- |
|
||
|
| datasources:delete | datasources:\*<br>datasources:id:\*<br>datasources:id:1 (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
10 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
DELETE /api/datasources/1 HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
10 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
![]()
10 years ago
|
|
||
![]()
8 years ago
|
{"message":"Data source deleted"}
|
||
|
```
|
||
![]()
10 years ago
|
|
||
![]()
5 years ago
|
## Delete an existing data source by UID
|
||
|
|
||
|
`DELETE /api/datasources/uid/:uid`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ------------------ | -------------------------------------------------------------------------------------- |
|
||
|
| datasources:delete | datasources:\*<br>datasources:uid:\*<br>datasources:uid:kLtEtcRGk (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
5 years ago
|
**Example request:**
|
||
|
|
||
|
```http
|
||
|
DELETE /api/datasources/uid/kLtEtcRGk HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
![]()
4 years ago
|
{
|
||
|
"message": "Data source deleted",
|
||
|
"id": 1
|
||
|
}
|
||
![]()
5 years ago
|
```
|
||
|
|
||
![]()
8 years ago
|
## Delete an existing data source by name
|
||
|
|
||
|
`DELETE /api/datasources/name/:datasourceName`
|
||
|
|
||
![]()
4 years ago
|
### Required permissions
|
||
|
|
||
|
See note in the [introduction]({{< ref "#data-source-api" >}}) for an explanation.
|
||
|
|
||
|
| Action | Scope |
|
||
|
| ------------------ | ---------------------------------------------------------------------------------------------- |
|
||
|
| datasources:delete | datasources:\*<br>datasources:name:\*<br>datasources:name:test_datasource (single data source) |
|
||
|
|
||
|
### Examples
|
||
|
|
||
![]()
8 years ago
|
**Example Request**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
DELETE /api/datasources/name/test_datasource HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
![]()
8 years ago
|
|
||
|
**Example Response**:
|
||
|
|
||
![]()
8 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
![]()
8 years ago
|
|
||
![]()
5 years ago
|
{
|
||
|
"message":"Data source deleted",
|
||
|
"id": 1
|
||
|
}
|
||
![]()
8 years ago
|
```
|
||
![]()
8 years ago
|
|
||
![]()
10 years ago
|
## Data source proxy calls
|
||
|
|
||
|
`GET /api/datasources/proxy/:datasourceId/*`
|
||
|
|
||
![]()
6 years ago
|
Proxies all calls to the actual data source.
|
||
![]()
4 years ago
|
|
||
![]()
3 years ago
|
## Check data source health by id
|
||
|
|
||
|
> **Warning:** This API is deprecated since Grafana v9.0.0 and will be removed in a future release. Refer to the [new data source health check API](#check-data-source-health).
|
||
|
|
||
|
`GET /api/datasources/:datasourceId/health`
|
||
|
|
||
|
Makes a call to the health endpoint of data source identified by the given `dashboardId`.
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
**Example Request**:
|
||
|
|
||
|
```http
|
||
|
GET api/datasources/112/health HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"message": "1. Successfully queried the CloudWatch metrics API.\n2. Successfully queried the CloudWatch logs API.",
|
||
|
"status": "OK"
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Check data source health
|
||
|
|
||
|
`GET /api/datasources/uid/:uid/health`
|
||
|
|
||
|
Makes a call to the health endpoint of data source identified by the given `uid`.
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
**Example Request**:
|
||
|
|
||
|
```http
|
||
|
GET api/datasources/uid/P8045C56BDA891CB2/health HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"message": "1. Successfully queried the CloudWatch metrics API.\n2. Successfully queried the CloudWatch logs API.",
|
||
|
"status": "OK"
|
||
|
}
|
||
|
```
|
||
|
|
||
|
## Fetch data source resources by id
|
||
|
|
||
|
> **Warning:** This API is deprecated since Grafana v9.0.0 and will be removed in a future release. Refer to the [new data source resources API](#fetch-data-source-resources).
|
||
|
|
||
|
`GET /api/datasources/:datasourceId/resources/*`
|
||
|
|
||
|
Makes a call to the resources endpoint of data source identified by the given `dashboardId`.
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
**Example Request**:
|
||
|
|
||
|
```http
|
||
|
GET api/datasources/112/resources/dimension-keys?region=us-east-2&namespace=AWS%2FEC2&dimensionFilters=%7B%7D&metricName=CPUUtilization HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
[
|
||
|
{
|
||
|
"text": "AutoScalingGroupName",
|
||
|
"value": "AutoScalingGroupName",
|
||
|
"label": "AutoScalingGroupName"
|
||
|
},
|
||
|
{
|
||
|
"text": "ImageId",
|
||
|
"value": "ImageId",
|
||
|
"label": "ImageId"
|
||
|
},
|
||
|
{
|
||
|
"text": "InstanceId",
|
||
|
"value": "InstanceId",
|
||
|
"label": "InstanceId"
|
||
|
},
|
||
|
{
|
||
|
"text": "InstanceType",
|
||
|
"value": "InstanceType",
|
||
|
"label": "InstanceType"
|
||
|
}
|
||
|
]
|
||
|
```
|
||
|
|
||
|
## Fetch data source resources
|
||
|
|
||
|
`GET /api/datasources/uid/:uid/resources/*`
|
||
|
|
||
|
Makes a call to the resources endpoint of data source identified by the given `uid`.
|
||
|
|
||
|
### Examples
|
||
|
|
||
|
**Example Request**:
|
||
|
|
||
|
```http
|
||
|
GET api/datasources/uid/P8045C56BDA891CB2/resources/dimension-keys?region=us-east-2&namespace=AWS%2FEC2&dimensionFilters=%7B%7D&metricName=CPUUtilization HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||
|
```
|
||
|
|
||
|
**Example Response**:
|
||
|
|
||
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
[
|
||
|
{
|
||
|
"text": "AutoScalingGroupName",
|
||
|
"value": "AutoScalingGroupName",
|
||
|
"label": "AutoScalingGroupName"
|
||
|
},
|
||
|
{
|
||
|
"text": "ImageId",
|
||
|
"value": "ImageId",
|
||
|
"label": "ImageId"
|
||
|
},
|
||
|
{
|
||
|
"text": "InstanceId",
|
||
|
"value": "InstanceId",
|
||
|
"label": "InstanceId"
|
||
|
},
|
||
|
{
|
||
|
"text": "InstanceType",
|
||
|
"value": "InstanceType",
|
||
|
"label": "InstanceType"
|
||
|
}
|
||
|
]
|
||
|
```
|
||
|
|
||
![]()
3 years ago
|
## Query a data source
|
||
![]()
4 years ago
|
|
||
![]()
3 years ago
|
Queries a data source having a backend implementation.
|
||
|
|
||
|
`POST /api/ds/query`
|
||
|
|
||
|
> **Note:** Grafana's built-in data sources usually have a backend implementation.
|
||
|
|
||
|
**Example request for the Test data source**:
|
||
|
|
||
|
```http
|
||
|
POST /api/ds/query HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"queries":[
|
||
|
{
|
||
|
"refId":"A",
|
||
|
"scenarioId":"csv_metric_values",
|
||
|
"datasource":{
|
||
|
"uid":"PD8C576611E62080A"
|
||
|
},
|
||
|
"format": "table"
|
||
|
"maxDataPoints":1848,
|
||
|
"intervalMs":200,
|
||
|
"stringInput":"1,20,90,30,5,0",
|
||
|
}
|
||
|
],
|
||
|
"from":"now-5m",
|
||
|
"to":"now"
|
||
|
}
|
||
|
```
|
||
|
|
||
|
JSON Body schema:
|
||
|
|
||
|
- **from/to** – Specifies the time range for the queries. The time can be either epoch timestamps in milliseconds or relative using Grafana time units. For example, `now-5m`.
|
||
|
- **queries** – Specifies one or more queries. Must contain at least 1.
|
||
|
- **queries.datasource.uid** – Specifies the UID of data source to be queried. Each query in the request must have a unique `datasource`.
|
||
|
- **queries.refId** – Specifies an identifier of the query. Defaults to "A".
|
||
|
- **queries.format** – Specifies the format the data should be returned in. Valid options are `time_series` or `table` depending on the data source.
|
||
|
- **queries.maxDataPoints** - Species the maximum amount of data points that a dashboard panel can render. Defaults to 100.
|
||
|
- **queries.intervalMs** - Specifies the time series time interval in milliseconds. Defaults to 1000.
|
||
|
|
||
|
In addition, specific properties of each data source should be added in a request (for example **queries.stringInput** as shown in the request above). To better understand how to form a query for a certain data source, use the Developer Tools in your browser of choice and inspect the HTTP requests being made to `/api/ds/query`.
|
||
|
|
||
|
**Example Test data source time series query response:**
|
||
|
|
||
|
```json
|
||
|
{
|
||
|
"results": {
|
||
|
"A": {
|
||
|
"frames": [
|
||
|
{
|
||
|
"schema": {
|
||
|
"refId": "A",
|
||
|
"fields": [
|
||
|
{
|
||
|
"name": "time",
|
||
|
"type": "time",
|
||
|
"typeInfo": {
|
||
|
"frame": "time.Time"
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
"name": "A-series",
|
||
|
"type": "number",
|
||
|
"typeInfo": {
|
||
|
"frame": "int64",
|
||
|
"nullable": true
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
"data": {
|
||
|
"values": [
|
||
|
[1644488152084, 1644488212084, 1644488272084, 1644488332084, 1644488392084, 1644488452084],
|
||
|
[1, 20, 90, 30, 5, 0]
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|
||
|
|
||
![]()
3 years ago
|
#### Status codes
|
||
|
|
||
|
| Code | Description |
|
||
|
| ---- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
|
| 200 | All data source queries returned a successful response. |
|
||
|
| 400 | Bad request due to invalid JSON, missing content type, missing or invalid fields, etc. Or one or more data source queries were unsuccessful. Refer to the body for more details. |
|
||
|
| 403 | Access denied. |
|
||
|
| 404 | Either the data source or plugin required to fulfil the request could not be found. |
|
||
|
| 500 | Unexpected error. Refer to the body and/or server logs for more details. |
|
||
|
|
||
![]()
3 years ago
|
## Deprecated resources
|
||
|
|
||
|
The following resources have been deprecated. They will be removed in a future release.
|
||
|
|
||
|
### Query a data source by ID
|
||
|
|
||
|
> **Warning:** This API is deprecated since Grafana v8.5.0 and will be removed in a future release. Refer to the [new data source query API](#query-a-data-source-by-id).
|
||
|
|
||
|
Queries a data source having a backend implementation.
|
||
![]()
4 years ago
|
|
||
|
`POST /api/tsdb/query`
|
||
|
|
||
![]()
3 years ago
|
> **Note:** Grafana's built-in data sources usually have a backend implementation.
|
||
![]()
4 years ago
|
|
||
|
**Example Request**:
|
||
|
|
||
|
```http
|
||
|
POST /api/tsdb/query HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"from": "1420066800000",
|
||
|
"to": "1575845999999",
|
||
|
"queries": [
|
||
|
{
|
||
|
"refId": "A",
|
||
|
"intervalMs": 86400000,
|
||
|
"maxDataPoints": 1092,
|
||
|
"datasourceId": 86,
|
||
|
"rawSql": "SELECT 1 as valueOne, 2 as valueTwo",
|
||
|
"format": "table"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
```
|
||
![]()
4 years ago
|
|
||
![]()
4 years ago
|
JSON Body schema:
|
||
|
|
||
![]()
3 years ago
|
- **from/to** – Specifies the time range for the queries. The time can be either epoch timestamps in milliseconds or relative using Grafana time units. For example, `now-5m`.
|
||
|
- **queries.refId** – Specifies an identifier of the query. Defaults to "A".
|
||
|
- **queries.format** – Specifies the format the data should be returned in. Valid options are `time_series` or `table` depending on the data source.
|
||
|
- **queries.datasourceId** – Specifies the data source to be queried. Each `query` in the request must have a unique `datasourceId`.
|
||
|
- **queries.maxDataPoints** - Species the maximum amount of data points that a dashboard panel can render. Defaults to 100.
|
||
|
- **queries.intervalMs** - Specifies the time series time interval in milliseconds. Defaults to 1000.
|
||
![]()
4 years ago
|
|
||
![]()
3 years ago
|
In addition, specific properties of each data source should be added in a request. To better understand how to form a query for a certain data source, use the Developer Tools in your browser of choice and inspect the HTTP requests being made to `/api/tsdb/query`.
|
||
![]()
4 years ago
|
|
||
|
**Example request for the MySQL data source:**
|
||
|
|
||
|
```http
|
||
|
POST /api/tsdb/query HTTP/1.1
|
||
|
Accept: application/json
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"from": "1420066800000",
|
||
|
"to": "1575845999999",
|
||
|
"queries": [
|
||
|
{
|
||
|
"refId": "A",
|
||
|
"intervalMs": 86400000,
|
||
|
"maxDataPoints": 1092,
|
||
|
"datasourceId": 86,
|
||
|
"rawSql": "SELECT\n time,\n sum(opened) AS \"Opened\",\n sum(closed) AS \"Closed\"\nFROM\n issues_activity\nWHERE\n $__unixEpochFilter(time) AND\n period = 'm' AND\n repo IN('grafana/grafana') AND\n opened_by IN('Contributor','Grafana Labs')\nGROUP BY 1\nORDER BY 1\n",
|
||
|
"format": "time_series"
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
```
|
||
|
|
||
|
**Example MySQL time series query response:**
|
||
![]()
4 years ago
|
|
||
![]()
4 years ago
|
```http
|
||
|
HTTP/1.1 200
|
||
|
Content-Type: application/json
|
||
|
|
||
|
{
|
||
|
"results": {
|
||
|
"A": {
|
||
|
"refId": "A",
|
||
|
"meta": {
|
||
|
"rowCount": 0,
|
||
|
"sql": "SELECT\n time,\n sum(opened) AS \"Opened\",\n sum(closed) AS \"Closed\"\nFROM\n issues_activity\nWHERE\n time >= 1420066800 AND time <= 1575845999 AND\n period = 'm' AND\n repo IN('grafana/grafana') AND\n opened_by IN('Contributor','Grafana Labs')\nGROUP BY 1\nORDER BY 1\n"
|
||
|
},
|
||
|
"series": [
|
||
|
{
|
||
|
"name": "Opened",
|
||
|
"points": [
|
||
|
[
|
||
|
109,
|
||
|
1420070400000
|
||
|
],
|
||
|
[
|
||
|
122,
|
||
|
1422748800000
|
||
|
]
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"name": "Closed",
|
||
|
"points": [
|
||
|
[
|
||
|
89,
|
||
|
1420070400000
|
||
|
]
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
```
|