diff --git a/README.md b/README.md index 8da3bb1..8c4d170 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ simple micro service for converting your RRD's to web services ### examples - last 24 hours ```curl 127.0.0.1:9000/?rrd_path=tests/port-id15.rrd``` - epoch date time filter ```curl 127.0.0.1:9000/?rrd_path=tests/port-id15.rrd&epoch_start_time=1622109000&epoch_end_time=1624787400``` +- epoch date filter with daily step ```curl 127.0.0.1:9000/?rrd_path=tests/port-id15.rrd&epoch_start_time=1630425600&epoch_end_time=1633017600&step=86400``` ### rrdtool - tested with version 1.7 diff --git a/backend/RRD_parse.py b/backend/RRD_parse.py index bc0827e..9f497f0 100644 --- a/backend/RRD_parse.py +++ b/backend/RRD_parse.py @@ -9,10 +9,10 @@ class RRD_parser: - def __init__(self, rrd_file=None, start_time=None, end_time=None): + def __init__(self, rrd_file=None, start_time=None, end_time=None, step=None): self.rrd_file = rrd_file self.ds = None - self.step = None + self.step = step self.time_format = "%Y-%m-%d %H:%M:%S" self.check_dependc() self.start_time = start_time @@ -53,7 +53,8 @@ def get_data_source(self): ds_val = match_obj.group(1) if ds_val not in DS_VALS: DS_VALS.append(ds_val) - self.step = STEP_VAL + + self.step = STEP_VAL if self.step is None else self.step self.ds = DS_VALS def get_rrd_json(self, ds): @@ -61,7 +62,7 @@ def get_rrd_json(self, ds): rrd_xport_command = f"rrdtool xport --step {self.step} DEF:data={self.rrd_file}:{ds}:AVERAGE XPORT:data:{ds} --showtime" if self.start_time: - rrd_xport_command = f"rrdtool xport DEF:data={self.rrd_file}:{ds}:AVERAGE XPORT:data:{ds} --showtime --start {self.start_time} --end {self.end_time}" + rrd_xport_command = f"rrdtool xport DEF:data={self.rrd_file}:{ds}:AVERAGE XPORT:data:{ds} --showtime --start {self.start_time} --end {self.end_time} --step {self.step}" result = subprocess.check_output( rrd_xport_command, shell=True diff --git a/rrdrest.py b/rrdrest.py index 1d7f6e7..373d5f0 100644 --- a/rrdrest.py +++ b/rrdrest.py @@ -16,7 +16,12 @@ "/", summary="Get the data from a RRD file, takes in a rrd file path" ) -async def get_rrd(rrd_path: str, epoch_start_time: Optional[int] = None, epoch_end_time: Optional[int] = None): +async def get_rrd( + rrd_path: str, + epoch_start_time: Optional[int] = None, + epoch_end_time: Optional[int] = None, + step: Optional[int] = None + ): is_file = os.path.isfile(rrd_path) if is_file: if (epoch_start_time and not epoch_end_time) or (epoch_end_time and not epoch_start_time): @@ -25,7 +30,8 @@ async def get_rrd(rrd_path: str, epoch_start_time: Optional[int] = None, epoch_e rr = RRD_parser( rrd_file=rrd_path, start_time=epoch_start_time, - end_time=epoch_end_time + end_time=epoch_end_time, + step=step ) r = rr.compile_result() return r