5.6 KiB
5.6 KiB
Fsync Redis Schema Documentation
This document describes the Redis data structures used by the Fsync file system monitor.
Overview
Fsync stores file system events in Redis with the following information:
- Hostname: The server where the change occurred
- File Path: The relative path of the changed file
- Event Type: The type of file system event
- Checksum: SHA256 checksum of file contents (for modify events)
- Metadata: File size, permissions, timestamp, PID
Data Structures
Event Hash Keys
Each file system event is stored as a Redis Hash with the following key format:
fsync:events:{timestamp}:{hostname}:{pid}
Example:
fsync:events:2026-05-18T13:28:51Z:server1:12345
Event Hash Fields
| Field | Type | Description |
|---|---|---|
hostname |
string | The hostname where the event occurred |
path |
string | Absolute file path |
event_type |
string | Type of event (OPEN, CLOSE_WRITE, MODIFY, CREATE, DELETE, MOVED_FROM, MOVED_TO, ATTRIB) |
checksum |
string | SHA256 checksum of file contents (64 hex chars) |
timestamp |
string | ISO8601 timestamp (2026-05-18T13:28:51Z) |
file_size |
number | Size of file in bytes |
permissions |
string | Octal permissions (e.g., "0644") |
process_id |
number | PID of process that triggered the event |
Example Event
Key: fsync:events:2026-05-18T13:28:51Z:server1:1234
Value:
hostname "server1"
path "/var/www/app.js"
event_type "MODIFY"
checksum "a1b2c3d4e5f6..."
timestamp "2026-05-18T13:28:51Z"
file_size "1024"
permissions "0644"
process_id "1234"
Events List
All event keys are added to a list for quick retrieval:
Key: fsync:events:list
Type: List (LPUSH)
This allows efficient range queries of all recorded events.
Common Queries
Get All Events
redis-cli LRANGE fsync:events:list 0 -1
Get Event Details
redis-cli HGETALL fsync:events:2026-05-18T13:28:51Z:server1:1234
Get Events by Hostname
# Get list of all events
redis-cli LRANGE fsync:events:list 0 -1
# Filter by hostname using pattern
redis-cli --pattern 'fsync:events:*:server1:*'
Get Events by Path
# Scan and filter by path field
redis-cli --scan --pattern 'fsync:events:*' | xargs redis-cli HGETALL
Get Recent Events (Last 100)
redis-cli LRANGE fsync:events:list 0 99
Get Events Modified in Last Hour
# Using Lua script or application-level filtering
redis-cli LRANGE fsync:events:list 0 -1 | \
xargs -I {} redis-cli HGET {} timestamp | \
grep -E '(2026-05-18T1[2-3]:[0-5][0-9]:[0-5][0-9]Z)'
Redis CLI Examples
Monitor Events in Real-time
redis-cli MONITOR | grep fsync:events
Get Event Count
redis-cli LLEN fsync:events:list
Delete Old Events
redis-cli EVAL "
local keys = redis.call('LRANGE', 'fsync:events:list', 0, -1)
for _, key in ipairs(keys) do
redis.call('DEL', key)
end
" 0
Export Events to JSON (with redis-cli)
redis-cli --json LRANGE fsync:events:list 0 -1
Event Types
| Event | Description |
|---|---|
OPEN |
File was opened |
CLOSE_WRITE |
File was closed after write |
CLOSE_NOWRITE |
File was closed without write |
MODIFY |
File contents were modified |
CREATE |
File was created |
DELETE |
File was deleted |
MOVED_FROM |
File was moved (source) |
MOVED_TO |
File was moved (destination) |
ATTRIB |
File attributes changed (permissions, owner, etc.) |
Checksum Calculation
SHA256 checksums are calculated for:
MODIFYevents: Capture content changesCLOSE_WRITEevents: Verify final content- Other events: Empty hash or error indicator
Special Cases:
- Files > 100MB: Checksum =
0000000000000000000000000000000000000000000000000000000000000000 - Files that can't be read: Checksum =
error - Directories/symlinks: No checksum (empty string)
Data Expiration
Events are automatically expired after 30 days using Redis EXPIRE command.
EXPIRE fsync:events:{key} 2592000 # 30 days in seconds
Performance Considerations
- List Growth: The
fsync:events:listcan grow large. Consider periodic cleanup or archival. - Hash Storage: Each event stores ~1-2KB of data in Redis memory.
- Network Events: High-frequency events (millions/day) may benefit from batching.
Development Usage
Python Example
import redis
import json
r = redis.Redis(host='localhost', port=6379, decode_responses=True)
# Get all event keys
event_keys = r.lrange('fsync:events:list', 0, -1)
# Get event details
for key in event_keys:
event = r.hgetall(key)
print(json.dumps(event, indent=2))
Node.js Example
const redis = require('redis');
const client = redis.createClient();
client.lrange('fsync:events:list', 0, -1, (err, keys) => {
keys.forEach(key => {
client.hgetall(key, (err, event) => {
console.log(event);
});
});
});
Troubleshooting
No Events Showing Up
- Verify Redis connection:
redis-cli PING→PONG - Check fsync-monitor is running:
ps aux | grep fsync-monitor - Verify file system activity:
touch /tmp/test.txt - Check Redis logs:
redis-cli INFO stats
Memory Growing Too Large
- Check event count:
redis-cli LLEN fsync:events:list - Manually cleanup old events
- Consider archiving to external storage
- Reduce monitored paths to high-priority directories
Checksum Errors
- Verify file permissions:
ls -la /path/to/file - Check OpenSSL installation:
which openssl - Monitor disk space:
df -h