Skip to content

Commit 2b968ca

Browse files
committed
metrics: upgrade to 0.3.0 version
1 parent 6857f69 commit 2b968ca

File tree

3 files changed

+25
-30
lines changed

3 files changed

+25
-30
lines changed
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
local cartridge = require('cartridge')
2-
local metrics = require("metrics")
3-
local json_metrics = require("metrics.plugins.json")
4-
local prometheus = require("metrics.plugins.prometheus")
5-
local http_middleware = metrics.http_middleware
6-
7-
metrics.set_global_labels({ alias = 'instance'})
8-
metrics.enable_default_metrics()
92

103
local function init(opts) -- luacheck: no unused args
114
-- if opts.is_master then
125
-- end
6+
local metrics = cartridge.service_get('metrics')
7+
local http_middleware = metrics.http_middleware
8+
139
local http_collector = http_middleware.build_default_collector('average')
1410

1511
local httpd = cartridge.service_get('httpd')
@@ -23,24 +19,6 @@ local function init(opts) -- luacheck: no unused args
2319
)
2420
)
2521

26-
httpd:route(
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-
)
34-
)
35-
36-
httpd:route(
37-
{ path = '/metrics/prometheus' },
38-
http_middleware.v1(
39-
prometheus.collect_http,
40-
http_collector
41-
)
42-
)
43-
4422
return true
4523
end
4624

@@ -64,5 +42,4 @@ return {
6442
stop = stop,
6543
validate_config = validate_config,
6644
apply_config = apply_config,
67-
-- dependencies = {'cartridge.roles.vshard-router'},
6845
}

example/project/init.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ else
2727
end
2828

2929
local cartridge = require('cartridge')
30-
local cartridge_admin = require('cartridge.admin')
3130
local membership = require('membership')
3231
local log = require("log")
3332
local ok, err = cartridge.cfg({
3433
workdir = 'tmp/db',
3534
roles = {
3635
'cartridge.roles.vshard-storage',
3736
'cartridge.roles.vshard-router',
38-
'app.roles.custom',
37+
'cartridge.roles.metrics',
38+
'app.roles.custom'
3939
},
4040
cluster_cookie = 'project-cluster-cookie',
4141
})
@@ -45,6 +45,7 @@ assert(ok, tostring(err))
4545
local all = {
4646
'vshard-storage',
4747
'vshard-router',
48+
'metrics',
4849
'app.roles.custom'
4950
}
5051

@@ -56,10 +57,27 @@ local _, err = cartridge.admin_join_server({
5657
if err ~= nil then
5758
log.warn('%s', tostring(err))
5859
else
59-
local _, err = cartridge_admin.bootstrap_vshard()
60+
local _, err = cartridge.admin_bootstrap_vshard()
6061
if err ~= nil then
6162
log.error('%s', tostring(err))
6263
os.exit(1)
6364
end
65+
66+
-- This code is only for example purposes
67+
-- DO NOT USE IT IN PROD CLUSTERS WITH MORE THAN 1 INSTANCE!
68+
cartridge.config_patch_clusterwide({
69+
metrics = {
70+
export = {
71+
{
72+
path = '/metrics',
73+
format = 'json'
74+
},
75+
{
76+
path = '/metrics/prometheus',
77+
format = 'prometheus'
78+
}
79+
}
80+
}
81+
})
6482
end
6583

example/project/project-scm-1.rockspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = {
1010
'checks == 3.0.1-1',
1111
'http == 1.1.0-1',
1212
'cartridge == 2.1.2-1',
13-
'metrics == 0.2.0'
13+
'metrics ~> 0.3'
1414
}
1515
build = {
1616
type = 'none';

0 commit comments

Comments
 (0)