Skip to content

Commit dbb3374

Browse files
DifferentialOrangevasiliy-t
authored andcommitted
Add HTTP metrics to example stand and HTTP panels to dashboard
Update metrics and fixate HTTP plugin version used by example stand Tarantool. Add metrics HTTP middleware to example stand Tarantool, update Telegraf config. Add HTTP panels with latency and rps, grouped by codes.
1 parent 82ae335 commit dbb3374

File tree

6 files changed

+1258
-42
lines changed

6 files changed

+1258
-42
lines changed

example/project/app/roles/custom.lua

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,44 @@ local cartridge = require('cartridge')
22
local metrics = require("metrics")
33
local json_metrics = require("metrics.plugins.json")
44
local prometheus = require("metrics.plugins.prometheus")
5+
local http_middleware = metrics.http_middleware
56

67
metrics.set_global_labels({ alias = 'instance'})
78
metrics.enable_default_metrics()
89

910
local function init(opts) -- luacheck: no unused args
1011
-- if opts.is_master then
1112
-- end
13+
local http_collector = http_middleware.build_default_collector('average')
1214

1315
local httpd = cartridge.service_get('httpd')
14-
httpd:route({method = 'GET', path = '/hello'}, function()
15-
return {body = 'Hello world!'}
16-
end)
16+
httpd:route(
17+
{ method = 'GET', path = '/hello' },
18+
http_middleware.v1(
19+
function()
20+
return { body = 'Hello world!' }
21+
end,
22+
http_collector
23+
)
24+
)
1725

18-
local httpd = cartridge.service_get("httpd")
1926
httpd:route(
20-
{method = "GET", path = "/metrics"},
21-
function(req)
22-
return req:render({text = json_metrics.export()})
23-
end
27+
{ method = 'GET', path = '/metrics' },
28+
http_middleware.v1(
29+
function(req)
30+
return req:render({ text = json_metrics.export() })
31+
end,
32+
http_collector
33+
)
2434
)
2535

26-
httpd:route({path = "/metrics/prometheus"}, prometheus.collect_http)
36+
httpd:route(
37+
{ path = '/metrics/prometheus' },
38+
http_middleware.v1(
39+
prometheus.collect_http,
40+
http_collector
41+
)
42+
)
2743

2844
return true
2945
end

example/project/project-scm-1.rockspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ dependencies = {
88
'tarantool',
99
'lua >= 5.1',
1010
'checks == 3.0.1-1',
11+
'http == 1.1.0-1',
1112
'cartridge == 2.1.2-1',
12-
'metrics == 0.1.8'
13+
'metrics == 0.2.0'
1314
}
1415
build = {
1516
type = 'none';

example/telegraf/telegraf.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[inputs.http]]
22
urls = ["http://example_project:8081/metrics"]
33
timeout = "30s"
4-
tag_keys = ["metric_name", "label_pairs_alias"]
4+
tag_keys = ["metric_name", "label_pairs_alias", "label_pairs_path", "label_pairs_method", "label_pairs_status"]
55
insecure_skip_verify = true
66
interval = "10s"
77
data_format = "json"

tarantool/dashboard.libsonnet

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local grafana = import 'grafonnet/grafana.libsonnet';
22

3+
local http = import 'http.libsonnet';
34
local slab = import 'slab.libsonnet';
45

56
local datasource = 'default';
@@ -61,73 +62,119 @@ dashboard
6162
version=''
6263
)
6364
.addPanel(
64-
grafana.row.new(title='Tarantool memory overview'),
65+
grafana.row.new(title='Tarantool HTTP statistics'),
6566
{ w: 24, h: 1, x: 0, y: 0 }
6667
)
68+
.addPanel(
69+
http.rps_success(
70+
datasource=datasource,
71+
measurement=measurement,
72+
),
73+
{ w: 8, h: 8, x: 0, y: 1 }
74+
)
75+
.addPanel(
76+
http.rps_error_4xx(
77+
datasource=datasource,
78+
measurement=measurement,
79+
),
80+
{ w: 8, h: 8, x: 8, y: 1 },
81+
)
82+
.addPanel(
83+
http.rps_error_5xx(
84+
datasource=datasource,
85+
measurement=measurement,
86+
),
87+
{ w: 8, h: 8, x: 16, y: 1 },
88+
)
89+
.addPanel(
90+
http.latency_success(
91+
datasource=datasource,
92+
measurement=measurement,
93+
),
94+
{ w: 8, h: 8, x: 0, y: 9 }
95+
)
96+
.addPanel(
97+
http.latency_error_4xx(
98+
datasource=datasource,
99+
measurement=measurement,
100+
),
101+
{ w: 8, h: 8, x: 8, y: 9 },
102+
)
103+
.addPanel(
104+
http.latency_error_5xx(
105+
datasource=datasource,
106+
measurement=measurement,
107+
),
108+
{ w: 8, h: 8, x: 16, y: 9 },
109+
)
110+
.addPanel(
111+
grafana.row.new(title='Tarantool memory overview'),
112+
{ w: 24, h: 1, x: 0, y: 17 }
113+
)
67114
.addPanel(
68115
slab.monitor_info(),
69-
{ w: 24, h: 3, x: 0, y: 1 }
116+
{ w: 24, h: 3, x: 0, y: 18 }
70117
)
71118
.addPanel(
72119
slab.quota_used_ratio(
73120
datasource=datasource,
74121
measurement=measurement,
75122
),
76-
{ w: 8, h: 8, x: 0, y: 4 }
123+
{ w: 8, h: 8, x: 0, y: 21 }
77124
)
78125
.addPanel(
79126
slab.arena_used_ratio(
80127
datasource=datasource,
81128
measurement=measurement,
82129
),
83-
{ w: 8, h: 8, x: 8, y: 4 },
130+
{ w: 8, h: 8, x: 8, y: 21 },
84131
)
85132
.addPanel(
86133
slab.items_used_ratio(
87134
datasource=datasource,
88135
measurement=measurement,
89136
),
90-
{ w: 8, h: 8, x: 16, y: 4 },
137+
{ w: 8, h: 8, x: 16, y: 21 },
91138
)
92139
.addPanel(
93140
slab.quota_used(
94141
datasource=datasource,
95142
measurement=measurement,
96143
),
97-
{ w: 8, h: 8, x: 0, y: 12 }
144+
{ w: 8, h: 8, x: 0, y: 29 }
98145
)
99146
.addPanel(
100147
slab.arena_used(
101148
datasource=datasource,
102149
measurement=measurement,
103150
),
104-
{ w: 8, h: 8, x: 8, y: 12 },
151+
{ w: 8, h: 8, x: 8, y: 29 },
105152
)
106153
.addPanel(
107154
slab.items_used(
108155
datasource=datasource,
109156
measurement=measurement,
110157
),
111-
{ w: 8, h: 8, x: 16, y: 12 },
158+
{ w: 8, h: 8, x: 16, y: 29 },
112159
)
113160
.addPanel(
114161
slab.quota_size(
115162
datasource=datasource,
116163
measurement=measurement,
117164
),
118-
{ w: 8, h: 8, x: 0, y: 20 }
165+
{ w: 8, h: 8, x: 0, y: 37 }
119166
)
120167
.addPanel(
121168
slab.arena_size(
122169
datasource=datasource,
123170
measurement=measurement,
124171
),
125-
{ w: 8, h: 8, x: 8, y: 20 },
172+
{ w: 8, h: 8, x: 8, y: 37 },
126173
)
127174
.addPanel(
128175
slab.items_size(
129176
datasource=datasource,
130177
measurement=measurement,
131178
),
132-
{ w: 8, h: 8, x: 16, y: 20 },
179+
{ w: 8, h: 8, x: 16, y: 37 },
133180
)

tarantool/http.libsonnet

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
local grafana = import 'grafonnet/grafana.libsonnet';
2+
3+
local graph = grafana.graphPanel;
4+
local influxdb = grafana.influxdb;
5+
6+
{
7+
local rps_graph(
8+
title,
9+
description,
10+
datasource,
11+
measurement,
12+
metric_name,
13+
status_regex,
14+
) = graph.new(
15+
title=title,
16+
description=description,
17+
datasource=datasource,
18+
19+
format='none',
20+
labelY1='requests per second',
21+
fill=0,
22+
decimals=2,
23+
decimalsY1=0,
24+
sort='decreasing',
25+
legend_alignAsTable=true,
26+
legend_avg=true,
27+
legend_current=true,
28+
legend_max=true,
29+
legend_values=true,
30+
legend_sort='current',
31+
legend_sortDesc=true,
32+
).addTarget(
33+
influxdb.target(
34+
measurement=measurement,
35+
group_tags=['label_pairs_alias', 'label_pairs_path', 'label_pairs_method', 'label_pairs_status'],
36+
alias='$tag_label_pairs_alias — $tag_label_pairs_method $tag_label_pairs_path (code $tag_label_pairs_status)',
37+
).where('metric_name', '=', metric_name).where('label_pairs_status', '=~', status_regex)
38+
.selectField('value').addConverter('mean').addConverter('non_negative_derivative', ['1s'])
39+
),
40+
41+
rps_success(
42+
title='Success requests (code 2xx)',
43+
description=|||
44+
Requests, processed with success (code 2xx) on Tarantool's side.
45+
Graph shows mean count per second.
46+
|||,
47+
48+
datasource=null,
49+
measurement=null,
50+
metric_name='http_server_request_latency_count',
51+
):: rps_graph(
52+
title=title,
53+
description=description,
54+
datasource=datasource,
55+
measurement=measurement,
56+
metric_name=metric_name,
57+
status_regex='/^2\\d{2}$/',
58+
),
59+
60+
rps_error_4xx(
61+
title='Error requests (code 4xx)',
62+
description=|||
63+
Requests, processed with 4xx error on Tarantool's side.
64+
Graph shows mean count per second.
65+
|||,
66+
67+
datasource=null,
68+
measurement=null,
69+
metric_name='http_server_request_latency_count',
70+
):: rps_graph(
71+
title=title,
72+
description=description,
73+
datasource=datasource,
74+
measurement=measurement,
75+
metric_name=metric_name,
76+
status_regex='/^4\\d{2}$/',
77+
),
78+
79+
rps_error_5xx(
80+
title='Error requests (code 5xx)',
81+
description=|||
82+
Requests, processed with 5xx error on Tarantool's side.
83+
Graph shows mean count per second.
84+
|||,
85+
86+
datasource=null,
87+
measurement=null,
88+
metric_name='http_server_request_latency_count',
89+
):: rps_graph(
90+
title=title,
91+
description=description,
92+
datasource=datasource,
93+
measurement=measurement,
94+
metric_name=metric_name,
95+
status_regex='/^5\\d{2}$/',
96+
),
97+
98+
local latency_graph(
99+
title,
100+
description,
101+
datasource,
102+
measurement,
103+
metric_name,
104+
status_regex,
105+
) = graph.new(
106+
title=title,
107+
description=description,
108+
datasource=datasource,
109+
110+
format='s',
111+
labelY1='average',
112+
fill=0,
113+
decimals=3,
114+
decimalsY1=2,
115+
sort='decreasing',
116+
legend_alignAsTable=true,
117+
legend_avg=true,
118+
legend_current=true,
119+
legend_max=true,
120+
legend_values=true,
121+
legend_sort='current',
122+
legend_sortDesc=true,
123+
).addTarget(
124+
influxdb.target(
125+
measurement=measurement,
126+
group_tags=['label_pairs_alias', 'label_pairs_path', 'label_pairs_method', 'label_pairs_status'],
127+
alias='$tag_label_pairs_alias — $tag_label_pairs_method $tag_label_pairs_path (code $tag_label_pairs_status)',
128+
).where('metric_name', '=', metric_name).where('label_pairs_status', '=~', status_regex)
129+
.selectField('value').addConverter('mean')
130+
),
131+
132+
latency_success(
133+
title='Success requests latency (code 2xx)',
134+
description=|||
135+
Latency of requests, processed with success (code 2xx) on Tarantool's side.
136+
|||,
137+
138+
datasource=null,
139+
measurement=null,
140+
metric_name='http_server_request_latency_avg',
141+
):: latency_graph(
142+
title=title,
143+
description=description,
144+
datasource=datasource,
145+
measurement=measurement,
146+
metric_name=metric_name,
147+
status_regex='/^2\\d{2}$/',
148+
),
149+
150+
latency_error_4xx(
151+
title='Error requests latency (code 4xx)',
152+
description=|||
153+
Latency of requests, processed with 4xx error on Tarantool's side.
154+
|||,
155+
156+
datasource=null,
157+
measurement=null,
158+
metric_name='http_server_request_latency_avg',
159+
):: latency_graph(
160+
title=title,
161+
description=description,
162+
datasource=datasource,
163+
measurement=measurement,
164+
metric_name=metric_name,
165+
status_regex='/^4\\d{2}$/',
166+
),
167+
168+
latency_error_5xx(
169+
title='Error requests latency (code 5xx)',
170+
description=|||
171+
Latency of requests, processed with 5xx error on Tarantool's side.
172+
|||,
173+
174+
datasource=null,
175+
measurement=null,
176+
metric_name='http_server_request_latency_avg',
177+
):: latency_graph(
178+
title=title,
179+
description=description,
180+
datasource=datasource,
181+
measurement=measurement,
182+
metric_name=metric_name,
183+
status_regex='/^5\\d{2}$/',
184+
),
185+
}

0 commit comments

Comments
 (0)