Skip to content

Commit 884461b

Browse files
Merge pull request #48 from tarantool/46-prometheus-rate-2
Make Prometheus rps graphs rate() time range configurable
2 parents 52335b9 + 0f6c345 commit 884461b

File tree

9 files changed

+104
-18
lines changed

9 files changed

+104
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
## Changed
10+
- Make Prometheus rps graphs rate() time range configurable
11+
712
## [0.2.1] - 2020-12-11
813
Grafana revisions: [Prometheus revision 2](https://grafana.com/api/dashboards/13054/revisions/2/download)
914

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Guide on Tarantool project prerequirements and metrics collectors configuration
2020
* Paste link to dashboard: https://grafana.com/grafana/dashboards/12567 for InfluxDB, https://grafana.com/grafana/dashboards/13054 for Prometheus;
2121
* Upload json file or paste json file contents: download it from Grafana page ([InfluxDB](https://grafana.com/grafana/dashboards/12567), [Prometheus](https://grafana.com/grafana/dashboards/13054)) or build it by yourself.
2222

23-
1. Set dashboard name, folder, uid (if needed), and metrics database parameters (i.e. InfluxDB source, measurement and policy or Prometheus source and job).
23+
1. Set dashboard name, folder, uid (if needed), and database-related query parameters (InfluxDB source, measurement and policy or Prometheus source, job and rate() time range).
2424
<br/><br/>![Grafana import setup in v6.6.0 for InfluxDB](./docs/grafana_import_setup_v6.png)
2525

2626
# How to build

example/prometheus/prometheus.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# my global config
22
global:
3-
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4-
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
3+
scrape_interval: 1m # Set the scrape interval to every 15 seconds. Default is every 1 minute.
4+
evaluation_interval: 1m # Evaluate rules every 15 seconds. The default is every 1 minute.
55
# scrape_timeout is set to the global default (10s).
66

77
# Alertmanager configuration

tarantool/cluster.libsonnet

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ local prometheus = grafana.prometheus;
230230
datasource=null,
231231
measurement=null,
232232
job=null,
233+
rate_time_range=null,
233234
):: overview_stat(
234235
title=title,
235236
description=(
@@ -251,7 +252,7 @@ local prometheus = grafana.prometheus;
251252
stat_title='Overall space load:',
252253
decimals=2,
253254
unit='ops',
254-
expr=std.format('sum(rate(tnt_stats_op_total{job=~"%s"}[1m]))', job),
255+
expr=std.format('sum(rate(tnt_stats_op_total{job=~"%s"}[%s]))', [job, rate_time_range]),
255256
),
256257

257258
http_rps_stat(
@@ -261,6 +262,7 @@ local prometheus = grafana.prometheus;
261262
datasource=null,
262263
measurement=null,
263264
job=null,
265+
rate_time_range=null,
264266
):: overview_stat(
265267
title=title,
266268
description=(
@@ -282,6 +284,6 @@ local prometheus = grafana.prometheus;
282284
stat_title='Overall HTTP load:',
283285
decimals=2,
284286
unit='reqps',
285-
expr=std.format('sum(rate(http_server_request_latency_count{job=~"%s"}[1m]))', job),
287+
expr=std.format('sum(rate(http_server_request_latency_count{job=~"%s"}[%s]))', [job, rate_time_range]),
286288
),
287289
}

tarantool/dashboard.libsonnet

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local row = grafana.row;
1212
policy=null,
1313
measurement=null,
1414
job=null,
15+
rate_time_range=null,
1516
offset=0
1617
)::
1718
dashboard
@@ -43,6 +44,7 @@ local row = grafana.row;
4344
policy=policy,
4445
measurement=measurement,
4546
job=job,
47+
rate_time_range=rate_time_range,
4648
),
4749
{ w: 8, h: 8, x: 0, y: 1 + offset }
4850
)
@@ -52,6 +54,7 @@ local row = grafana.row;
5254
policy=policy,
5355
measurement=measurement,
5456
job=job,
57+
rate_time_range=rate_time_range,
5558
),
5659
{ w: 8, h: 8, x: 8, y: 1 + offset },
5760
)
@@ -61,6 +64,7 @@ local row = grafana.row;
6164
policy=policy,
6265
measurement=measurement,
6366
job=job,
67+
rate_time_range=rate_time_range,
6468
),
6569
{ w: 8, h: 8, x: 16, y: 1 + offset },
6670
)
@@ -190,6 +194,7 @@ local row = grafana.row;
190194
policy=policy,
191195
measurement=measurement,
192196
job=job,
197+
rate_time_range=rate_time_range,
193198
),
194199
{ w: 8, h: 8, x: 0, y: 46 + offset },
195200
)
@@ -199,6 +204,7 @@ local row = grafana.row;
199204
policy=policy,
200205
measurement=measurement,
201206
job=job,
207+
rate_time_range=rate_time_range,
202208
),
203209
{ w: 8, h: 8, x: 8, y: 46 + offset },
204210
)
@@ -208,6 +214,7 @@ local row = grafana.row;
208214
policy=policy,
209215
measurement=measurement,
210216
job=job,
217+
rate_time_range=rate_time_range,
211218
),
212219
{ w: 8, h: 8, x: 16, y: 46 + offset },
213220
)
@@ -217,6 +224,7 @@ local row = grafana.row;
217224
policy=policy,
218225
measurement=measurement,
219226
job=job,
227+
rate_time_range=rate_time_range,
220228
),
221229
{ w: 8, h: 8, x: 0, y: 46 + offset },
222230
)
@@ -226,6 +234,7 @@ local row = grafana.row;
226234
policy=policy,
227235
measurement=measurement,
228236
job=job,
237+
rate_time_range=rate_time_range,
229238
),
230239
{ w: 8, h: 8, x: 8, y: 46 + offset },
231240
)
@@ -235,6 +244,7 @@ local row = grafana.row;
235244
policy=policy,
236245
measurement=measurement,
237246
job=job,
247+
rate_time_range=rate_time_range,
238248
),
239249
{ w: 8, h: 8, x: 16, y: 46 + offset },
240250
),

tarantool/http.libsonnet

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local prometheus = grafana.prometheus;
1212
policy,
1313
measurement,
1414
job,
15+
rate_time_range,
1516
metric_name,
1617
status_regex,
1718
) = graph.new(
@@ -35,7 +36,8 @@ local prometheus = grafana.prometheus;
3536
).addTarget(
3637
if datasource == '${DS_PROMETHEUS}' then
3738
prometheus.target(
38-
expr=std.format('rate(%s{job=~"%s",status=~"%s"}[1m])', [metric_name, job, std.strReplace(status_regex, '\\', '\\\\')]),
39+
expr=std.format('rate(%s{job=~"%s",status=~"%s"}[%s])',
40+
[metric_name, job, std.strReplace(status_regex, '\\', '\\\\'), rate_time_range]),
3941
legendFormat='{{alias}} — {{method}} {{path}} (code {{status}})',
4042
)
4143
else if datasource == '${DS_INFLUXDB}' then
@@ -59,6 +61,7 @@ local prometheus = grafana.prometheus;
5961
policy=null,
6062
measurement=null,
6163
job=null,
64+
rate_time_range=null,
6265
metric_name='http_server_request_latency_count',
6366
):: rps_graph(
6467
title=title,
@@ -67,6 +70,7 @@ local prometheus = grafana.prometheus;
6770
policy=policy,
6871
measurement=measurement,
6972
job=job,
73+
rate_time_range=rate_time_range,
7074
metric_name=metric_name,
7175
status_regex='^2\\d{2}$',
7276
),
@@ -82,6 +86,7 @@ local prometheus = grafana.prometheus;
8286
policy=null,
8387
measurement=null,
8488
job=null,
89+
rate_time_range=null,
8590
metric_name='http_server_request_latency_count',
8691
):: rps_graph(
8792
title=title,
@@ -90,6 +95,7 @@ local prometheus = grafana.prometheus;
9095
policy=policy,
9196
measurement=measurement,
9297
job=job,
98+
rate_time_range=rate_time_range,
9399
metric_name=metric_name,
94100
status_regex='^4\\d{2}$',
95101
),
@@ -105,6 +111,7 @@ local prometheus = grafana.prometheus;
105111
policy=null,
106112
measurement=null,
107113
job=null,
114+
rate_time_range=null,
108115
metric_name='http_server_request_latency_count',
109116
):: rps_graph(
110117
title=title,
@@ -113,6 +120,7 @@ local prometheus = grafana.prometheus;
113120
policy=policy,
114121
measurement=measurement,
115122
job=job,
123+
rate_time_range=rate_time_range,
116124
metric_name=metric_name,
117125
status_regex='^5\\d{2}$',
118126
),

tarantool/prometheus_dashboard.jsonnet

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local raw_dashboard = grafana.dashboard.new(
1515
);
1616

1717
local datasource = '${DS_PROMETHEUS}';
18+
local rate_time_range = '$rate_time_range';
1819
local job = '[[job]]';
1920

2021
dashboard.build(
@@ -35,6 +36,13 @@ dashboard.build(
3536
pluginName=null,
3637
description='Prometheus Tarantool metrics job'
3738
)
39+
.addInput(
40+
name='PROMETHEUS_RATE_TIME_RANGE',
41+
label='Rate time range',
42+
type='constant',
43+
value='2m',
44+
description='Time range for computing rps graphs with rate(). At the very minimum it should be two times the scrape interval.'
45+
)
3846
.addRequired(
3947
type='datasource',
4048
id='prometheus',
@@ -61,6 +69,15 @@ dashboard.build(
6169
hide='variable',
6270
label='Prometheus job',
6371
),
72+
)
73+
.addTemplate(
74+
grafana.template.custom(
75+
name='rate_time_range',
76+
query='${PROMETHEUS_RATE_TIME_RANGE}',
77+
current='${PROMETHEUS_RATE_TIME_RANGE}',
78+
hide='variable',
79+
label='rate() time range',
80+
),
6481
).addPanel(
6582
cluster.health_overview_table(
6683
datasource=datasource,
@@ -89,16 +106,19 @@ dashboard.build(
89106
cluster.space_ops_stat(
90107
datasource=datasource,
91108
job=job,
109+
rate_time_range=rate_time_range,
92110
),
93111
{ w: 4, h: 4, x: 20, y: 0 }
94112
).addPanel(
95113
cluster.http_rps_stat(
96114
datasource=datasource,
97115
job=job,
116+
rate_time_range=rate_time_range,
98117
),
99118
{ w: 4, h: 4, x: 20, y: 4 }
100119
),
101120
datasource,
102121
job=job,
122+
rate_time_range=rate_time_range,
103123
offset=8,
104124
)

tarantool/space.libsonnet

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ local prometheus = grafana.prometheus;
1212
policy=null,
1313
measurement=null,
1414
job=null,
15+
rate_time_range=null,
1516
operation=null,
1617
) = graph.new(
1718
title=(if title != null then title else std.format('%s requests', std.asciiUpper(operation))),
@@ -39,7 +40,7 @@ local prometheus = grafana.prometheus;
3940
).addTarget(
4041
if datasource == '${DS_PROMETHEUS}' then
4142
prometheus.target(
42-
expr=std.format('rate(tnt_stats_op_total{job=~"%s",operation="%s"}[1m])', [job, operation]),
43+
expr=std.format('rate(tnt_stats_op_total{job=~"%s",operation="%s"}[%s])', [job, operation, rate_time_range]),
4344
legendFormat='{{alias}}'
4445
)
4546
else if datasource == '${DS_INFLUXDB}' then
@@ -59,13 +60,15 @@ local prometheus = grafana.prometheus;
5960
policy=null,
6061
measurement=null,
6162
job=null,
63+
rate_time_range=null,
6264
):: operation_rps(
6365
title=title,
6466
description=description,
6567
datasource=datasource,
6668
policy=policy,
6769
measurement=measurement,
6870
job=job,
71+
rate_time_range=rate_time_range,
6972
operation='select'
7073
),
7174

@@ -76,13 +79,15 @@ local prometheus = grafana.prometheus;
7679
policy=null,
7780
measurement=null,
7881
job=null,
82+
rate_time_range=null,
7983
):: operation_rps(
8084
title=title,
8185
description=description,
8286
datasource=datasource,
8387
policy=policy,
8488
measurement=measurement,
8589
job=job,
90+
rate_time_range=rate_time_range,
8691
operation='insert'
8792
),
8893

@@ -93,13 +98,15 @@ local prometheus = grafana.prometheus;
9398
policy=null,
9499
measurement=null,
95100
job=null,
101+
rate_time_range=null,
96102
):: operation_rps(
97103
title=title,
98104
description=description,
99105
datasource=datasource,
100106
policy=policy,
101107
measurement=measurement,
102108
job=job,
109+
rate_time_range=rate_time_range,
103110
operation='replace'
104111
),
105112

@@ -110,13 +117,15 @@ local prometheus = grafana.prometheus;
110117
policy=null,
111118
measurement=null,
112119
job=null,
120+
rate_time_range=null,
113121
):: operation_rps(
114122
title=title,
115123
description=description,
116124
datasource=datasource,
117125
policy=policy,
118126
measurement=measurement,
119127
job=job,
128+
rate_time_range=rate_time_range,
120129
operation='upsert'
121130
),
122131

@@ -127,13 +136,15 @@ local prometheus = grafana.prometheus;
127136
policy=null,
128137
measurement=null,
129138
job=null,
139+
rate_time_range=null,
130140
):: operation_rps(
131141
title=title,
132142
description=description,
133143
datasource=datasource,
134144
policy=policy,
135145
measurement=measurement,
136146
job=job,
147+
rate_time_range=rate_time_range,
137148
operation='update'
138149
),
139150

@@ -144,13 +155,15 @@ local prometheus = grafana.prometheus;
144155
policy=null,
145156
measurement=null,
146157
job=null,
158+
rate_time_range=null,
147159
):: operation_rps(
148160
title=title,
149161
description=description,
150162
datasource=datasource,
151163
policy=policy,
152164
measurement=measurement,
153165
job=job,
166+
rate_time_range=rate_time_range,
154167
operation='delete'
155168
),
156169
}

0 commit comments

Comments
 (0)