1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
/*
* Copyright (c) 2002-2017 Balabit
* Copyright (c) 1998-2013 Balázs Scheidler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As an additional exemption you are allowed to compile & link against the
* OpenSSL libraries as published by the OpenSSL project. See the file
* COPYING for details.
*
*/
#ifndef STATS_CLUSTER_H_INCLUDED
#define STATS_CLUSTER_H_INCLUDED 1
#include "stats/stats-counter.h"
#include "stats/stats-cluster-logpipe.h"
enum
{
/* direction bits, used to distinguish between source/destination drivers */
SCS_SOURCE = 0x0100,
SCS_DESTINATION = 0x0200,
SCS_GROUP = 1,
SCS_GLOBAL,
SCS_CENTER,
SCS_HOST,
SCS_SENDER,
SCS_PROGRAM,
SCS_SEVERITY,
SCS_FACILITY,
SCS_TAG,
SCS_FILTER,
SCS_PARSER,
SCS_SOURCE_MASK = 0xff
};
typedef enum _StatsClusterUnit
{
SCU_NONE = 0,
SCU_SECONDS,
SCU_MINUTES,
SCU_HOURS,
SCU_MILLISECONDS,
SCU_NANOSECONDS,
SCU_BYTES,
SCU_KIB,
SCU_MIB,
SCU_GIB,
} StatsClusterUnit;
typedef enum _StatsClusterFrameOfReference
{
SCFOR_NONE = 0,
SCFOR_ABSOLUTE,
/*
* Only applicable for counters with seconds, minutes or hours unit.
* Has a 1 second precision.
* Results in a positive value for timestamps older than the time of query.
*/
SCFOR_RELATIVE_TO_TIME_OF_QUERY,
} StatsClusterFrameOfReference;
typedef struct _StatsCounterGroup StatsCounterGroup;
typedef struct _StatsCounterGroupInit StatsCounterGroupInit;
struct _StatsCounterGroup
{
StatsCounterItem *counters;
const gchar **counter_names;
guint16 capacity;
gboolean (*get_type_label)(StatsCounterGroup *self, gint type, StatsClusterLabel *label);
void (*free_fn)(StatsCounterGroup *self);
};
struct _StatsCounterGroupInit
{
union
{
const gchar **names;
const gchar *name;
} counter;
void (*init)(StatsCounterGroupInit *self, StatsCounterGroup *counter_group);
gboolean (*equals)(const StatsCounterGroupInit *self, const StatsCounterGroupInit *other);
void (*clone)(StatsCounterGroupInit *dst, const StatsCounterGroupInit *src);
void (*cloned_free)(StatsCounterGroupInit *self);
};
gboolean stats_counter_group_init_equals(const StatsCounterGroupInit *self, const StatsCounterGroupInit *other);
void stats_counter_group_free(StatsCounterGroup *self);
struct _StatsClusterLabel
{
const gchar *name;
const gchar *value;
};
static inline StatsClusterLabel
stats_cluster_label(const gchar *name, const gchar *value)
{
return (StatsClusterLabel)
{
.name = name, .value = value
};
}
struct _StatsClusterKey
{
const gchar *name;
StatsClusterLabel *labels;
gsize labels_len;
struct
{
StatsClusterUnit stored_unit;
StatsClusterFrameOfReference frame_of_reference;
} formatting;
struct
{
const gchar *id;
/* syslog-ng component/driver/subsystem that registered this cluster */
guint16 component;
const gchar *instance;
guint set:1;
} legacy;
StatsCounterGroupInit counter_group_init;
};
/* NOTE: This struct can only be used by the stats implementation and not by client code. */
/* StatsCluster encapsulates a set of related counters that are registered
* to the same stats source. In a lot of cases, the same stats source uses
* multiple counters, so keeping them at the same location makes sense.
*
* This also improves performance for dynamic counters that relate to
* information found in the log stream. In that case multiple counters can
* be registered with a single hash lookup */
typedef struct _StatsCluster
{
StatsClusterKey key;
StatsCounterGroup counter_group;
guint16 use_count;
guint16 live_mask;
guint16 dynamic:1;
gchar *query_key;
} StatsCluster;
typedef void (*StatsForeachCounterFunc)(StatsCluster *sc, gint type, StatsCounterItem *counter, gpointer user_data);
void stats_cluster_init(void);
void stats_cluster_deinit(void);
guint stats_register_type(const gchar *type_name);
const gchar *stats_cluster_get_type_name(StatsCluster *self, gint type);
const gchar *stats_cluster_get_component_name(StatsCluster *self, gchar *buf, gsize buf_len);
void stats_cluster_foreach_counter(StatsCluster *self, StatsForeachCounterFunc func, gpointer user_data);
StatsClusterKey *stats_cluster_key_clone(StatsClusterKey *dst, const StatsClusterKey *src);
void stats_cluster_key_cloned_free(StatsClusterKey *self);
void stats_cluster_key_free(StatsClusterKey *self);
gboolean stats_cluster_key_equal(const StatsClusterKey *key1, const StatsClusterKey *key2);
guint stats_cluster_key_hash(const StatsClusterKey *self);
StatsCounterItem *stats_cluster_track_counter(StatsCluster *self, gint type);
StatsCounterItem *stats_cluster_get_counter(StatsCluster *self, gint type);
void stats_cluster_untrack_counter(StatsCluster *self, gint type, StatsCounterItem **counter);
gboolean stats_cluster_is_alive(StatsCluster *self, gint type);
void stats_cluster_reset_counter_if_needed(StatsCluster *sc, StatsCounterItem *counter);
static inline gboolean
stats_cluster_is_orphaned(StatsCluster *self)
{
return self->use_count == 0;
}
static inline gboolean
stats_cluster_get_type_label(StatsCluster *self, gint type, StatsClusterLabel *label)
{
if (!self->counter_group.get_type_label)
return FALSE;
return self->counter_group.get_type_label(&self->counter_group, type, label);
}
StatsCluster *stats_cluster_new(const StatsClusterKey *key);
StatsCluster *stats_cluster_dynamic_new(const StatsClusterKey *key);
void stats_cluster_free(StatsCluster *self);
void stats_cluster_key_set(StatsClusterKey *self, const gchar *name, StatsClusterLabel *labels, gsize labels_len,
StatsCounterGroupInit counter_group_ctor);
void stats_cluster_key_legacy_set(StatsClusterKey *self, guint16 component, const gchar *id, const gchar *instance,
StatsCounterGroupInit counter_group_ctor);
void stats_cluster_key_add_legacy_alias(StatsClusterKey *self, guint16 component, const gchar *id,
const gchar *instance,
StatsCounterGroupInit counter_group_ctor);
static inline gboolean
stats_cluster_key_is_legacy(const StatsClusterKey *self)
{
return self->legacy.set;
}
#endif
|