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 API Grafana dengan ruang kerja Grafana yang Dikelola Amazon, Anda harus memiliki token akun layanan yang valid. Anda menyertakan ini di Authorization bidang dalam permintaan API.
Dapatkan semua sumber data
GET /api/datasources
Contoh permintaan
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
Contoh permintaan
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
Contoh permintaan
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
Contoh permintaan
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
Contoh permintaan
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" }
Contoh CloudWatch permintaan
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
Contoh permintaan
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
Contoh permintaan
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
Contoh permintaan
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
Contoh permintaan
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
POST /api/ds/query
Kueri sumber data yang memiliki implementasi backend. Sebagian besar sumber data bawaan memiliki implementasi backend.
Contoh permintaan
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" }
Skema tubuh JSON:
from/to- Menentukan rentang waktu untuk pertanyaan. Waktu dapat berupa stempel waktu epoch dalam milidetik atau relatif menggunakan satuan waktu Grafana. Misalnya,
now-5m.query - Menentukan satu atau lebih pertanyaan. Harus mengandung setidaknya 1.
queries.datasource.uid - Menentukan UID sumber data yang akan ditanyakan. Setiap kueri dalam permintaan harus memiliki yang unik
datasource.Queries.refid - Menentukan identifier dari query. Default ke “A”.
queries.format - Menentukan format data harus dikembalikan. Opsi yang valid adalah
time_seriesatautabletergantung pada sumber data.queries.max DataPoints — Spesies jumlah maksimum titik data yang dapat dirender oleh panel dasbor. Default ke 100.
Queries.intervalms - Menentukan interval waktu deret waktu dalam milidetik. Default ke 1000.
Selain itu, properti spesifik dari setiap sumber data harus ditambahkan dalam permintaan (misalnya queries.StringInput seperti yang ditunjukkan pada permintaan di atas). Untuk lebih memahami cara membentuk kueri untuk sumber data tertentu, gunakan Alat Pengembang di browser pilihan Anda dan periksa permintaan HTTP yang sedang dibuat. /api/ds/query
Contoh uji respons kueri deret waktu sumber data
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] ] } } ] } } }
Sumber data kueri oleh Id
POST /api/tsdb/query
penting
Mulai Versi 9, /api/tsdb/query tidak didukung. Gunakan Sumber data kueri.
Kueri sumber data yang memiliki implementasi backend. Sebagian besar sumber data bawaan memiliki implementasi backend.
Contoh permintaan
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:
-
from/to— Harus absolut 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 unik
datasourceId. -
queries.max DataPoints - (Opsional) Menentukan jumlah maksimum titik data yang panel dashboard dapat membuat. 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 ] ] } ] } } }