inotify-tools / inotify-tools

inotify-tools is a C library and a set of command-line programs providing a simple interface to inotify.
GNU General Public License v2.0
3.16k stars 392 forks source link

Can inotifywait (or another inotify tool) show filesize with listing the event? #225

Open gitthnx opened 1 month ago

gitthnx commented 1 month ago

For monitoring data throughput on a Linux filesystem directory (e.g. ext4, btrfs, xfs, ntfs, vfat, f2fs, etc.) it is necessary to list directory name or filename, absolute path, event and directory or file size.
Are there options for resolving this task with inotifywait or other inotify tools? Would there be interest in adding this feature detail for the --format option of inotifywait?

example for referencing a starting point on common experience:

cat /proc/sys/fs/inotify/max_user_watches; inotifywait --format "[%T] %w%f %e" --timefmt "%Y/%m/%d, %H:%M:%S" -m -e modify,create,delete,move -r "/sys/kernel/debug/tracing/events/ext4/" --outfile /dev/shm/filesystem-changes.log;

(thx)

ericcurtin commented 1 month ago

Open to a PR like this, in general we are open to PRs that don't break any existing functionality

gitthnx commented 3 weeks ago

An example suggestion can show a possibility, without verification if it is useful for all functionality or avoids covered drawbacks. Maybe it's too much information output for what is expected for io monitoring and might require error handling.

//#ifdef EXAMPLE_FMTOPTION_FILESIZE     
if (ch1 == 'x') {

            sprintf(sizeval, "%s ", "helloWorld" );
        len_sizeval=strlen(sizeval);
        //len_sizeval=sizeof(sizeval);

        sprintf(event_pth, "%s%s", filename, eventname);
        stat(event_pth, &stats);
                filesize = stats.st_size;

        //sprintf(&out->buf[ind], "%s %lu %s %lu filesize %lu %lu %lu %lu ", sizeval, strlen(filename), eventname, strlen(eventname), filesize, dirnamelen, len_sizeval, sizeof(sizeval) );
        ind+=len_sizeval+strlen(filename)+strlen(eventname)+41;

            /*out->buf[ind++] = '\t';           
            out->buf[ind++] = 'h';
            out->buf[ind++] = 'e';
            out->buf[ind++] = 'l';
            out->buf[ind++] = 'l';
            out->buf[ind++] = 'o';
            out->buf[ind++] = 'W';
            out->buf[ind++] = 'o';
            out->buf[ind++] = 'r';
            out->buf[ind++] = 'l';
            out->buf[ind++] = 'd';
            out->buf[ind++] = '\t';
            */

            ++i;
            continue;

        }       
//#endif        

Why does inotifywait list several MODIFY events for a file within a short period of time?

(thx)