-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjrctl.subr
84 lines (69 loc) · 1.72 KB
/
jrctl.subr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
if [ ! "$_CBSD_JRCTL_SUBR" ]; then
_CBSD_JRCTL_SUBR=1
###
# return true if variable in RCTL_HUMANIZE list
rctl_humanize()
{
local _i _res=0
[ "${human}" = "0" ] && return 1
for _i in ${RCTL_HUMANIZE}; do
[ "${1}" = "${_i}" ] && return 0
done
return 1
}
# -m method: process|jail (req.)
# -h humanize values if set (opt, default = unset)
# -j jname (req. for jail method)
# -p pid (req. for process method)
# -s show field, e.g memoryuse, pcpu
# sample:
# get_rctl_values -m process -p 14896 -s memoryuse -h
get_rctl_values()
{
local _str
local _human=0
local _jname=
local _method=
local _pid=
local _human_arg=
local _show=
local _res=
local _vm_cpus
while getopts "hj:m:p:s:" opt; do
case "$opt" in
h) _human="1" ;;
j) _jname="${OPTARG}" ;;
m) _method="${OPTARG}" ;;
p) _pid="${OPTARG}" ;;
s) _show="${OPTARG}" ;;
esac
shift $(($OPTIND - 1))
done
[ "${_human}" = "1" ] && _human_arg="-h"
[ -z "${_jname}" ] && _jname="${jname}"
[ -z "${_jname}" ] && return 0
#_str="/usr/bin/rctl -a jail:${jname}:$_p"
#_out=$( eval $_str )
case "${_method}" in
process)
eval $( /usr/bin/rctl -u ${_human_arg} process:${_pid} 2>/dev/null )
;;
jail)
eval $( /usr/bin/rctl -a jail:${_jname}:$_p 2>/dev/null )
;;
esac
if [ "${emulator}" = "bhyve" ]; then
_vm_cpus=$( cbsdsql ${jailsysdir}/${_jname}/local.sqlite "SELECT vm_cpus FROM settings ORDER BY (created) DESC LIMIT 1" )
# take into account multi-core guest in pcpu value
# On multi-core guest we need to: pcpu / vm_cpus
[ ${_vm_cpus} -gt 1 ] && pcpu=$(( pcpu / _vm_cpus ))
fi
# todo: for each $rctl and validate
# if _show=1, unset unecessary variables
if [ -n "${_show}" ]; then
eval _res="\$${_show}"
echo "${_res}"
fi
}
###
fi