Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxmox ve plugin additions #785

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.gui.i18n import _
from cmk.gui.plugins.wato.utils import (
CheckParameterRulespecWithoutItem,
rulespec_registry,
RulespecGroupCheckParametersOperatingSystem,
)
from cmk.gui.valuespec import Alternative, Dictionary, FixedValue, Float, Integer, Tuple


def _parameter_valuespec_proxmox_ve_cpu_util():
return Dictionary(
required_keys=["util"],
elements=[
(
"util",
Alternative(
title=_("CPU Utilization levels"),
elements=[
Tuple(
title=_("Set conditions"),
elements=[
Float(
minvalue=0.0,
maxvalue=100.0,
unit="%",
default_value=90.0,
title=_("Warning at"),
),
Float(
minvalue=0.0,
maxvalue=100.0,
unit="%",
default_value=95.0,
title=_("Critical at"),
),
],
),
FixedValue(value=None, title=_("No Conditions"), totext=""),
],
),
),
("average", Integer(minvalue=1, unit="minutes", title=_("Average CPU Value over"))),
],
)


rulespec_registry.register(
CheckParameterRulespecWithoutItem(
check_group_name="proxmox_ve_cpu_util",
group=RulespecGroupCheckParametersOperatingSystem,
match_type="dict",
parameter_valuespec=_parameter_valuespec_proxmox_ve_cpu_util,
title=lambda: _("Proxmox VE CPU Utilization"),
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.gui.i18n import _
from cmk.gui.plugins.wato.utils import (
CheckParameterRulespecWithoutItem,
rulespec_registry,
RulespecGroupCheckParametersOperatingSystem,
)
from cmk.gui.valuespec import Alternative, Dictionary, FixedValue, Integer, Tuple


def _parameter_valuespec_proxmox_ve_disk_throughput():
return Dictionary(
required_keys=["read_levels", "write_levels"],
elements=[
(
"read_levels",
Alternative(
title=_("Read levels"),
elements=[
Tuple(
title=_("Set conditions"),
elements=[
Integer(unit="MiB/s", title=_("Warning at")),
Integer(unit="MiB/s", title=_("Critical at")),
],
),
FixedValue(value=None, title=_("No Conditions"), totext=""),
],
),
),
(
"write_levels",
Alternative(
title=_("Write levels"),
elements=[
Tuple(
title=_("Set conditions"),
elements=[
Integer(unit="MiB/s", title=_("Warning at")),
Integer(unit="MiB/s", title=_("Critical at")),
],
),
FixedValue(value=None, title=_("No Conditions"), totext=""),
],
),
),
],
)


rulespec_registry.register(
CheckParameterRulespecWithoutItem(
check_group_name="proxmox_ve_disk_throughput",
group=RulespecGroupCheckParametersOperatingSystem,
match_type="dict",
parameter_valuespec=_parameter_valuespec_proxmox_ve_disk_throughput,
title=lambda: _("Proxmox VE disk throughput"),
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.

from cmk.gui.i18n import _
from cmk.gui.plugins.wato.utils import (
CheckParameterRulespecWithoutItem,
rulespec_registry,
RulespecGroupCheckParametersOperatingSystem,
)
from cmk.gui.valuespec import Alternative, Dictionary, FixedValue, Integer, Tuple


def _parameter_valuespec_proxmox_ve_network_throughput():
return Dictionary(
required_keys=["in_levels", "out_levels"],
elements=[
(
"in_levels",
Alternative(
title=_("Inbound levels"),
elements=[
Tuple(
title=_("Set conditions"),
elements=[
Integer(unit="MiB/s", title=_("Warning at")),
Integer(unit="MiB/s", title=_("Critical at")),
],
),
FixedValue(value=None, title=_("No Conditions"), totext=""),
],
),
),
(
"out_levels",
Alternative(
title=_("Outbound levels"),
elements=[
Tuple(
title=_("Set conditions"),
elements=[
Integer(unit="MiB/s", title=_("Warning at")),
Integer(unit="MiB/s", title=_("Critical at")),
],
),
FixedValue(value=None, title=_("No Conditions"), totext=""),
],
),
),
],
)


rulespec_registry.register(
CheckParameterRulespecWithoutItem(
check_group_name="proxmox_ve_network_throughput",
group=RulespecGroupCheckParametersOperatingSystem,
match_type="dict",
parameter_valuespec=_parameter_valuespec_proxmox_ve_network_throughput,
title=lambda: _("Proxmox VE network throughput"),
)
)
81 changes: 81 additions & 0 deletions cmk/plugins/proxmox_ve/agent_based/proxmox_ve_cpu_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import json
from collections.abc import Mapping
from typing import Any

from cmk.agent_based.v1 import check_levels as check_levels_v1
from cmk.agent_based.v2 import (
AgentSection,
CheckPlugin,
CheckResult,
DiscoveryResult,
get_value_store,
Result,
Service,
State,
StringTable,
)
from cmk.plugins.lib.cpu_util import check_cpu_util

Section = Mapping[str, float]


def parse_proxmox_ve_cpu_util(string_table: StringTable) -> Section:
return {key: float(value) for key, value in json.loads(string_table[0][0]).items()}


def discover_single(section: Section) -> DiscoveryResult:
yield Service()


def check_proxmox_ve_cpu_util(params: Mapping[str, Any], section: Section) -> CheckResult:
max_cpu = int(section.get("max_cpu", 0))
cpu_util = float(section.get("cpu", 0))
uptime = int(section.get("uptime", 0))
try:
value_store = get_value_store()

yield from check_cpu_util(
util=cpu_util * 100,
params=params,
value_store=value_store,
this_time=uptime,
)

yield Result(state=State.OK, summary=f"CPU cores assigned: {max_cpu}")

if params["util"] is not None:
(warn, crit) = params["util"]
cores_levels = (warn * max_cpu / 100, crit * max_cpu / 100)
else:
cores_levels = None

yield from check_levels_v1(
value=round(max_cpu * cpu_util, 2),
levels_upper=cores_levels,
metric_name="cpu_core_usage",
label="CPU Core usage",
boundaries=(0.0, max_cpu),
)
except AssertionError:
yield Result(state=State.UNKNOWN, summary="error checking datastore status")


agent_section_proxmox_ve_cpu_util = AgentSection(
name="proxmox_ve_cpu_util",
parse_function=parse_proxmox_ve_cpu_util,
)

check_plugin_proxmox_ve_cpu_util = CheckPlugin(
name="proxmox_ve_cpu_util",
service_name="Proxmox VE CPU Utilization",
discovery_function=discover_single,
check_function=check_proxmox_ve_cpu_util,
check_ruleset_name="proxmox_ve_cpu_util",
check_default_parameters={
"util": (90.0, 95.0),
},
)
103 changes: 103 additions & 0 deletions cmk/plugins/proxmox_ve/agent_based/proxmox_ve_disk_throughput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env python3
# Copyright (C) 2019 Checkmk GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
import json
from collections.abc import Mapping
from typing import Any

from cmk.agent_based.v1 import check_levels as check_levels_v1
from cmk.agent_based.v2 import (
AgentSection,
CheckPlugin,
CheckResult,
DiscoveryResult,
get_value_store,
render,
Result,
Service,
State,
StringTable,
)

Section = Mapping[str, int]


def parse_proxmox_ve_disk_throughput(string_table: StringTable) -> Section:
return {key: int(value) for key, value in json.loads(string_table[0][0]).items()}


def discover_single(section: Section) -> DiscoveryResult:
yield Service()


def check_proxmox_ve_disk_throughput(params: Mapping[str, Any], section: Section) -> CheckResult:
disk_read = section.get("disk_read", 0)
disk_write = section.get("disk_write", 0)
uptime = section.get("uptime", 0)

try:
value_store = get_value_store()

last_read = value_store.get("last_read", 0)
last_write = value_store.get("last_write", 0)
last_uptime = value_store.get("last_uptime", 0)

if uptime == 0:
read_throughput: float = disk_read
write_throughput: float = disk_write
elif uptime > last_uptime:
read_throughput = (disk_read - last_read) / (uptime - last_uptime)
write_throughput = (disk_write - last_write) / (uptime - last_uptime)
else:
read_throughput = disk_read / uptime
write_throughput = disk_write / uptime

value_store["last_read"] = disk_read
value_store["last_write"] = disk_write
value_store["last_uptime"] = uptime

read_levels = params["read_levels"]
write_levels = params["write_levels"]
if read_levels is not None:
read_levels = (read_levels[0] * 1024**2, read_levels[1] * 1024**2)
if write_levels is not None:
write_levels = (write_levels[0] * 1024**2, write_levels[1] * 1024**2)

yield from check_levels_v1(
value=read_throughput,
levels_upper=read_levels,
metric_name="disk_read_throughput",
render_func=render.iobandwidth,
label="Read",
boundaries=(0, None),
)

yield from check_levels_v1(
value=write_throughput,
levels_upper=write_levels,
metric_name="disk_write_throughput",
render_func=render.iobandwidth,
label="Write",
boundaries=(0, None),
)
except AssertionError:
yield Result(state=State.UNKNOWN, summary="error checking datastore status")


agent_section_proxmox_ve_disk_throughput = AgentSection(
name="proxmox_ve_disk_throughput",
parse_function=parse_proxmox_ve_disk_throughput,
)

check_plugin_proxmox_ve_disk_throughput = CheckPlugin(
name="proxmox_ve_disk_throughput",
service_name="Proxmox VE Disk Throughput",
discovery_function=discover_single,
check_function=check_proxmox_ve_disk_throughput,
check_ruleset_name="proxmox_ve_disk_throughput",
check_default_parameters={
"read_levels": None,
"write_levels": None,
},
)
Loading