Files
WesandClaude Sonnet 4.5 27afedb32e Complete rewrite: SnapRAID SMART logger with BackBlaze algorithm
Fetches SMART data from Scrutiny's InfluxDB and calculates failure
probabilities using the exact BackBlaze tables from SnapRAID source.

Key features:
- Calculates both v12 (with attr 193) and v13 (without attr 193) algorithms
- v12 matches SnapRAID pre-v13.0 (includes Load Cycle Count)
- v13 matches modern SnapRAID v13.0+ (excludes Load Cycle Count)
- Stores both values for trending and comparison
- Correctly applies bit masks (16-bit for 187/188, 32-bit for others)
- Annualizes monthly rates and applies Poisson distribution
- Logs to PostgreSQL with device metadata

Solved the mystery: SnapRAID v12 uses attribute 193 which was removed
in v13.0. Load cycle count has massive impact on failure predictions
for some drives (80% vs 4% difference).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-07 06:55:39 -05:00

4.7 KiB

Setup Guide - Smart Logger V3

This version uses a PostgreSQL devices table for metadata instead of the Scrutiny API. Much simpler!

Quick Setup

1. Create the Database Schema

# Run the new schema (includes devices table)
psql -h <your-pg-host> -U <user> -d smart_monitoring -f schema_v2.sql

2. Get Your Device WWNs

Run the helper script to see all devices in InfluxDB:

python get_device_info.py

This will show:

Device 1:
  WWN: 0x5000c500744487c5
  Protocol: ATA
  Temperature: 24°C
  Power-On Time: 1968 days (47232 hours)

Device 2:
  ...

3. Populate Device Metadata

Now match each WWN with its actual device info from snapraid smart:

   Temp  Power   Error   FP Size
      C OnDays   Count        TB  Serial        Device        Disk
 -----------------------------------------------------------------------
     24   1968       0  81% 12.0  ZLW0A3QJ      /dev/sdc      d1
     25    637       0  22% 20.0  ZX22EJ3Y      /dev/sdb      d2
     21   1014       0  51% 12.0  ZTN1BNEZ      /dev/sdd      d5
     25    636       0  49% 20.0  ZX20AAMV      /dev/sda      parity
     25   2540       0  30% 10.0  2TJ97M6D      /dev/sdg      2-parity
     28   2354       1   4% 10.0  7JJVJ65C      /dev/sdh      2-parity
     32   1983       0   4%  3.0  YVGGG6EC      /dev/sde      -
     30   2072       0  84%  8.0  ZA1GX9F4      /dev/sdf      -
      -      -       0    -    -  25243X801438  /dev/nvme0n1  -
     32   2074       0  84%  8.0  ZA1GW0XM      /dev/sdi      -

Match the power-on days from get_device_info.py with the power-on days from snapraid smart to identify each WWN.

For example:

  • WWN 0x5000c500744487c5 has 1968 days → matches /dev/sdc (ZLW0A3QJ, d1)

4. Edit populate_devices.sql

Update populate_devices.sql with your actual device information:

INSERT INTO devices (device_wwn, device_path, serial_number, model, manufacturer, capacity_bytes, size_tb, disk_role, notes)
VALUES (
    '0x5000c500744487c5',
    '/dev/sdc',
    'ZLW0A3QJ',
    'WDC WD120EFAX-68FB5N0',  -- Get from smartctl -i /dev/sdc
    'Western Digital',
    12000000000000,
    12.0,
    'd1',
    'Data drive 1'
);

Repeat for all 9 drives.

5. Load the Data

psql -h <your-pg-host> -U <user> -d smart_monitoring -f populate_devices.sql

6. Run the Logger!

python smart_logger_v3.py

Expected Output

Connecting to InfluxDB at http://cyrion.c0smere.net:8086...
✓ Connected to InfluxDB
Connecting to PostgreSQL...
✓ Connected to PostgreSQL
Loading device metadata from database...
✓ Loaded metadata for 9 device(s)
Querying InfluxDB for SMART data...
✓ Found data for 9 device(s)

/dev/sdc
  WWN: 0x5000c500744487c5
  Serial: ZLW0A3QJ
  Model: WDC WD120EFAX
  Role: d1
  Temp: 24°C
  Power-On: 1968 days
  Size: 12.0 TB
  SMART Attrs: [5, 187, 197, 198]
  Failure Probability: 81.00%

...

================================================================================
SnapRAID-style SMART Summary
================================================================================
 Temp  Power   Error   FP  Size
    C OnDays   Count        TB  Serial           Device           Disk
--------------------------------------------------------------------------------
   24   1968       0  81% 12.0  ZLW0A3QJ         /dev/sdc         d1
   25    637       0  22% 20.0  ZX22EJ3Y         /dev/sdb         d2
   21   1014       0  51% 12.0  ZTN1BNEZ         /dev/sdd         d5
   25    636       0  49% 20.0  ZX20AAMV         /dev/sda         parity
   25   2540       0  30% 10.0  2TJ97M6D         /dev/sdg         2-parity

Querying the Data

-- Latest status for all drives
SELECT * FROM smart_summary;

-- Historical data for a specific drive
SELECT timestamp, temperature_celsius, failure_probability_pct
FROM smart_metrics sm
JOIN devices d ON sm.device_wwn = d.device_wwn
WHERE d.device_path = '/dev/sdc'
ORDER BY timestamp DESC
LIMIT 100;

-- High-risk drives
SELECT * FROM smart_high_risk;

Automation

Add to cron to run hourly:

0 * * * * cd /home/wes/projects/snapraid_smart_logger && /home/wes/projects/snapraid_smart_logger/venv/bin/python smart_logger_v3.py >> /var/log/smart_logger.log 2>&1

Updating Device Info

If you add/remove drives, just update the devices table:

-- Add a new drive
INSERT INTO devices (device_wwn, device_path, serial_number, model, manufacturer, capacity_bytes, size_tb, disk_role)
VALUES ('0xNEW_WWN', '/dev/sdj', 'NEWSERIAL', 'MODEL', 'MANUFACTURER', 12000000000000, 12.0, 'd6');

-- Remove a drive
DELETE FROM devices WHERE device_wwn = '0xOLD_WWN';

-- Update drive role
UPDATE devices SET disk_role = 'parity' WHERE device_path = '/dev/sda';