You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -146,202 +146,62 @@ local element_count = my_heap:count()
146
146
147
147
The `rmean` module provides functionality for efficient moving average calculations with specified window sizes.
148
148
149
-
### Usage
149
+
The best use of rmean would be when you want to have Average Calls per second during last 5 seconds.
150
150
151
-
For the most convenient use of the `rmean` module, the `default` instance is provided with a window size of 5 seconds, similar to what is used in Tarantool. Here are some examples demonstrating the usage of the `default` rmean instance:
151
+
Easy to set and use:
152
152
153
153
```lua
154
-
localrmean=require('algo.rmean')
154
+
localrmean=require'algo.rmean'
155
155
156
-
-- Create a new collector in the default rmean instance with the same window size (5 seconds)
157
-
localmy_collector=rmean.collector('my_collector')
158
-
```
159
-
160
-
#### Observing Values and Calculating Metrics
161
-
162
-
```lua
163
-
-- Observe values for the collector
164
-
my_collector:observe(10)
165
-
my_collector:observe(15)
166
-
my_collector:observe(20)
167
-
168
-
-- Calculate the moving average per second for the collector
169
-
localavg_per_sec=my_collector:per_second()
170
-
```
171
-
172
-
#### Getting All Registered Collectors in the Default rmean Instance
- The `default` rmean instance is the most preferred way to use `rmean`, as it has a window size of 5 seconds, aligning with the common practice in Tarantool.
190
-
191
-
#### Collector methods
192
-
193
-
The `rmean` module provides methods to efficiently calculate and access various metrics within the moving average collectors.
174
+
Rmean can be used to collect statistics of both discreate and continious variables.
194
175
195
-
##### `sum([depth=window_size])`
196
-
197
-
-**Usage**: Retrieves the moving sum value within a specified time depth.
198
-
-**When to Use**: This method is useful when you need to track the cumulative sum of values observed by the collector over a specific time period.
199
-
200
-
##### `min([depth=window_size])`
201
-
202
-
-**Usage**: Returns the moving minimum value within a specified time depth.
203
-
-**When to Use**: Use this method when you want to find the minimum value observed by the collector within a specific time window.
204
-
205
-
##### `max([depth=window_size])`
206
-
207
-
-**Usage**: Retrieves the moving maximum value within a specified time depth.
208
-
-**When to Use**: Utilize this method to determine the maximum value observed by the collector within a particular time frame.
209
-
210
-
##### `count and total fields`
211
-
212
-
-**Count Field**: The `count` field represents the monotonic counter of all collected values from the last reset.
213
-
-**Total Field**: The `total` field stores the sum of all values collected by the collector from the last reset.
214
-
-**When to Use**: You can access these fields to keep track of the total count of observations and the cumulative total sum of values collected by the collector.
176
+
Collect Running Mean (Moving Average) of Latency of your calls:
215
177
216
178
```lua
217
-
-- Obtain the moving sum value for the last 4 seconds
218
-
localsum_last_4_sec=my_collector:sum(4)
179
+
locallatency_rmean=rmean.collector('latency')
219
180
220
-
-- Get the minimum value observed in the last 3 seconds
221
-
localmin_last_3_sec=my_collector:min(3)
181
+
latency_rmean:max() -- Will produce Moving maximum of the latency within specified window
182
+
latency_rmean:min() -- Will produce Moving minimum of the latency within specified window
183
+
latency_rmean:mean() -- Will produce Moving average of the latency within specified window
222
184
223
-
-- Retrieve the maximum value in the last 2 seconds
224
-
localmax_last_2_sec=my_collector:max(2)
185
+
-- latency_rmean:per_second() DOES not posses any meaningfull stats
225
186
226
-
-- Access the total sum and count fields of the collector
227
-
localtotal_sum=my_collector.total
228
-
localobservation_count=my_collector.count
187
+
latency_rmean:hits() -- Will produce Moving count of observed values within specified window
229
188
```
230
189
231
-
**Note:** Ensure that the `depth` parameter does not exceed the `window size` of the collector.
232
-
233
-
### Integrating with tarantool/metrics
190
+
Collect Per Second statistics for your calls or bytes
234
191
235
192
```lua
236
-
localmetrics=require('metrics')
237
-
metrics.registry:register(rmean)
238
-
```
239
-
240
-
After registering `rmean` in `tarantool/metrics`, you can seamlessly collect metrics from all registered named rmean collectors.
tuple_size_rmean:per_second() -- will produce Moving average of bytes per second
199
+
tuple_size_rmean:max()
200
+
tuple_size_rmean:min()
201
+
tuple_size_rmean:hits()
249
202
```
250
203
251
-
Each collector within the `rmean` module provides metrics suitable for export to Prometheus via the `tarantool/metrics` module. The metrics available for export are as follows:
252
-
253
-
-**rmean_per_second**: Represents the running average of the collected values.
254
-
-**rmean_sum**: Represents the running sum of the collected values.
255
-
-**rmean_min**: Represents the minimum value observed within the collector's window.
256
-
-**rmean_max**: Represents the maximum value observed within the collector's window.
257
-
-**rmean_count**: Represents the number of observations made by the collector.
258
-
-**rmean_total**: Represents the total sum of all collected values.
259
-
260
-
### Advanced Usage
261
-
262
-
1.**Creating a New `rmean` Instance**:
263
-
264
-
```lua
265
-
localrmean=require('algo.rmean')
266
-
267
-
-- Create a new rmean instance with a specified name, resolution, and window size
-- Stop the system and disable creating new collectors
314
-
my_rmean:stop()
315
-
316
-
-- Start the system to begin calculating averages
317
-
my_rmean:start()
318
-
```
319
-
320
-
7.**Freeing Collectors**:
321
-
322
-
```lua
323
-
-- Free a specific collector
324
-
my_rmean:free(specific_collector)
325
-
```
326
-
327
-
8.**Metrics Collection**:
328
-
329
-
```lua
330
-
-- Collect metrics from all registered collectors
331
-
localmetrics_data=my_rmean:collect()
332
-
```
333
-
334
-
9.**Setting Metrics Registry**:
335
-
336
-
```lua
337
-
-- Set a metrics registry for the rmean instance
338
-
my_rmean:set_registry(metrics_registry)
339
-
```
340
-
341
-
### Notes
342
-
343
-
- The system is automatically started when the rmean instance is created. Manual starting is only required if it was previously stopped.
344
-
- The module efficiently handles moving average calculations even with a large number of parallel running collectors and provides high-performance metrics collection capabilities.
0 commit comments