Exemplo n.º 1
0
def test_calculate_data_for_prediction(cfg_setup, utcdate, timezone, params):

    period_info = prediction.prediction_periods[params['period']]
    with on_time(utcdate, timezone):
        now = int(time.time())
        groupby = period_info["groupby"]
        assert callable(groupby)
        timegroup = groupby(now)[0]

        time_windows = prediction.time_slices(now, int(params["horizon"] * 86400), period_info,
                                              timegroup)

    hostname, service_description, dsname = 'test-prediction', "CPU load", 'load15'
    rrd_datacolumn = cmk.utils.prediction.rrd_datacolum(hostname, service_description, dsname,
                                                        "MAX")
    data_for_pred = prediction.calculate_data_for_prediction(time_windows, rrd_datacolumn)

    path = "%s/tests-py3/integration/cmk/base/test-files/%s/%s" % (repo_path(), timezone, timegroup)
    reference = cmk.utils.prediction.retrieve_data_for_prediction(path, timegroup)
    data_points = data_for_pred.pop('points')
    assert reference is not None
    ref_points = reference.pop('points')
    for cal, ref in zip(data_points, ref_points):
        assert cal == pytest.approx(ref, rel=1e-12, abs=1e-12)
    assert data_for_pred == reference
Exemplo n.º 2
0
def test_retieve_grouped_data_from_rrd(cfg_setup, utcdate, timezone, params, reference):
    "This mostly verifies the up-sampling"

    period_info = prediction.prediction_periods[params['period']]
    with on_time(utcdate, timezone):
        now = time.time()
        timegroup = period_info["groupby"](now)[0]
        time_windows = prediction.time_slices(now, int(params["horizon"] * 86400), period_info,
                                              timegroup)

    hostname, service_description, dsname = 'test-prediction', "CPU load", 'load15'
    rrd_datacolumn = cmk.utils.prediction.rrd_datacolum(hostname, service_description, dsname,
                                                        "MAX")
    result = prediction.retrieve_grouped_data_from_rrd(rrd_datacolumn, time_windows)

    assert result == reference
Exemplo n.º 3
0
def test_calculate_data_for_prediction(cfg_setup, utcdate, timezone, params):

    period_info = prediction.prediction_periods[params['period']]
    with on_time(utcdate, timezone):
        now = time.time()
        timegroup = period_info["groupby"](now)[0]

        time_windows = prediction.time_slices(now, int(params["horizon"] * 86400), period_info,
                                              timegroup)

    hostname, service_description, dsname = 'test-prediction', "CPU load", 'load15'
    rrd_datacolumn = cmk.utils.prediction.rrd_datacolum(hostname, service_description, dsname,
                                                        "MAX")
    data_for_pred = prediction.calculate_data_for_prediction(time_windows, rrd_datacolumn)

    path = "%s/tests/integration/cmk_base/test-files/%s/%s" % (repo_path(), timezone, timegroup)
    reference = cmk.utils.prediction.retrieve_data_for_prediction(path, timegroup)
    assert data_for_pred == reference