solved duplicate points error

This commit is contained in:
2026-08-30 13:38:55 +02:00
parent 4c216abb1f
commit 67d8b50333
3 changed files with 33 additions and 6 deletions
+15 -2
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import colorsys
import logging
import re
import tempfile
from pathlib import Path
@@ -10,6 +11,7 @@ import rrdtool
from .data import Sample
RRD_ERROR = rrdtool.OperationalError
LOG = logging.getLogger(__name__)
STEP = 600
HEARTBEAT = 1500
@@ -53,15 +55,26 @@ class RRDStore:
"RRA:AVERAGE:0.5:36:1464", "RRA:MIN:0.5:36:1464", "RRA:MAX:0.5:36:1464"]
rrdtool.create(str(path), *args)
def update(self, name: str, sample: Sample) -> None:
def update(self, name: str, sample: Sample) -> bool:
"""Store at most one sample per RRD step; return whether it was written."""
path = self.path(name)
last_timestamp = int(rrdtool.last(str(path)))
if sample.timestamp // STEP <= last_timestamp // STEP:
LOG.info(
"Skipping %s RRD update: sample interval already stored "
"(sample_timestamp=%d last_timestamp=%d)",
name, sample.timestamp, last_timestamp,
)
return False
schema = SCHEMAS[name]
fields = list(schema)
values = ["U" if sample.values.get(field) is None else str(sample.values[field]) for field in fields]
rrdtool.update(
str(self.path(name)),
str(path),
"--template", ":".join(fields),
f"{sample.timestamp}:{':'.join(values)}",
)
return True
def last(self, name: str, field: str) -> dict:
if name not in SCHEMAS or field not in SCHEMAS[name]: