summaryrefslogtreecommitdiffstats
path: root/collectors/systemd-journal.plugin
diff options
context:
space:
mode:
Diffstat (limited to 'collectors/systemd-journal.plugin')
-rw-r--r--collectors/systemd-journal.plugin/systemd-journal-annotations.c74
-rw-r--r--collectors/systemd-journal.plugin/systemd-journal-files.c2
-rw-r--r--collectors/systemd-journal.plugin/systemd-journal.c12
-rw-r--r--collectors/systemd-journal.plugin/systemd-main.c13
-rw-r--r--collectors/systemd-journal.plugin/systemd-units.c2
5 files changed, 63 insertions, 40 deletions
diff --git a/collectors/systemd-journal.plugin/systemd-journal-annotations.c b/collectors/systemd-journal.plugin/systemd-journal-annotations.c
index 00fced912b..73d1560e97 100644
--- a/collectors/systemd-journal.plugin/systemd-journal-annotations.c
+++ b/collectors/systemd-journal.plugin/systemd-journal-annotations.c
@@ -408,35 +408,50 @@ void netdata_systemd_journal_transform_boot_id(FACETS *facets __maybe_unused, BU
};
sd_journal *j = NULL;
- if(sd_journal_open_files(&j, files, ND_SD_JOURNAL_OPEN_FLAGS) < 0 || !j) {
- internal_error(true, "JOURNAL: cannot open file '%s' to get boot_id", jf_dfe.name);
+ int r = sd_journal_open_files(&j, files, ND_SD_JOURNAL_OPEN_FLAGS);
+ if(r < 0 || !j) {
+ internal_error(true, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
+ "sd_journal_open_files('%s') returned %d",
+ boot_id, jf_dfe.name, r);
continue;
}
char m[100];
size_t len = snprintfz(m, sizeof(m), "_BOOT_ID=%s", boot_id);
- if(sd_journal_add_match(j, m, len) < 0) {
- internal_error(true, "JOURNAL: cannot add match '%s' to file '%s'", m, jf_dfe.name);
+ r = sd_journal_add_match(j, m, len);
+ if(r < 0) {
+ internal_error(true, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
+ "sd_journal_add_match('%s') on file '%s' returned %d",
+ boot_id, m, jf_dfe.name, r);
sd_journal_close(j);
continue;
}
- if(sd_journal_seek_head(j) < 0) {
- internal_error(true, "JOURNAL: cannot seek head to file '%s'", jf_dfe.name);
+ r = sd_journal_seek_head(j);
+ if(r < 0) {
+ internal_error(true, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
+ "sd_journal_seek_head() on file '%s' returned %d",
+ boot_id, jf_dfe.name, r);
sd_journal_close(j);
continue;
}
- if(sd_journal_next(j) < 0) {
- internal_error(true, "JOURNAL: cannot get next of file '%s'", jf_dfe.name);
+ r = sd_journal_next(j);
+ if(r < 0) {
+ internal_error(true, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
+ "sd_journal_next() on file '%s' returned %d",
+ boot_id, jf_dfe.name, r);
sd_journal_close(j);
continue;
}
usec_t t_ut = 0;
- if(sd_journal_get_realtime_usec(j, &t_ut) < 0 || !t_ut) {
- internal_error(true, "JOURNAL: cannot get realtime_usec of file '%s'", jf_dfe.name);
+ r = sd_journal_get_realtime_usec(j, &t_ut);
+ if(r < 0 || !t_ut) {
+ internal_error(r != -EADDRNOTAVAIL, "JOURNAL: while looking for the first timestamp of boot_id '%s', "
+ "sd_journal_get_realtime_usec() on file '%s' returned %d",
+ boot_id, jf_dfe.name, r);
sd_journal_close(j);
continue;
}
@@ -454,25 +469,21 @@ void netdata_systemd_journal_transform_boot_id(FACETS *facets __maybe_unused, BU
ut = *p_ut;
if(ut != UINT64_MAX) {
- time_t timestamp_sec = (time_t)(ut / USEC_PER_SEC);
- struct tm tm;
- char buffer[30];
-
- gmtime_r(&timestamp_sec, &tm);
- strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
+ char buffer[ISO8601_MAX_LENGTH];
+ iso8601_datetime_ut(buffer, sizeof(buffer), ut, ISO8601_UTC);
switch(scope) {
default:
case FACETS_TRANSFORM_DATA:
case FACETS_TRANSFORM_VALUE:
- buffer_sprintf(wb, " (%s UTC) ", buffer);
+ buffer_sprintf(wb, " (%s) ", buffer);
break;
case FACETS_TRANSFORM_FACET:
case FACETS_TRANSFORM_FACET_SORT:
case FACETS_TRANSFORM_HISTOGRAM:
buffer_flush(wb);
- buffer_sprintf(wb, "%s UTC", buffer);
+ buffer_sprintf(wb, "%s", buffer);
break;
}
}
@@ -537,13 +548,9 @@ void netdata_systemd_journal_transform_timestamp_usec(FACETS *facets __maybe_unu
if(*v && isdigit(*v)) {
uint64_t ut = str2ull(buffer_tostring(wb), NULL);
if(ut) {
- time_t timestamp_sec = (time_t)(ut / USEC_PER_SEC);
- struct tm tm;
- char buffer[30];
-
- gmtime_r(&timestamp_sec, &tm);
- strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm);
- buffer_sprintf(wb, " (%s.%06llu UTC)", buffer, ut % USEC_PER_SEC);
+ char buffer[ISO8601_MAX_LENGTH];
+ iso8601_datetime_ut(buffer, sizeof(buffer), ut, ISO8601_UTC | ISO8601_MICROSECONDS);
+ buffer_sprintf(wb, " (%s)", buffer);
}
}
}
@@ -703,6 +710,23 @@ void netdata_systemd_journal_message_ids_init(void) {
// gnome-shell
// https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/ui/main.js#L56
i.msg = "Gnome shell started";dictionary_set(known_journal_messages_ids, "f3ea493c22934e26811cd62abe8e203a", &i, sizeof(i));
+
+ // flathub
+ // https://docs.flatpak.org/de/latest/flatpak-command-reference.html
+ i.msg = "Flatpak cache"; dictionary_set(known_journal_messages_ids, "c7b39b1e006b464599465e105b361485", &i, sizeof(i));
+
+ // ???
+ i.msg = "Flathub pulls"; dictionary_set(known_journal_messages_ids, "75ba3deb0af041a9a46272ff85d9e73e", &i, sizeof(i));
+ i.msg = "Flathub pull errors"; dictionary_set(known_journal_messages_ids, "f02bce89a54e4efab3a94a797d26204a", &i, sizeof(i));
+
+ // ??
+ i.msg = "Boltd starting"; dictionary_set(known_journal_messages_ids, "dd11929c788e48bdbb6276fb5f26b08a", &i, sizeof(i));
+
+ // Netdata
+ i.msg = "Netdata connection from child"; dictionary_set(known_journal_messages_ids, "ed4cdb8f1beb4ad3b57cb3cae2d162fa", &i, sizeof(i));
+ i.msg = "Netdata connection to parent"; dictionary_set(known_journal_messages_ids, "6e2e3839067648968b646045dbf28d66", &i, sizeof(i));
+ i.msg = "Netdata alert transition"; dictionary_set(known_journal_messages_ids, "9ce0cb58ab8b44df82c4bf1ad9ee22de", &i, sizeof(i));
+ i.msg = "Netdata alert notification"; dictionary_set(known_journal_messages_ids, "6db0018e83e34320ae2a659d78019fb7", &i, sizeof(i));
}
void netdata_systemd_journal_transform_message_id(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope __maybe_unused, void *data __maybe_unused) {
diff --git a/collectors/systemd-journal.plugin/systemd-journal-files.c b/collectors/systemd-journal.plugin/systemd-journal-files.c
index d4a48b2c74..1fd0284ed8 100644
--- a/collectors/systemd-journal.plugin/systemd-journal-files.c
+++ b/collectors/systemd-journal.plugin/systemd-journal-files.c
@@ -333,8 +333,8 @@ static void files_registry_delete_cb(const DICTIONARY_ITEM *item, void *value, v
struct journal_file *jf = value; (void)jf;
const char *filename = dictionary_acquired_item_name(item); (void)filename;
- string_freez(jf->source);
internal_error(true, "removed journal file '%s'", filename);
+ string_freez(jf->source);
}
void journal_directory_scan(const char *dirname, int depth, usec_t last_scan_ut) {
diff --git a/collectors/systemd-journal.plugin/systemd-journal.c b/collectors/systemd-journal.plugin/systemd-journal.c
index c1dce14bc5..ab01c97eb3 100644
--- a/collectors/systemd-journal.plugin/systemd-journal.c
+++ b/collectors/systemd-journal.plugin/systemd-journal.c
@@ -165,6 +165,18 @@
"|IMAGE_NAME" /* undocumented */ \
/* "|CONTAINER_PARTIAL_MESSAGE" */ \
\
+ \
+ /* --- NETDATA --- */ \
+ \
+ "|ND_NIDL_NODE" \
+ "|ND_NIDL_CONTEXT" \
+ "|ND_LOG_SOURCE" \
+ /*"|ND_MODULE" */ \
+ "|ND_ALERT_NAME" \
+ "|ND_ALERT_CLASS" \
+ "|ND_ALERT_COMPONENT" \
+ "|ND_ALERT_TYPE" \
+ \
""
// ----------------------------------------------------------------------------
diff --git a/collectors/systemd-journal.plugin/systemd-main.c b/collectors/systemd-journal.plugin/systemd-main.c
index ceb7f73051..be06bf698a 100644
--- a/collectors/systemd-journal.plugin/systemd-main.c
+++ b/collectors/systemd-journal.plugin/systemd-main.c
@@ -9,19 +9,8 @@ netdata_mutex_t stdout_mutex = NETDATA_MUTEX_INITIALIZER;
static bool plugin_should_exit = false;
int main(int argc __maybe_unused, char **argv __maybe_unused) {
- stderror = stderr;
clocks_init();
-
- program_name = "systemd-journal.plugin";
-
- // disable syslog
- error_log_syslog = 0;
-
- // set errors flood protection to 100 logs per hour
- error_log_errors_per_period = 100;
- error_log_throttle_period = 3600;
-
- log_set_global_severity_for_external_plugins();
+ nd_log_initialize_for_external_plugins("systemd-journal.plugin");
netdata_configured_host_prefix = getenv("NETDATA_HOST_PREFIX");
if(verify_netdata_host_prefix() == -1) exit(1);
diff --git a/collectors/systemd-journal.plugin/systemd-units.c b/collectors/systemd-journal.plugin/systemd-units.c
index 81cda786fc..dac1588174 100644
--- a/collectors/systemd-journal.plugin/systemd-units.c
+++ b/collectors/systemd-journal.plugin/systemd-units.c
@@ -676,8 +676,6 @@ static void update_freezer_state(UnitInfo *u, UnitAttribute *ua) {
// ----------------------------------------------------------------------------
// common helpers
-#define _cleanup_(x) __attribute__((__cleanup__(x)))
-
static void log_dbus_error(int r, const char *msg) {
netdata_log_error("SYSTEMD_UNITS: %s failed with error %d (%s)", msg, r, strerror(-r));
}