|
NOW = $(shell date +%s )
|
|
STEP = 60
|
|
|
|
SUCCESS = 198754
|
|
DANGER = DC3545
|
|
INFO = 0DCAF0
|
|
|
|
DANGER1 = F8D7DA
|
|
DANGER2 = F1AEB5
|
|
DANGER3 = EA868F
|
|
DANGER4 = E35D6A
|
|
DANGER5 = DC3545
|
|
DANGER6 = B02A37
|
|
DANGER7 = 842029
|
|
DANGER8 = 58151C
|
|
DANGER9 = 2C0B0E
|
|
|
|
INFO1 = 0AA2C0
|
|
INFO2 = 0DCAF0
|
|
INFO3 = 3DD5F3
|
|
|
|
IFACE = eth0
|
|
|
|
FORMAT = SVG
|
|
EXTENSION = .$(shell echo $(FORMAT) |tr '[:upper:]' '[:lower:]')
|
|
|
|
DAY_IN_SECS = 86400
|
|
|
|
BUILD_DIR = web
|
|
|
|
all:
|
|
|
|
cpu.rrd:
|
|
rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
|
|
DS:user:GAUGE:120:0:100 \
|
|
DS:nice:GAUGE:120:0:100 \
|
|
DS:sys:GAUGE:120:0:100 \
|
|
DS:iowait:GAUGE:120:0:100 \
|
|
DS:steal:GAUGE:120:0:100 \
|
|
DS:irq:GAUGE:120:0:100 \
|
|
DS:soft:GAUGE:120:0:100 \
|
|
DS:guest:GAUGE:120:0:100 \
|
|
DS:gnice:GAUGE:120:0:100 \
|
|
DS:idle:GAUGE:120:0:100 \
|
|
RRA:LAST:0.5:1:1440 \
|
|
RRA:AVERAGE:0.5:420:1440 \
|
|
RRA:AVERAGE:0.5:1860:1440 \
|
|
RRA:AVERAGE:0.5:21900:1440
|
|
|
|
update_cpu: cpu.rrd
|
|
rrdtool update $< $(NOW):$(shell LANG=C sar -u ALL 0 -1 |tail -n1 |awk '{print $$3,$$4,$$5,$$6,$$7,$$8,$$9,$$10,$$11,$$12}' |tr ' ' ':' )
|
|
|
|
load.rrd:
|
|
rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
|
|
DS:ldavg-1:GAUGE:120:0:U \
|
|
DS:ldavg-5:GAUGE:120:0:U \
|
|
DS:ldavg-15:GAUGE:120:0:U \
|
|
RRA:LAST:0.5:1:1440 \
|
|
RRA:AVERAGE:0.5:420:1440 \
|
|
RRA:AVERAGE:0.5:1860:1440 \
|
|
RRA:AVERAGE:0.5:21900:1440
|
|
|
|
update_load: load.rrd
|
|
rrdtool update $< $(NOW):$(shell LANG=C sar -q LOAD 0 -1 |tail -n1 |awk '{print $$4,$$5,$$6}' |tr ' ' ':' )
|
|
|
|
mem.rrd:
|
|
rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
|
|
DS:kbmemfree:GAUGE:120:0:U \
|
|
DS:kbbuffers:GAUGE:120:0:U \
|
|
DS:kbcached:GAUGE:120:0:U \
|
|
DS:kbslab:GAUGE:120:0:U \
|
|
RRA:LAST:0.5:1:1440 \
|
|
RRA:AVERAGE:0.5:420:1440 \
|
|
RRA:AVERAGE:0.5:1860:1440 \
|
|
RRA:AVERAGE:0.5:21900:1440
|
|
|
|
update_mem: mem.rrd
|
|
rrdtool update $< $(NOW):$(shell LANG=C sar -r ALL 0 -1 |tail -n1 |awk '{print $$2,$$6,$$7,$$14}' |tr ' ' ':' )
|
|
|
|
net.rrd:
|
|
rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
|
|
DS:rbytes:COUNTER:120:0:U \
|
|
DS:tbytes:COUNTER:120:0:U \
|
|
RRA:LAST:0.5:1:1440 \
|
|
RRA:AVERAGE:0.5:420:1440 \
|
|
RRA:AVERAGE:0.5:1860:1440 \
|
|
RRA:AVERAGE:0.5:21900:1440
|
|
|
|
update_net: net.rrd
|
|
rrdtool update $< $(NOW):$(shell cat /proc/net/dev |grep $(IFACE) |awk '{print $$2,$$10}' |tr ' ' ':' )
|
|
|
|
disk.rrd:
|
|
rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
|
|
DS:mbfsfree:GAUGE:120:0:U \
|
|
DS:mbfsused:GAUGE:120:0:U \
|
|
RRA:LAST:0.5:1:1440 \
|
|
RRA:AVERAGE:0.5:420:1440 \
|
|
RRA:AVERAGE:0.5:1860:1440 \
|
|
RRA:AVERAGE:0.5:21900:1440
|
|
|
|
update_disk: disk.rrd
|
|
rrdtool update $< $(NOW):$(shell LANG=C sar -F MOUNT --fs=/ 0 -1 |tail -n 1 |awk '{print $$2,$$3}' |tr ' ' ':' )
|
|
|
|
update: update_cpu update_load update_mem update_net update_disk
|
|
|
|
run:
|
|
while true; do make update; sleep $(STEP); done
|
|
|
|
$(BUILD_DIR)/cpu-daily$(EXTENSION): cpu.rrd
|
|
rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
|
|
DEF:user=$<:user:AVERAGE \
|
|
DEF:nice=$<:nice:AVERAGE \
|
|
DEF:sys=$<:sys:AVERAGE \
|
|
DEF:iowait=$<:iowait:AVERAGE \
|
|
DEF:steal=$<:steal:AVERAGE \
|
|
DEF:irq=$<:irq:AVERAGE \
|
|
DEF:soft=$<:soft:AVERAGE \
|
|
DEF:guest=$<:guest:AVERAGE \
|
|
DEF:gnice=$<:gnice:AVERAGE \
|
|
DEF:idle=$<:idle:AVERAGE \
|
|
AREA:user#$(DANGER1):user:STACK \
|
|
AREA:nice#$(DANGER2):nice:STACK \
|
|
AREA:sys#$(DANGER3):sys:STACK \
|
|
AREA:iowait#$(DANGER4):iowait:STACK \
|
|
AREA:steal#$(DANGER5):steal:STACK \
|
|
AREA:irq#$(DANGER6):irq:STACK \
|
|
AREA:soft#$(DANGER7):soft:STACK \
|
|
AREA:guest#$(DANGER8):guest:STACK \
|
|
AREA:gnice#$(DANGER9):gnice:STACK \
|
|
AREA:idle#$(SUCCESS):idle:STACK
|
|
|
|
$(BUILD_DIR)/load-daily$(EXTENSION): load.rrd
|
|
rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
|
|
DEF:ldavg-1=$<:ldavg-1:AVERAGE \
|
|
DEF:ldavg-5=$<:ldavg-5:AVERAGE \
|
|
DEF:ldavg-15=$<:ldavg-15:AVERAGE \
|
|
LINE1:ldavg-1#$(INFO1):ldavg-1 \
|
|
LINE1:ldavg-5#$(INFO2):ldavg-5 \
|
|
LINE1:ldavg-15#$(INFO3):ldavg-15
|
|
|
|
$(BUILD_DIR)/mem-daily$(EXTENSION): mem.rrd
|
|
rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
|
|
DEF:kbmemfree=$<:kbmemfree:AVERAGE \
|
|
DEF:kbbuffers=$<:kbbuffers:AVERAGE \
|
|
DEF:kbcached=$<:kbcached:AVERAGE \
|
|
DEF:kbslab=$<:kbslab:AVERAGE \
|
|
AREA:kbbuffers#$(DANGER1):kbbuffers:STACK \
|
|
AREA:kbcached#$(DANGER2):kbcached:STACK \
|
|
AREA:kbslab#$(DANGER3):kbslab:STACK \
|
|
AREA:kbmemfree#$(SUCCESS):kbmemfree:STACK
|
|
|
|
$(BUILD_DIR)/net-daily$(EXTENSION): net.rrd
|
|
rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
|
|
DEF:rbytes=$<:rbytes:AVERAGE \
|
|
DEF:tbytes=$<:tbytes:AVERAGE \
|
|
CDEF:ntbytes=tbytes,-1,* \
|
|
AREA:rbytes#$(DANGER):rbytes \
|
|
AREA:ntbytes#$(SUCCESS):tbytes
|
|
|
|
$(BUILD_DIR)/disk-daily$(EXTENSION): disk.rrd
|
|
rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
|
|
DEF:mbfsfree=$<:mbfsfree:AVERAGE \
|
|
DEF:mbfsused=$<:mbfsused:AVERAGE \
|
|
AREA:mbfsused#$(DANGER):mbfsused:STACK \
|
|
AREA:mbfsfree#$(SUCCESS):mbfsfree:STACK
|
|
|
|
$(BUILD_DIR)/%.html: %.php
|
|
php $< >$@
|
|
|
|
graph: $(BUILD_DIR)/cpu-daily$(EXTENSION) $(BUILD_DIR)/load-daily$(EXTENSION) $(BUILD_DIR)/mem-daily$(EXTENSION) $(BUILD_DIR)/net-daily$(EXTENSION) $(BUILD_DIR)/disk-daily$(EXTENSION) $(BUILD_DIR)/index.html
|