syslog-ng source
stats-aggregator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 One Identity
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef STATS_AGGREGATOR_H
25 #define STATS_AGGREGATOR_H
26 
27 #include "stats/stats-counter.h"
28 #include "stats/stats-cluster.h"
29 #include <iv.h>
30 
31 typedef struct _StatsAggregator StatsAggregator;
32 
34 {
35  void (*add_data_point)(StatsAggregator *self, gsize value);
36  void (*aggregate)(StatsAggregator *self);
37  void (*reset)(StatsAggregator *self);
38  void (*free_fn)(StatsAggregator *self);
39  gboolean (*is_orphaned)(StatsAggregator *self);
40 
41  void (*register_aggr)(StatsAggregator *self);
42  void (*unregister_aggr)(StatsAggregator *self);
43 
44  gssize use_count;
45  StatsClusterKey key;
49  struct iv_timer update_timer;
50 };
51 
52 static inline void
53 stats_aggregator_add_data_point(StatsAggregator *self, gsize value)
54 {
55  if (self && self->add_data_point)
56  self->add_data_point(self, value);
57 }
58 
59 static inline void
60 stats_aggregator_aggregate(StatsAggregator *self)
61 {
62  if (self && self->aggregate)
63  self->aggregate(self);
64 }
65 
66 static inline gboolean
67 stats_aggregator_is_orphaned(StatsAggregator *self)
68 {
69  if (self && self->is_orphaned)
70  return self->is_orphaned(self);
71 
72  return TRUE;
73 }
74 
75 void stats_aggregator_register(StatsAggregator *self);
76 void stats_aggregator_unregister(StatsAggregator *self);
77 
78 /* public */
79 void stats_aggregator_add_data_point(StatsAggregator *self, gsize value);
80 void stats_aggregator_aggregate(StatsAggregator *self);
81 void stats_aggregator_reset(StatsAggregator *self);
82 
83 /* stats-internals */
84 void stats_aggregator_start(StatsAggregator *self);
85 void stats_aggregator_stop(StatsAggregator *self);
86 void stats_aggregator_init_instance(StatsAggregator *self, StatsClusterKey *sc_key, gint stats_level);
87 void stats_aggregator_free(StatsAggregator *self);
88 
89 /* type specific constructors */
90 
91 StatsAggregator *stats_aggregator_maximum_new(gint level, StatsClusterKey *sc_key);
92 
93 StatsAggregator *stats_aggregator_average_new(gint level, StatsClusterKey *sc_key);
94 
95 StatsAggregator *stats_aggregator_cps_new(gint level, StatsClusterKey *sc_key, StatsClusterKey *sc_key_input,
96  gint stats_type);
97 
98 #endif /* STATS_AGGREGATOR_H */
#define self
Definition: rcptid.c:38
void stats_aggregator_free(StatsAggregator *self)
Definition: stats-aggregator.c:195
StatsAggregator * stats_aggregator_average_new(gint level, StatsClusterKey *sc_key)
Definition: stats-average.c:93
void stats_aggregator_reset(StatsAggregator *self)
Definition: stats-aggregator.c:133
void stats_aggregator_stop(StatsAggregator *self)
Definition: stats-aggregator.c:116
void stats_aggregator_register(StatsAggregator *self)
Definition: stats-aggregator.c:85
StatsAggregator * stats_aggregator_cps_new(gint level, StatsClusterKey *sc_key, StatsClusterKey *sc_key_input, gint stats_type)
Definition: stats-change-per-second.c:307
void stats_aggregator_start(StatsAggregator *self)
Definition: stats-aggregator.c:103
void stats_aggregator_init_instance(StatsAggregator *self, StatsClusterKey *sc_key, gint stats_level)
Definition: stats-aggregator.c:181
StatsAggregator * stats_aggregator_maximum_new(gint level, StatsClusterKey *sc_key)
Definition: stats-maximum.c:57
void stats_aggregator_unregister(StatsAggregator *self)
Definition: stats-aggregator.c:93
Definition: stats-counter.h:67
Definition: stats-aggregator.h:34
void(* free_fn)(StatsAggregator *self)
Definition: stats-aggregator.h:38
gint stats_level
Definition: stats-aggregator.h:47
void(* add_data_point)(StatsAggregator *self, gsize value)
Definition: stats-aggregator.h:35
gint timer_period
Definition: stats-aggregator.h:48
void(* reset)(StatsAggregator *self)
Definition: stats-aggregator.h:37
gboolean(* is_orphaned)(StatsAggregator *self)
Definition: stats-aggregator.h:39
StatsCounterItem * output_counter
Definition: stats-aggregator.h:46
gssize use_count
Definition: stats-aggregator.h:44
void(* aggregate)(StatsAggregator *self)
Definition: stats-aggregator.h:36
void(* unregister_aggr)(StatsAggregator *self)
Definition: stats-aggregator.h:42
struct iv_timer update_timer
Definition: stats-aggregator.h:49
void(* register_aggr)(StatsAggregator *self)
Definition: stats-aggregator.h:41
StatsClusterKey key
Definition: stats-aggregator.h:45
GString * value
Definition: test_decode.c:28