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

in_head: a simple plugin to read a file. #37

Merged
merged 2 commits into from
Feb 1, 2016
Merged

Conversation

nokute78
Copy link
Collaborator

I added a new input plugin, in_head.
This plugin read a file from head regularly.

We can get some sensor state by reading a file.
e.g How to read RPi2 GPIO state.

$ cat /sys/class/gpio/gpio25/value

So, this plugin may collect such sensor state.

This plugin needs in_head.conf.
You can configure filepath, intervals and buffer size to read.

$ bin/fluent-bit -i head -o stdout -c ../../in_head.conf -V
Fluent-Bit v0.7.0
Copyright (C) Treasure Data

[2016/01/29 22:45:46] [ info] Configuration
 flush time     : 5 seconds
 input plugins  : head 
 collectors     : 
[2016/01/29 22:45:46] [ info] starting engine
[2016/01/29 22:45:46] [debug] Head config: buf_size=256 path=/proc/uptime
[2016/01/29 22:45:46] [debug] Head config: interval_sec=1 interval_nsec=0
[2016/01/29 22:45:46] [debug] in_head_init read_len=0 buf_size=8
[2016/01/29 22:45:46] [debug] [stats] register in plugin: head
[2016/01/29 22:45:46] [debug] [stats] register out plugin: stdout
[2016/01/29 22:45:47] [debug] in_head_collect read_len=20 buf_size=256
[2016/01/29 22:45:48] [debug] in_head_collect read_len=20 buf_size=256
[2016/01/29 22:45:49] [debug] in_head_collect read_len=20 buf_size=256
[2016/01/29 22:45:50] [debug] in_head_collect read_len=20 buf_size=256
[2016/01/29 22:45:51] [debug] [thread 0x2584210] created
[0] [1454075147, {"head"=>"155706.38 142978.31"}]
[1] [1454075148, {"head"=>"155707.38 142979.25"}]
[2] [1454075149, {"head"=>"155708.38 142980.23"}]
[3] [1454075150, {"head"=>"155709.38 142981.20"}]
[2016/01/29 22:45:51] [debug] [thread 0x2584210] ended
[2016/01/29 22:45:51] [debug] in_head_collect read_len=20 buf_size=256
[2016/01/29 22:45:51] [debug] [stats] dump
{"input_plugins":{"head":{"data":[{"time":1454075147,"bytes":0,"events":1},{"time":1454075148,"bytes":0,"events":1},{"time":1454075149,"bytes":0,"events":1}]}},"output_plugins":{"stdout":{"data":[]}}}

Thanks!

Signed-off-by: nokute78 [email protected]

in_head is a simple input plugin to read a file.
You can configure filepath, intervals and buffer size to read.

Signed-off-by: nokute78 <[email protected]>
perror("read");
goto collect_fin;
}
head_config->buf[head_config->buf_len -1] = '\0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On this line, you are setting a NULL character in the wrong position, e.g:

{"head":"96996.47 187893.47\u0000"}

two workarounds:

  • right position: head_config->buf[head_config->buf_len] = '\0';
  • since you are packaging directly to msgpack, there is no need for this.

so I think number 2 is better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to get rid of that line, if the read(2) call reads the maximum allowed by the buffer, it will generate an overflow. At the end it's not required.

@edsiper
Copy link
Member

edsiper commented Jan 29, 2016

thanks for this contribution!, the plugin looks pretty good, I just added a small note that needs to be fixed, so then it can be merged.

@nokute78
Copy link
Collaborator Author

Thank you for reviewing.
I deleted the wrong null termination.

edsiper added a commit that referenced this pull request Feb 1, 2016
in_head: a simple plugin to read a file.
@edsiper edsiper merged commit 1ece33a into fluent:master Feb 1, 2016
@edsiper
Copy link
Member

edsiper commented Feb 1, 2016

merged, thanks!

@prashantvicky prashantvicky mentioned this pull request Aug 28, 2018
fujimotos pushed a commit to fujimotos/fluent-bit that referenced this pull request Jul 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants