You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
5.1 KiB

  1. NOW = $(shell date +%s )
  2. STEP = 60
  3. SUCCESS = 198754
  4. DANGER = DC3545
  5. INFO = 0DCAF0
  6. DANGER1 = F8D7DA
  7. DANGER2 = F1AEB5
  8. DANGER3 = EA868F
  9. DANGER4 = E35D6A
  10. DANGER5 = DC3545
  11. DANGER6 = B02A37
  12. DANGER7 = 842029
  13. DANGER8 = 58151C
  14. DANGER9 = 2C0B0E
  15. INFO1 = 0AA2C0
  16. INFO2 = 0DCAF0
  17. INFO3 = 3DD5F3
  18. IFACE = eth0
  19. FORMAT = SVG
  20. EXTENSION = .$(shell echo $(FORMAT) |tr '[:upper:]' '[:lower:]')
  21. DAY_IN_SECS = 86400
  22. BUILD_DIR = web
  23. all:
  24. cpu.rrd:
  25. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  26. DS:user:GAUGE:120:0:100 \
  27. DS:nice:GAUGE:120:0:100 \
  28. DS:sys:GAUGE:120:0:100 \
  29. DS:iowait:GAUGE:120:0:100 \
  30. DS:steal:GAUGE:120:0:100 \
  31. DS:irq:GAUGE:120:0:100 \
  32. DS:soft:GAUGE:120:0:100 \
  33. DS:guest:GAUGE:120:0:100 \
  34. DS:gnice:GAUGE:120:0:100 \
  35. DS:idle:GAUGE:120:0:100 \
  36. RRA:LAST:0.5:1:1440 \
  37. RRA:AVERAGE:0.5:420:1440 \
  38. RRA:AVERAGE:0.5:1860:1440 \
  39. RRA:AVERAGE:0.5:21900:1440
  40. update_cpu: cpu.rrd
  41. 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 ' ' ':' )
  42. load.rrd:
  43. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  44. DS:ldavg-1:GAUGE:120:0:U \
  45. DS:ldavg-5:GAUGE:120:0:U \
  46. DS:ldavg-15:GAUGE:120:0:U \
  47. RRA:LAST:0.5:1:1440 \
  48. RRA:AVERAGE:0.5:420:1440 \
  49. RRA:AVERAGE:0.5:1860:1440 \
  50. RRA:AVERAGE:0.5:21900:1440
  51. update_load: load.rrd
  52. rrdtool update $< $(NOW):$(shell LANG=C sar -q LOAD 0 -1 |tail -n1 |awk '{print $$4,$$5,$$6}' |tr ' ' ':' )
  53. mem.rrd:
  54. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  55. DS:kbmemfree:GAUGE:120:0:U \
  56. DS:kbbuffers:GAUGE:120:0:U \
  57. DS:kbcached:GAUGE:120:0:U \
  58. DS:kbslab:GAUGE:120:0:U \
  59. RRA:LAST:0.5:1:1440 \
  60. RRA:AVERAGE:0.5:420:1440 \
  61. RRA:AVERAGE:0.5:1860:1440 \
  62. RRA:AVERAGE:0.5:21900:1440
  63. update_mem: mem.rrd
  64. rrdtool update $< $(NOW):$(shell LANG=C sar -r ALL 0 -1 |tail -n1 |awk '{print $$2,$$6,$$7,$$14}' |tr ' ' ':' )
  65. net.rrd:
  66. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  67. DS:rbytes:COUNTER:120:0:U \
  68. DS:tbytes:COUNTER:120:0:U \
  69. RRA:LAST:0.5:1:1440 \
  70. RRA:AVERAGE:0.5:420:1440 \
  71. RRA:AVERAGE:0.5:1860:1440 \
  72. RRA:AVERAGE:0.5:21900:1440
  73. update_net: net.rrd
  74. rrdtool update $< $(NOW):$(shell cat /proc/net/dev |grep $(IFACE) |awk '{print $$2,$$10}' |tr ' ' ':' )
  75. disk.rrd:
  76. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  77. DS:MBfsfree:COUNTER:120:0:U \
  78. DS:MBfsused:COUNTER:120:0:U \
  79. RRA:LAST:0.5:1:1440 \
  80. RRA:AVERAGE:0.5:420:1440 \
  81. RRA:AVERAGE:0.5:1860:1440 \
  82. RRA:AVERAGE:0.5:21900:1440
  83. update_disk: disk.rrd
  84. rrdtool update $< $(NOW):$(shell sar -F MOUNT --fs=/ 0 -1 |tail -n 1 |awk '{print $$2,$$3}' |tr ' ' ':' )
  85. update: update_cpu update_load update_mem update_net update_disk
  86. run:
  87. while true; do make update; sleep $(STEP); done
  88. $(BUILD_DIR)/cpu-daily$(EXTENSION): cpu.rrd
  89. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  90. DEF:user=$<:user:AVERAGE \
  91. DEF:nice=$<:nice:AVERAGE \
  92. DEF:sys=$<:sys:AVERAGE \
  93. DEF:iowait=$<:iowait:AVERAGE \
  94. DEF:steal=$<:steal:AVERAGE \
  95. DEF:irq=$<:irq:AVERAGE \
  96. DEF:soft=$<:soft:AVERAGE \
  97. DEF:guest=$<:guest:AVERAGE \
  98. DEF:gnice=$<:gnice:AVERAGE \
  99. DEF:idle=$<:idle:AVERAGE \
  100. AREA:user#$(DANGER1):user:STACK \
  101. AREA:nice#$(DANGER2):nice:STACK \
  102. AREA:sys#$(DANGER3):sys:STACK \
  103. AREA:iowait#$(DANGER4):iowait:STACK \
  104. AREA:steal#$(DANGER5):steal:STACK \
  105. AREA:irq#$(DANGER6):irq:STACK \
  106. AREA:soft#$(DANGER7):soft:STACK \
  107. AREA:guest#$(DANGER8):guest:STACK \
  108. AREA:gnice#$(DANGER9):gnice:STACK \
  109. AREA:idle#$(SUCCESS):idle:STACK
  110. $(BUILD_DIR)/load-daily$(EXTENSION): load.rrd
  111. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  112. DEF:ldavg-1=$<:ldavg-1:AVERAGE \
  113. DEF:ldavg-5=$<:ldavg-5:AVERAGE \
  114. DEF:ldavg-15=$<:ldavg-15:AVERAGE \
  115. LINE1:ldavg-1#$(INFO1):ldavg-1 \
  116. LINE1:ldavg-5#$(INFO2):ldavg-5 \
  117. LINE1:ldavg-15#$(INFO3):ldavg-15
  118. $(BUILD_DIR)/mem-daily$(EXTENSION): mem.rrd
  119. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  120. DEF:kbmemfree=$<:kbmemfree:AVERAGE \
  121. DEF:kbbuffers=$<:kbbuffers:AVERAGE \
  122. DEF:kbcached=$<:kbcached:AVERAGE \
  123. DEF:kbslab=$<:kbslab:AVERAGE \
  124. AREA:kbbuffers#$(DANGER1):kbbuffers:STACK \
  125. AREA:kbcached#$(DANGER2):kbcached:STACK \
  126. AREA:kbslab#$(DANGER3):kbslab:STACK \
  127. AREA:kbbuffers#$(DANGER4):kbbuffers:STACK \
  128. AREA:kbmemfree#$(SUCCESS):kbmemfree:STACK
  129. $(BUILD_DIR)/net-daily$(EXTENSION): net.rrd
  130. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  131. DEF:rbytes=$<:rbytes:AVERAGE \
  132. DEF:tbytes=$<:tbytes:AVERAGE \
  133. CDEF:ntbytes=tbytes,-1,* \
  134. AREA:rbytes#$(DANGER):rbytes \
  135. AREA:ntbytes#$(SUCCESS):tbytes
  136. $(BUILD_DIR)/disk-daily$(EXTENSION): disk.rrd
  137. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  138. DEF:MBfsfree=$<:MBfsfree:AVERAGE \
  139. DEF:MBfsused=$<:MBfsused:AVERAGE \
  140. AREA:MBfsused#$(DANGER):MBfsused:STACK \
  141. AREA:MBfsfree#$(SUCCESS):MBfsfree:STACK
  142. $(BUILD_DIR)/%.html: %.php
  143. php $< >$@
  144. 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