mirror of
https://github.com/pstadler/metrics.sh.git
synced 2025-07-08 16:42:15 -04:00
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
|
#!/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
|
#!/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
|
#!/bin/sh
|
||||||
echo $(free | awk '/Swap/{print $3/$2 * 100.0;}')
|
|
||||||
|
collect () {
|
||||||
|
echo $(free | awk '/Swap/{print $3/$2 * 100.0;}')
|
||||||
|
}
|
7
reporters/stathat.sh
Normal file
7
reporters/stathat.sh
Normal file
@ -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
|
||||||
|
}
|
7
reporters/stdout.sh
Normal file
7
reporters/stdout.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
report () {
|
||||||
|
METRIC=$1
|
||||||
|
VALUE=$2
|
||||||
|
echo $METRIC: $VALUE
|
||||||
|
}
|
@ -1,5 +1,43 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
for script in $(find ./metrics -type f -name '*.sh'); do
|
# config
|
||||||
sh $script
|
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
|
done
|
Loading…
x
Reference in New Issue
Block a user