diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-08-17 19:08:27 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-17 19:08:27 +0300 |
commit | 45c016c8b890b0dcb65a09be955cd5b4a82934e1 (patch) | |
tree | 0436b717435bd20a985c0997f437e88549f4b79f /collectors/systemd-journal.plugin/systemd-journal.c | |
parent | 6420e675f4324c0f75a54c6c3e6f460ed935a31f (diff) |
systemd-journal in containers (#15830)
Diffstat (limited to 'collectors/systemd-journal.plugin/systemd-journal.c')
-rw-r--r-- | collectors/systemd-journal.plugin/systemd-journal.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/collectors/systemd-journal.plugin/systemd-journal.c b/collectors/systemd-journal.plugin/systemd-journal.c index 0aaa360444..debe7906bb 100644 --- a/collectors/systemd-journal.plugin/systemd-journal.c +++ b/collectors/systemd-journal.plugin/systemd-journal.c @@ -11,12 +11,6 @@ #include "libnetdata/libnetdata.h" #include "libnetdata/required_dummies.h" -#ifndef SD_JOURNAL_ALL_NAMESPACES -#define JOURNAL_NAMESPACE SD_JOURNAL_LOCAL_ONLY -#else -#define JOURNAL_NAMESPACE SD_JOURNAL_ALL_NAMESPACES -#endif - #include <systemd/sd-journal.h> #include <syslog.h> @@ -65,15 +59,21 @@ static bool plugin_should_exit = false; DICTIONARY *uids = NULL; DICTIONARY *gids = NULL; - // ---------------------------------------------------------------------------- int systemd_journal_query(BUFFER *wb, FACETS *facets, usec_t after_ut, usec_t before_ut, usec_t stop_monotonic_ut) { - sd_journal *j; + sd_journal *j = NULL; int r; - // Open the system journal for reading - r = sd_journal_open(&j, JOURNAL_NAMESPACE); + if(*netdata_configured_host_prefix) { + // Give our host prefix to systemd journal + r = sd_journal_open_directory(&j, netdata_configured_host_prefix, SD_JOURNAL_OS_ROOT); + } + else { + // Open the system journal for reading + r = sd_journal_open(&j, 0); + } + if (r < 0) return HTTP_RESP_INTERNAL_SERVER_ERROR; @@ -543,6 +543,9 @@ int main(int argc __maybe_unused, char **argv __maybe_unused) { uids = dictionary_create(0); gids = dictionary_create(0); + netdata_configured_host_prefix = getenv("NETDATA_HOST_PREFIX"); + if(verify_netdata_host_prefix() == -1) exit(1); + // ------------------------------------------------------------------------ // debug |