View a markdown version of this page

Datenquellen-API - Amazon Managed Grafana

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.

Datenquellen-API

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 Dienstkonto-Token. Sie fügen dies in das Authorization Feld in der API-Anfrage ein.

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 einzige Datenquelle nach UID

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 Datenquelle anhand der UID

PUT /api/datasources/uid/:uid

Aktualisiert die Datenquelle, die der angegebenen UID entspricht.

Beispielanforderung

PUT /api/datasources/uid/kLtEtcRGk 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, "isDefault": false }

Beispielantwort

HTTP/1.1 200 Content-Type: application/json { "datasource": { "id": 1, "uid": "kLtEtcRGk", "orgId": 1, "name": "test_datasource", "type": "graphite", "access": "proxy", "url": "http://mydatasource.com", "basicAuth": false, "isDefault": false }, "name": "test_datasource" }

Löscht die Datenquelle anhand der 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:

  • from/to— 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 oder table hängen von der Datenquelle ab.

  • queries.max DataPoints — Gibt die maximale Anzahl von 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] ] } } ] } } }

Aktualisieren Sie eine vorhandene Datenquelle (veraltet)

Wichtig

Dieser Endpunkt ist veraltet. Verwenden Sie stattdessen Aktualisieren Sie eine Datenquelle anhand der UID.

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

Es wird empfohlen, sie secureJsonData so zu definieren password und basicAuthPassword darin zu speichern, dass sie sicher als verschlüsselter Blob in der Datenbank gespeichert werden. In der Antwort werden dann die verschlüsselten Felder in aufgeführt. secureJsonFields

Ruft eine einzelne Datenquelle nach ID ab (veraltet)

Wichtig

Dieser Endpunkt ist veraltet. Verwenden Sie stattdessen Holen Sie sich eine einzige Datenquelle nach UID.

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 }

Datenquelle nach ID löschen (veraltet)

Wichtig

Dieser Endpunkt ist veraltet. Verwenden Sie stattdessen Löscht die Datenquelle anhand der UID.

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"}