Software /
code /
prosody
Annotate
util/statsd.lua @ 11772:e2155e2703dd
mod_s2s: Factor out procedure for newly encrypted sessions
Goal is to call this if the connection is using Direct TLS, either via
multiplexing or a future Direct TLS S2S port.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 10 Aug 2021 20:51:31 +0200 |
parent | 11523:5f15ab7c6ae5 |
child | 12123:7ba686696250 |
rev | line source |
---|---|
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local socket = require "socket"; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
2 local time = require "util.time".now; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
3 local array = require "util.array"; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
4 local t_concat = table.concat; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
5 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
6 local new_metric_registry = require "util.openmetrics".new_metric_registry; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
7 local render_histogram_le = require "util.openmetrics".render_histogram_le; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
8 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
9 -- BEGIN of Metric implementations |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
10 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
11 -- Gauges |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
12 local gauge_metric_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
13 gauge_metric_mt.__index = gauge_metric_mt |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
14 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
15 local function new_gauge_metric(full_name, impl) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
16 local metric = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
17 _full_name = full_name; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
18 _impl = impl; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
19 value = 0; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
20 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
21 setmetatable(metric, gauge_metric_mt) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
22 return metric |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
23 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
24 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
25 function gauge_metric_mt:set(value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
26 self.value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
27 self._impl:push_gauge(self._full_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
28 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
29 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
30 function gauge_metric_mt:add(delta) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
31 self.value = self.value + delta |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
32 self._impl:push_gauge(self._full_name, self.value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
33 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
34 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
35 function gauge_metric_mt:reset() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
36 self.value = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
37 self._impl:push_gauge(self._full_name, 0) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
38 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
39 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
40 function gauge_metric_mt.iter_samples() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
41 -- statsd backend does not support iteration. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
42 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
43 return nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
44 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
45 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
46 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
47 -- Counters |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
48 local counter_metric_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
49 counter_metric_mt.__index = counter_metric_mt |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
50 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
51 local function new_counter_metric(full_name, impl) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
52 local metric = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
53 _full_name = full_name, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
54 _impl = impl, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
55 value = 0, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
56 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
57 setmetatable(metric, counter_metric_mt) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
58 return metric |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
59 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
60 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
61 function counter_metric_mt:set(value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
62 local delta = value - self.value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
63 self.value = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
64 self._impl:push_counter_delta(self._full_name, delta) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
65 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
66 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
67 function counter_metric_mt:add(value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
68 self.value = (self.value or 0) + value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
69 self._impl:push_counter_delta(self._full_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
70 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
71 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
72 function counter_metric_mt.iter_samples() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
73 -- statsd backend does not support iteration. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
74 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
75 return nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
76 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
77 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
78 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
79 function counter_metric_mt:reset() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
80 self.value = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
81 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
82 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
83 -- Histograms |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
84 local histogram_metric_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
85 histogram_metric_mt.__index = histogram_metric_mt |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
86 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
87 local function new_histogram_metric(buckets, full_name, impl) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
88 -- NOTE: even though the more or less proprietrary dogstatsd has its own |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
89 -- histogram implementation, we push the individual buckets in this statsd |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
90 -- backend for both consistency and compatibility across statsd |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
91 -- implementations. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
92 local metric = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
93 _sum_name = full_name..".sum", |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
94 _count_name = full_name..".count", |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
95 _impl = impl, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
96 _created = time(), |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
97 _sum = 0, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
98 _count = 0, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
99 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
100 -- the order of buckets matters unfortunately, so we cannot directly use |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
101 -- the thresholds as table keys |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
102 for i, threshold in ipairs(buckets) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
103 local threshold_s = render_histogram_le(threshold) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
104 metric[i] = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
105 threshold = threshold, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
106 threshold_s = threshold_s, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
107 count = 0, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
108 _full_name = full_name..".bucket."..(threshold_s:gsub("%.", "_")), |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
109 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
110 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
111 setmetatable(metric, histogram_metric_mt) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
112 return metric |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
113 end |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
115 function histogram_metric_mt:sample(value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
116 -- According to the I-D, values must be part of all buckets |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
117 for i, bucket in pairs(self) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
118 if "number" == type(i) and bucket.threshold > value then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
119 bucket.count = bucket.count + 1 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
120 self._impl:push_counter_delta(bucket._full_name, 1) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
121 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
122 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
123 self._sum = self._sum + value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
124 self._count = self._count + 1 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
125 self._impl:push_gauge(self._sum_name, self._sum) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
126 self._impl:push_counter_delta(self._count_name, 1) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
127 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
128 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
129 function histogram_metric_mt.iter_samples() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
130 -- statsd backend does not support iteration. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
131 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
132 return nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
133 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
134 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
135 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
136 function histogram_metric_mt:reset() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
137 self._created = time() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
138 self._count = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
139 self._sum = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
140 for i, bucket in pairs(self) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
141 if "number" == type(i) then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
142 bucket.count = 0 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
143 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
144 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
145 self._impl:push_gauge(self._sum_name, self._sum) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
146 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
147 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
148 -- Summaries |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
149 local summary_metric_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
150 summary_metric_mt.__index = summary_metric_mt |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
151 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
152 local function new_summary_metric(full_name, impl) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
153 local metric = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
154 _sum_name = full_name..".sum", |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
155 _count_name = full_name..".count", |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
156 _impl = impl, |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
157 } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
158 setmetatable(metric, summary_metric_mt) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
159 return metric |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
160 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
161 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
162 function summary_metric_mt:sample(value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
163 self._impl:push_counter_delta(self._sum_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
164 self._impl:push_counter_delta(self._count_name, 1) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
165 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
166 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
167 function summary_metric_mt.iter_samples() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
168 -- statsd backend does not support iteration. |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
169 return function() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
170 return nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
171 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
172 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
173 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
174 function summary_metric_mt.reset() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
175 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
176 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
177 -- BEGIN of statsd client implementation |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
178 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
179 local statsd_mt = {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
180 statsd_mt.__index = statsd_mt |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
181 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
182 function statsd_mt:cork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
183 self.corked = true |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
184 self.cork_buffer = self.cork_buffer or {} |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
185 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
186 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
187 function statsd_mt:uncork() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
188 self.corked = false |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
189 self:_flush_cork_buffer() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
190 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
191 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
192 function statsd_mt:_flush_cork_buffer() |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
193 local buffer = self.cork_buffer |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
194 for metric_name, value in pairs(buffer) do |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
195 self:_send_gauge(metric_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
196 buffer[metric_name] = nil |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
197 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
198 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
199 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
200 function statsd_mt:push_gauge(metric_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
201 if self.corked then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
202 self.cork_buffer[metric_name] = value |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
203 else |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
204 self:_send_gauge(metric_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
205 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
206 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
207 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
208 function statsd_mt:_send_gauge(metric_name, value) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
209 self:_send(self.prefix..metric_name..":"..tostring(value).."|g") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
210 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
211 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
212 function statsd_mt:push_counter_delta(metric_name, delta) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
213 self:_send(self.prefix..metric_name..":"..tostring(delta).."|c") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
214 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
215 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
216 function statsd_mt:_send(s) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
217 return self.sock:send(s) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
218 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
219 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
220 -- END of statsd client implementation |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
221 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
222 local function build_metric_name(family_name, labels) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
223 local parts = array { family_name } |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
224 if labels then |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
225 parts:append(labels) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
226 end |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
227 return t_concat(parts, "/"):gsub("%.", "_"):gsub("/", ".") |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
228 end |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 local function new(config) |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 if not config or not config.statsd_server then |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 return nil, "No statsd server specified in the config, please see https://prosody.im/doc/statistics"; |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 end |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 local sock = socket.udp(); |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 sock:setpeername(config.statsd_server, config.statsd_port or 8125); |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 local prefix = (config.prefix or "prosody").."."; |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
240 local impl = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
241 metric_registry = nil; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
242 sock = sock; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
243 prefix = prefix; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
244 }; |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
245 setmetatable(impl, statsd_mt) |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
247 local backend = { |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
248 gauge = function(family_name, labels) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
249 return new_gauge_metric(build_metric_name(family_name, labels), impl) |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 end; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
251 counter = function(family_name, labels) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
252 return new_counter_metric(build_metric_name(family_name, labels), impl) |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 end; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
254 histogram = function(buckets, family_name, labels) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
255 return new_histogram_metric(buckets, build_metric_name(family_name, labels), impl) |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 end; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
257 summary = function(family_name, labels, extra) |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
258 return new_summary_metric(build_metric_name(family_name, labels), impl, extra) |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 end; |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 }; |
11523
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
261 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
262 impl.metric_registry = new_metric_registry(backend); |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
263 |
5f15ab7c6ae5
Statistics: Rewrite statistics backends to use OpenMetrics
Jonas Schäfer <jonas@wielicki.name>
parents:
10924
diff
changeset
|
264 return impl; |
7522
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 end |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 return { |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 new = new; |
ebf2e77ac8a7
statsmanager, util.statsd: Add built-in statsd provider
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 } |