

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

# API Sumber Data
<a name="v12-Grafana-API-Datasource"></a>

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
<a name="v12-Grafana-API-Datasource-getall"></a>

```
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 UID
<a name="v12-Grafana-API-Datasource-getbyUID"></a>

```
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
<a name="v12-Grafana-API-Datasource-getbyName"></a>

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

```
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
<a name="v12-Grafana-API-Datasource-create"></a>

```
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 dalamnya`secureJsonData`, 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 dengan UID
<a name="v12-Grafana-API-Datasource-updatebyUID"></a>

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

Memperbarui sumber data yang cocok dengan UID yang diberikan.

**Permintaan contoh**

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

**Contoh respon**

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

## Hapus sumber data dengan UID
<a name="v12-Grafana-API-Datasource-deletebyUID"></a>

```
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
<a name="v12-Grafana-API-Datasource-deletebyname"></a>

```
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
<a name="v12-Grafana-API-Datasource-proxycall"></a>

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

Proksi semua panggilan ke sumber data aktual.

## Sumber data kueri
<a name="v12-Grafana-API-Datasource-querydatasource"></a>

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

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

**Permintaan contoh**

```
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_series` atau `table` tergantung 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 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]
            ]
          }
        }
      ]
    }
  }
}
```

## Memperbarui sumber data yang ada (tidak digunakan lagi)
<a name="v12-Grafana-API-Datasource-update"></a>

**penting**  
Titik akhir ini tidak digunakan lagi. Gunakan [Perbarui sumber data dengan UID](#v12-Grafana-API-Datasource-updatebyUID) sebagai gantinya.

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

## Dapatkan satu sumber data dengan Id (tidak digunakan lagi)
<a name="v12-Grafana-API-Datasource-getbyId"></a>

**penting**  
Titik akhir ini tidak digunakan lagi. Gunakan [Dapatkan satu sumber data dengan UID](#v12-Grafana-API-Datasource-getbyUID) sebagai gantinya.

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

## Hapus sumber data dengan Id (tidak digunakan lagi)
<a name="v12-Grafana-API-Datasource-deletebyId"></a>

**penting**  
Titik akhir ini tidak digunakan lagi. Gunakan [Hapus sumber data dengan UID](#v12-Grafana-API-Datasource-deletebyUID) sebagai gantinya.

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