@cryptotaxi247 / netdata-1 / commits / 45c016c8b

systemd-journal in containers (#15830)

Costa Tsaousis committed Aug 17, 2023 at 19:08 UTC 45c016c8b890b0dcb65a09be955cd5b4a82934e1
1 file changed +13 -10
collectors/systemd-journal.plugin/systemd-journal.c
+13 -10
@@ -11,12 +11,6 @@
11 #include "libnetdata/libnetdata.h"
12 #include "libnetdata/required_dummies.h"
13
14 -#ifndef SD_JOURNAL_ALL_NAMESPACES
15 -#define JOURNAL_NAMESPACE SD_JOURNAL_LOCAL_ONLY
16 -#else
17 -#define JOURNAL_NAMESPACE SD_JOURNAL_ALL_NAMESPACES
18 -#endif
19 -
14 #include <systemd/sd-journal.h>
15 #include <syslog.h>
16
@@ -65,15 +59,21 @@ static bool plugin_should_exit = false;
59 DICTIONARY *uids = NULL;
60 DICTIONARY *gids = NULL;
61
68 -
62 // ----------------------------------------------------------------------------
63
64 int systemd_journal_query(BUFFER *wb, FACETS *facets, usec_t after_ut, usec_t before_ut, usec_t stop_monotonic_ut) {
72 - sd_journal *j;
65 + sd_journal *j = NULL;
66 int r;
67
75 - // Open the system journal for reading
76 - r = sd_journal_open(&j, JOURNAL_NAMESPACE);
68 + if(*netdata_configured_host_prefix) {
69 + // Give our host prefix to systemd journal
70 + r = sd_journal_open_directory(&j, netdata_configured_host_prefix, SD_JOURNAL_OS_ROOT);
71 + }
72 + else {
73 + // Open the system journal for reading
74 + r = sd_journal_open(&j, 0);
75 + }
76 +
77 if (r < 0)
78 return HTTP_RESP_INTERNAL_SERVER_ERROR;
79
@@ -543,6 +543,9 @@ int main(int argc __maybe_unused, char **argv __maybe_unused) {
543 uids = dictionary_create(0);
544 gids = dictionary_create(0);
545
546 + netdata_configured_host_prefix = getenv("NETDATA_HOST_PREFIX");
547 + if(verify_netdata_host_prefix() == -1) exit(1);
548 +
549 // ------------------------------------------------------------------------
550 // debug
551