Go to the documentation of this file.
35 intmax_t output_flush_interval = 0;
36 if (
SCConfGetInt(
"heartbeat.output-flush-interval", &output_flush_interval) == 0) {
37 output_flush_interval = 0;
39 if (output_flush_interval < 0 || output_flush_interval > 60) {
40 SCLogConfig(
"flush_interval must be 0 or less than 60; using 0");
41 output_flush_interval = 0;
44 return (
int)output_flush_interval;
47 static void *LogMaintenanceThread(
void *arg)
51 if (output_flush_interval > 0) {
52 SCLogConfig(
"Log maintenance thread started: rotation check every 1s, flush interval %ds",
53 output_flush_interval);
55 SCLogConfig(
"Log maintenance thread started: rotation check every 1s, flush disabled");
63 const int maintenance_sleep_time = 500;
64 const int rotation_wait_count = 1000 / maintenance_sleep_time;
65 const int flush_wait_count =
66 output_flush_interval > 0 ? (1000 * output_flush_interval) / maintenance_sleep_time : 0;
71 if (tv_local->thread_setup_flags != 0)
75 tv_local->cap_flags = 0;
80 int rotation_counter = 0;
81 int flush_counter = 0;
82 uint64_t rotation_check_count = 0;
83 uint64_t worker_flush_count = 0;
89 if (++rotation_counter >= rotation_wait_count) {
90 rotation_check_count++;
96 if (flush_wait_count > 0 && ++flush_counter >= flush_wait_count) {
110 SCLogInfo(
"%s: performed %" PRIu64
" rotation checks, %" PRIu64
" flushes", tv_local->name,
111 rotation_check_count, worker_flush_count);
119 if (!tv_maintenance || (
TmThreadSpawn(tv_maintenance) != 0)) {
120 FatalError(
"Unable to create and start log maintenance thread");
TmEcode TmThreadSpawn(ThreadVars *tv)
Spawns a thread associated with the ThreadVars instance tv.
TmEcode TmThreadSetupOptions(ThreadVars *tv)
Set the thread options (cpu affinitythread). Priority should be already set by pthread_create.
void LogMaintenanceThreadSpawn(void)
void LogFileRotateAll(void)
Check rotation for all registered LogFileCtx instances.
void TmThreadsSetFlag(ThreadVars *tv, uint32_t flag)
Set a thread flag.
void TmThreadWaitForFlag(ThreadVars *tv, uint32_t flags)
Waits till the specified flag(s) is(are) set. We don't bother if the kill flag has been set or not on...
#define SCSetThreadName(n)
int OutputFlushInterval(void)
int SCConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
Per thread variable structure.
void LogFileFlushAll(void)
Flush all registered LogFileCtx instances.
ThreadVars * TmThreadCreateMgmtThread(const char *name, void *(fn_p)(void *), int mucond)
Creates and returns the TV instance for a Management thread(MGMT). This function supports only custom...
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
const char * thread_name_heartbeat
bool TmThreadsWaitForUnpause(ThreadVars *tv)
Wait for a thread to become unpaused.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
int TmThreadsCheckFlag(ThreadVars *tv, uint32_t flag)
Check if a thread flag is set.