Esempio n. 1
0
def test_size_trend_growing(args: ArgsDict) -> None:
    with suppress(GetRateError):
        list(size_trend(**args))

    args["levels"] = {
        "trend_range": 1,
        "trend_perfdata": True,
        "trend_bytes": (150 * 1024**2, 250 * 1024**2),
        "trend_perc": (5.0, 15.0),
    }
    args.update({"used_mb": 200, "timestamp": 1801.0})
    assert list(size_trend(**args)) == [
        Metric(name="growth", value=4800.0),
        Result(
            state=State.WARN,
            summary=
            "trend per 1 hour 0 minutes: +200 MiB (warn/crit at +150 MiB/+250 MiB)",
        ),
        Result(
            state=State.WARN,
            summary=
            "trend per 1 hour 0 minutes: +10.00% (warn/crit at +5.00%/+15.00%)",
        ),
        Metric("trend",
               4800.0,
               levels=(100.0, 250.0),
               boundaries=(0.0, 2000.0)),
        Result(
            state=State.OK,
            summary="Time left until resource_name full: 9 hours 0 minutes"),
    ]
Esempio n. 2
0
def test_size_trend_shrinking_warn(args: ArgsDict) -> None:
    args["used_mb"] = 1000
    with suppress(GetRateError):
        list(size_trend(**args))

    args["levels"] = {
        "trend_range": 1,
        "trend_perfdata": True,
        "trend_shrinking_bytes": (100 * 1024**2, 200 * 1024**2),
        "trend_shrinking_perc": (5.0, 10.0),
    }
    args.update({
        "timestamp": 1801.0,
        "used_mb": 900,
    })
    assert list(size_trend(**args)) == [
        Metric(name="growth", value=-4800.0),
        Result(
            state=State.WARN,
            summary=
            "trend per 1 hour 0 minutes: -200 MiB (warn/crit below -100 MiB/-200 MiB)",
        ),
        Result(
            state=State.WARN,
            summary=
            "trend per 1 hour 0 minutes: -10.00% (warn/crit below -5.00%/-10.00%)",
        ),
        Metric("trend", -4800.0, boundaries=(0.0, 2000.0)),
    ]
Esempio n. 3
0
def test_size_trend(args: ArgsDict) -> None:
    # size_trend returns generator, but we need to evaluate it
    # so the valuestore is written properly
    with suppress(GetRateError):
        list(size_trend(**args))

    # New measurement half an hour later with 100MB more
    args.update({"used_mb": 200, "timestamp": 1.0 + 1800})
    # (100 (MB) / 1800) * 3600 * 24
    assert list(size_trend(**args)) == [
        Metric(name="growth", value=4800.0),
        Result(state=State.OK, summary="trend per 1 hour 0 minutes: +200 MiB"),
        Result(state=State.OK, summary="trend per 1 hour 0 minutes: +10.00%"),
        Metric("trend", 4800.0, boundaries=(0.0, 2000.0)),
        Result(state=State.OK, summary="Time left until resource_name full: 9 hours 0 minutes"),
    ]
Esempio n. 4
0
def _call_size_trend_with(args: ArgsDict) -> list[Union[IgnoreResults, Metric, Result]]:
    return list(
        size_trend(
            value_store=args["value_store"],
            value_store_key=args["value_store_key"],
            resource=args["resource"],
            levels=args["levels"],
            used_mb=args["used_mb"],
            size_mb=args["size_mb"],
            timestamp=args["timestamp"],
        )
    )
Esempio n. 5
0
def check_cisco_mem_sub(
    value_store: ValueStore,
    item: str,
    params: Parameters,
    mem_used: int,
    mem_total: int,
) -> CheckGenerator:
    if not mem_total:
        yield Result(
            state=state.UNKNOWN,
            summary=
            "Cannot calculate memory usage: Device reports total memory 0")
        return

    warn, crit = params.get("levels", (None, None))
    mode = get_levels_mode_from_value(warn)
    mega = 1024 * 1024
    if isinstance(warn, int):
        warn *= mega  # convert from megabyte to byte
        crit *= mega
    if warn is not None:
        warn = abs(warn)
        crit = abs(crit)

    yield from check_element(
        "Usage",
        mem_used,
        mem_total,
        (mode, (warn, crit)),
        create_percent_metric=True,
    )

    if params.get("trend_range"):
        with suppress(GetRateError):
            yield from size_trend(
                value_store=value_store,
                check="cisco_mem",
                item=item,
                resource="memory",
                levels=params,
                used_mb=mem_used / mega,
                size_mb=mem_total / mega,
                timestamp=None,
            )