Skip to main content

🔍 File Watch Diagnostics

A comprehensive toolkit for diagnosing and troubleshooting file watching issues in Linux environments

Python License Watchdog PyInotify Rich PSUtil

📋 Overview

This toolkit helps identify and resolve common problems that can cause file watching to fail or miss events in Linux environments. It provides both quick diagnostics and comprehensive analysis tools to pinpoint issues with inotify limits, filesystem compatibility, resource constraints, and more.

📁 Project Structure

file_watch_diagnostics/
├── cli/                  # Command-line interfaces
│   ├── diagnostics.py    # Full diagnostics CLI
│   └── quick_check.py    # Quick check CLI
├── utils/                # Utility modules
│   ├── event_monitor.py  # File system event monitoring
│   ├── logging_utils.py  # Logging utilities
│   ├── system_limits.py  # System limits checking
│   └── watch_test.py     # File watching library tests
└── diagnostics.py        # Core diagnostics functionality

🔎 Common File Watching Issues

  1. Inotify Watch Limits: Linux has limits on the number of inotify watches a user can have. When this limit is reached, file watching may fail silently.
  2. Filesystem Compatibility: Some filesystems (NFS, SMBFS, etc.) have limited or no support for inotify events.
  3. Resource Constraints: High CPU usage, memory pressure, or too many processes can cause file watching to miss events.
  4. Process-specific Issues: Some processes may consume a large number of watches, leaving fewer for other applications.
  5. Event Coalescing: Rapid file changes may be coalesced into fewer events, causing some changes to be missed.

🚀 Setup

Install the required dependencies:

pip install -r requirements.txt

🛠️ Tools

Comprehensive Diagnostics

For a more detailed analysis:

python -m file_watch_diagnostics.cli.diagnostics [directory] --testing-mode

This will:

  • Check all system limits related to file watching
  • Monitor file system events in real-time
  • Test file watching with different libraries
  • Provide detailed logs and recommendations

Quick Check

For a faster, targeted analysis:

python -m file_watch_diagnostics.cli.quick_check --directory /path/to/directory --testing

This performs a subset of the full diagnostics, focusing on the most common issues.

Individual Utilities

The package includes several utility modules that can be used independently:

  • system_limits.py: Check inotify limits and current usage
  • event_monitor.py: Monitor file system events in real-time
  • watch_test.py: Test file watching with different libraries

📝 Example Usage

See the examples directory for example scripts:

  • basic_usage.py: Demonstrates basic usage of the diagnostic tools
  • issue_detector.py: Quickly identifies common file watching issues

🧪 Testing

The package includes both unit tests and integration tests to ensure functionality.

Running Unit Tests

python -m pytest /path/to/file_watch_issue_investigation/tests/ -v

Running Integration Tests

python -m pytest /path/to/file_watch_issue_investigation/tests/integration/ -v

Running Tests with Coverage

python -m pytest /path/to/file_watch_issue_investigation/tests/ --cov=file_watch_diagnostics

Test Configuration

The project uses pytest.ini for test configuration:

  • Default test discovery in the tests directory
  • Integration tests are marked with the integration marker
  • Warnings from third-party libraries are filtered

Test Coverage

Current test coverage is at 83%, with the following breakdown:

  • CLI modules: 93-94%
  • Core diagnostics: 81%
  • Event monitoring: 81%
  • System limits: 78%
  • Watch testing: 83%
  • Logging utilities: 72%

🔧 Common Solutions

If issues are detected, the following solutions may help:

  1. Increase inotify limits:

    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
    
  2. Use polling instead of inotify (for incompatible filesystems): Configure your file watching tool to use polling instead of inotify.

  3. Reduce watch scope: Watch fewer directories or use more specific patterns to reduce the number of watches needed.

  4. Restart problematic processes: Identify and restart processes that are using a large number of watches.

📄 License

See the LICENSE file for details.

🚧 Development Status

This project is actively maintained and tested. Current focus areas include:

  • Improving test coverage, especially for error handling paths
  • Optimizing event monitoring performance
  • Enhancing the CLI interfaces for better user experience
  • Adding more comprehensive documentation

🔮 Future Improvements

Planned improvements include:

  • Adding type hints for better code readability and static type checking
  • Creating a simplified API for common diagnostic tasks
  • Supporting more file watching libraries and frameworks
  • Providing more detailed recommendations for fixing detected issues
  • Adding visualization tools for monitoring file watching performance

Metadata

Release files for file-watch-diagnostics 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for file-watch-diagnostics 0.1.0
File Size Uploaded
file_watch_diagnostics-0.1.0.tar.gz 17.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for file-watch-diagnostics 0.1.0
File Interpreter ABI Platform
file_watch_diagnostics-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.9 kB

Release files / file_watch_diagnostics-0.1.0.tar.gz

Download URL file_watch_diagnostics-0.1.0.tar.gz
Size 17.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4fe943334082f5d72dea1abb6173fe16d974eb83a9844380f9625555903cee46
BLAKE2b-256 checksum
How to use checksums
1ca855a477a450677615724ece152df0b2b986c32816e495802e861b50b5caf7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.11.10 Linux/5.15.0-131-generic

Release files / file_watch_diagnostics-0.1.0-py3-none-any.whl

Download URL file_watch_diagnostics-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9eb5c8b8e31570722dff14234683da3ba68fcc749b7d82fb6ec7086bd632fd4d
BLAKE2b-256 checksum
How to use checksums
0a387027bd49d630990957b038fc8926bf7b8873dea61446b8fca33e4fce4810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.4 CPython/3.11.10 Linux/5.15.0-131-generic

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page