Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.
Verwenden Sie die Datenquellen-API, um Datenquellen im Amazon Managed Grafana-Arbeitsbereich zu erstellen, zu aktualisieren, zu löschen und mit ihnen zu arbeiten.
Anmerkung
Um eine Grafana-API mit Ihrem Amazon Managed Grafana-Workspace verwenden zu können, benötigen Sie ein gültiges Grafana-API-Token. Sie fügen dies in das Authorization
Feld in der API-Anfrage ein. Informationen zum Erstellen eines Tokens zur Authentifizierung Ihrer API-Aufrufe finden Sie unterAuthentifizieren Sie sich mit Tokens.
Holen Sie sich alle Datenquellen
GET /api/datasources
Beispielanforderung
GET /api/datasources HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
[
{
"id": 1,
"orgId": 1,
"uid": "H8joYFVGz"
"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
}
]
Holen Sie sich eine einzelne Datenquelle nach ID
GET /api/datasources/:datasourceId
Beispielanforderung
GET /api/datasources/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{
"id": 1,
"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
}
Ruft eine einzelne Datenquelle nach UID ab
GET /api/datasources/uid/:uid
Beispielanforderung
GET /api/datasources/uid/kLtEtcRGk HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{
"id": 1,
"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
}
Ruft eine einzelne Datenquelle nach Namen ab
GET /api/datasources/name/:name
Beispielanforderung
GET /api/datasources/name/test_datasource HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{
"id": 1,
"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
}
Ruft die Datenquellen-ID nach Namen ab
GET /api/datasources/id/:name
Beispielanforderung
GET /api/datasources/id/test_datasource HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{
"id":1
}
Erstellen einer Datenquelle
POST /api/datasources
Beispiel für eine Graphite-Anfrage
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
}
Beispiel für eine Graphite-Antwort
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"
}
Anmerkung
Wenn Sie sie definieren password
und basicAuthPassword
innerhalbsecureJsonData
, verschlüsselt Amazon Managed Grafana sie sicher als verschlüsselten Blob in der Datenbank. In der Antwort werden dann die verschlüsselten Felder in aufgeführt. secureJsonFields
Beispiel für eine Graphite-Anfrage mit aktivierter Basisauthentifizierung
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"
}
}
Beispielantwort mit aktivierter Basisauthentifizierung
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"
}
Beispiel für CloudWatch eine Anfrage
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": {
"accessKey": "Ol4pIDpeKSA6XikgOl4p",
"secretKey": "dGVzdCBrZXkgYmxlYXNlIGRvbid0IHN0ZWFs"
}
}
Aktualisieren Sie eine vorhandene Datenquelle
PUT /api/datasources/:datasourceId
Beispielanforderung
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",
"secureJsonData": {
"basicAuthPassword": "basicpassword"
},
"isDefault":false,
"jsonData":null
}
Beispielantwort
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 updated",
"name": "test_datasource"
}
Anmerkung
Wir empfehlen, dass Sie sie definieren password
und basicAuthPassword
darin speichern, secureJsonData
sodass sie sicher als verschlüsselter Blob in der Datenbank gespeichert werden. In der Antwort werden dann die verschlüsselten Felder in aufgeführt. secureJsonFields
Löschen Sie die Datenquelle nach ID
DELETE /api/datasources/:datasourceId
Beispielanforderung
DELETE /api/datasources/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{"message":"Data source deleted"}
Löschen Sie die Datenquelle nach UID
DELETE /api/datasources/uid/:uid
Beispielanforderung
DELETE /api/datasources/uid/kLtEtcRGk HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{"message":"Data source deleted"}
Löschen Sie die Datenquelle nach Namen
DELETE /api/datasources/name/:datasourceName
Beispielanforderung
DELETE /api/datasources/name/test_datasource HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
Beispielantwort
HTTP/1.1 200
Content-Type: application/json
{
"message":"Data source deleted",
"id": 1
}
Proxy-Aufrufe für Datenquellen
GET /api/datasources/proxy/:datasourceId/*
Leitet alle Aufrufe an die tatsächliche Datenquelle weiter.
Datenquellen abfragen
POST /api/ds/query
Fragt eine Datenquelle mit einer Backend-Implementierung ab. Die meisten integrierten Datenquellen verfügen über eine Backend-Implementierung.
Beispielanforderung
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-Textschema:
von/bis — Gibt den Zeitraum für die Abfragen an. Bei der Zeit kann es sich entweder um Epochenzeitstempel in Millisekunden oder um relative Zeitstempel mit Grafana-Zeiteinheiten handeln. Beispiel,
now-5m
.Abfragen — Gibt eine oder mehrere Abfragen an. Muss mindestens 1 enthalten.
queries.datasource.uid — Gibt die UID der Datenquelle an, die abgefragt werden soll. Jede Abfrage in der Anfrage
datasource
muss eindeutig sein.queries.Refid — Gibt einen Bezeichner der Abfrage an. Der Standardwert ist „A“.
queries.format — Gibt das Format an, in dem die Daten zurückgegeben werden sollen. Gültige Optionen sind
time_series
odertable
hängen von der Datenquelle ab.Abfragen. maxDataPoints— Gibt die maximale Menge an Datenpunkten an, die ein Dashboard-Panel rendern kann. Der Standardwert ist 100.
queries.intervalMS — Gibt das Zeitreihen-Zeitintervall in Millisekunden an. Der Standardwert ist 1000.
Darüber hinaus sollten einer Anfrage spezifische Eigenschaften jeder Datenquelle hinzugefügt werden (z. B. queries.stringInput, wie in der obigen Anfrage gezeigt). Um besser zu verstehen, wie eine Abfrage für eine bestimmte Datenquelle erstellt wird, verwenden Sie die Entwicklertools in Ihrem Browser Ihrer Wahl und überprüfen Sie die HTTP-Anfragen, an die gestellt werden. /api/ds/query
Beispiel für eine Antwort auf eine Testdatenquelle, eine Zeitreihenabfrage
HTTP/1.1 200
Content-Type: application/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]
]
}
}
]
}
}
}
Datenquelle nach ID abfragen
POST /api/tsdb/query
Wichtig
Ab Version 9 /api/tsdb/query
wird es nicht unterstützt. Verwenden Sie Datenquellen abfragen.
Fragt eine Datenquelle mit Backend-Implementierung ab. Die meisten integrierten Datenquellen verfügen über eine Backend-Implementierung.
Beispielanforderung
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"
}
]
}
Anmerkung
Die queries
Eigenschaften from
to
, und sind erforderlich.
JSON-Textschema:
-
von/bis — Muss entweder absolut in Epochenzeitstempeln in Millisekunden oder relativ unter Verwendung von Grafana-Zeiteinheiten sein. Beispiel,
now-1h
. -
queries.Refid — (Optional) Gibt einen Bezeichner für die Abfrage an. Der Standardwert ist
A
. -
queries.dataSourceID — Gibt die Datenquelle an, die abgefragt werden soll. Jede Abfrage in der Anfrage muss eindeutig sein.
datasourceId
-
Abfragen. maxDataPoints— (Optional) Gibt die maximale Anzahl von Datenpunkten an, die ein Dashboard-Panel rendern kann. Der Standardwert ist 100.
-
queries.interval IMs — (Optional) Gibt das Zeitintervall in Millisekunden für Zeitreihen an. Die Standardeinstellung ist 1000
Beispielanfrage für die MySQL-Datenquelle:
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"
}
]
}
Beispielantwort für die MySQL-Datenquellenanforderung:
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
]
]
}
]
}
}
}