forked from RageZBla/docs-metric-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusing.html.md.erb
293 lines (228 loc) · 8.82 KB
/
using.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
---
title: Querying the Metric Store
owner: Log Cache
---
Learn how to configure and use Metric Store.
Metric Store implements the Prometheus Query Language for querying metrics for which you have access.
## <a id='prerequisites'></a> Prerequisites
- Completed [installation](installing.html) of the Metric Store Tile.
- [curl](https://github.com/curl/curl)
- [CF Auth Token](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html)
## <a id='using'></a> Using Metric Store
### <a id='authorization-authentication'></a> Authorization & Authentication
When querying the API through HTTPS, each request must have the `Authorization`
header set with a UAA provided token.
#### For Metric Store admins
As a Metric Store admin, you have access to all recorded metrics (platform and application) and can
run Label and Series queries.
You need to add either `doppler.firehose` or `logs.admin` scope to your admin account.
You then can run the following query:
```shell
cf login
curl -vvv -H "Authorization: $(cf oauth-token)" -G https://metric-store.SYSTEM-DOMAIN/api/v1/label/source_id/values
```
The status code is 200 if everything is working properly.
#### For Tanzu Application Service developers
As a Tanzu Application Service developer, you can query metrics for applications that you have access.
When querying with PromQL, you must specify the `source_id` label with the application `guid` as the label value.
For example:
```shell
curl -H "Authorization: $(cf oauth-token)" -G "https://metric-store.SYSTEM-DOMAIN/api/v1/query" \
--data-urlencode "query=cpu{source_id=\"$(cf app --guid your-app-name)\"}"
```
##### Standard Tanzu Application Service application metrics
<table class=“table”>
<thead>
<tr>
<th>Metric Name</th>
<th>Description</th>
<th>PromQL Example</th>
</tr>
</thead>
<tbody>
<tr>
<td>cpu</td>
<td>CPU usage percentage</td>
<td><code>avg(cpu{source_id="$app_guid"})</code></td>
</tr>
<tr>
<td>memory</td>
<td>Memory usage in bytes</td>
<td><code>avg(memory{source_id="$app_guid"})</code></td>
</tr>
<tr>
<td>memory_quota</td>
<td>Memory Quota allocated in bytes</td>
<td><code>memory{source_id="$app_guid"} / memory_quota{source_id="$app_guid"}</code></td>
</tr>
<tr>
<td>disk</td>
<td>Disk usage in bytes</td>
<td><code>avg(disk{source_id="$app_guid"}) / 1024 / 1024 / 1024 # in gigabytes</code></td>
</tr>
<tr>
<td>disk_quota</td>
<td>Disk quota allocated in bytes</td>
<td><code>disk{source_id="$app_guid"} / disk_quota{source_id="$app_guid"}</code></td>
</tr>
<tr>
<td>http_total</td>
<td>HTTP request counts includes status</td>
<td><code>sum(rate(http_total{source_id="$app_guid"})) by (status)</code></td>
</tr>
<tr>
<td>http_duration_seconds_*</td>
<td>HTTP request request latencies bucketed by duration</td>
<td><code>histogram_quantile(0.95, sum(rate(http_duration_seconds_bucket[5m])) by (le))</code></td>
</tr>
</tbody>
</table>
## <a id='querying'></a> Querying through Prometheus-Compatible HTTP Endpoints
### Notes on PromQL
The ultimate goal of these endpoints is to create a fully-compliant,
Prometheus-compatible interface. This allows tools such as Grafana to
work directly with Metric Store without any additional translation.
A valid PromQL metric name consists of the character [a-Z][0-9] and underscore. Names can begin with [a-Z] or underscore. Names cannot begin with [0-9].
As a measure to work with existing metrics that do not comply with the previous mentioned format a conversion process takes place when matching on metric names.
Any character that is not in the set of valid characters is converted to an underscore.
The metric is not changed in the store.
For example, to match on a metric name ``http.latency`` use the name ``http_latency`` as a search term.
### **GET** `/api/v1/query`
Issues a PromQL instant query against Metric Store data. You can read more
detail in the Prometheus documentation [here](https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries).
Query Parameters:
- **query** is a [Prometheus expression query string](https://prometheus.io/docs/prometheus/latest/querying/basics/#querying-prometheus).
- **time** is an optional UNIX timestamp in seconds or RFC3339. (e.g. `date -d '24 hours ago' +%s`).
Admins (`doppler.firehose` or `logs.admin`) are permitted to use this query without specifying a source_id in the query parameter. Non-admins cannot use regex matchers on source_id.
```shell
$ curl -H "Authorization: $(cf oauth-token)" -G "https://metric-store.SYSTEM-DOMAIN/api/v1/query" --data-urlencode 'query=metric_name_0{source_id="source_id_0"}'
```
##### Response Body
```json
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {"__name__": "metric_name"},
"value": [ "<timestamp>", "<value>" ]
},
"..."
]
}
}
```
### **GET** `/api/v1/query_range`
Issues a PromQL range query against Metric Store data. You can read more detail
in the Prometheus documentation [here](https://prometheus.io/docs/prometheus/latest/querying/api/#range-queries).
Query Parameters:
- **query** is a [Prometheus expression query string](https://prometheus.io/docs/prometheus/latest/querying/basics/#querying-prometheus).
- **start** is a UNIX timestamp in seconds or RFC3339. (e.g. `date -d '24 hours ago' +%s`). Start time is inclusive. `[start..end)`
- **end** is a UNIX timestamp in seconds or RFC3339. (e.g. `date +%s`). End time is exclusive. `[start..end)`
- **step** is a query resolution step width in `duration` format or float number of seconds.
<p> Admins (`doppler.firehose` or `logs.admin`) are permitted to use this query without specifying a source_id in the query parameter. Non-admins cannot use regex matchers on source_id.</p>
```shell
$ curl -H "Authorization: $(cf oauth-token)" -G "https://metric-store.SYSTEM-DOMAIN/api/v1/query_range" \
--data-urlencode 'query=metric_name_0{source_id="source_id_0"}' \
--data-urlencode "start=$(date -d '24 hours ago' +%s)" \
--data-urlencode "end=$(date +%s)" \
--data-urlencode 'step=1h'
```
##### Response Body
```json
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {"__name__": "metric_name"},
"values": [
[ "<timestamp>", "<value>" ],
"..."
]
},
"..."
]
}
}
```
### **GET** `/api/v1/series`
Issues a PromQL series query against Metric Store data. You can read more detail
in the Prometheus documentation [here](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers).
<p> Non-admins (`doppler.firehose` or `logs.admin`) are not permitted to use this query.</p>
Query Parameters:
- **start** is a UNIX timestamp in seconds or RFC3339. (e.g. `date -d '24 hours ago' +%s`). Start time is inclusive. `[start..end)`
- **end** is a UNIX timestamp in seconds or RFC3339. (e.g. `date +%s`). End time is exclusive. `[start..end)`
- **match[]** is a [series selector](https://prometheus.io/docs/prometheus/latest/querying/basics/#time-series-selectors).
```shell
$ curl -H "Authorization: $(cf oauth-token)" -G "https://metric-store.SYSTEM-DOMAIN/api/v1/series" \
--data-urlencode 'match[]=metric_name_0' \
--data-urlencode 'match[]=metric_name_1' \
--data-urlencode "start=$(date -d '24 hours ago' +%s)" \
--data-urlencode "end=$(date +%s)"
```
##### Response Body
```json
{
"status": "success",
"data": [
{
"__name__": "metric_name_0",
"source_id": "source_id_0",
"...": ".."
},
"..."
]
}
```
### **GET** `/api/v1/labels`
Retrieve all label names for authorized source ids from the store.
<p> Non-admins (`doppler.firehose` or `logs.admin`) are not permitted to use this query.</p>
##### Request
```shell
$ curl -H "Authorization: $(cf oauth-token)" "https://metric-store.SYSTEM-DOMAIN/api/v1/labels"
```
##### Response Body
```json
{
"status": "success",
"data": [
"__name__",
"deployment",
"..."
"ip",
"origin",
"request_type",
"source_id",
"status_code",
"unit"
]
}
```
### **GET** `/api/v1/label/<label_name>/values`
Retrieve label values by `label_name` for all authorized source ids. The special label `__name__` can be used to retrieve metric names from the store.
<p> Non-admins (`doppler.firehose` or `logs.admin`) are not permitted to use this query.</p>
##### Request
```shell
$ curl -H "Authorization: $(cf oauth-token)" "https://metric-store.SYSTEM-DOMAIN/api/v1/label/<label-name>/values"
```
##### Response Body
```json
{
"status":"success",
"data":["10", "1"]
}
```
##### Request
```shell
$ curl -H "Authorization: $(cf oauth-token)" "https://metric-store.SYSTEM-DOMAIN/api/v1/label/__name__/values"
```
##### Response Body
```json
{
"status":"success",
"data":["metric_name_0", "metric_name_1", "..." ]
}
```