

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

# 데이터 소스 API
<a name="v12-Grafana-API-Datasource"></a>

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

**참고**  
Amazon Managed Grafana 워크스페이스에서 Grafana API를 사용하려면 유효한 서비스 계정 토큰이 있어야 합니다. API 요청의 `Authorization` 필드에 이를 포함합니다.

## 모든 데이터 소스 가져오기
<a name="v12-Grafana-API-Datasource-getall"></a>

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

## UID로 단일 데이터 소스 가져오기
<a name="v12-Grafana-API-Datasource-getbyUID"></a>

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

## 이름으로 단일 데이터 소스 가져오기
<a name="v12-Grafana-API-Datasource-getbyName"></a>

```
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 가져오기
<a name="v12-Grafana-API-Datasource-getIDbyName"></a>

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

## 데이터 소스 생성
<a name="v12-Grafana-API-Datasource-create"></a>

```
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`에서 `password` 및 `basicAuthPassword`를 정의하면 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"
  }
}
```

## UID로 데이터 소스 업데이트
<a name="v12-Grafana-API-Datasource-updatebyUID"></a>

```
PUT /api/datasources/uid/:uid
```

지정된 UID와 일치하는 데이터 소스를 업데이트합니다.

**요청 예제**

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

**응답의 예**

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

## UID로 데이터 소스 삭제
<a name="v12-Grafana-API-Datasource-deletebyUID"></a>

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

## 이름으로 데이터 소스 삭제
<a name="v12-Grafana-API-Datasource-deletebyname"></a>

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

## 데이터 소스 프록시 직접 호출
<a name="v12-Grafana-API-Datasource-proxycall"></a>

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

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

## 데이터 소스 쿼리
<a name="v12-Grafana-API-Datasource-querydatasource"></a>

```
POST /api/ds/query
```

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

**요청 예제**

```
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 본문 스키마:
+ **시작/종료** - 쿼리의 시간 범위를 지정합니다. 시간은 밀리초 단위의 에포크 타임스탬프이거나 Grafana 시간 단위를 사용한 상대 시간이어야 합니다. 예를 들어 `now-5m`입니다.
+ **쿼리** - 하나 이상의 쿼리를 지정합니다. 최소 1개를 포함해야 합니다.
+ **queries.datasource.uid** - 쿼리할 데이터 소스의 UID를 지정합니다. 요청의 각 쿼리에는 고유한 `datasource`가 있어야 합니다.
+ **queries.refId** - 쿼리 식별자를 지정합니다. 기본값은 ‘A’입니다.
+ **queries.format** - 데이터가 반환될 형식을 지정합니다. 유효한 옵션은 데이터 소스에 따라 `time_series` 또는 `table`입니다.
+ **queries.maxDataPoints** - 대시보드 패널에서 렌더링할 수 있는 최대 데이터 포인트 수를 지정합니다. 기본값은 100입니다.
+ **queries.intervalMs** - 밀리초 단위의 시계열 시간 간격을 지정합니다. 기본값은 1,000입니다.

또한 각 데이터 소스의 특정 속성을 요청에 추가해야 합니다(예: 위 요청에 표시된 **queries.stringInput**). 특정 데이터 소스에 대한 쿼리 구성 방법을 더 잘 이해하려면 선택한 브라우저에서 개발자 도구를 사용하고 `/api/ds/query`에 대한 HTTP 요청을 검사합니다.

**테스트 데이터 소스 시계열 쿼리 응답의 예**

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

## 기존 데이터 소스 업데이트(사용되지 않음)
<a name="v12-Grafana-API-Datasource-update"></a>

**중요**  
이 엔드포인트는 더 이상 사용되지 않습니다. 대신 [UID로 데이터 소스 업데이트](#v12-Grafana-API-Datasource-updatebyUID)을 사용하세요.

```
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`에서 `password` 및 `basicAuthPassword`를 정의하는 것이 좋습니다. 그러면 응답에서 `secureJsonFields`에 암호화 필드가 나열됩니다.

## ID별로 단일 데이터 소스 가져오기(사용되지 않음)
<a name="v12-Grafana-API-Datasource-getbyId"></a>

**중요**  
이 엔드포인트는 더 이상 사용되지 않습니다. 대신 [UID로 단일 데이터 소스 가져오기](#v12-Grafana-API-Datasource-getbyUID)을 사용하세요.

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

## ID별로 데이터 소스 삭제(사용되지 않음)
<a name="v12-Grafana-API-Datasource-deletebyId"></a>

**중요**  
이 엔드포인트는 더 이상 사용되지 않습니다. 대신 [UID로 데이터 소스 삭제](#v12-Grafana-API-Datasource-deletebyUID)을 사용하세요.

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