[collectd] tail plugin counting problems

Florian Forster octo at verplant.org
Fri Oct 10 10:17:48 CEST 2008

Hi Matthias,

On Wed, Oct 08, 2008 at 03:41:35PM +0200, Matthias Lay wrote:
> > I'm not sure. From what I've seen, your config looks okay. I haven't
> > seen this behavior yet, though, so it doesn't seem to be a every-day
> > issue either.. Is there anything that makes your setup special or
> > uncommon?

> The only thing that comes to my mind that is "unusual", is that I have
> compiled collectd against dietlibc.

this is indeed a severe difference - another libc always is ;)

We're using `fgets' to read the file line-wise until we get to the end
of the file. In the next iteration, we will simply call `fgets' again to
see what it returns. Apparently, it doesn't return anything and simply
signals EOF right away.

If you truncate the file, a second mechanism comes into play: After
reading to the end of file, we check the file's inode number. If it
changed, we know the file has been moved away, for example because a log
file has been rotated. If the inode has *not* changed, we check the size
of the file. If it decreased, we assume that the file was overwritten or
something similar and start reading from the beginning. So this behavior
is explainable and expected ;)

So the problem appears to be that `fgets' doesn't check the file again.
Could you please try if the following fix works for you?
-- 8< --
diff --git a/src/utils_tail.c b/src/utils_tail.c
index eaf8f73..904a521 100644
--- a/src/utils_tail.c
+++ b/src/utils_tail.c
@@ -162,6 +162,7 @@ int cu_tail_readline (cu_tail_t *obj, char *buf, int buflen)
   /* Try to read from the filehandle. If that succeeds, everything appears to
    * be fine and we can return. */
+  clearerr (obj->fh);
   if (fgets (buf, buflen, obj->fh) != NULL)
     buf[buflen - 1] = 0;
-- 8< --

This will clear the `end of file' indicator on obj->fh before calling `fgets',
hopefully the dietlibc will then check the file again..

Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20081010/81e5fcea/attachment.pgp 

More information about the collectd mailing list