fluent-plugins-nursery / fluent-plugin-systemd

This is a fluentd input plugin. It reads logs from the systemd journal.
Apache License 2.0
153 stars 43 forks source link

Does support Journal Namespaces? #105

Closed ogis-yamazaki closed 1 year ago

ogis-yamazaki commented 1 year ago

I'm using the systemd-journald namespace.

[Journal Namespaces] https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html#Journal%20Namespaces

I have prepared a namespace with the name broker.

So I have two journals in /var/log/journal as follows

$ pwd
/var/log/journal/ec27f1ab87d25a7c63d1c9af177d59d7
$ ls -l
total 20
drwxr-sr-x+ 2 root systemd-journal 16384 May 18 16:42 ec27f1ab87d25a7c63d1c9af177d59d7
drwxr-sr-x+ 2 root systemd-journal  4096 May 18 16:35 ec27f1ab87d25a7c63d1c9af177d59d7.broker

Does the plugin support more than 2 journals?

daipom commented 1 year ago

I'm not familiar with journal namespaces, but the path option specifies the directory, so it might be possible to set up two plugins to collect each data if the directories are separated.

The path option is passed to Systemd::Journal's path.

https://github.com/fluent-plugin-systemd/fluent-plugin-systemd/blob/9ffe8e14de75ca94e9bfe7428efd5c1a59421511/lib/fluent/plugin/in_systemd.rb#L78

It seems to be passed to sd_journal_open_directory.

https://github.com/ledbettj/systemd-journal/blob/2f5d259116a5e759311ff16097aadcb48e1989c7/lib/systemd/journal.rb#L232-L252

If we can open them as separate directories, we might be able to do that.

ogis-yamazaki commented 1 year ago

@daipom

Thank you.

In my environment, I have been specifying /var/log/journal for the path option. It might be possible to refer to the journal in two places by specifying an absolute path including machine ID in the path option. I will experiment.

It would be easier if the problem could be solved by simply specifying the parent directory.

ogis-yamazaki commented 1 year ago

I verified it and report that it worked.

My environment has two journals as follows

$ pwd
/var/log/journal/ec27f1ab87d25a7c63d1c9af177d59d7
$ ls -l
total 20
drwxr-sr-x+ 2 root systemd-journal 16384 May 18 16:42 ec27f1ab87d25a7c63d1c9af177d59d7
drwxr-sr-x+ 2 root systemd-journal  4096 May 18 16:35 ec27f1ab87d25a7c63d1c9af177d59d7.broker

As an experiment, I changed the path options as follows

from

path /var/log/journal

to

path /var/log/journal/ec27f1ab87d25a7c63d1c9af177d59d7.broker

I was able to track my journal using the namespace.

thank you.

daipom commented 1 year ago

Thanks for your report! I'm glad to hear that!