|
| 1 | +local metrics = require('metrics') |
| 2 | + |
| 3 | +local has_mics_module, misc = pcall(require, 'misc') |
| 4 | + |
| 5 | +local gauges_storage = {} |
| 6 | + |
| 7 | +local LJ_PREFIX = 'lj_' |
| 8 | + |
| 9 | +local function prefix_name(name) |
| 10 | + return LJ_PREFIX .. name |
| 11 | +end |
| 12 | + |
| 13 | +local function set_gauge(name, description, value, labels) |
| 14 | + if (gauges_storage[name] == nil) then |
| 15 | + gauges_storage[name] = metrics.gauge(prefix_name(name), description) |
| 16 | + end |
| 17 | + |
| 18 | + gauges_storage[name]:set(value, labels or {}) |
| 19 | +end |
| 20 | + |
| 21 | +local function update_lj_metrics() |
| 22 | + -- Details: https://github.com/tarantool/doc/issues/1597 |
| 23 | + local lj_metrics = misc.getmetrics() |
| 24 | + set_gauge('gc_freed', 'Total amount of freed memory', |
| 25 | + lj_metrics.gc_freed) |
| 26 | + set_gauge('strhash_hit', 'Number of strings being interned', |
| 27 | + lj_metrics.strhash_hit) |
| 28 | + set_gauge('gc_steps_atomic', 'Count of incremental GC steps (atomic state)', |
| 29 | + lj_metrics.gc_steps_atomic) |
| 30 | + set_gauge('strhash_miss', 'Total number of strings allocations during the platform lifetime', |
| 31 | + lj_metrics.strhash_miss) |
| 32 | + set_gauge('gc_steps_sweepstring', 'Count of incremental GC steps (sweepstring state)', |
| 33 | + lj_metrics.gc_steps_sweepstring) |
| 34 | + set_gauge('gc_strnum', 'Amount of allocated string objects', |
| 35 | + lj_metrics.gc_strnum) |
| 36 | + set_gauge('gc_tabnum', 'Amount of allocated table objects', |
| 37 | + lj_metrics.gc_tabnum) |
| 38 | + set_gauge('gc_cdatanum', 'Amount of allocated cdata objects', |
| 39 | + lj_metrics.gc_cdatanum) |
| 40 | + set_gauge('jit_snap_restore', 'Overall number of snap restores', |
| 41 | + lj_metrics.jit_snap_restore) |
| 42 | + set_gauge('gc_total', 'Memory currently allocated', |
| 43 | + lj_metrics.gc_total) |
| 44 | + set_gauge('gc_udatanum', 'Amount of allocated udata objects', |
| 45 | + lj_metrics.gc_udatanum) |
| 46 | + set_gauge('gc_steps_finalize', 'Count of incremental GC steps (finalize state)', |
| 47 | + lj_metrics.gc_steps_finalize) |
| 48 | + set_gauge('gc_allocated', 'Total amount of allocated memory', |
| 49 | + lj_metrics.gc_allocated) |
| 50 | + set_gauge('jit_trace_num', 'Amount of JIT traces', |
| 51 | + lj_metrics.jit_trace_num) |
| 52 | + set_gauge('gc_steps_sweep', 'Count of incremental GC steps (sweep state)', |
| 53 | + lj_metrics.gc_steps_sweep) |
| 54 | + set_gauge('jit_trace_abort', 'Overall number of abort traces', |
| 55 | + lj_metrics.jit_trace_abort) |
| 56 | + set_gauge('jit_mcode_size', 'Total size of all allocated machine code areas', |
| 57 | + lj_metrics.jit_mcode_size) |
| 58 | + set_gauge('gc_steps_propagate', 'Count of incremental GC steps (propagate state)', |
| 59 | + lj_metrics.gc_steps_propagate) |
| 60 | + set_gauge('gc_steps_pause', 'Count of incremental GC steps (pause state)', |
| 61 | + lj_metrics.gc_steps_pause) |
| 62 | +end |
| 63 | + |
| 64 | +local update = function() end |
| 65 | + |
| 66 | +if has_mics_module and misc.getmetrics ~= nil then |
| 67 | + update = update_lj_metrics |
| 68 | +end |
| 69 | + |
| 70 | +return { |
| 71 | + update = update, |
| 72 | +} |
0 commit comments