diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f8917c72..d6df0fe6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,7 +2,7 @@ name: Tests on: push: branches: - - '*' + - '**' paths-ignore: - 'doc/**' jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 16bc630e..1755dc1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Handle to clear psutils metrics +- `invoke_callbacks` option for `metrics.collect()` +- Ability to set metainfo for collectors +- Set `metainfo.default` to `true` for all collectors + from `enable_default_metrics()` and psutils collectors +- `default_only` option for `metrics.collect()` ### Fixed diff --git a/doc/monitoring/api_reference.rst b/doc/monitoring/api_reference.rst index 452c20bc..128ca3fb 100644 --- a/doc/monitoring/api_reference.rst +++ b/doc/monitoring/api_reference.rst @@ -24,12 +24,13 @@ A collector represents one or more observations that change over time. counter ~~~~~~~ -.. function:: counter(name [, help]) +.. function:: counter(name [, help, metainfo]) Register a new counter. :param string name: collector name. Must be unique. :param string help: collector description. + :param table metainfo: collector metainfo. :return: A counter object. :rtype: counter_obj @@ -85,12 +86,13 @@ counter gauge ~~~~~ -.. function:: gauge(name [, help]) +.. function:: gauge(name [, help, metainfo]) Register a new gauge. :param string name: collector name. Must be unique. :param string help: collector description. + :param table metainfo: collector metainfo. :return: A gauge object. @@ -127,7 +129,7 @@ gauge histogram ~~~~~~~~~ -.. function:: histogram(name [, help, buckets]) +.. function:: histogram(name [, help, buckets, metainfo]) Register a new histogram. @@ -136,6 +138,7 @@ histogram :param table buckets: histogram buckets (an array of sorted positive numbers). The infinity bucket (``INF``) is appended automatically. Default: ``{.005, .01, .025, .05, .075, .1, .25, .5, .75, 1.0, 2.5, 5.0, 7.5, 10.0, INF}``. + :param table metainfo: collector metainfo. :return: A histogram object. @@ -184,7 +187,7 @@ histogram summary ~~~~~~~ -.. function:: summary(name [, help, objectives, params]) +.. function:: summary(name [, help, objectives, params, metainfo]) Register a new summary. Quantile computation is based on the `"Effective computation of biased quantiles over data streams" `_ @@ -217,6 +220,8 @@ summary and how smooth the time window moves. Default value: ``{max_age_time = math.huge, age_buckets_count = 1}``. + :param table metainfo: collector metainfo. + :return: A summary object. :rtype: summary_obj @@ -328,6 +333,7 @@ Metrics functions * ``event_loop`` See :ref:`metrics reference ` for details. + All metric collectors from the collection have ``metainfo.default = true``. .. function:: set_global_labels(label_pairs) @@ -347,10 +353,15 @@ Metrics functions Note that both label names and values in ``label_pairs`` are treated as strings. -.. function:: collect() +.. function:: collect([opts]) Collect observations from each collector. + :param table opts: table of collect options: + + * ``invoke_callbacks`` -- if ``true``, ``invoke_callbacks()`` is triggerred before actual collect. + * ``default_only`` -- if ``true``, observations contain only default metrics (``metainfo.default = true``). + .. class:: registry .. method:: unregister(collector) @@ -431,6 +442,7 @@ Metrics functions .. function:: invoke_callbacks() Invoke all registered callbacks. Has to be called before each ``collect()``. + (Since version **0.16.0**, you may use ``collect{invoke_callbacks = true}`` instead.) If you're using one of the default exporters, ``invoke_callbacks()`` will be called by the exporter. @@ -605,6 +617,8 @@ To enable CPU metrics, first register a callback function: sum by (thread_name) (idelta(tnt_cpu_thread[$__interval])) / scalar(idelta(tnt_cpu_total[$__interval]) / tnt_cpu_count) +All psutils metric collectors have ``metainfo.default = true``. + To clear CPU metrics when you don't need them anymore, remove the callback and clear the collectors with a method: .. code-block:: lua diff --git a/metrics/cartridge/failover.lua b/metrics/cartridge/failover.lua index 8b4e5945..28de70a3 100644 --- a/metrics/cartridge/failover.lua +++ b/metrics/cartridge/failover.lua @@ -18,7 +18,10 @@ local function update() utils.set_counter( 'cartridge_failover_trigger_total', 'Count of Cartridge Failover triggers', - trigger_cnt + trigger_cnt, + nil, + nil, + {default = true} ) end end diff --git a/metrics/cartridge/issues.lua b/metrics/cartridge/issues.lua index 7b5318b2..1c9207ee 100644 --- a/metrics/cartridge/issues.lua +++ b/metrics/cartridge/issues.lua @@ -21,13 +21,15 @@ local function update() for _, level in ipairs(levels) do local len = fun.iter(issues):filter(function(x) return x.level == level end):length() collectors_list.cartridge_issues = - utils.set_gauge('cartridge_issues', 'Tarantool Cartridge issues', len, {level = level}) + utils.set_gauge('cartridge_issues', 'Tarantool Cartridge issues', + len, {level = level}, nil, {default = true}) end local global_issues_cnt = rawget(_G, '__cartridge_issues_cnt') if global_issues_cnt ~= nil then collectors_list.global_issues = - utils.set_gauge('cartridge_cluster_issues', 'Tarantool Cartridge cluster issues', global_issues_cnt) + utils.set_gauge('cartridge_cluster_issues', 'Tarantool Cartridge cluster issues', + global_issues_cnt, nil, nil, {default = true}) end end diff --git a/metrics/collectors/histogram.lua b/metrics/collectors/histogram.lua index b1d496a0..2e4b7575 100644 --- a/metrics/collectors/histogram.lua +++ b/metrics/collectors/histogram.lua @@ -18,8 +18,9 @@ function Histogram.check_buckets(buckets) return true end -function Histogram:new(name, help, buckets) - local obj = Shared.new(self, name, help) +function Histogram:new(name, help, buckets, metainfo) + metainfo = table.copy(metainfo) or {} + local obj = Shared.new(self, name, help, metainfo) obj.buckets = buckets or DEFAULT_BUCKETS table.sort(obj.buckets) @@ -27,9 +28,9 @@ function Histogram:new(name, help, buckets) obj.buckets[#obj.buckets+1] = INF end - obj.count_collector = Counter:new(name .. '_count', help) - obj.sum_collector = Counter:new(name .. '_sum', help) - obj.bucket_collector = Counter:new(name .. '_bucket', help) + obj.count_collector = Counter:new(name .. '_count', help, metainfo) + obj.sum_collector = Counter:new(name .. '_sum', help, metainfo) + obj.bucket_collector = Counter:new(name .. '_bucket', help, metainfo) return obj end diff --git a/metrics/collectors/shared.lua b/metrics/collectors/shared.lua index 81f08b09..2cb195b4 100644 --- a/metrics/collectors/shared.lua +++ b/metrics/collectors/shared.lua @@ -24,7 +24,9 @@ function Shared:new_class(kind, method_names) return setmetatable(class, {__index = methods}) end -function Shared:new(name, help) +function Shared:new(name, help, metainfo) + metainfo = table.copy(metainfo) or {} + if not name then error("Name should be set for %s") end @@ -33,6 +35,7 @@ function Shared:new(name, help) help = help or "", observations = {}, label_pairs = {}, + metainfo = metainfo, }, self) end diff --git a/metrics/collectors/summary.lua b/metrics/collectors/summary.lua index 03b58757..30d37f75 100644 --- a/metrics/collectors/summary.lua +++ b/metrics/collectors/summary.lua @@ -6,12 +6,13 @@ local fiber = require('fiber') local Summary = Shared:new_class('summary', {'observe_latency'}) -function Summary:new(name, help, objectives, params) +function Summary:new(name, help, objectives, params, metainfo) params = params or {} - local obj = Shared.new(self, name, help) + metainfo = table.copy(metainfo) or {} + local obj = Shared.new(self, name, help, metainfo) - obj.count_collector = Counter:new(name .. '_count', help) - obj.sum_collector = Counter:new(name .. '_sum', help) + obj.count_collector = Counter:new(name .. '_count', help, metainfo) + obj.sum_collector = Counter:new(name .. '_sum', help, metainfo) obj.objectives = objectives obj.max_age_time = params.max_age_time obj.age_buckets_count = params.age_buckets_count or 1 diff --git a/metrics/init.lua b/metrics/init.lua index 9e0d42ac..56eae4ec 100644 --- a/metrics/init.lua +++ b/metrics/init.lua @@ -41,40 +41,64 @@ local function invoke_callbacks() return registry:invoke_callbacks() end -local function collect() - return registry:collect() +local function get_collector_values(collector, result) + for _, obs in ipairs(collector:collect()) do + table.insert(result, obs) + end +end + +local function collect(opts) + checks({invoke_callbacks = '?boolean', default_only = '?boolean'}) + opts = opts or {} + + if opts.invoke_callbacks then + registry:invoke_callbacks() + end + + local result = {} + for _, collector in pairs(registry.collectors) do + if opts.default_only then + if collector.metainfo.default then + get_collector_values(collector, result) + end + else + get_collector_values(collector, result) + end + end + + return result end local function clear() registry:clear() end -local function counter(name, help) - checks('string', '?string') +local function counter(name, help, metainfo) + checks('string', '?string', '?table') - return registry:find_or_create(Counter, name, help) + return registry:find_or_create(Counter, name, help, metainfo) end -local function gauge(name, help) - checks('string', '?string') +local function gauge(name, help, metainfo) + checks('string', '?string', '?table') - return registry:find_or_create(Gauge, name, help) + return registry:find_or_create(Gauge, name, help, metainfo) end -local function histogram(name, help, buckets) - checks('string', '?string', '?table') +local function histogram(name, help, buckets, metainfo) + checks('string', '?string', '?table', '?table') if buckets ~= nil and not Histogram.check_buckets(buckets) then error('Invalid value for buckets') end - return registry:find_or_create(Histogram, name, help, buckets) + return registry:find_or_create(Histogram, name, help, buckets, metainfo) end -local function summary(name, help, objectives, params) +local function summary(name, help, objectives, params, metainfo) checks('string', '?string', '?table', { age_buckets_count = '?number', max_age_time = '?number', - }) + }, '?table') if objectives ~= nil and not Summary.check_quantiles(objectives) then error('Invalid value for objectives') end @@ -91,7 +115,7 @@ local function summary(name, help, objectives, params) error('Age buckets count and max age must be present only together') end - return registry:find_or_create(Summary, name, help, objectives, params) + return registry:find_or_create(Summary, name, help, objectives, params, metainfo) end local function set_global_labels(label_pairs) diff --git a/metrics/psutils/cpu.lua b/metrics/psutils/cpu.lua index 01d2bb9f..39f8d88c 100644 --- a/metrics/psutils/cpu.lua +++ b/metrics/psutils/cpu.lua @@ -14,9 +14,10 @@ local threads = {} local function update_cpu_metrics() collectors_list.cpu_number = utils.set_gauge('cpu_number', 'The number of processors', - psutils.get_cpu_count()) + psutils.get_cpu_count(), nil, nil, {default = true}) - collectors_list.cpu_time = utils.set_gauge('cpu_time', 'Host CPU time', psutils.get_cpu_time()) + collectors_list.cpu_time = utils.set_gauge('cpu_time', 'Host CPU time', + psutils.get_cpu_time(), nil, nil, {default = true}) local new_threads = {} for _, thread_info in ipairs(psutils.get_process_cpu_time()) do @@ -29,12 +30,12 @@ local function update_cpu_metrics() local utime_labels = table.copy(labels) utime_labels.kind = 'user' collectors_list.cpu_thread = utils.set_gauge('cpu_thread', 'Tarantool thread cpu time', - thread_info.utime, utime_labels) + thread_info.utime, utime_labels, nil, {default = true}) local stime_labels = table.copy(labels) stime_labels.kind = 'system' collectors_list.cpu_thread = utils.set_gauge('cpu_thread', 'Tarantool thread cpu time', - thread_info.stime, stime_labels) + thread_info.stime, stime_labels, nil, {default = true}) threads[thread_info.pid] = nil new_threads[thread_info.pid] = labels diff --git a/metrics/tarantool/clock.lua b/metrics/tarantool/clock.lua index b0f72e2e..078d8e7d 100644 --- a/metrics/tarantool/clock.lua +++ b/metrics/tarantool/clock.lua @@ -25,8 +25,10 @@ local function update_clock_metrics() end end - collectors_list.clock_delta = utils.set_gauge('clock_delta', 'Clock difference', min_delta * 1e-6, {delta = 'min'}) - collectors_list.clock_delta = utils.set_gauge('clock_delta', 'Clock difference', max_delta * 1e-6, {delta = 'max'}) + collectors_list.clock_delta = utils.set_gauge('clock_delta', 'Clock difference', + min_delta * 1e-6, {delta = 'min'}, nil, {default = true}) + collectors_list.clock_delta = utils.set_gauge('clock_delta', 'Clock difference', + max_delta * 1e-6, {delta = 'max'}, nil, {default = true}) end return { diff --git a/metrics/tarantool/cpu.lua b/metrics/tarantool/cpu.lua index f094be67..8286790c 100644 --- a/metrics/tarantool/cpu.lua +++ b/metrics/tarantool/cpu.lua @@ -70,8 +70,10 @@ end local function update_info_metrics() local cpu_time = ss_get_rusage() if cpu_time then - collectors_list.cpu_user_time = utils.set_gauge('cpu_user_time', 'CPU user time usage', cpu_time.ru_utime) - collectors_list.cpu_system_time = utils.set_gauge('cpu_system_time', 'CPU system time usage', cpu_time.ru_stime) + collectors_list.cpu_user_time = utils.set_gauge('cpu_user_time', 'CPU user time usage', + cpu_time.ru_utime, nil, nil, {default = true}) + collectors_list.cpu_system_time = utils.set_gauge('cpu_system_time', 'CPU system time usage', + cpu_time.ru_stime, nil, nil, {default = true}) end end diff --git a/metrics/tarantool/event_loop.lua b/metrics/tarantool/event_loop.lua index ed6d3998..7baa79af 100644 --- a/metrics/tarantool/event_loop.lua +++ b/metrics/tarantool/event_loop.lua @@ -42,9 +42,12 @@ end local function update_info_metrics() local ev_once_time, ev_prolog, ev_epilog = evloop_time() - collectors_list.ev_loop_time = utils.set_gauge('ev_loop_time', 'Event loop time (ms)', ev_once_time) - collectors_list.ev_prolog_time = utils.set_gauge('ev_loop_prolog_time', 'Event loop prolog time (ms)', ev_prolog) - collectors_list.ev_epilog_time = utils.set_gauge('ev_loop_epilog_time', 'Event loop epilog time (ms)', ev_epilog) + collectors_list.ev_loop_time = utils.set_gauge('ev_loop_time', 'Event loop time (ms)', + ev_once_time, nil, nil, {default = true}) + collectors_list.ev_prolog_time = utils.set_gauge('ev_loop_prolog_time', 'Event loop prolog time (ms)', + ev_prolog, nil, nil, {default = true}) + collectors_list.ev_epilog_time = utils.set_gauge('ev_loop_epilog_time', 'Event loop epilog time (ms)', + ev_epilog, nil, nil, {default = true}) end return { diff --git a/metrics/tarantool/fibers.lua b/metrics/tarantool/fibers.lua index d959abc3..78ee72cd 100644 --- a/metrics/tarantool/fibers.lua +++ b/metrics/tarantool/fibers.lua @@ -17,10 +17,14 @@ local function update_fibers_metrics() fused = fused + f.memory.used end - collectors_list.fiber_amount = utils.set_gauge('fiber_amount', 'Amount of fibers', fibers) - collectors_list.fiber_csw = utils.set_gauge('fiber_csw', 'Fibers csw', csws) - collectors_list.fiber_memalloc = utils.set_gauge('fiber_memalloc', 'Fibers memalloc', falloc) - collectors_list.fiber_memused = utils.set_gauge('fiber_memused', 'Fibers memused', fused) + collectors_list.fiber_amount = utils.set_gauge('fiber_amount', 'Amount of fibers', + fibers, nil, nil, {default = true}) + collectors_list.fiber_csw = utils.set_gauge('fiber_csw', 'Fibers csw', + csws, nil, nil, {default = true}) + collectors_list.fiber_memalloc = utils.set_gauge('fiber_memalloc', 'Fibers memalloc', + falloc, nil, nil, {default = true}) + collectors_list.fiber_memused = utils.set_gauge('fiber_memused', 'Fibers memused', + fused, nil, nil, {default = true}) end return { diff --git a/metrics/tarantool/info.lua b/metrics/tarantool/info.lua index efe60731..3190cffa 100644 --- a/metrics/tarantool/info.lua +++ b/metrics/tarantool/info.lua @@ -20,66 +20,75 @@ local function update_info_metrics() local info = box.info() - collectors_list.info_lsn = utils.set_gauge('info_lsn', 'Tarantool lsn', info.lsn) - collectors_list.info_uptime = utils.set_gauge('info_uptime', 'Tarantool uptime', info.uptime) + collectors_list.info_lsn = utils.set_gauge('info_lsn', 'Tarantool lsn', + info.lsn, nil, nil, {default = true}) + collectors_list.info_uptime = utils.set_gauge('info_uptime', 'Tarantool uptime', + info.uptime, nil, nil, {default = true}) for k, v in pairs(info.vclock) do - collectors_list.info_vclock = utils.set_gauge('info_vclock', 'VClock', v, {id = k}) + collectors_list.info_vclock = utils.set_gauge('info_vclock', 'VClock', + v, {id = k}, nil, {default = true}) end for k, v in pairs(info.replication) do if v.upstream ~= nil then collectors_list.replication_lag = - utils.set_gauge('replication_lag', 'Replication lag', v.upstream.lag, {stream = 'upstream', id = k}) + utils.set_gauge('replication_lag', 'Replication lag', + v.upstream.lag, {stream = 'upstream', id = k}, nil, {default = true}) collectors_list.replication_status = - utils.set_gauge('replication_status', 'Replication status', v.upstream.status == 'follow' and 1 or 0, - {stream = 'upstream', id = k}) + utils.set_gauge('replication_status', 'Replication status', + v.upstream.status == 'follow' and 1 or 0, {stream = 'upstream', id = k}, + nil, {default = true}) end if v.downstream ~= nil then collectors_list.replication_lag = - utils.set_gauge('replication_lag', 'Replication lag', v.downstream.lag, {stream = 'downstream', id = k}) + utils.set_gauge('replication_lag', 'Replication lag', + v.downstream.lag, {stream = 'downstream', id = k}, + nil, {default = true}) collectors_list.replication_status = - utils.set_gauge('replication_status', 'Replication status', v.downstream.status == 'follow' and 1 or 0, - {stream = 'downstream', id = k}) + utils.set_gauge('replication_status', 'Replication status', + v.downstream.status == 'follow' and 1 or 0, {stream = 'downstream', id = k}, + nil, {default = true}) end end - collectors_list.read_only = utils.set_gauge('read_only', 'Is instance read only', read_only_status[info.ro]) + collectors_list.read_only = utils.set_gauge('read_only', 'Is instance read only', + read_only_status[info.ro], nil, nil, {default = true}) if info.synchro ~= nil then collectors_list.synchro_queue_owner = utils.set_gauge('synchro_queue_owner', 'Synchro queue owner', - info.synchro.queue.owner) + info.synchro.queue.owner, nil, nil, {default = true}) collectors_list.synchro_queue_term = utils.set_gauge('synchro_queue_term', 'Synchro queue term', - info.synchro.queue.term) + info.synchro.queue.term, nil, nil, {default = true}) collectors_list.synchro_queue_len = utils.set_gauge('synchro_queue_len', 'Amount of transactions are collecting confirmations now', - info.synchro.queue.len) + info.synchro.queue.len, nil, nil, {default = true}) collectors_list.synchro_queue_busy = utils.set_gauge('synchro_queue_busy', 'Is synchro queue busy', - info.synchro.busy == true and 1 or 0) + info.synchro.busy == true and 1 or 0, nil, nil, {default = true}) end if info.election ~= nil then collectors_list.election_state = utils.set_gauge('election_state', 'Election state of the node', - election_states[info.election.state]) + election_states[info.election.state], nil, nil, {default = true}) collectors_list.election_vote = utils.set_gauge('election_vote', 'ID of a node the current node votes for', - info.election.vote) + info.election.vote, nil, nil, {default = true}) collectors_list.election_leader = utils.set_gauge('election_leader', 'Leader node ID in the current term', - info.election.leader) + info.election.leader, nil, nil, {default = true}) collectors_list.election_term = utils.set_gauge('election_term', 'Current election term', - info.election.term) + info.election.term, nil, nil, {default = true}) end end diff --git a/metrics/tarantool/luajit.lua b/metrics/tarantool/luajit.lua index ff607b04..8ecac11b 100644 --- a/metrics/tarantool/luajit.lua +++ b/metrics/tarantool/luajit.lua @@ -13,55 +13,62 @@ local function update() -- Details: https://github.com/tarantool/doc/issues/1597 local lj_metrics = misc.getmetrics() collectors_list.gc_freed_total = - utils.set_counter('gc_freed_total', 'Total amount of freed memory', lj_metrics.gc_freed, nil, LJ_PREFIX) + utils.set_counter('gc_freed_total', 'Total amount of freed memory', + lj_metrics.gc_freed, nil, LJ_PREFIX, {default = true}) collectors_list.strhash_hit_total = utils.set_counter('strhash_hit_total', 'Total number of strings being interned', - lj_metrics.strhash_hit, nil, LJ_PREFIX) + lj_metrics.strhash_hit, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_atomic_total = utils.set_counter('gc_steps_atomic_total', 'Total count of incremental GC steps (atomic state)', - lj_metrics.gc_steps_atomic, nil, LJ_PREFIX) + lj_metrics.gc_steps_atomic, nil, LJ_PREFIX, {default = true}) collectors_list.strhash_miss_total = utils.set_counter('strhash_miss_total', 'Total number of strings allocations during the platform lifetime', - lj_metrics.strhash_miss, nil, LJ_PREFIX) + lj_metrics.strhash_miss, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_sweepstring_total = utils.set_counter('gc_steps_sweepstring_total', 'Total count of incremental GC steps (sweepstring state)', - lj_metrics.gc_steps_sweepstring, nil, LJ_PREFIX) + lj_metrics.gc_steps_sweepstring, nil, LJ_PREFIX, {default = true}) collectors_list.gc_strnum = - utils.set_gauge('gc_strnum', 'Amount of allocated string objects', lj_metrics.gc_strnum, nil, LJ_PREFIX) + utils.set_gauge('gc_strnum', 'Amount of allocated string objects', + lj_metrics.gc_strnum, nil, LJ_PREFIX, {default = true}) collectors_list.gc_tabnum = - utils.set_gauge('gc_tabnum', 'Amount of allocated table objects', lj_metrics.gc_tabnum, nil, LJ_PREFIX) + utils.set_gauge('gc_tabnum', 'Amount of allocated table objects', + lj_metrics.gc_tabnum, nil, LJ_PREFIX, {default = true}) collectors_list.gc_cdatanum = - utils.set_gauge('gc_cdatanum', 'Amount of allocated cdata objects', lj_metrics.gc_cdatanum, nil, LJ_PREFIX) + utils.set_gauge('gc_cdatanum', 'Amount of allocated cdata objects', + lj_metrics.gc_cdatanum, nil, LJ_PREFIX, {default = true}) collectors_list.jit_snap_restore_total = utils.set_counter('jit_snap_restore_total', 'Overall number of snap restores', - lj_metrics.jit_snap_restore, nil, LJ_PREFIX) + lj_metrics.jit_snap_restore, nil, LJ_PREFIX, {default = true}) collectors_list.gc_memory = - utils.set_gauge('gc_memory', 'Memory currently allocated', lj_metrics.gc_total, nil, LJ_PREFIX) + utils.set_gauge('gc_memory', 'Memory currently allocated', + lj_metrics.gc_total, nil, LJ_PREFIX, {default = true}) collectors_list.gc_udatanum = - utils.set_gauge('gc_udatanum', 'Amount of allocated udata objects', lj_metrics.gc_udatanum, nil, LJ_PREFIX) + utils.set_gauge('gc_udatanum', 'Amount of allocated udata objects', + lj_metrics.gc_udatanum, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_finalize_total = utils.set_counter('gc_steps_finalize_total', 'Total count of incremental GC steps (finalize state)', - lj_metrics.gc_steps_finalize, nil, LJ_PREFIX) + lj_metrics.gc_steps_finalize, nil, LJ_PREFIX, {default = true}) collectors_list.gc_allocated_total = utils.set_counter('gc_allocated_total', 'Total amount of allocated memory', - lj_metrics.gc_allocated, nil, LJ_PREFIX) + lj_metrics.gc_allocated, nil, LJ_PREFIX, {default = true}) collectors_list.jit_trace_num = - utils.set_gauge('jit_trace_num', 'Amount of JIT traces', lj_metrics.jit_trace_num, nil, LJ_PREFIX) + utils.set_gauge('jit_trace_num', 'Amount of JIT traces', + lj_metrics.jit_trace_num, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_sweep_total = utils.set_counter('gc_steps_sweep_total', 'Total count of incremental GC steps (sweep state)', - lj_metrics.gc_steps_sweep, nil, LJ_PREFIX) + lj_metrics.gc_steps_sweep, nil, LJ_PREFIX, {default = true}) collectors_list.jit_trace_abort_total = utils.set_counter('jit_trace_abort_total', 'Overall number of abort traces', - lj_metrics.jit_trace_abort, nil, LJ_PREFIX) + lj_metrics.jit_trace_abort, nil, LJ_PREFIX, {default = true}) collectors_list.jit_mcode_size = utils.set_gauge('jit_mcode_size', 'Total size of all allocated machine code areas', - lj_metrics.jit_mcode_size, nil, LJ_PREFIX) + lj_metrics.jit_mcode_size, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_propagate_total = utils.set_counter('gc_steps_propagate_total', 'Total count of incremental GC steps (propagate state)', - lj_metrics.gc_steps_propagate, nil, LJ_PREFIX) + lj_metrics.gc_steps_propagate, nil, LJ_PREFIX, {default = true}) collectors_list.gc_steps_pause_total = utils.set_counter('gc_steps_pause_total', 'Total count of incremental GC steps (pause state)', - lj_metrics.gc_steps_pause, nil, LJ_PREFIX) + lj_metrics.gc_steps_pause, nil, LJ_PREFIX, {default = true}) end return { diff --git a/metrics/tarantool/memory.lua b/metrics/tarantool/memory.lua index 2eade57a..766c162d 100644 --- a/metrics/tarantool/memory.lua +++ b/metrics/tarantool/memory.lua @@ -11,7 +11,8 @@ local function update_memory_metrics() local i = box.info.memory() for k, v in pairs(i) do local metric_name = 'info_memory_' .. k - collectors_list[metric_name] = utils.set_gauge(metric_name, 'Memory ' .. k, v) + collectors_list[metric_name] = utils.set_gauge(metric_name, 'Memory ' .. k, v, + nil, nil, {default = true}) end end end diff --git a/metrics/tarantool/memtx.lua b/metrics/tarantool/memtx.lua index 94eccd20..754b50c7 100644 --- a/metrics/tarantool/memtx.lua +++ b/metrics/tarantool/memtx.lua @@ -15,110 +15,110 @@ local function update() collectors_list.memtx_tnx_statements = utils.set_gauge('memtx_tnx_statements', 'Maximum number of bytes used by one transaction for statements', - memtx_stat.txn.statements.max, {kind = "max"}) + memtx_stat.txn.statements.max, {kind = "max"}, nil, {default = true}) collectors_list.memtx_tnx_statements = utils.set_gauge('memtx_tnx_statements', 'Average bytes used by transactions for statements', - memtx_stat.txn.statements.avg, {kind = "average"}) + memtx_stat.txn.statements.avg, {kind = "average"}, nil, {default = true}) collectors_list.memtx_tnx_statements = utils.set_gauge('memtx_tnx_statements', 'The number of bytes that are allocated for the statements of all current transactions', - memtx_stat.txn.statements.total, {kind = "total"}) + memtx_stat.txn.statements.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_tnx_user = utils.set_gauge('memtx_tnx_user', 'The maximum number of bytes allocated by `box_txn_alloc()` function per transaction', - memtx_stat.txn.user.max, {kind = "max"}) + memtx_stat.txn.user.max, {kind = "max"}, nil, {default = true}) collectors_list.memtx_tnx_user = utils.set_gauge('memtx_tnx_user', 'Transaction average (total memory / number of all current transactions)', - memtx_stat.txn.user.avg, {kind = "average"}) + memtx_stat.txn.user.avg, {kind = "average"}, nil, {default = true}) collectors_list.memtx_tnx_user = utils.set_gauge('memtx_tnx_user', 'Memory allocated by the `box_txn_alloc()` function on all current transactions', - memtx_stat.txn.user.total, {kind = "total"}) + memtx_stat.txn.user.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_tnx_system = utils.set_gauge('memtx_tnx_system', 'The maximum number of bytes allocated by internals per transaction', - memtx_stat.txn.system.max, {kind = "max"}) + memtx_stat.txn.system.max, {kind = "max"}, nil, {default = true}) collectors_list.memtx_tnx_system = utils.set_gauge('memtx_tnx_system', 'Average allocated memory by internals (total memory / number of all current transactions)', - memtx_stat.txn.system.avg, {kind = "average"}) + memtx_stat.txn.system.avg, {kind = "average"}, nil, {default = true}) collectors_list.memtx_tnx_system = utils.set_gauge('memtx_tnx_system', 'Memory allocated by internals on all transactions', - memtx_stat.txn.system.total, {kind = "total"}) + memtx_stat.txn.system.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_trackers = utils.set_gauge('memtx_mvcc_trackers', 'Maximum trackers allocated per transaction', - memtx_stat.mvcc.trackers.max, {kind = "max"}) + memtx_stat.mvcc.trackers.max, {kind = "max"}, nil, {default = true}) collectors_list.memtx_mvcc_trackers = utils.set_gauge('memtx_mvcc_trackers', 'Average for all current transactions (total memory / number of transactions)', - memtx_stat.mvcc.trackers.avg, {kind = "average"}) + memtx_stat.mvcc.trackers.avg, {kind = "average"}, nil, {default = true}) collectors_list.memtx_mvcc_trackers = utils.set_gauge('memtx_mvcc_trackers', 'Trackers are allocated in total', - memtx_stat.mvcc.trackers.total, {kind = "total"}) + memtx_stat.mvcc.trackers.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_conflicts = utils.set_gauge('memtx_mvcc_conflicts', 'Maximum bytes allocated for conflicts per transaction', - memtx_stat.mvcc.conflicts.max, {kind = "max"}) + memtx_stat.mvcc.conflicts.max, {kind = "max"}, nil, {default = true}) collectors_list.memtx_mvcc_conflicts = utils.set_gauge('memtx_mvcc_conflicts', 'Average for all current transactions (total memory / number of transactions)', - memtx_stat.mvcc.conflicts.avg, {kind = "average"}) + memtx_stat.mvcc.conflicts.avg, {kind = "average"}, nil, {default = true}) collectors_list.memtx_mvcc_conflicts = utils.set_gauge('memtx_mvcc_conflicts', 'Bytes allocated for conflicts in total', - memtx_stat.mvcc.conflicts.total, {kind = "total"}) + memtx_stat.mvcc.conflicts.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_tracking_stories = utils.set_gauge('memtx_mvcc_tuples_tracking_stories', 'Number of `tracking` tuples / number of tracking stories.', - memtx_stat.mvcc.tuples.tracking.stories.count, {kind = "count"}) + memtx_stat.mvcc.tuples.tracking.stories.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_tracking_stories = utils.set_gauge('memtx_mvcc_tuples_tracking_stories', 'Amount of bytes used by stories `tracking` tuples', - memtx_stat.mvcc.tuples.tracking.stories.total, {kind = "total"}) + memtx_stat.mvcc.tuples.tracking.stories.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_tracking_retained = utils.set_gauge('memtx_mvcc_tuples_tracking_retained', 'Number of retained `tracking` tuples / number of stories', - memtx_stat.mvcc.tuples.tracking.retained.count, {kind = "count"}) + memtx_stat.mvcc.tuples.tracking.retained.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_tracking_retained = utils.set_gauge('memtx_mvcc_tuples_tracking_retained', 'Amount of bytes used by retained `tracking` tuples', - memtx_stat.mvcc.tuples.tracking.retained.total, {kind = "total"}) + memtx_stat.mvcc.tuples.tracking.retained.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_used_stories = utils.set_gauge('memtx_mvcc_tuples_used_stories', 'Number of `used` tuples / number of stories', - memtx_stat.mvcc.tuples.used.stories.count, {kind = "count"}) + memtx_stat.mvcc.tuples.used.stories.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_used_stories = utils.set_gauge('memtx_mvcc_tuples_used_stories', 'Amount of bytes used by stories ``used`` tuples', - memtx_stat.mvcc.tuples.used.stories.total, {kind = "total"}) + memtx_stat.mvcc.tuples.used.stories.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_used_retained = utils.set_gauge('memtx_mvcc_tuples_used_retained', 'Number of retained `used` tuples / number of stories', - memtx_stat.mvcc.tuples.used.retained.count, {kind = "count"}) + memtx_stat.mvcc.tuples.used.retained.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_used_retained = utils.set_gauge('memtx_mvcc_tuples_used_retained', 'Amount of bytes used by retained `used` tuples', - memtx_stat.mvcc.tuples.used.retained.total, {kind = "total"}) + memtx_stat.mvcc.tuples.used.retained.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_read_view_stories = utils.set_gauge('memtx_mvcc_tuples_read_view_stories', 'Number of `read_view` tuples / number of stories', - memtx_stat.mvcc.tuples.read_view.stories.count, {kind = "count"}) + memtx_stat.mvcc.tuples.read_view.stories.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_read_view_stories = utils.set_gauge('memtx_mvcc_tuples_read_view_stories', 'Amount of bytes used by stories `read_view` tuples', - memtx_stat.mvcc.tuples.read_view.stories.total, {kind = "total"}) + memtx_stat.mvcc.tuples.read_view.stories.total, {kind = "total"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_read_view_retained = utils.set_gauge('memtx_mvcc_tuples_read_view_retained', 'Number of retained `read_view` tuples / number of stories', - memtx_stat.mvcc.tuples.read_view.retained.count, {kind = "count"}) + memtx_stat.mvcc.tuples.read_view.retained.count, {kind = "count"}, nil, {default = true}) collectors_list.memtx_mvcc_tuples_read_view_retained = utils.set_gauge('memtx_mvcc_tuples_read_view_retained', 'Amount of bytes used by retained `read_view` tuples', - memtx_stat.mvcc.tuples.read_view.retained.total, {kind = "total"}) + memtx_stat.mvcc.tuples.read_view.retained.total, {kind = "total"}, nil, {default = true}) end diff --git a/metrics/tarantool/network.lua b/metrics/tarantool/network.lua index 347a81e4..1f4dae5c 100644 --- a/metrics/tarantool/network.lua +++ b/metrics/tarantool/network.lua @@ -10,47 +10,56 @@ local function update_network_metrics() local box_stat_net = box.stat.net() collectors_list.net_sent_total = - utils.set_counter('net_sent_total', 'Totally sent in bytes', box_stat_net.SENT.total) + utils.set_counter('net_sent_total', 'Totally sent in bytes', + box_stat_net.SENT.total, nil, nil, {default = true}) collectors_list.net_received_total = - utils.set_counter('net_received_total', 'Totally received in bytes', box_stat_net.RECEIVED.total) + utils.set_counter('net_received_total', 'Totally received in bytes', + box_stat_net.RECEIVED.total, nil, nil, {default = true}) -- https://github.com/tarantool/doc/issues/760 -- before tnt version 2.2.0 if box_stat_net.CONNECTIONS ~= nil and type(box_stat_net.CONNECTIONS) ~= 'number' then collectors_list.net_connections_total = - utils.set_counter('net_connections_total', 'Connections total amount', box_stat_net.CONNECTIONS.total) + utils.set_counter('net_connections_total', 'Connections total amount', + box_stat_net.CONNECTIONS.total, nil, nil, {default = true}) collectors_list.net_connections_current = - utils.set_gauge('net_connections_current', 'Current connections amount', box_stat_net.CONNECTIONS.current) + utils.set_gauge('net_connections_current', 'Current connections amount', + box_stat_net.CONNECTIONS.current, nil, nil, {default = true}) elseif box_stat_net.CONNECTIONS ~= nil then collectors_list.net_connections_current = - utils.set_gauge('net_connections_current', 'Current connections amount', box_stat_net.CONNECTIONS) + utils.set_gauge('net_connections_current', 'Current connections amount', + box_stat_net.CONNECTIONS, nil, nil, {default = true}) end if box_stat_net.REQUESTS ~= nil then collectors_list.net_requests_total = - utils.set_counter('net_requests_total', 'Requests total amount', box_stat_net.REQUESTS.total) + utils.set_counter('net_requests_total', 'Requests total amount', + box_stat_net.REQUESTS.total, nil, nil, {default = true}) collectors_list.net_requests_current = - utils.set_gauge('net_requests_current', 'Pending requests', box_stat_net.REQUESTS.current) + utils.set_gauge('net_requests_current', 'Pending requests', + box_stat_net.REQUESTS.current, nil, nil, {default = true}) end if box_stat_net.REQUESTS_IN_PROGRESS ~= nil then collectors_list.net_requests_in_progress_total = utils.set_counter('net_requests_in_progress_total', 'Requests in progress total amount', - box_stat_net.REQUESTS_IN_PROGRESS.total) + box_stat_net.REQUESTS_IN_PROGRESS.total, nil, nil, {default = true}) collectors_list.net_requests_in_progress_current = utils.set_gauge('net_requests_in_progress_current', - 'Count of requests currently being processed in the tx thread', box_stat_net.REQUESTS_IN_PROGRESS.current) + 'Count of requests currently being processed in the tx thread', + box_stat_net.REQUESTS_IN_PROGRESS.current, nil, nil, {default = true}) end if box_stat_net.REQUESTS_IN_STREAM_QUEUE ~= nil then collectors_list.net_requests_in_stream_total = utils.set_counter('net_requests_in_stream_queue_total', 'Total count of requests, which was placed in queues of streams', - box_stat_net.REQUESTS_IN_STREAM_QUEUE.total) + box_stat_net.REQUESTS_IN_STREAM_QUEUE.total, nil, nil, {default = true}) collectors_list.net_requests_in_stream_current = utils.set_gauge('net_requests_in_stream_queue_current', - 'count of requests currently waiting in queues of streams', box_stat_net.REQUESTS_IN_STREAM_QUEUE.current) + 'count of requests currently waiting in queues of streams', + box_stat_net.REQUESTS_IN_STREAM_QUEUE.current, nil, nil, {default = true}) end if box.stat.net.thread ~= nil then @@ -61,58 +70,58 @@ local function update_network_metrics() collectors_list.net_per_thread_sent_total = utils.set_counter('net_per_thread_sent_total', 'Totally sent in bytes', - per_thread_mertics.SENT.total, {thread = index}) + per_thread_mertics.SENT.total, {thread = index}, nil, {default = true}) collectors_list.net_per_thread_received_total = utils.set_counter('net_per_thread_received_total', 'Totally received in bytes', - per_thread_mertics.RECEIVED.total, {thread = index}) + per_thread_mertics.RECEIVED.total, {thread = index}, nil, {default = true}) if per_thread_mertics.CONNECTIONS ~= nil and type(per_thread_mertics.CONNECTIONS) ~= 'number' then collectors_list.net_per_thread_connections_total = utils.set_counter('net_per_thread_connections_total', 'Connections total amount', - per_thread_mertics.CONNECTIONS.total, {thread = index}) + per_thread_mertics.CONNECTIONS.total, {thread = index}, nil, {default = true}) collectors_list.net_per_thread_connections_current = utils.set_gauge('net_per_thread_connections_current', 'Current connections amount', - per_thread_mertics.CONNECTIONS.current, {thread = index}) + per_thread_mertics.CONNECTIONS.current, {thread = index}, nil, {default = true}) elseif per_thread_mertics.CONNECTIONS ~= nil then collectors_list.net_per_thread_connections_current = utils.set_gauge('net_per_thread_connections_current', 'Current connections amount', - per_thread_mertics.CONNECTIONS, {thread = index}) + per_thread_mertics.CONNECTIONS, {thread = index}, nil, {default = true}) end if per_thread_mertics.REQUESTS ~= nil then collectors_list.net_per_thread_requests_total = utils.set_counter('net_per_thread_requests_total', 'Requests total amount', - per_thread_mertics.REQUESTS.total, {thread = index}) + per_thread_mertics.REQUESTS.total, {thread = index}, nil, {default = true}) collectors_list.net_per_thread_requests_current = utils.set_gauge('net_per_thread_requests_current', 'Pending requests', - per_thread_mertics.REQUESTS.current, {thread = index}) + per_thread_mertics.REQUESTS.current, {thread = index}, nil, {default = true}) end if per_thread_mertics.REQUESTS_IN_PROGRESS ~= nil then collectors_list.net_per_thread_requests_in_progress_total = utils.set_counter('net_per_thread_requests_in_progress_total', 'Requests in progress total amount', - per_thread_mertics.REQUESTS_IN_PROGRESS.total, {thread = index}) + per_thread_mertics.REQUESTS_IN_PROGRESS.total, {thread = index}, nil, {default = true}) collectors_list.net_per_thread_requests_in_progress_current = utils.set_gauge('net_per_thread_requests_in_progress_current', 'Count of requests currently being processed in the tx thread', - per_thread_mertics.REQUESTS_IN_PROGRESS.current, {thread = index}) + per_thread_mertics.REQUESTS_IN_PROGRESS.current, {thread = index}, nil, {default = true}) end if per_thread_mertics.REQUESTS_IN_STREAM_QUEUE ~= nil then collectors_list.net_per_thread_requests_in_stream_queue_total = utils.set_counter('net_per_thread_requests_in_stream_queue_total', 'Total count of requests, which was placed in queues of streams', - per_thread_mertics.REQUESTS_IN_STREAM_QUEUE.total, {thread = index}) + per_thread_mertics.REQUESTS_IN_STREAM_QUEUE.total, {thread = index}, nil, {default = true}) collectors_list.net_per_thread_requests_in_stream_queue_current = utils.set_gauge('net_per_thread_requests_in_stream_queue_current', 'Count of requests currently waiting in queues of streams', - per_thread_mertics.REQUESTS_IN_STREAM_QUEUE.current, {thread = index}) + per_thread_mertics.REQUESTS_IN_STREAM_QUEUE.current, {thread = index}, nil, {default = true}) end end end diff --git a/metrics/tarantool/operations.lua b/metrics/tarantool/operations.lua index 86831626..1368bfb7 100644 --- a/metrics/tarantool/operations.lua +++ b/metrics/tarantool/operations.lua @@ -11,7 +11,8 @@ local function update_operations_metrics() for k, v in pairs(current_stat) do collectors_list.stats_op_total = - utils.set_counter('stats_op_total', 'Total amount of operations', v.total, {operation = k:lower()}) + utils.set_counter('stats_op_total', 'Total amount of operations', + v.total, {operation = k:lower()}, nil, {default = true}) end end diff --git a/metrics/tarantool/replicas.lua b/metrics/tarantool/replicas.lua index a9942882..110501ba 100644 --- a/metrics/tarantool/replicas.lua +++ b/metrics/tarantool/replicas.lua @@ -15,7 +15,8 @@ local function update_replicas_metrics() if replication_info then local lsn = replication_info.lsn collectors_list.replication_lsn = - utils.set_gauge('replication_lsn', 'lsn for instance', lsn - v, {type = 'replica', id = k}) + utils.set_gauge('replication_lsn', 'lsn for instance', + lsn - v, {type = 'replica', id = k}, nil, {default = true}) end end else @@ -27,7 +28,9 @@ local function update_replicas_metrics() 'replication_lsn', 'lsn for instance', current_box_info.lsn - lsn, - {type = 'master', id = k} + {type = 'master', id = k}, + nil, + {default = true} ) end end diff --git a/metrics/tarantool/runtime.lua b/metrics/tarantool/runtime.lua index 00331b49..9763beed 100644 --- a/metrics/tarantool/runtime.lua +++ b/metrics/tarantool/runtime.lua @@ -8,7 +8,8 @@ local function update_runtime_metrics() for k, v in pairs(runtime_info) do if k ~= 'maxalloc' then local metric_name = 'runtime_' .. k - collectors_list[metric_name] = utils.set_gauge(metric_name, 'Runtime ' .. k, v) + collectors_list[metric_name] = utils.set_gauge(metric_name, 'Runtime ' .. k, v, + nil, nil, {default = true}) end end end diff --git a/metrics/tarantool/slab.lua b/metrics/tarantool/slab.lua index b1cd8f33..e802be32 100644 --- a/metrics/tarantool/slab.lua +++ b/metrics/tarantool/slab.lua @@ -12,10 +12,12 @@ local function update_slab_metrics() for k, v in pairs(slab_info) do local metric_name = 'slab_' .. k if not k:match('_ratio$') then - collectors_list[metric_name] = utils.set_gauge(metric_name, 'Slab ' .. k .. ' info', v) + collectors_list[metric_name] = utils.set_gauge(metric_name, 'Slab ' .. k .. ' info', v, + nil, nil, {default = true}) else collectors_list[metric_name] = - utils.set_gauge(metric_name, 'Slab ' .. k .. ' info', tonumber(v:match('^([0-9%.]+)%%?$'))) + utils.set_gauge(metric_name, 'Slab ' .. k .. ' info', tonumber(v:match('^([0-9%.]+)%%?$')), + nil, nil, {default = true}) end end end diff --git a/metrics/tarantool/spaces.lua b/metrics/tarantool/spaces.lua index fa0e1d0b..60da511c 100644 --- a/metrics/tarantool/spaces.lua +++ b/metrics/tarantool/spaces.lua @@ -34,7 +34,8 @@ local function update_spaces_metrics() local l = table.copy(labels) l.index_name = i.name collectors_list.space_index_bsize = - utils.set_gauge('space_index_bsize', 'Index bsize', i:bsize(), l) + utils.set_gauge('space_index_bsize', 'Index bsize', i:bsize(), l, + nil, {default = true}) total = total + i:bsize() if spaces[space_name] ~= nil then @@ -56,13 +57,16 @@ local function update_spaces_metrics() labels.engine = 'memtx' collectors_list.space_len = - utils.set_gauge('space_len' , 'Space length', sp:len(), labels) + utils.set_gauge('space_len' , 'Space length', sp:len(), labels, + nil, {default = true}) collectors_list.space_bsize = - utils.set_gauge('space_bsize', 'Space bsize', sp_bsize, labels) + utils.set_gauge('space_bsize', 'Space bsize', sp_bsize, labels, + nil, {default = true}) collectors_list.space_total_bsize = - utils.set_gauge('space_total_bsize', 'Space total bsize', sp_bsize + total, labels) + utils.set_gauge('space_total_bsize', 'Space total bsize', sp_bsize + total, labels, + nil, {default = true}) new_spaces[space_name].memtx_labels = labels spaces[space_name] = nil @@ -71,7 +75,8 @@ local function update_spaces_metrics() labels.engine = 'vinyl' local count = sp:count() collectors_list.vinyl_tuples = - utils.set_gauge('vinyl_tuples', 'Vinyl space tuples count', count, labels) + utils.set_gauge('vinyl_tuples', 'Vinyl space tuples count', count, labels, + nil, {default = true}) new_spaces[space_name].vinyl_labels = labels spaces[space_name] = nil diff --git a/metrics/tarantool/system.lua b/metrics/tarantool/system.lua index aef59b26..0b282fa4 100644 --- a/metrics/tarantool/system.lua +++ b/metrics/tarantool/system.lua @@ -8,7 +8,8 @@ local function update_system_metrics() return end - collectors_list.cfg_current_time = utils.set_gauge('cfg_current_time', 'Tarantool cfg time', clock.time() + 0ULL) + collectors_list.cfg_current_time = utils.set_gauge('cfg_current_time', 'Tarantool cfg time', clock.time() + 0ULL, + nil, nil, {default = true}) end return { diff --git a/metrics/tarantool/vinyl.lua b/metrics/tarantool/vinyl.lua index 07d97fe7..7a9ea34d 100644 --- a/metrics/tarantool/vinyl.lua +++ b/metrics/tarantool/vinyl.lua @@ -9,61 +9,73 @@ local function update() local vinyl_stat = box.stat.vinyl() collectors_list.vinyl_disk_data_size = - utils.set_gauge('vinyl_disk_data_size', 'Amount of data stored in files', vinyl_stat.disk.data) + utils.set_gauge('vinyl_disk_data_size', 'Amount of data stored in files', + vinyl_stat.disk.data, nil, nil, {default = true}) collectors_list.vinyl_disk_index_size = - utils.set_gauge('vinyl_disk_index_size', 'Amount of index stored in files', vinyl_stat.disk.index) + utils.set_gauge('vinyl_disk_index_size', 'Amount of index stored in files', + vinyl_stat.disk.index, nil, nil, {default = true}) collectors_list.vinyl_regulator_dump_bandwidth = utils.set_gauge('vinyl_regulator_dump_bandwidth', 'Estimated average rate at which dumps are done', - vinyl_stat.regulator.dump_bandwidth) + vinyl_stat.regulator.dump_bandwidth, nil, nil, {default = true}) collectors_list.vinyl_regulator_write_rate = utils.set_gauge('vinyl_regulator_write_rate', 'Average rate at which recent writes to disk are done', - vinyl_stat.regulator.write_rate) + vinyl_stat.regulator.write_rate, nil, nil, {default = true}) collectors_list.vinyl_regulator_rate_limit = - utils.set_gauge('vinyl_regulator_rate_limit', 'Write rate limit', vinyl_stat.regulator.rate_limit) + utils.set_gauge('vinyl_regulator_rate_limit', 'Write rate limit', + vinyl_stat.regulator.rate_limit, nil, nil, {default = true}) collectors_list.vinyl_regulator_dump_watermark = utils.set_gauge('vinyl_regulator_dump_watermark', 'Point when dumping must occur', - vinyl_stat.regulator.dump_watermark) + vinyl_stat.regulator.dump_watermark, nil, nil, {default = true}) if vinyl_stat.regulator.blocked_writers ~= nil then collectors_list.vinyl_regulator_blocked_writers = utils.set_gauge('vinyl_regulator_blocked_writers', 'The number of fibers that are blocked waiting ' .. - 'for Vinyl level0 memory quota', vinyl_stat.regulator.blocked_writers) + 'for Vinyl level0 memory quota', + vinyl_stat.regulator.blocked_writers, nil, nil, {default = true}) end collectors_list.vinyl_tx_conflict = - utils.set_gauge('vinyl_tx_conflict', 'Count of transaction conflicts', vinyl_stat.tx.conflict) + utils.set_gauge('vinyl_tx_conflict', 'Count of transaction conflicts', + vinyl_stat.tx.conflict, nil, nil, {default = true}) collectors_list.vinyl_tx_commit = - utils.set_gauge('vinyl_tx_commit', 'Count of commits', vinyl_stat.tx.commit) + utils.set_gauge('vinyl_tx_commit', 'Count of commits', + vinyl_stat.tx.commit, nil, nil, {default = true}) collectors_list.vinyl_tx_rollback = - utils.set_gauge('vinyl_tx_rollback', 'Count of rollbacks', vinyl_stat.tx.rollback) + utils.set_gauge('vinyl_tx_rollback', 'Count of rollbacks', + vinyl_stat.tx.rollback, nil, nil, {default = true}) collectors_list.vinyl_tx_read_views = - utils.set_gauge('vinyl_tx_read_views', 'Count of open read views', vinyl_stat.tx.read_views) + utils.set_gauge('vinyl_tx_read_views', 'Count of open read views', + vinyl_stat.tx.read_views, nil, nil, {default = true}) collectors_list.vinyl_memory_tuple_cache = utils.set_gauge('vinyl_memory_tuple_cache', 'Number of bytes that are being used for tuple', - vinyl_stat.memory.tuple_cache) + vinyl_stat.memory.tuple_cache, nil, nil, {default = true}) collectors_list.vinyl_memory_level0 = - utils.set_gauge('vinyl_memory_level0', 'Size of in-memory storage of an LSM tree', vinyl_stat.memory.level0) + utils.set_gauge('vinyl_memory_level0', 'Size of in-memory storage of an LSM tree', + vinyl_stat.memory.level0, nil, nil, {default = true}) collectors_list.vinyl_memory_page_index = - utils.set_gauge('vinyl_memory_page_index', 'Size of page indexes', vinyl_stat.memory.page_index) + utils.set_gauge('vinyl_memory_page_index', 'Size of page indexes', + vinyl_stat.memory.page_index, nil, nil, {default = true}) collectors_list.vinyl_memory_bloom_filter = - utils.set_gauge('vinyl_memory_bloom_filter', 'Size of bloom filter', vinyl_stat.memory.bloom_filter) + utils.set_gauge('vinyl_memory_bloom_filter', 'Size of bloom filter', + vinyl_stat.memory.bloom_filter, nil, nil, {default = true}) collectors_list.vinyl_scheduler_tasks = - utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', vinyl_stat.scheduler.tasks_inprogress, - {status = 'inprogress'}) + utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', + vinyl_stat.scheduler.tasks_inprogress, {status = 'inprogress'}, nil, {default = true}) collectors_list.vinyl_scheduler_tasks = - utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', vinyl_stat.scheduler.tasks_completed, - {status = 'completed'}) + utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', + vinyl_stat.scheduler.tasks_completed, {status = 'completed'}, nil, {default = true}) collectors_list.vinyl_scheduler_tasks = - utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', vinyl_stat.scheduler.tasks_failed, - {status = 'failed'}) + utils.set_gauge('vinyl_scheduler_tasks', 'Vinyl tasks count', + vinyl_stat.scheduler.tasks_failed, {status = 'failed'}, nil, {default = true}) collectors_list.vinyl_scheduler_dump_time = utils.set_gauge('vinyl_scheduler_dump_time', 'Total time spent by all worker threads performing dump', - vinyl_stat.scheduler.dump_time) + vinyl_stat.scheduler.dump_time, nil, nil, {default = true}) collectors_list.vinyl_scheduler_dump_total = - utils.set_counter('vinyl_scheduler_dump_total', 'The count of completed dumps', vinyl_stat.scheduler.dump_count) + utils.set_counter('vinyl_scheduler_dump_total', 'The count of completed dumps', + vinyl_stat.scheduler.dump_count, nil, nil, {default = true}) end return { diff --git a/metrics/utils.lua b/metrics/utils.lua index 2353a83c..18335626 100644 --- a/metrics/utils.lua +++ b/metrics/utils.lua @@ -3,16 +3,16 @@ local metrics = require('metrics') local TNT_PREFIX = 'tnt_' local utils = {} -function utils.set_gauge(name, description, value, labels, prefix) +function utils.set_gauge(name, description, value, labels, prefix, metainfo) prefix = prefix or TNT_PREFIX - local gauge = metrics.gauge(prefix .. name, description) + local gauge = metrics.gauge(prefix .. name, description, metainfo) gauge:set(value, labels or {}) return gauge end -function utils.set_counter(name, description, value, labels, prefix) +function utils.set_counter(name, description, value, labels, prefix, metainfo) prefix = prefix or TNT_PREFIX - local counter = metrics.counter(prefix .. name, description) + local counter = metrics.counter(prefix .. name, description, metainfo) counter:reset(labels or {}) counter:inc(value, labels or {}) return counter diff --git a/test/collectors/counter_test.lua b/test/collectors/counter_test.lua index 1c6fda13..9bd77403 100644 --- a/test/collectors/counter_test.lua +++ b/test/collectors/counter_test.lua @@ -90,3 +90,16 @@ g.test_insert_non_number = function() local c = metrics.counter('cnt') t.assert_error_msg_contains('Counter increment should be a number', c.inc, c, true) end + +g.test_metainfo = function() + local metainfo = {my_useful_info = 'here'} + local c = metrics.counter('cnt', nil, metainfo) + t.assert_equals(c.metainfo, metainfo) +end + +g.test_metainfo_immutable = function() + local metainfo = {my_useful_info = 'here'} + local c = metrics.counter('cnt', nil, metainfo) + metainfo['my_useful_info'] = 'there' + t.assert_equals(c.metainfo, {my_useful_info = 'here'}) +end diff --git a/test/collectors/gauge_test.lua b/test/collectors/gauge_test.lua index 0748ca0e..e089ae31 100644 --- a/test/collectors/gauge_test.lua +++ b/test/collectors/gauge_test.lua @@ -78,3 +78,15 @@ g.test_inc_non_number = function() t.assert_error_msg_contains('Collector set value should be a number', c.set, c, true) end +g.test_metainfo = function() + local metainfo = {my_useful_info = 'here'} + local c = metrics.gauge('gauge', nil, metainfo) + t.assert_equals(c.metainfo, metainfo) +end + +g.test_metainfo_immutable = function() + local metainfo = {my_useful_info = 'here'} + local c = metrics.gauge('gauge', nil, metainfo) + metainfo['my_useful_info'] = 'there' + t.assert_equals(c.metainfo, {my_useful_info = 'here'}) +end diff --git a/test/collectors/histogram_test.lua b/test/collectors/histogram_test.lua index ac0bffdb..d765ec13 100644 --- a/test/collectors/histogram_test.lua +++ b/test/collectors/histogram_test.lua @@ -97,3 +97,22 @@ g.test_insert_non_number = function() t.assert_error_msg_contains('Histogram observation should be a number', h.observe, h, true) end + +g.test_metainfo = function() + local metainfo = {my_useful_info = 'here'} + local h = metrics.histogram('hist', 'some histogram', {2, 4}, metainfo) + t.assert_equals(h.metainfo, metainfo) + t.assert_equals(h.sum_collector.metainfo, metainfo) + t.assert_equals(h.count_collector.metainfo, metainfo) + t.assert_equals(h.bucket_collector.metainfo, metainfo) +end + +g.test_metainfo_immutable = function() + local metainfo = {my_useful_info = 'here'} + local h = metrics.histogram('hist', 'some histogram', {2, 4}, metainfo) + metainfo['my_useful_info'] = 'there' + t.assert_equals(h.metainfo, {my_useful_info = 'here'}) + t.assert_equals(h.sum_collector.metainfo, {my_useful_info = 'here'}) + t.assert_equals(h.count_collector.metainfo, {my_useful_info = 'here'}) + t.assert_equals(h.bucket_collector.metainfo, {my_useful_info = 'here'}) +end diff --git a/test/collectors/shared_test.lua b/test/collectors/shared_test.lua index cd041033..e76c02d2 100644 --- a/test/collectors/shared_test.lua +++ b/test/collectors/shared_test.lua @@ -30,3 +30,17 @@ g.test_remove_metric_by_label = function() {'test', 1, {a = 1, b = 2}}, }) end + +g.test_metainfo = function() + local metainfo = {my_useful_info = 'here'} + local c = Shared:new('collector', nil, metainfo) + t.assert_equals(c.metainfo, metainfo) +end + + +g.test_metainfo_immutable = function() + local metainfo = {my_useful_info = 'here'} + local c = Shared:new('collector', nil, metainfo) + metainfo['my_useful_info'] = 'there' + t.assert_equals(c.metainfo, {my_useful_info = 'here'}) +end diff --git a/test/collectors/summary_test.lua b/test/collectors/summary_test.lua index 6d065b41..389db0e1 100644 --- a/test/collectors/summary_test.lua +++ b/test/collectors/summary_test.lua @@ -237,3 +237,20 @@ g.test_insert_non_number = function() t.assert_error_msg_contains('Summary observation should be a number', s.observe, s, true) end + +g.test_metainfo = function() + local metainfo = {my_useful_info = 'here'} + local c = Summary:new('collector', nil, nil, nil, metainfo) + t.assert_equals(c.metainfo, metainfo) + t.assert_equals(c.sum_collector.metainfo, metainfo) + t.assert_equals(c.count_collector.metainfo, metainfo) +end + +g.test_metainfo_immutable = function() + local metainfo = {my_useful_info = 'here'} + local c = Summary:new('collector', nil, nil, nil, metainfo) + metainfo['my_useful_info'] = 'there' + t.assert_equals(c.metainfo, {my_useful_info = 'here'}) + t.assert_equals(c.sum_collector.metainfo, {my_useful_info = 'here'}) + t.assert_equals(c.count_collector.metainfo, {my_useful_info = 'here'}) +end diff --git a/test/metrics_test.lua b/test/metrics_test.lua index e8f1969d..1a58cb9e 100755 --- a/test/metrics_test.lua +++ b/test/metrics_test.lua @@ -128,15 +128,14 @@ g.test_default_metrics_clear = function() metrics.enable_default_metrics() t.assert_equals(#metrics.collect(), 0) - metrics.invoke_callbacks() - t.assert(#metrics.collect() > 0) + t.assert(#metrics.collect{invoke_callbacks = true} > 0) metrics.clear() t.assert_equals(#metrics.collect(), 0) + t.assert_equals(#metrics.collect{invoke_callbacks = true}, 0) metrics.enable_default_metrics() - metrics.invoke_callbacks() - t.assert(#metrics.collect() > 0) + t.assert(#metrics.collect{invoke_callbacks = true} > 0) end g.test_hotreload_remove_callbacks = function() @@ -156,3 +155,82 @@ g.test_hotreload_remove_callbacks = function() t.assert_equals(len_before_hotreload, len_after_hotreload) end + +local collect_invoke_callbacks_cases = { + default = { + args = nil, + value = 0, + }, + ['true'] = { + args = {invoke_callbacks = true}, + value = 1, + }, + ['false'] = { + args = {invoke_callbacks = false}, + value = 0, + }, +} + +for name, case in pairs(collect_invoke_callbacks_cases) do + g['test_collect_invoke_callbacks_' .. name] = function() + local c = metrics.counter('mycounter') + + local callback = function() + c:inc() + end + metrics.register_callback(callback) + + -- Initialize a value in the registry. + -- Otherwise collector would be empty. + c:reset() + + local observations = metrics.collect(case.args) + local obs = utils.find_obs('mycounter', {}, observations) + t.assert_equals(obs.value, case.value) + end +end + +g.test_default_metrics_metainfo = function() + metrics.enable_default_metrics() + metrics.invoke_callbacks() + + for k, c in pairs(metrics.collectors()) do + t.assert_equals(c.metainfo.default, true, + ('default collector %s has metainfo label "default"'):format(k)) + end +end + +local collect_default_only_cases = { + default = { + args = {invoke_callbacks = true}, + custom_expected = true, + }, + ['true'] = { + args = {invoke_callbacks = true, default_only = true}, + custom_expected = false, + }, + ['false'] = { + args = {invoke_callbacks = true, default_only = false}, + custom_expected = true, + }, +} + +for name, case in pairs(collect_default_only_cases) do + g['test_collect_default_only_' .. name] = function() + metrics.enable_default_metrics() + local c = metrics.gauge('custom_metric') + c:set(42) + + local observations = metrics.collect(case.args) + + local default_obs = utils.find_metric('tnt_info_memory_lua', observations) + t.assert_not_equals(default_obs, nil) + + local custom_obs = utils.find_metric('custom_metric', observations) + if case.custom_expected then + t.assert_not_equals(custom_obs, nil) + else + t.assert_equals(custom_obs, nil) + end + end +end diff --git a/test/psutils_linux_thread_clean_test.lua b/test/psutils_linux_thread_clean_test.lua index 223da520..a5310444 100644 --- a/test/psutils_linux_thread_clean_test.lua +++ b/test/psutils_linux_thread_clean_test.lua @@ -94,3 +94,12 @@ g.test_clear = function() cpu.update() check_cpu_metrics(true) end + +g.test_default_metrics_metainfo = function() + cpu.update() + + for k, c in pairs(metrics.collectors()) do + t.assert_equals(c.metainfo.default, true, + ('psutils collector %s has metainfo label "default"'):format(k)) + end +end diff --git a/test/tarantool/lj_metrics_test.lua b/test/tarantool/lj_metrics_test.lua index 69e3c4df..fbe505bf 100755 --- a/test/tarantool/lj_metrics_test.lua +++ b/test/tarantool/lj_metrics_test.lua @@ -19,10 +19,9 @@ g.test_lj_metrics = function() t.skip_if(metrics_available == false, 'metrics are not available') metrics.enable_default_metrics() - metrics.invoke_callbacks() local lj_metrics = {} - for _, v in pairs(metrics.collect()) do + for _, v in pairs(metrics.collect{invoke_callbacks = true}) do if v.metric_name:startswith(LJ_PREFIX) then table.insert(lj_metrics, v.metric_name) end diff --git a/test/tarantool/spaces_test.lua b/test/tarantool/spaces_test.lua index d8bf92d1..fd06f972 100644 --- a/test/tarantool/spaces_test.lua +++ b/test/tarantool/spaces_test.lua @@ -34,8 +34,7 @@ g.after_each(function() end) local function get_space_metrics(metric_name) - metrics.invoke_callbacks() - return fun.iter(metrics.collect()):filter(function(x) + return fun.iter(metrics.collect{invoke_callbacks = true}):filter(function(x) return x.metric_name:find(metric_name) end):map(function(m) return m.label_pairs end):totable() end diff --git a/test/tarantool/vinyl_test.lua b/test/tarantool/vinyl_test.lua index 65cf9b14..e3a89639 100644 --- a/test/tarantool/vinyl_test.lua +++ b/test/tarantool/vinyl_test.lua @@ -22,8 +22,7 @@ g.before_each(function() end) g.test_vinyl_metrics_present = function() - metrics.invoke_callbacks() - local metrics_cnt = fun.iter(metrics.collect()):filter(function(x) + local metrics_cnt = fun.iter(metrics.collect{invoke_callbacks = true}):filter(function(x) return x.metric_name:find('tnt_vinyl') end):length() if utils.is_version_less(_TARANTOOL, '2.8.3')