API Sumber Data - Amazon Managed Grafana

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

API Sumber Data

Gunakan API Sumber Data untuk membuat, memperbarui, menghapus, dan bekerja dengan sumber data di ruang kerja Grafana Terkelola Amazon.

catatan

Untuk menggunakan Grafana API dengan ruang kerja Grafana Amazon Managed, Anda harus memiliki token Grafana API yang valid. Anda menyertakan ini di Authorization bidang dalam permintaan API. Untuk informasi tentang cara membuat token untuk mengautentikasi panggilan API Anda, lihatOtentikasi dengan token.

Dapatkan semua sumber data

GET /api/datasources

Permintaan contoh

GET /api/datasources HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

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

Dapatkan satu sumber data dengan Id

GET /api/datasources/:datasourceId

Permintaan contoh

GET /api/datasources/1 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

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 }

Dapatkan satu sumber data dengan UID

GET /api/datasources/uid/:uid

Permintaan contoh

GET /api/datasources/uid/kLtEtcRGk HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

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 }

Dapatkan satu sumber data dengan nama

GET /api/datasources/name/:name

Permintaan contoh

GET /api/datasources/name/test_datasource HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

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 }

Dapatkan Id sumber data berdasarkan nama

GET /api/datasources/id/:name

Permintaan contoh

GET /api/datasources/id/test_datasource HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

HTTP/1.1 200 Content-Type: application/json { "id":1 }

Buat sumber data

POST /api/datasources

Contoh permintaan Grafit

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 }

Contoh respon grafit

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

Saat Anda menentukan password dan basicAuthPassword di dalamnyasecureJsonData, Grafana Terkelola Amazon mengenkripsi mereka dengan aman sebagai gumpalan terenkripsi dalam database. Respons kemudian mencantumkan bidang enkripsi di. secureJsonFields

Contoh permintaan Grafit dengan autentikasi dasar diaktifkan

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

Contoh respons dengan autentikasi dasar diaktifkan

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

CloudWatch Permintaan contoh

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

Perbarui sumber data yang ada

PUT /api/datasources/:datasourceId

Permintaan contoh

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 }

Contoh respon

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

Kami menyarankan Anda mendefinisikan password dan basicAuthPassword di dalam secureJsonData sehingga mereka disimpan dengan aman sebagai gumpalan terenkripsi dalam database. Respons kemudian mencantumkan bidang enkripsi di. secureJsonFields

Hapus sumber data dengan Id

DELETE /api/datasources/:datasourceId

Permintaan contoh

DELETE /api/datasources/1 HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

HTTP/1.1 200 Content-Type: application/json {"message":"Data source deleted"}

Hapus sumber data dengan UID

DELETE /api/datasources/uid/:uid

Permintaan contoh

DELETE /api/datasources/uid/kLtEtcRGk HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

HTTP/1.1 200 Content-Type: application/json {"message":"Data source deleted"}

Hapus sumber data dengan nama

DELETE /api/datasources/name/:datasourceName

Permintaan contoh

DELETE /api/datasources/name/test_datasource HTTP/1.1 Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk

Contoh respon

HTTP/1.1 200 Content-Type: application/json { "message":"Data source deleted", "id": 1 }

Panggilan proxy sumber data

GET /api/datasources/proxy/:datasourceId/*

Proksi semua panggilan ke sumber data aktual.

Sumber data kueri oleh Id

POST /api/tsdb/query

Kueri sumber data yang memiliki implementasi backend. Sebagian besar sumber data bawaan memiliki implementasi backend.

Permintaan contoh

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

Itufrom,to, dan queries properti diperlukan.

Skema tubuh JSON:

  • dari/ke — Harus mutlak dalam stempel waktu epoch dalam milidetik, atau relatif menggunakan satuan waktu Grafana. Misalnya, now-1h.

  • Queries.refid - (Opsional) Menentukan identifier untuk query. Nilai default-nya A.

  • Queries.DataSourceID - Menentukan sumber data yang akan ditanyakan. Setiap kueri dalam permintaan harus memiliki yang unikdatasourceId.

  • pertanyaan. maxDataPoints— (Opsional) Menentukan jumlah maksimum titik data yang panel dashboard dapat render. Secara default, nilainya adalah 100.

  • Queries.intervalims - (Opsional) Menentukan interval waktu dalam milidetik deret waktu. Defaultnya adalah 1000

Contoh permintaan untuk sumber data MySQL:

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

Contoh respon untuk permintaan sumber data MySQL:

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