This page covers prometheus connector properties for dataSource configuration and the nuances associated with prometheus connector.
Prometheus Connector Properties.
prometheus.uri[Required].- This parameters provides the URI information to connect to a prometheus instance.
prometheus.auth.type[Optional]- This parameters provides the authentication type information.
- Prometheus connector currently supports
basicauthandawssigv4authentication mechanisms. - If prometheus.auth.type is basicauth, following are required parameters.
prometheus.auth.usernameandprometheus.auth.password.
- If prometheus.auth.type is awssigv4, following are required parameters.
prometheus.auth.region,prometheus.auth.access_keyandprometheus.auth.secret_key
No Auth
[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:9090"
}
}]
Basic Auth
[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:9090",
"prometheus.auth.type" : "basicauth",
"prometheus.auth.username" : "admin",
"prometheus.auth.password" : "admin"
}
}]
AWSSigV4 Auth
[{
"name" : "my_prometheus",
"connector": "prometheus",
"properties" : {
"prometheus.uri" : "http://localhost:8080",
"prometheus.auth.type" : "awssigv4",
"prometheus.auth.region" : "us-east-1",
"prometheus.auth.access_key" : "{{accessKey}}",
"prometheus.auth.secret_key" : "{{secretKey}}"
}
}]
Each connector has to abstract the underlying datasource constructs into a table as part of the interface contract with the PPL query engine.
Prometheus connector abstracts each metric as a table and the columns of this table are @value, @timestamp, label1, label2---.
@value represents metric measurement and @timestamp represents the timestamp at which the metric is collected. labels are tags associated with metric queried.
For eg: handler, code, instance, code are the labels associated with prometheus_http_requests_total metric. With this abstraction, we can query prometheus
data using PPL syntax similar to opensearch indices.
Sample Example
source = my_prometheus.prometheus_http_requests_total
Expected output:
+--------+-----------------------+--------------+------+------------+------------+
| @value | @timestamp | handler | code | instance | job |
|--------+-----------------------+--------------+------+------------+------------|
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 400 | 192.15.2.1 | prometheus |
| 9 | "2022-11-03 07:18:54" | "/-/promql" | 400 | 192.15.2.1 | prometheus |
| 11 | "2022-11-03 07:18:64" | "/-/metrics" | 500 | 192.15.2.1 | prometheus |
+--------+-----------------------+--------------+------+------------+------------+
Since time range and resolution are required parameters for query apis and these parameters are determined in the following manner from the PPL commands.
- Time range is determined through filter clause on
@timestamp. If there is no such filter clause, time range will be set to 1h with endtime set to now(). - In case of stats, resolution is determined by
span(@timestamp,15s)expression. For normal select queries, resolution is auto determined from the time range set.
- Only one aggregation is supported in stats command.
- Span Expression is compulsory in stats command.
- AVG, MAX, MIN, SUM, COUNT are the only aggregations supported in prometheus connector.
- Where clause only supports EQUALS(=) operation on metric dimensions and Comparative(> , < , >= , <=) Operations on @timestamp attribute.
- Metric Selection Query
source = my_prometheus.prometheus_http_requests_total
Expected output:
+--------+-----------------------+--------------+------+------------+------------+
| @value | @timestamp | handler | code | instance | job |
|--------+-----------------------+--------------+------+------------+------------|
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 400 | 192.15.2.1 | prometheus |
| 9 | "2022-11-03 07:18:54" | "/-/promql" | 400 | 192.15.2.1 | prometheus |
| 11 | "2022-11-03 07:18:64" | "/-/metrics" | 500 | 192.15.2.1 | prometheus |
+--------+-----------------------+--------------+------+------------+------------+
- Metric Selecting Query with specific dimensions
source = my_prometheus.prometheus_http_requests_total
| where handler='/-/ready' and code='200'
Expected output:
+--------+-----------------------+------------+------+------------+------------+
| @value | @timestamp | handler | code | instance | job |
|--------+-----------------------+------------+------+------------+------------|
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 200 | 192.15.2.1 | prometheus |
| 9 | "2022-11-03 07:18:54" | "/-/ready" | 200 | 192.15.2.1 | prometheus |
| 11 | "2022-11-03 07:18:64" | "/-/ready" | 200 | 192.15.2.1 | prometheus |
+--------+-----------------------+------------+------+------------+------------+
- Average aggregation on a metric
source = my_prometheus.prometheus_http_requests_total
| stats avg(@value) by span(@timestamp,15s)
Expected output:
+------------+------------------------+
| avg(@value)| span(@timestamp,15s) |
|------------+------------------------+
| 5 | "2022-11-03 07:18:14" |
| 3 | "2022-11-03 07:18:24" |
| 7 | "2022-11-03 07:18:34" |
| 2 | "2022-11-03 07:18:44" |
| 9 | "2022-11-03 07:18:54" |
| 11 | "2022-11-03 07:18:64" |
+------------+------------------------+
- Average aggregation grouped by dimensions
source = my_prometheus.prometheus_http_requests_total
| stats avg(@value) by span(@timestamp,15s), handler, code
Expected output:
+------------+------------------------+--------------------------------+---------------+
| avg(@value)| span(@timestamp,15s) | handler | code |
|------------+------------------------+--------------------------------+---------------+
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 400 |
| 9 | "2022-11-03 07:18:54" | "/-/promql" | 400 |
| 11 | "2022-11-03 07:18:64" | "/-/metrics" | 500 |
+------------+------------------------+--------------------------------+---------------+
- Count aggregation query
source = my_prometheus.prometheus_http_requests_total
| stats count() by span(@timestamp,15s), handler, code
Expected output:
+------------+------------------------+--------------------------------+---------------+
| count() | span(@timestamp,15s) | handler | code |
|------------+------------------------+--------------------------------+---------------+
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 400 |
| 9 | "2022-11-03 07:18:54" | "/-/promql" | 400 |
| 11 | "2022-11-03 07:18:64" | "/-/metrics" | 500 |
+------------+------------------------+--------------------------------+---------------+
- Prometheus connector offers
query_rangetable function. This table function can be used to query metrics in a specific time range using promQL. - The function takes inputs similar to parameters mentioned for query range api mentioned here: Prometheus query_range API
- Arguments should be either passed by name or positionArguments should be either passed by name or position.
source=my_prometheus.query_range('prometheus_http_requests_total', 1686694425, 1686700130, 14)source=my_prometheus.query_range(query='prometheus_http_requests_total', starttime=1686694425, endtime=1686700130, step=14)
Example
source=my_prometheus.query_range('prometheus_http_requests_total', 1686694425, 1686700130, 14)
Expected output:
+--------+-----------------------+--------------+------+------------+------------+
| @value | @timestamp | handler | code | instance | job |
|--------+-----------------------+--------------+------+------------+------------|
| 5 | "2022-11-03 07:18:14" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 3 | "2022-11-03 07:18:24" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 7 | "2022-11-03 07:18:34" | "/-/ready" | 200 | 192.15.1.1 | prometheus |
| 2 | "2022-11-03 07:18:44" | "/-/ready" | 400 | 192.15.2.1 | prometheus |
| 9 | "2022-11-03 07:18:54" | "/-/promql" | 400 | 192.15.2.1 | prometheus |
| 11 | "2022-11-03 07:18:64" | "/-/metrics" | 500 | 192.15.2.1 | prometheus |
+--------+-----------------------+--------------+------+------------+------------+
- This table function can be used to fetch exemplars of a query in a specific time range.
- The function takes inputs similar to parameters mentioned for query exemplars api mentioned here: Prometheus query_exemplars API
- Arguments should be either passed by name or positionArguments should be either passed by name or position.
source=my_prometheus.query_exemplars('prometheus_http_requests_total', 1686694425, 1686700130)source=my_prometheus.query_exemplars(query='prometheus_http_requests_total', starttime=1686694425, endtime=1686700130)
Example
source=my_prometheus.query_exemplars('prometheus_http_requests_total', 1686694425, 1686700130)
Expected output:
"schema": [
{
"name": "seriesLabels",
"type": "struct"
},
{
"name": "exemplars",
"type": "array"
}
],
"datarows": [
[
{
"instance": "localhost:8090",
"__name__": "test_exemplar_metric_total",
"service": "bar",
"job": "prometheus"
},
[
{
"labels": {
"traceID": "EpTxMJ40fUus7aGY"
},
"timestamp": "2020-09-14 15:22:25.479",
"value": 6.0
}
]
],
[
{
"instance": "localhost:8090",
"__name__": "test_exemplar_metric_total",
"service": "foo",
"job": "prometheus"
},
[
{
"labels": {
"traceID": "Olp9XHlq763ccsfa"
},
"timestamp": "2020-09-14 15:22:35.479",
"value": 19.0
},
{
"labels": {
"traceID": "hCtjygkIHwAN9vs4"
},
"timestamp": "2020-09-14 15:22:45.489",
"value": 20.0
}
]
]
]