basic script flow implemented
This commit is contained in:
parent
ae2ec619d3
commit
5d3a3fcdb1
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
# curl -d "stat=$METRIC&ezkey=$API_KEY&value=$VALUE" http://api.stathat.com/ez
|
|
@ -1,2 +1,5 @@
|
|||
#!/bin/sh
|
||||
echo $(ps aux | awk {'sum+=$3;print sum'} | tail -n 1)
|
||||
|
||||
collect () {
|
||||
echo $(ps aux | awk {'sum+=$3;print sum'} | tail -n 1)
|
||||
}
|
|
@ -1,2 +1,5 @@
|
|||
#!/bin/sh
|
||||
echo $(free | awk '/buffers\/cache/{print $4/($3+$4) * 100.0;}')
|
||||
|
||||
collect () {
|
||||
echo $(free | awk '/buffers\/cache/{print $4/($3+$4) * 100.0;}')
|
||||
}
|
|
@ -1,2 +1,5 @@
|
|||
#!/bin/sh
|
||||
echo $(free | awk '/Swap/{print $3/$2 * 100.0;}')
|
||||
|
||||
collect () {
|
||||
echo $(free | awk '/Swap/{print $3/$2 * 100.0;}')
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
report () {
|
||||
METRIC=$1
|
||||
VALUE=$2
|
||||
curl -d "stat=$METRIC&ezkey=$API_KEY&value=$VALUE" http://api.stathat.com/ez
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
report () {
|
||||
METRIC=$1
|
||||
VALUE=$2
|
||||
echo $METRIC: $VALUE
|
||||
}
|
|
@ -1,5 +1,43 @@
|
|||
#!/bin/sh
|
||||
|
||||
for script in $(find ./metrics -type f -name '*.sh'); do
|
||||
sh $script
|
||||
# config
|
||||
INTERVAL=2
|
||||
REPORTER=stdout
|
||||
|
||||
# init
|
||||
source utils.sh
|
||||
_METRICS=()
|
||||
|
||||
# load reporter
|
||||
source ./reporters/${REPORTER}.sh
|
||||
copy_function report _r_${REPORTER}_report
|
||||
unset -f report
|
||||
|
||||
# load metrics
|
||||
for file in $(find ./metrics -type f -name '*.sh'); do
|
||||
source $file
|
||||
filename=$(basename $file)
|
||||
metric=${filename%.*}
|
||||
copy_function collect _m_${metric}_collect
|
||||
_METRICS+=($metric)
|
||||
unset -f collect
|
||||
unset -f init
|
||||
done
|
||||
|
||||
# init metrics
|
||||
for metric in ${_METRICS[@]}; do
|
||||
[ "`type -t _m_${metric}_init`" != 'function' ] && continue
|
||||
echo init metric "$metric"
|
||||
_m_${metric}_init
|
||||
done
|
||||
|
||||
# collect metrics
|
||||
while true; do
|
||||
for metric in ${_METRICS[@]}; do
|
||||
[ "`type -t _m_${metric}_collect`" != 'function' ] && continue
|
||||
result=$(_m_${metric}_collect)
|
||||
_r_${REPORTER}_report $metric $result
|
||||
done
|
||||
|
||||
sleep $INTERVAL
|
||||
done
|
Loading…
Reference in New Issue