PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB` #!/bin/bash # 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. export MK_VARDIR=/var/lib/check_mk_agent help() { echo "Usage: mk-job IDENT PROGRAM [ARGS...]" echo "" echo "Execute PROGRAM as subprocess while measuring performance information" echo "about the running process and writing it to an output file. This file" echo "can be monitored using Check_MK. The Check_MK Agent will forward the" echo "information of all job files to the monitoring server." echo "" echo "This file is being distributed with the Check_MK Agent." } if [ $# -lt 2 ]; then help >&2 exit 1 fi MYSELF=$(id -nu) OUTPUT_PATH=$MK_VARDIR/job/$MYSELF IDENT=$1 RUNNING_FILE="$OUTPUT_PATH/$IDENT.$$running" shift if [ ! -d "$OUTPUT_PATH" ]; then if [ "$MYSELF" = root ]; then mkdir -p "$OUTPUT_PATH" else echo "ERROR: Missing output directory $OUTPUT_PATH for non-root user '$MYSELF'." >&2 exit 1 fi fi if ! type "$1" >/dev/null 2>&1; then echo -e "ERROR: Cannot run $1. Command not found.\n" >&2 help >&2 exit 1 fi cleanup() { # shellcheck disable=SC2317 # shellcheck doesn't understand trap rm "${RUNNING_FILE}" 2>/dev/null } date +"start_time %s" >"$RUNNING_FILE" 2>/dev/null if [ ! -w "$RUNNING_FILE" ]; then # Looks like we are lacking the permissions to create this file.. # In this scenario no mk-job status file is created. We simply execute the command exec "$@" fi trap "cleanup" 0 /usr/bin/time -o "$RUNNING_FILE" --append \ -f "exit_code %x\nreal_time %E\nuser_time %U\nsystem_time %S\nreads %I\nwrites %O\nmax_res_kbytes %M\navg_mem_kbytes %K\ninvol_context_switches %c\nvol_context_switches %w" "$@" RC=$? mv "$RUNNING_FILE" "$OUTPUT_PATH/$IDENT" exit $RC