metrics.sh/metrics.sh

128 lines
2.3 KiB
Bash
Raw Normal View History

2015-02-19 14:15:38 -05:00
#!/bin/sh
2015-02-21 12:18:27 -05:00
# config
2015-03-14 09:49:41 -04:00
INTERVAL=2
REPORTER=stdout
METRICS=cpu,disk_io,disk_usage,heartbeat,memory,network_io,swap
2015-03-19 16:14:14 -04:00
CONFIG_FILE=
2015-03-08 12:51:15 -04:00
2015-03-12 16:31:45 -04:00
# env
2015-03-14 08:32:26 -04:00
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
2015-03-08 12:51:15 -04:00
usage () {
echo " Usage: $0 [-d] [-h] [-v] [-m metrics] [-r reporter] [-i interval]"
}
help () {
echo
usage
echo
echo " Options: "
echo
2015-03-19 16:14:14 -04:00
echo " -c, --config <file> path to config file"
2015-03-17 15:22:26 -04:00
echo " -m, --metrics <metrics> comma-separated list of metrics to collect"
echo " -r, --reporter <reporter> use specified reporter (default: stdout)"
echo " -i, --interval <seconds> collect metrics every n seconds (default: 2)"
echo " -v, --verbose enable verbose mode"
echo " -d, --docs show documentation"
echo " -h, --help show this text"
echo
}
2015-03-15 16:14:44 -04:00
# handle opts
opt_docs=false
opt_verbose=false
while [ $# -gt 0 ]; do
case $1 in
2015-03-19 16:14:14 -04:00
-c|--config)
shift
CONFIG_FILE=$1
;;
-m|--metrics)
shift
METRICS=$1
;;
-r|--reporter)
shift
REPORTER=$1
;;
-i|--interval)
shift
INTERVAL=$1
;;
-v|-verbose)
opt_verbose=true
;;
-d|--docs)
opt_docs=true
;;
-h|--help)
help
exit
2015-03-14 09:59:17 -04:00
;;
*)
usage
exit 1
;;
esac
shift
done
# run
. ./lib/main.sh
if [ $opt_verbose = "true" ]; then
verbose_on
verbose "Started in verbose mode"
fi
verbose "OS detected: $OS_TYPE"
main_load
verbose "Available metrics: $__AVAILABLE_METRICS"
verbose "Available reporters: $__AVAILABLE_REPORTERS"
2015-03-15 16:14:44 -04:00
if [ $opt_docs = true ]; then
main_docs
exit
fi
2015-03-19 16:14:14 -04:00
if [ -n "$CONFIG_FILE" ]; then
verbose "Loading configuration file: $CONFIG_FILE"
parse_config $CONFIG_FILE
if [ $? -ne 0 ]; then
exit 1
fi
if is_function global_config; then
global_config
fi
configured_reporters=$(get_configured_reporters)
if [ -n "$configured_reporters" ]; then
REPORTER=$configured_reporters
fi
configured_metrics=$(get_configured_metrics)
if [ -n "$configured_metrics" ]; then
METRICS=$configured_metrics
fi
fi
main_init "$METRICS" "$REPORTER"
verbose "Using metrics: $__METRICS"
verbose "Using reporter: $__REPORTER"
verbose "Collecting metrics every $INTERVAL second(s)"
main_collect