File Activity Monitoring on Linux OS
There are many tasks within web development, that actively interact with the file system in order to monitor chages of files and catalogs. In order to solve these tasks it is necessary to provide the processing of the immediate file changes that should be performed with the minimal resource consumption. The DropBox service might be a nice example of such type of applications. It has to process all the changes inside the assigned catalog – immediately and consuming the minimum of resources.
Lets imagine we need to develop an application (or a website) like DropBox that should be running on Linux OS. Traditionally this kind of the project consists of two subsystems – server and client subsystem.
Server subsystem regularly tracks and authorizes users, provides synchronization of file changes, conflict solution or file exporting, etc.
Client subsystem provides a limited way to access file information, tracks user interaction and informs the server about them. The key problem of the this application is to provide immediate way to inform client subsystem about file changes.
Requirements for this subsystem:
- Immediate processing of changes.
- Minimum of resources consumed.
- Monitoring of such operations as file movement and renaming, and others that do not lead to data modification in certain files but change the structure.
Initial approach is the checking of the file system with the using file checksums. In order to do this we have to visit every element in the targeted catalog, then to find out its data (attribute, checksum, etc.) and to make a conclusion about the change in the required catalog. At first, when an application is beeing developed such an operation might be worthwhile, but then such polling consumes too much resources and might complicate server administration. That is why it is necessary to use some automated solution that would operate only in the case of available changes. For the Linux OS it would be Inotify.
Inotify is the subsystem of the Linux kernel which monitors file system changes and sends associated events to necessary applications instantly (data deletion, reading, recording, and even unmount). Among others it is also possible to monitor start and end moving points.
Inotify raises events:
- IN_ACCESS The most minimal file event
- IN_ATTRIB Metadata change
- IN_CLOSE_WRITE A file that was opened for recording — closed
- IN_CLOSE_NOWRITE A file that was opened not for recording — closed
- IN_CREATE Creating a file/directory
- IN_DELETE Deleting a file/directory
- IN_DELETE_SELF Deleting a file/directory that is a “viewpoint”
- IN_MODIFY Changing a file
- IN_MOVE_SELF Changing a file/directory that is a “viewpoint”
- IN_MOVED_FROM File movement from a monitor catalog out of a certain monitoring area
- IN_MOVED_TO File movement from a certain area to the monitor catalog
- IN_OPEN Opening a file
We suggest using this approach to resolve such kind of issues.
If you have any questions or would like to contact us about possible request on design or mobile friendly websites/mobile apps development please use Contact form.