Hi Kentaro,
So I did some more digging into Fluentd and Prometheus client code. Here is a solution I came up with.
So in the plugin I implemented the following logic
1) Check if the io_handler for the watcher is nil.
2) If yes, unregister all the metrics from registry and intialize @metric again otherwise we cannot add metric again for other watchers. This means even if one file is rotated the metrics will not be available for a brief moment of time.
3) In the next iteration of the tails loop, a watcher that is still being tracked by Fluentd will add the metrics back and at the end of the tails.clone.each loop we will have metrics for all the watchers which are still being tracked by Fluentd.
Please let me know if this solution sounds reasonable to you. Also I am not super proficient with ruby code so I couldnt figure out why :unwatched flag is not available.
Thanks,
Suvelee