Fix OOM reporting

This commit is contained in:
Michael Vines
2018-09-08 17:46:43 -07:00
committed by Grimes
parent 5afcdcbbe6
commit 7029e4395c
4 changed files with 39 additions and 20 deletions

View File

@ -3,19 +3,21 @@
# Reports Linux OOM Killer activity
#
here=$(dirname "$0")
# shellcheck source=scripts/oom-score-adj.sh
source "$here"/oom-score-adj.sh
cd "$(dirname "$0")"
if [[ $(uname) != Linux ]]; then
exit 0
fi
# shellcheck source=scripts/oom-score-adj.sh
source oom-score-adj.sh
# shellcheck source=scripts/configure-metrics.sh
source configure-metrics.sh
[[ $(uname) = Linux ]] || exit 0
syslog=/var/log/syslog
if [[ ! -r $syslog ]]; then
[[ -r $syslog ]] || {
echo Unable to read $syslog
exit 0
fi
exit 1
}
# Adjust OOM score to reduce the chance that this script will be killed
# during an Out of Memory event since the purpose of this script is to
@ -24,9 +26,10 @@ oom_score_adj "self" -500
while read -r victim; do
echo "Out of memory event detected, $victim killed"
"$here"/metrics-write-datapoint.sh "oom-killer,victim=$victim killed=1"
./metrics-write-datapoint.sh "oom-killer,victim=$victim,hostname=$HOSTNAME killed=1"
done < <( \
tail --follow=name --retry -n0 $syslog \
| sed --unbuffered -n 's/^.* Out of memory: Kill process [1-9][0-9]* (\([^)]*\)) .*/\1/p' \
)
exit 1

22
scripts/snap-config-to-env.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
#
# Snap daemons have no access to the environment so |snap set solana ...| is
# used to set runtime configuration.
#
# This script exports the snap runtime configuration options back as
# environment variables before invoking the specified program
#
if [[ -d $SNAP ]]; then # Running inside a Linux Snap?
RUST_LOG="$(snapctl get rust-log)"
SOLANA_CUDA="$(snapctl get enable-cuda)"
SOLANA_DEFAULT_METRICS_RATE="$(snapctl get default-metrics-rate)"
SOLANA_METRICS_CONFIG="$(snapctl get metrics-config)"
export RUST_LOG
export SOLANA_CUDA
export SOLANA_DEFAULT_METRICS_RATE
export SOLANA_METRICS_CONFIG
fi
exec "$@"