aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <Andy Carlson>2018-01-09 02:34:54 +0000
committerroot <Andy Carlson>2018-01-09 02:34:54 +0000
commit1acf1df95cbb8e2666422ac300f73bd4dfaeccb8 (patch)
treebf50cc375529357c37297fde2a31d73f4d127228
parentd541502f51b5460880e9dede7fd451b503cd1449 (diff)
updated for custom stats
-rw-r--r--Makefile63
-rw-r--r--quickstat.m4 (renamed from quickstat.sh)33
-rw-r--r--stats/cpu1
-rw-r--r--stats/cpu.comments1
-rw-r--r--stats/disk1
-rw-r--r--stats/disk.comments1
-rw-r--r--stats/mem1
-rw-r--r--stats/mem.comments1
-rw-r--r--stats/partition1
-rw-r--r--stats/partition.comments1
-rw-r--r--stats/swap1
-rw-r--r--stats/swap.comments1
12 files changed, 58 insertions, 48 deletions
diff --git a/Makefile b/Makefile
index af375f9..4f1bb3a 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,8 @@ define getsetting
$$(grep "^$(2)[ \t]*" $(1) | sed 's/^$(2)[ \t]*//g')
endef
+installpath := $(call getsetting,tmp/settings.txt,PATH)
+
all:
@echo "Directions:"
@echo " 1) make setup"
@@ -16,42 +18,65 @@ all:
@echo ""
@echo "Use 'make clean' to clear build environment"
-install: tmp/xinetd.ok build/quickstat build/quickstat.sh
- cp build/quickstat /etc/xinetd.d
- cp build/quickstat.sh /usr/sbin
- echo -e "#Adding quickstat service" >> /etc/services
- echo -e "quickstat\t$(call getsetting,tmp/port.txt,PORT)/tcp" >> /etc/services
- echo -e "quickstat\t$(call getsetting,tmp/port.txt,PORT)/udp" >> /etc/services
+install: etc-services
+ mkdir -p $(call getsetting,tmp/settings.txt,PATH)
+ mkdir -p $(call getsetting,tmp/settings.txt,PATH)/bin
+ mkdir -p $(call getsetting,tmp/settings.txt,PATH)/etc
+ mkdir -p $(call getsetting,tmp/settings.txt,PATH)/lib
+ find build/ -type f | while read line; do cp $$line $(call getsetting,tmp/settings.txt,PATH)$$(echo $$line | sed 's/^build//g') ; done
+ (rm /etc/xinetd.d/quickstat && ln -s $(call getsetting,tmp/settings.txt,PATH)/etc/quickstat /etc/xinetd.d/quickstat) || ln -s $(call getsetting,tmp/settings.txt,PATH)/etc/quickstat /etc/xinetd.d/quickstat
+
+etc-services:
+ [[ -z "$$(grep "$(call getsetting,tmp/settings.txt,PORT)/tcp" /etc/services)" ]] && echo -e "quickstat\t$(call getsetting,tmp/settings.txt,PORT)/tcp\t# Added by quickstat Makefile" >> /etc/services
+ [[ -z "$$(grep "$(call getsetting,tmp/settings.txt,PORT)/udp" /etc/services)" ]] && echo -e "quickstat\t$(call getsetting,tmp/settings.txt,PORT)/tcp\t# Added by quickstat Makefile" >> /etc/services
-updatebin: tmp/xinetd.ok build/quickstat.sh
- cp build/quickstat.sh /usr/sbin
+updatebin: tmp/newbuild.ok
+ find ./stats -type f | grep -v '.comments' | awk 'function readfile(file) { save_rs = RS; RS = "^$$"; getline tmp < file; close(file); RS = save_rs; return tmp; } { contents = readfile($$0); comments = readfile($$0 ".comments"); printf("%s\ngen%s() {\n%s}\n\n",comments,gensub(/^.*stats\//,"","g",$$0),contents); }' > build/lib/monitors.inc.sh
+ rm tmp/newbuild.ok
+
+tmp/newbuild.ok: tmp
+ rm build/lib/monitors.inc.sh
+ touch tmp/newbuild.ok
tmp/xinetd.ok: tmp
@[[ -n "$$(which xinetd)" ]] && touch tmp/xinetd.ok
-setup: build/quickstat build/quickstat.sh
+setup: build/etc/quickstat build/bin/quickstat.sh build/lib/monitors.inc.sh
clean:
rm -rf tmp
rm -rf build
-build/quickstat: build tmp/port.ok tmp/m4.ok
- m4 -DPORT=$(call getsetting,tmp/port.txt,PORT) service.m4 > build/quickstat
+build/etc/quickstat: build/etc tmp/port.ok tmp/m4.ok
+ [[ ! -f build/etc/quickstat ]] && m4 -DPORT=$(call getsetting,tmp/settings.txt,PORT) service.m4 > build/etc/quickstat
+
+build/lib/monitors.inc.sh: build/lib
+ [[ ! -f build/lib/monitors.inc.sh ]] && find ./stats -type f | grep -v '.comments' | awk 'function readfile(file) { save_rs = RS; RS = "^$$"; getline tmp < file; close(file); RS = save_rs; return tmp; } { contents = readfile($$0); comments = readfile($$0 ".comments"); printf("%s\ngen%s() {\n%s}\n\n",comments,gensub(/^.*stats\//,"","g",$$0),contents); }' > build/lib/monitors.inc.sh
+
+build/lib: build
+ mkdir -p build/lib
+
+build/bin: build
+ mkdir -p build/bin
+
+build/etc: build
+ mkdir -p build/etc
tmp/m4.ok: tmp
@[[ -n "$$(which m4)" ]] && touch tmp/m4.ok
-tmp/port.txt: tmp
- $(call newsetting,Enter port number,PORT,8080,tmp/port.txt)
+tmp/settings.txt: tmp
+ $(call newsetting,Enter install path,PATH,/opt/quickstat,tmp/settings.txt)
+ $(call newsetting,Enter port number,PORT,8080,tmp/settings.txt)
-tmp/port.ok: tmp/port.txt
- @[[ -z "$$(grep "$(call getsetting,tmp/port.txt,PORT)" /etc/services)" ]] && touch tmp/port.ok
+tmp/port.ok: tmp/settings.txt
+ @[[ -z "$$(grep "$(call getsetting,tmp/settings.txt,PORT)" /etc/services)" ]] && touch tmp/port.ok
-build/quickstat.sh: build
- cp quickstat.sh build
+build/bin/quickstat.sh: build/bin
+ [[ ! -f build/bin/quickstat.sh ]] && (echo "define(\`MONLIST',\`" ; find ./stats -type f | grep -v '.comments$$' | sed 's/^\.\/stats\///g;s/^/gen/g;s/$$/\nprintf ","/g' | sed '$$ d' ; echo "')" ; echo -n "define(\`RESLIST',\`" ; find ./stats | sed 's/^\.//g' | tr '\n' ' ' ; echo "')" ; cat quickstat.m4) | m4 -DROOTDIR=/opt | grep -v '^[ \t]*$$' > build/bin/quickstat.sh
build:
- mkdir build
+ [[ ! -d build ]] && mkdir build
tmp:
- mkdir tmp
+ [[ ! -d tmp ]] && mkdir tmp
diff --git a/quickstat.sh b/quickstat.m4
index b2691b5..dfdd1df 100644
--- a/quickstat.sh
+++ b/quickstat.m4
@@ -1,39 +1,14 @@
#!/bin/bash
+APPROOT="ROOTDIR"
-gencpu() {
- (iostat -c ; echo -n "Load: " ; cat /proc/loadavg ) | tail -n 3 | awk '/^[ \t]*[0-9]/ { print gensub(/^[ \t]*/,"CPU%: ","g",$0) } END { print }' | awk 'BEGIN { printf("\"cpu\":{\n") } /^Load:/ { printf("\"1minavg\":\"%s\",\n\"5minavg\":\"%s\",\n\"15minavg\":\"%s\"\n",$1,$2,$3) } /^CPU%:/ { printf("\"pctuser\":\"%s\",\n\"pctsystem\":\"%s\",\n\"pctwait\":\"%s\",\n\"pctidle\":\"%s\",\n",$2,$4,$5,$7) } END { printf("}") }'
-}
-
-genmem() {
- free | awk '/^Mem:/ { printf("\"mem\":{\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n}",$2,$3,$4) }'
-}
-
-genswap() {
- free | awk '/^Swap:/ { printf("\"swap\":{\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n}",$2,$3,$4) }'
-}
-
-gendisk() {
- iostat -d | awk 'BEGIN { printf("\"disk\": [") } /^[a-zA-Z0-9]/ {if(NR>3) printf("{\n\"device\":\"%s\",\n\"read-kbps\":\"%s\",\n\"write-kbps\":\"%s\"\n},",$1,$3,$4) } END { printf("\b]") }'
-}
-
-genpartition() {
- df -P | awk 'BEGIN { printf("\"partition\":[") } /^\// { printf("{\n\"device\":\"%s\",\n\"mount\":\"%s\",\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n},",$1,$6,$3+$4,$3,$4) } END { printf("\b]\n") }'
-}
+. $APPROOT/lib/monitors.inc.sh
genall() {
- gencpu
- printf ","
- genmem
- printf ","
- genswap
- printf ","
- gendisk
- printf ","
- genpartition
+ MONLIST
}
-availres=(/stats /stats/cpu /stats/mem /stats/swap /stats/disk /stats/partition)
+availres=(RESLIST)
availact=(GET)
read request
action=$(printf "$request" | awk '{ print $1 }')
diff --git a/stats/cpu b/stats/cpu
new file mode 100644
index 0000000..952fb84
--- /dev/null
+++ b/stats/cpu
@@ -0,0 +1 @@
+(iostat -c ; echo -n "Load: " ; cat /proc/loadavg ) | tail -n 3 | awk '/^[ \t]*[0-9]/ { print gensub(/^[ \t]*/,"CPU%: ","g",$0) } END { print }' | awk 'BEGIN { printf("\"cpu\":{\n") } /^Load:/ { printf("\"1minavg\":\"%s\",\n\"5minavg\":\"%s\",\n\"15minavg\":\"%s\"\n",$1,$2,$3) } /^CPU%:/ { printf("\"pctuser\":\"%s\",\n\"pctsystem\":\"%s\",\n\"pctwait\":\"%s\",\n\"pctidle\":\"%s\",\n",$2,$4,$5,$7) } END { printf("}") }'
diff --git a/stats/cpu.comments b/stats/cpu.comments
new file mode 100644
index 0000000..ec394c7
--- /dev/null
+++ b/stats/cpu.comments
@@ -0,0 +1 @@
+# monitor CPU load average and percent utilization
diff --git a/stats/disk b/stats/disk
new file mode 100644
index 0000000..5260508
--- /dev/null
+++ b/stats/disk
@@ -0,0 +1 @@
+iostat -d | awk 'BEGIN { printf("\"disk\": [") } /^[a-zA-Z0-9]/ {if(NR>3) printf("{\n\"device\":\"%s\",\n\"read-kbps\":\"%s\",\n\"write-kbps\":\"%s\"\n},",$1,$3,$4) } END { printf("\b]") }'
diff --git a/stats/disk.comments b/stats/disk.comments
new file mode 100644
index 0000000..7142ead
--- /dev/null
+++ b/stats/disk.comments
@@ -0,0 +1 @@
+# monitor disk device I/O
diff --git a/stats/mem b/stats/mem
new file mode 100644
index 0000000..5c12e08
--- /dev/null
+++ b/stats/mem
@@ -0,0 +1 @@
+free | awk '/^Mem:/ { printf("\"mem\":{\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n}",$2,$3,$4) }'
diff --git a/stats/mem.comments b/stats/mem.comments
new file mode 100644
index 0000000..658f107
--- /dev/null
+++ b/stats/mem.comments
@@ -0,0 +1 @@
+# monitor memory free, used, and total
diff --git a/stats/partition b/stats/partition
new file mode 100644
index 0000000..119adc8
--- /dev/null
+++ b/stats/partition
@@ -0,0 +1 @@
+df -P | awk 'BEGIN { printf("\"partition\":[") } /^\// { printf("{\n\"device\":\"%s\",\n\"mount\":\"%s\",\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n},",$1,$6,$3+$4,$3,$4) } END { printf("\b]\n") }'
diff --git a/stats/partition.comments b/stats/partition.comments
new file mode 100644
index 0000000..f141333
--- /dev/null
+++ b/stats/partition.comments
@@ -0,0 +1 @@
+# monitor partition used, available, total, and percent used
diff --git a/stats/swap b/stats/swap
new file mode 100644
index 0000000..5329d39
--- /dev/null
+++ b/stats/swap
@@ -0,0 +1 @@
+free | awk '/^Swap:/ { printf("\"swap\":{\n\"total\":\"%s\",\n\"used\":\"%s\",\n\"free\":\"%s\"\n}",$2,$3,$4) }'
diff --git a/stats/swap.comments b/stats/swap.comments
new file mode 100644
index 0000000..7263386
--- /dev/null
+++ b/stats/swap.comments
@@ -0,0 +1 @@
+# monitor swap space free, used, and total