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

Add sysctl_mem option for FreeBSD #723

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 20 additions & 0 deletions agents/check_mk_agent.freebsd
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,24 @@ section_fileinfo() {
' -- "${MK_CONFDIR}"
}

section_sysctlmem() {
# Output FreeBSD memory info from sysctl
echo '<<<sysctl_mem>>>'
_page_size=$( sysctl -n vm.stats.vm.v_page_size )
echo "mem.cache $(( _page_size * $( sysctl -n vm.stats.vm.v_cache_count ) ))"
echo "mem.free $(( _page_size * $( sysctl -n vm.stats.vm.v_free_count ) ))"
echo "mem.total $( sysctl -n vm.kmem_size )"
echo "mem.used $(( _page_size * ( $( sysctl -n vm.stats.vm.v_active_count ) + $( sysctl -n vm.stats.vm.v_wire_count ) ) ))"
_swap_total=$( sysctl -n vm.swap_total )
_swap_used=$(( $( swapinfo | tail -1 | awk '{print $3}' ) * 1024 ))
echo "swap.free $(( _swap_total - _swap_used ))"
echo "swap.total ${_swap_total}"
echo "swap.used ${_swap_used}"
unset -v _page_size
unset -v _swap_total
unset -v _swap_used
}

#
# END COMMON AGENT CODE
#
Expand All @@ -376,6 +394,8 @@ run_purely_synchronous_sections() {

section_checkmk_agent_plugins

section_sysctlmem

osver="$(uname -r)"
is_jailed="$(sysctl -n security.jail.jailed)"

Expand Down
58 changes: 58 additions & 0 deletions cmk/plugins/collection/agent_based/mem_used_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,61 @@ def parse_openbsd_mem(string_table: StringTable) -> SectionMemUsed | None:
parsed_section_name="mem_used",
parse_function=parse_openbsd_mem,
)


def parse_freebsd_mem(string_table: StringTable) -> SectionMemUsed | None:
"""
>>> import pprint
>>> pprint.pprint(parse_statgrab_mem([
... ['mem.cache', '0'],
... ['mem.free', '677666816'],
... ['mem.total', '4294967296'],
... ['mem.used', '3617300480'],
... ['swap.free', '4976402432'],
... ['swap.total', '8589934592'],
... ['swap.used', '3613532160']
... ]))
{'Cached': 0,
'MemFree': 677666816,
'MemUsed': 3617300480,
'MemTotal': 4294967296,
'SwapFree': 4976402432,
'SwapUsed': 3613532160,
'SwapTotal': 8589934592}

"""
parsed: dict[str, int] = {}
for var, value in string_table:
try:
parsed.setdefault(var, int(value))
except ValueError:
pass

try:
totalmem = parsed["mem.total"]
memused = parsed["mem.used"]
memfree = parsed["mem.free"]
totalswap = parsed["swap.total"]
swapused = parsed["swap.used"]
swapfree = parsed["swap.free"]
except KeyError:
return None

section: SectionMemUsed = {
"MemTotal": totalmem,
"MemUsed": memused,
"MemFree": memfree,
"SwapTotal": totalswap,
"SwapUsed": swapused
"SwapFree": swapfree,
}
if "mem.cache" in parsed:
section["Cached"] = parsed["mem.cache"]


agent_section_freebsd_mem = AgentSection(
name="sysctl_mem",
parsed_section_name="mem_used",
parse_function=parse_freebsd_mem,
supersedes=["statgrab_mem","ucd_mem"],
)
Loading