add --update option. minor fixes
This commit is contained in:
parent
b508c27b64
commit
c4246b9ab0
|
@ -6,8 +6,8 @@ metrics.sh is a lightweight metrics collection and fowarding utility implemented
|
|||
|
||||
```
|
||||
$ ./metrics.sh --help
|
||||
|
||||
Usage: ./metrics.sh [-d] [-h] [-v] [-c] [-m] [-r] [-i]
|
||||
|
||||
Usage: ./metrics.sh [-d] [-h] [-v] [-c] [-m] [-r] [-i] [-C] [-u]
|
||||
|
||||
Options:
|
||||
|
||||
|
@ -16,6 +16,8 @@ $ ./metrics.sh --help
|
|||
-r, --reporter <reporter> use specified reporter (default: stdout)
|
||||
-i, --interval <seconds> collect metrics every n seconds (default: 2)
|
||||
-v, --verbose enable verbose mode
|
||||
-C, --print-config print output to be used in a config file
|
||||
-u, --update pull the latest version (requires git)
|
||||
-d, --docs show documentation
|
||||
-h, --help show this text
|
||||
```
|
||||
|
@ -28,7 +30,7 @@ $ git clone git@github.com:pstadler/metrics.sh.git
|
|||
|
||||
### Requirements
|
||||
|
||||
metrics.sh has been tested on Ubuntu 14.04 and Mac OS X but is supposed to run on most Unix-like operating systems. Some of the provided metrics require [procfs](http://en.wikipedia.org/wiki/Procfs) to be available when running on *nix. POSIX compliancy means that metrics.sh works with minimalistic command interpreters such as [dash](http://manpages.ubuntu.com/manpages/trusty/en/man1/dash.1.html). Built-in metrics do **not** require root privileges.
|
||||
metrics.sh has been tested on Ubuntu 14.04 and Mac OS X but is supposed to run on most Unix-like operating systems. Some of the provided metrics require [procfs](http://en.wikipedia.org/wiki/Procfs) to be available when running on *nix. POSIX compliancy means that metrics.sh works with minimalistic command interpreters such as [dash](http://manpages.ubuntu.com/manpages/trusty/en/man1/dash.1.html). Built-in metrics do __not__ require root privileges.
|
||||
|
||||
## Metrics
|
||||
|
||||
|
|
|
@ -3,4 +3,8 @@
|
|||
# this is bad, but `declare -f -F` is not portable
|
||||
is_function () {
|
||||
type $1 2> /dev/null | grep -q 'function$'
|
||||
}
|
||||
}
|
||||
|
||||
command_exists () {
|
||||
type $1 > /dev/null 2>&1
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ unique_id () {
|
|||
|
||||
print_prefixed () {
|
||||
printf "$2" | sed -e "s/^/$1/g"
|
||||
}
|
||||
}
|
||||
|
|
32
metrics.sh
32
metrics.sh
|
@ -6,7 +6,7 @@ LANG=en_US.UTF-8
|
|||
LANGUAGE=en_US.UTF-8
|
||||
|
||||
usage () {
|
||||
echo " Usage: $0 [-d] [-h] [-v] [-c] [-m] [-r] [-i] [-C]"
|
||||
echo " Usage: $0 [-d] [-h] [-v] [-c] [-m] [-r] [-i] [-C] [-u]"
|
||||
}
|
||||
|
||||
help () {
|
||||
|
@ -20,8 +20,9 @@ help () {
|
|||
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 " -C, --print-config print output to be used in a config file"
|
||||
echo " -u, --update pull the latest version (requires git)"
|
||||
echo " -d, --docs show documentation"
|
||||
echo " -h, --help show this text"
|
||||
echo
|
||||
}
|
||||
|
@ -31,9 +32,10 @@ opt_config_file=
|
|||
opt_metrics=
|
||||
opt_reporter=
|
||||
opt_interval=
|
||||
opt_docs=false
|
||||
opt_verbose=false
|
||||
opt_print_config=false
|
||||
opt_do_update=false
|
||||
opt_docs=false
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
|
@ -57,18 +59,22 @@ while [ $# -gt 0 ]; do
|
|||
opt_interval=$1
|
||||
;;
|
||||
|
||||
-v|-verbose)
|
||||
-v|--verbose)
|
||||
opt_verbose=true
|
||||
;;
|
||||
|
||||
-d|--docs)
|
||||
opt_docs=true
|
||||
;;
|
||||
|
||||
-C|--print-config)
|
||||
opt_print_config=true
|
||||
;;
|
||||
|
||||
-u|--update)
|
||||
opt_do_update=true
|
||||
;;
|
||||
|
||||
-d|--docs)
|
||||
opt_docs=true
|
||||
;;
|
||||
|
||||
-h|--help)
|
||||
help
|
||||
exit
|
||||
|
@ -86,6 +92,16 @@ done
|
|||
# run
|
||||
. ./lib/main.sh
|
||||
|
||||
if [ $opt_do_update = true ]; then
|
||||
if ! command_exists git; then
|
||||
echo "Error: --update requires `git` to be in the PATH"
|
||||
exit 1
|
||||
fi
|
||||
echo "Fetching latest version..."
|
||||
git pull https://github.com/pstadler/metrics.sh.git master
|
||||
exit $?
|
||||
fi
|
||||
|
||||
if [ $opt_verbose = true ]; then
|
||||
verbose_on
|
||||
verbose "Started in verbose mode"
|
||||
|
|
Loading…
Reference in New Issue