Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdin support? #3

Closed
filippog opened this issue May 16, 2015 · 19 comments · Fixed by #838
Closed

stdin support? #3

filippog opened this issue May 16, 2015 · 19 comments · Fixed by #838
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today mtail-Log Tailing Issues related to log polling and tailing mtail-Operating Issues related to deploying and running mtail

Comments

@filippog
Copy link
Contributor

hi,
thanks for mtail, looks really useful! Is reading from stdin something supported or considered? the use case I have in mind would be programs that don't log to file but in a ring memory buffer (e.g. varnish)

thanks!

@jaqx0r
Copy link
Contributor

jaqx0r commented May 17, 2015

This is a good idea, I think I can add support for reading from a file
descriptor instead of only stdin. The only caveat is that this changes the
reader to need to keep up with the log stream, where currently it does not
(by being buffered on the file system.)

But by removing the filesystem, we can potentially improve performance by
not waiting on disk seeks.

Thanks! I am not sure how soon I could implement this though.
On 16 May 2015 20:42, "Filippo Giunchedi" notifications@github.com wrote:

hi,
thanks for mtail, looks really useful! Is reading from stdin something
supported or considered? the use case I have in mind would be programs that
don't log to file but in a ring memory buffer (e.g. varnish)

thanks!


Reply to this email directly or view it on GitHub
#3.

@filippog
Copy link
Contributor Author

true! Yeah in practice I'd say the reader won't be a bottleneck for most cases, also there shouldn't be a lot of memory required for buffering while reading (?)

anyways no problem on the timeline, thanks for the quick reply!

@jaqx0r
Copy link
Contributor

jaqx0r commented Jun 1, 2015

I'm thinking about this some more. How does varnish emit its logs that you'd want mtail to read from stdin? Would you want to open a named pipe or unix socket, or open a file descriptor?

If you can give me more information about how you think it would work that would be very helpful.

@filippog
Copy link
Contributor Author

filippog commented Jun 1, 2015

so in this particular case varnishlog (https://www.varnish-cache.org/docs/3.0/reference/varnishlog.html) would read log entries from shared memory ring buffer and output those on stdout, e.g.

   18 TxProtocol   c HTTP/1.1
   18 TxStatus     c 204
   18 TxResponse   c Cache miss
   18 TxHeader     c Server: Varnish
   18 TxHeader     c Accept-Ranges: bytes

Also there would be cross-line correlation to do for some things, so it might be more complicated than I initially thought.

Anyways, do you still see value in accepting stdin? thanks!

@jaqx0r
Copy link
Contributor

jaqx0r commented Jun 2, 2015

The mtail language supports temporary state, iirc, so you could write a
program that handles multiline messages if there is a common term to
correlate with.

Right now I am thinking of generalising inputs as taking an arbitrary open
file descriptor, so reading stdin would be supported. I'm still trying to
imagine how it would be configured.
On 2 Jun 2015 9:46 am, "Filippo Giunchedi" notifications@github.com wrote:

so in this particular case varnishlog (
https://www.varnish-cache.org/docs/3.0/reference/varnishlog.html) would
read log entries from shared memory ring buffer and output those on stdout,
e.g.

18 TxProtocol c HTTP/1.1
18 TxStatus c 204
18 TxResponse c Cache miss
18 TxHeader c Server: Varnish
18 TxHeader c Accept-Ranges: bytes

Also there would be cross-line correlation to do for some things, so it
might be more complicated than I initially thought.

Anyways, do you still see value in accepting stdin? thanks!


Reply to this email directly or view it on GitHub
#3 (comment).

@jaqx0r
Copy link
Contributor

jaqx0r commented Jun 2, 2015

BTW thanks the link to the varnish docs.
On 2 Jun 2015 1:24 pm, "Jamie Wilkinson" jaq@spacepants.org wrote:

The mtail language supports temporary state, iirc, so you could write a
program that handles multiline messages if there is a common term to
correlate with.

Right now I am thinking of generalising inputs as taking an arbitrary open
file descriptor, so reading stdin would be supported. I'm still trying to
imagine how it would be configured.
On 2 Jun 2015 9:46 am, "Filippo Giunchedi" notifications@github.com
wrote:

so in this particular case varnishlog (
https://www.varnish-cache.org/docs/3.0/reference/varnishlog.html) would
read log entries from shared memory ring buffer and output those on stdout,
e.g.

18 TxProtocol c HTTP/1.1
18 TxStatus c 204
18 TxResponse c Cache miss
18 TxHeader c Server: Varnish
18 TxHeader c Accept-Ranges: bytes

Also there would be cross-line correlation to do for some things, so it
might be more complicated than I initially thought.

Anyways, do you still see value in accepting stdin? thanks!


Reply to this email directly or view it on GitHub
#3 (comment).

@jaqx0r jaqx0r closed this as completed in c56116b Jun 8, 2015
@jaqx0r
Copy link
Contributor

jaqx0r commented Jun 8, 2015

I've added a flag -logfds that you can pass numerical file descriptors to, e.g.:

mtail -progs examples -logfds 0

which will load the programs in the examples directory, and open stdin for tailing logs.

It's a bit rough at the moment, so more feedback appreciated -- open new bugs please!

@filippog
Copy link
Contributor Author

filippog commented Jun 9, 2015

👍 I'll give it a try, thanks @jaqx0r !

@b4ldr
Copy link

b4ldr commented Jul 11, 2019

@jaqx0r thanks for your work and this tool. I notice that this feature was removed about a year ago[1] which I have just noticed after upgrading. Do you have more information on why this 'can't ever work'. As it appears to be working for us.

[1]8cd80a9

@jaqx0r
Copy link
Contributor

jaqx0r commented Jul 14, 2019 via email

@b4ldr
Copy link

b4ldr commented Jul 15, 2019

Thanks for getting back and also it seems my colleague filippog (who originally opened this issue) also contacted you. I think its best to continue the discussion here and save you answering both of us. To answer your question we run the program with the following

/usr/bin/varnishncsa -n frontend -F "${FMT}" | mtail -progs "${PROGS}" -logfds 0

https://github.com/wikimedia/puppet/blob/production/modules/varnish/files/varnishmtail#L23

@jaqx0r
Copy link
Contributor

jaqx0r commented Jul 16, 2019 via email

@jaqx0r jaqx0r reopened this Jul 16, 2019
@b4ldr
Copy link

b4ldr commented Jul 16, 2019

I have had a quick look at it seems [to me] that -log /dev/stdin does work however i want filippog to confirm as I'm not that familiar with mtail/Prometheus etc. It it does work as it seems then we will update our usage to use -logs, I have already prepared the PR[1]

Thanks

[1]https://gerrit.wikimedia.org/r/#/c/operations/puppet/+/523739

@filippog
Copy link
Contributor Author

I can confirm that -logs /dev/stdin does indeed work as intended!

@b4ldr
Copy link

b4ldr commented Jul 17, 2019

@jaqx0r with filippog's confirmation i will merge my change tomorrow and will use -log /dev/stdin as such there is no need to add -logfds back if its just us asking for it

Thanks

@jaqx0r
Copy link
Contributor

jaqx0r commented Jul 17, 2019 via email

wmfgerrit pushed a commit to wikimedia/operations-puppet that referenced this issue Jul 18, 2019
The logfds switch has been removed[1] and -logs /dev/stdin seems to
provide the same functionality

see this thread: google/mtail#3 (comment)

Bug: T225604
Change-Id: I92554432d05698c5adbea1392eb300161573f55d
@slomo
Copy link

slomo commented Mar 12, 2020

When using /dev/stdin as an parameter I am seeing those errors in the log:

I0312 05:41:25.819354   22098 store.go:107] Running Store.Expire()
I0312 06:41:25.819325   22098 store.go:107] Running Store.Expire()
I0312 07:41:25.819406   22098 tail.go:253] read /dev/stdin: file already closed
I0312 07:41:25.819556   22098 store.go:107] Running Store.Expire()
I0312 07:41:25.822624   22098 log_watcher.go:254] Found this processor in watched list
I0312 07:41:25.822852   22098 log_watcher.go:249] No abspath in watched list, added new one for /dev/stdin
I0312 07:41:25.822861   22098 tail.go:300] Tailing /dev/stdin
W0312 08:18:12.649910   22098 tail.go:242] Internal error finding file handle for "/dev/null" after create
W0312 08:18:12.651290   22098 tail.go:242] Internal error finding file handle for "/dev/null" after create
W0312 08:18:12.651341   22098 tail.go:242] Internal error finding file handle for "/dev/null" after create
... hundred times same error message ...
W0312 08:18:12.657091   22098 tail.go:242] Internal error finding file handle for "/dev/null" after create
I0312 08:41:25.819368   22098 store.go:107] Running Store.Expire()

Am I doing somehing wrong? My starting command looks like this:

/usr/bin/journalctl  -o cat -f -n 0 | /opt/mtail/mtail_3.0.0-rc34 -progs progs -logs /dev/stdin -logtostderr

EDIT: These are the logs during startup:

I0312 10:42:56.397491   66735 main.go:100] mtail version v3.0.0-rc34 git revision 7b4270cb6e8b6ed1f2febe48e370cb68d38681f9 go version go1.12.15 go arch amd64 go os linux
I0312 10:42:56.397587   66735 main.go:101] Commandline: ["/opt/mtail/mtail_3.0.0-rc34" "-progs" "/opt/mtail" "-logs" "/dev/stdin" "-logtostderr"]
I0312 10:42:56.398401   66735 log_watcher.go:249] No abspath in watched list, added new one for progs
I0312 10:42:56.398759   66735 checker.go:214] declaration of capture group reference `total_time' at haproxy.mtail:5:1-179 appears to be unused
I0312 10:42:56.398775   66735 checker.go:214] declaration of capture group reference `total_time' at haproxy.mtail:5:1-179 appears to be unused
I0312 10:42:56.398864   66735 loader.go:229] Loaded program haproxy.mtail
I0312 10:42:56.398902   66735 log_watcher.go:249] No abspath in watched list, added new one for /dev
I0312 10:42:56.398929   66735 log_watcher.go:249] No abspath in watched list, added new one for /dev/stdin
I0312 10:42:56.398935   66735 log_watcher.go:254] Found this processor in watched list
I0312 10:42:56.398965   66735 log_watcher.go:254] Found this processor in watched list
I0312 10:42:56.398974   66735 tail.go:300] Tailing /dev/stdin
I0312 10:42:56.399089   66735 tail.go:446] Starting log handle expiry loop every 1h0m0s
I0312 10:42:56.399511   66735 store.go:136] Starting metric store expiry loop every 1h0m0s
I0312 10:42:56.399262   66735 mtail.go:321] Listening on [::]:3903

@jaqx0r jaqx0r added the enhancement This is considered a feature request, not currently guaranteed by the code or design today label Mar 20, 2021
@jaqx0r
Copy link
Contributor

jaqx0r commented Mar 20, 2021

In #479 we're adding functionality to parse the log path pattern, once that has landed I'll add the ability to pass - like I mentioned earlier.

@jaqx0r
Copy link
Contributor

jaqx0r commented Mar 20, 2021

@slomo Please can you try again with a current mtail ? I think rc34 was using inotify and also polling all the files in the parent directory, which is why you were seeing /dev/null show up. Now mtail doesn't do that, so I'd be interested to know if you get the same behaviour.

@jaqx0r jaqx0r added mtail-Operating Issues related to deploying and running mtail mtail-Log Tailing Issues related to log polling and tailing labels Mar 21, 2021
jaqx0r added a commit that referenced this issue Apr 22, 2024
jaqx0r added a commit that referenced this issue Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today mtail-Log Tailing Issues related to log polling and tailing mtail-Operating Issues related to deploying and running mtail
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants