데이터 소스 API - Amazon Managed Grafana

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

데이터 소스 API

데이터 소스 API를 사용하여 Amazon Managed Grafana 워크스페이스에서 데이터 소스를 생성, 업데이트, 삭제하고 관련 작업을 수행합니다.

참고

Amazon Managed Grafana 워크스페이스에서 Grafana API를 사용하려면 유효한 Grafana API 토큰이 있어야 합니다. API 요청의 Authorization 필드에 이를 포함합니다. API 직접 호출을 인증하기 위해 토큰을 생성하는 방법에 대한 자세한 내용은 토큰으로 인증 섹션을 참조하세요.

모든 데이터 소스 가져오기

GET /api/datasources

요청 예제

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

응답의 예

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

ID로 단일 데이터 소스 가져오기

GET /api/datasources/:datasourceId

요청 예제

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

응답의 예

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 }

UID로 단일 데이터 소스 가져오기

GET /api/datasources/uid/:uid

요청 예제

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

응답의 예

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 }

이름으로 단일 데이터 소스 가져오기

GET /api/datasources/name/:name

요청 예제

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

응답의 예

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 }

이름으로 데이터 소스 ID 가져오기

GET /api/datasources/id/:name

요청 예제

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

응답의 예

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

데이터 소스 생성

POST /api/datasources

Graphite 요청 예제

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 }

Graphite 응답 예제

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

secureJsonData에서 passwordbasicAuthPassword를 정의하면 Amazon Managed Grafana는 데이터베이스에서 암호화된 blob로 해당 항목을 안전하게 암호화합니다. 그러면 응답에서 secureJsonFields에 암호화 필드가 나열됩니다.

기본 인증이 활성화된 Graphite 요청 예제

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

기본 인증이 활성화된 응답 예제

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 요청 예제

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

기존 데이터 소스 업데이트

PUT /api/datasources/:datasourceId

요청 예제

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 }

응답의 예

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

데이터베이스에서 암호화된 blob로 안전하게 저장되도록 secureJsonData에서 passwordbasicAuthPassword를 정의하는 것이 좋습니다. 그러면 응답에서 secureJsonFields에 암호화 필드가 나열됩니다.

ID로 데이터 소스 삭제

DELETE /api/datasources/:datasourceId

요청 예제

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

응답의 예

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

UID로 데이터 소스 삭제

DELETE /api/datasources/uid/:uid

요청 예제

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

응답의 예

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

이름으로 데이터 소스 삭제

DELETE /api/datasources/name/:datasourceName

요청 예제

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

응답의 예

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

데이터 소스 프록시 직접 호출

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

실제 데이터 소스에 대한 모든 호출을 프록시합니다.

ID로 데이터 소스 쿼리

POST /api/tsdb/query

백엔드 구현이 있는 데이터 소스를 쿼리합니다. 대부분의 기본 제공 데이터 소스에는 백엔드 구현이 있습니다.

요청 예제

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

from, toqueries 속성은 필수입니다.

JSON 본문 스키마:

  • 시작/종료 - 밀리초 단위 에포크 타임스탬프의 절댓값이거나 Grafana 시간 단위를 사용하는 상댓값이어야 합니다. 예: now-1h.

  • queries.refId - (선택 사항) 쿼리의 식별자를 지정합니다. 기본값은 A입니다.

  • queries.datasourceId - 쿼리할 데이터 소스를 지정합니다. 요청의 각 쿼리에는 고유한 datasourceId가 있어야 합니다.

  • queries.maxDataPoints - (선택 사항) 대시보드 패널에서 렌더링할 수 있는 최대 데이터 포인트 수를 지정합니다. 기본값은 100입니다.

  • queries.intervalIMs - (선택 사항) 시계열의 시간 간격(밀리초 단위)을 지정합니다. 기본값은 1,000입니다.

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

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