File: logsource.h

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (162 lines) | stat: -rw-r--r-- 5,277 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright (c) 2002-2011 Balabit
 * Copyright (c) 1998-2011 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 LOGSOURCE_H_INCLUDED
#define LOGSOURCE_H_INCLUDED

#include "logpipe.h"
#include "stats/stats-registry.h"
#include "stats/stats-compat.h"
#include "stats/stats-cluster-key-builder.h"
#include "window-size-counter.h"
#include "dynamic-window.h"

typedef struct _LogSourceOptions
{
  gssize init_window_size;
  const gchar *group_name;
  gboolean keep_timestamp;
  gboolean keep_hostname;
  gboolean chain_hostnames;
  HostResolveOptions host_resolve_options;
  gchar *program_override;
  gint program_override_len;
  gchar *host_override;
  gint host_override_len;
  LogTagId source_group_tag;
  gboolean read_old_records;
  gboolean use_syslogng_pid;
  GArray *tags;
  GList *source_queue_callbacks;
  gint stats_level;
  gint stats_source;
} LogSourceOptions;

typedef struct _LogSource LogSource;

/**
 * LogSource:
 *
 * This structure encapsulates an object which generates messages without
 * defining how those messages are accepted by peers. The most prominent
 * derived class is LogReader which is an extended RFC3164 capable syslog
 * message processor used everywhere.
 **/
struct _LogSource
{
  LogPipe super;
  LogSourceOptions *options;
  gboolean threaded;
  gchar *name;
  gchar *stats_id;
  WindowSizeCounter window_size;
  DynamicWindow dynamic_window;
  gboolean window_initialized;
  gsize initial_window_size;
  /* full_window_size = static + dynamic */
  gsize full_window_size;
  atomic_gssize window_size_to_be_reclaimed;
  atomic_gssize pending_reclaimed;

  struct
  {
    StatsClusterKeyBuilder *stats_kb;

    StatsCounterItem *stat_window_size;
    StatsCounterItem *stat_full_window;
    StatsCounterItem *last_message_seen;

    StatsClusterKey *recvd_messages_key;
    StatsCounterItem *recvd_messages;

    gboolean raw_bytes_enabled;
    StatsClusterKey *recvd_bytes_key;
    StatsByteCounter recvd_bytes;

    StatsCluster *stat_window_size_cluster;
    StatsCluster *stat_full_window_cluster;
  } metrics;

  guint32 last_ack_count;
  guint32 ack_count;
  glong window_full_sleep_nsec;
  struct timespec last_ack_rate_time;
  AckTrackerFactory *ack_tracker_factory;
  AckTracker *ack_tracker;

  void (*wakeup)(LogSource *s);
  void (*schedule_dynamic_window_realloc)(LogSource *s);
};

static inline gboolean
log_source_free_to_send(LogSource *self)
{
  return !window_size_counter_suspended(&self->window_size);
}

static inline gsize
log_source_get_init_window_size(LogSource *self)
{
  return self->initial_window_size;
}

static inline void
log_source_schedule_dynamic_window_realloc(LogSource *s)
{
  if (!s || !s->schedule_dynamic_window_realloc)
    return;
  s->schedule_dynamic_window_realloc(s);
}

gboolean log_source_init(LogPipe *s);
gboolean log_source_deinit(LogPipe *s);

void log_source_post(LogSource *self, LogMessage *msg);

void log_source_set_options(LogSource *self, LogSourceOptions *options, const gchar *stats_id,
                            StatsClusterKeyBuilder *kb, gboolean threaded, LogExprNode *expr_node);
void log_source_set_ack_tracker_factory(LogSource *self, AckTrackerFactory *factory);
void log_source_set_name(LogSource *self, const gchar *name);
void log_source_mangle_hostname(LogSource *self, LogMessage *msg);
void log_source_init_instance(LogSource *self, GlobalConfig *cfg);
void log_source_options_defaults(LogSourceOptions *options);
void log_source_options_init(LogSourceOptions *options, GlobalConfig *cfg, const gchar *group_name);
void log_source_options_destroy(LogSourceOptions *options);
void log_source_options_set_tags(LogSourceOptions *options, GList *tags);
void log_source_free(LogPipe *s);
void log_source_wakeup(LogSource *self);
void log_source_flow_control_adjust(LogSource *self, guint32 window_size_increment);
void log_source_flow_control_adjust_when_suspended(LogSource *self, guint32 window_size_increment);
void log_source_flow_control_suspend(LogSource *self);
void log_source_disable_bookmark_saving(LogSource *self);
void log_source_enable_dynamic_window(LogSource *self, DynamicWindowPool *window_ctr);
void log_source_dynamic_window_update_statistics(LogSource *self);
gboolean log_source_is_dynamic_window_enabled(LogSource *self);

void log_source_global_init(void);

/* protected */
void log_source_dynamic_window_realloc(LogSource *self);

#endif