@cryptotaxi247 / netdata-1 / commits / ee9de6746

respect flood protection configuration for daemon (#19360)

* respect flood protection configuration for daemon * added journal message id for flood protection; netdata startup; added new systemd message id to journal annotations

Costa Tsaousis committed Jan 9, 2025 at 18:11 UTC ee9de6746587bd71b7e10e71976c8645fb795122
7 files changed +36 -9
src/collectors/systemd-journal.plugin/systemd-journal-annotations.c
+5
@@ -570,6 +570,9 @@ static void netdata_systemd_journal_message_ids_init(void) {
570 msgid_into_dict("a8fa8dacdb1d443e9503b8be367a6adb", "SysV Service Found");
571 msgid_into_dict("187c62eb1e7f463bb530394f52cb090f", "Portable Service attached");
572 msgid_into_dict("76c5c754d628490d8ecba4c9d042112b", "Portable Service detached");
573 + msgid_into_dict("9cf56b8baf9546cf9478783a8de42113", "systemd-networkd sysctl changed by foreign process");
574 + msgid_into_dict("ad7089f928ac4f7ea00c07457d47ba8a", "SRK into TPM authorization failure");
575 + msgid_into_dict("b2bcbaf5edf948e093ce50bbea0e81ec", "Secure Attention Key (SAK) was pressed");
576
577 // dbus
578 // https://github.com/bus1/dbus-broker/blob/main/src/catalog/catalog-ids.h
@@ -606,12 +609,14 @@ static void netdata_systemd_journal_message_ids_init(void) {
609 msgid_into_dict("dd11929c788e48bdbb6276fb5f26b08a", "Boltd starting");
610
611 // Netdata
612 + msgid_into_dict("1e6061a9fbd44501b3ccc368119f2b69", "Netdata startup");
613 msgid_into_dict("ed4cdb8f1beb4ad3b57cb3cae2d162fa", "Netdata connection from child");
614 msgid_into_dict("6e2e3839067648968b646045dbf28d66", "Netdata connection to parent");
615 msgid_into_dict("9ce0cb58ab8b44df82c4bf1ad9ee22de", "Netdata alert transition");
616 msgid_into_dict("6db0018e83e34320ae2a659d78019fb7", "Netdata alert notification");
617 msgid_into_dict("23e93dfccbf64e11aac858b9410d8a82", "Netdata fatal message");
618 msgid_into_dict("8ddaf5ba33a74078b609250db1e951f3", "Sensor state transition");
619 + msgid_into_dict("ec87a56120d5431bace51e2fb8bba243", "Netdata log flood protection");
620 }
621
622 void netdata_systemd_journal_transform_message_id(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
src/daemon/main.c
+9 -1
@@ -739,7 +739,15 @@ int netdata_main(int argc, char **argv) {
739
740 // initialize the log files
741 nd_log_initialize();
742 - netdata_log_info("Netdata agent version '%s' is starting", NETDATA_VERSION);
742 + {
743 + ND_LOG_STACK lgs[] = {
744 + ND_LOG_FIELD_UUID(NDF_MESSAGE_ID, &netdata_startup_msgid),
745 + ND_LOG_FIELD_END(),
746 + };
747 + ND_LOG_STACK_PUSH(lgs);
748 +
749 + netdata_log_info("Netdata agent version '%s' is starting", NETDATA_VERSION);
750 + }
751
752 // ----------------------------------------------------------------------------------------------------------------
753 // global configuration
src/libnetdata/log/nd_log-config.c
+10 -8
@@ -191,17 +191,19 @@ void nd_log_set_facility(const char *facility) {
191 }
192
193 void nd_log_set_flood_protection(size_t logs, time_t period) {
194 - nd_log.sources[NDLS_DAEMON].limits.logs_per_period =
195 - nd_log.sources[NDLS_DAEMON].limits.logs_per_period_backup;
196 - nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period =
197 - nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period_backup = logs;
194 + // daemon logs
195 + nd_log.sources[NDLS_DAEMON].limits.logs_per_period = logs;
196 + nd_log.sources[NDLS_DAEMON].limits.logs_per_period_backup = logs;
197 + nd_log.sources[NDLS_DAEMON].limits.throttle_period = period;
198
199 - nd_log.sources[NDLS_DAEMON].limits.throttle_period =
200 - nd_log.sources[NDLS_COLLECTORS].limits.throttle_period = period;
199 + // collectors logs
200 + nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period = logs;
201 + nd_log.sources[NDLS_COLLECTORS].limits.logs_per_period_backup = logs;
202 + nd_log.sources[NDLS_COLLECTORS].limits.throttle_period = period;
203
204 char buf[100];
203 - snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t )period);
205 + snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t)period);
206 nd_setenv("NETDATA_ERRORS_THROTTLE_PERIOD", buf, 1);
205 - snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t )logs);
207 + snprintfz(buf, sizeof(buf), "%" PRIu64, (uint64_t)logs);
208 nd_setenv("NETDATA_ERRORS_PER_PERIOD", buf, 1);
209 }
src/libnetdata/log/nd_log-internals.h
+1
@@ -107,6 +107,7 @@ struct nd_log_source {
107 FILE *fp;
108
109 ND_LOG_FIELD_PRIORITY min_priority;
110 + const nd_uuid_t *pending_msgid;
111 const char *pending_msg;
112 struct nd_log_limit limits;
113
src/libnetdata/log/nd_log.c
+7
@@ -329,12 +329,19 @@ static void nd_logger(const char *file, const char *function, const unsigned lon
329 .txt = nd_log.sources[source].pending_msg,
330 };
331
332 + thread_log_fields[NDF_MESSAGE_ID].entry = (struct log_stack_entry){
333 + .set = nd_log.sources[source].pending_msgid != NULL,
334 + .type = NDFT_UUID,
335 + .uuid = nd_log.sources[source].pending_msgid,
336 + };
337 +
338 nd_logger_log_fields(spinlock, fp, false, priority, output,
339 &nd_log.sources[source],
340 thread_log_fields, THREAD_FIELDS_MAX);
341
342 freez((void *)nd_log.sources[source].pending_msg);
343 nd_log.sources[source].pending_msg = NULL;
344 + nd_log.sources[source].pending_msgid = NULL;
345 }
346
347 errno_clear();
src/libnetdata/log/nd_log_limit.c
+2
@@ -54,6 +54,7 @@ bool nd_log_limit_reached(struct nd_log_source *source) {
54 freez((void *)source->pending_msg);
55
56 source->pending_msg = strdupz(buffer_tostring(wb));
57 + source->pending_msgid = &log_flood_protection_msgid;
58 buffer_free(wb);
59 }
60
@@ -84,6 +85,7 @@ bool nd_log_limit_reached(struct nd_log_source *source) {
85 freez((void *)source->pending_msg);
86
87 source->pending_msg = strdupz(buffer_tostring(wb));
88 + source->pending_msgid = &log_flood_protection_msgid;
89 buffer_free(wb);
90 }
91
src/libnetdata/uuid/uuid.h
+2
@@ -33,6 +33,8 @@ ND_UUID_DEFINE(health_alert_transition_msgid, 0x9c, 0xe0, 0xcb, 0x58, 0xab, 0x8b
33 // this is also defined in alarm-notify.sh.in
34 ND_UUID_DEFINE(health_alert_notification_msgid, 0x6d, 0xb0, 0x01, 0x8e, 0x83, 0xe3, 0x43, 0x20, 0xae, 0x2a, 0x65, 0x9d, 0x78, 0x01, 0x9f, 0xb7);
35 ND_UUID_DEFINE(sensors_state_transition_msgid, 0x8d, 0xda, 0xf5, 0xba, 0x33, 0xa7, 0x40, 0x78, 0xb6, 0x09, 0x25, 0x0d, 0xb1, 0xe9, 0x51, 0xf3);
36 +ND_UUID_DEFINE(log_flood_protection_msgid, 0xec, 0x87, 0xa5, 0x61, 0x20, 0xd5, 0x43, 0x1b, 0xac, 0xe5, 0x1e, 0x2f, 0xb8, 0xbb, 0xa2, 0x43);
37 +ND_UUID_DEFINE(netdata_startup_msgid, 0x1e, 0x60, 0x61, 0xa9, 0xfb, 0xd4, 0x45, 0x01, 0xb3, 0xcc, 0xc3, 0x68, 0x11, 0x9f, 0x2b, 0x69);
38
39 ND_UUID UUID_generate_from_hash(const void *payload, size_t payload_len);
40