| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """Write the periodic history row from the last complete snapshot.
- This runs every minute from cron, independently of the heavier full collection.
- The SQL guard in l2_snapshot.write_history() enforces the configured interval,
- so it only inserts when a new interval is due. Keeping this out of the
- refresh_alarms.sh full-lock gate is what guarantees a five-minute history even
- while a full collection is running.
- """
- import json
- import os
- import sys
- import time
- HERE = os.path.dirname(os.path.abspath(__file__))
- sys.path.insert(0, HERE)
- import l2_snapshot # noqa: E402
- def main():
- try:
- with open(l2_snapshot.OUT, encoding='utf-8') as f:
- snap = json.load(f)
- if not isinstance(snap, dict):
- return
- generated = int(snap.get('generated') or 0)
- # Do not snapshot a stale file if the full collector has stopped.
- if generated and time.time() - generated > 3600:
- return
- l2_snapshot.write_history(snap, int(time.time()))
- except Exception as e:
- print('history tick error:', e)
- if __name__ == '__main__':
- main()
|