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.

187 lines
5.6 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. FS ?= /
  20. FORMAT = SVG
  21. EXTENSION = .$(shell echo $(FORMAT) |tr '[:upper:]' '[:lower:]')
  22. DAY_IN_SECS = 86400
  23. BUILD_DIR = web
  24. all:
  25. cpu.rrd:
  26. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  27. DS:user:GAUGE:120:0:100 \
  28. DS:nice:GAUGE:120:0:100 \
  29. DS:sys:GAUGE:120:0:100 \
  30. DS:iowait:GAUGE:120:0:100 \
  31. DS:steal:GAUGE:120:0:100 \
  32. DS:irq:GAUGE:120:0:100 \
  33. DS:soft:GAUGE:120:0:100 \
  34. DS:guest:GAUGE:120:0:100 \
  35. DS:gnice:GAUGE:120:0:100 \
  36. DS:idle:GAUGE:120:0:100 \
  37. RRA:LAST:0.5:1:1440 \
  38. RRA:AVERAGE:0.5:420:1440 \
  39. RRA:AVERAGE:0.5:1860:1440 \
  40. RRA:AVERAGE:0.5:21900:1440
  41. update_cpu: cpu.rrd
  42. 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 ' ' ':' )
  43. load.rrd:
  44. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  45. DS:ldavg-1:GAUGE:120:0:U \
  46. DS:ldavg-5:GAUGE:120:0:U \
  47. DS:ldavg-15:GAUGE:120:0:U \
  48. RRA:LAST:0.5:1:1440 \
  49. RRA:AVERAGE:0.5:420:1440 \
  50. RRA:AVERAGE:0.5:1860:1440 \
  51. RRA:AVERAGE:0.5:21900:1440
  52. update_load: load.rrd
  53. rrdtool update $< $(NOW):$(shell LANG=C sar -q LOAD 0 -1 |tail -n1 |awk '{print $$4,$$5,$$6}' |tr ' ' ':' )
  54. mem.rrd:
  55. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  56. DS:kbmemfree:GAUGE:120:0:U \
  57. DS:kbbuffers:GAUGE:120:0:U \
  58. DS:kbcached:GAUGE:120:0:U \
  59. DS:kbslab:GAUGE:120:0:U \
  60. RRA:LAST:0.5:1:1440 \
  61. RRA:AVERAGE:0.5:420:1440 \
  62. RRA:AVERAGE:0.5:1860:1440 \
  63. RRA:AVERAGE:0.5:21900:1440
  64. update_mem: mem.rrd
  65. rrdtool update $< $(NOW):$(shell LANG=C sar -r ALL 0 -1 |tail -n1 |awk '{print $$2,$$6,$$7,$$14}' |tr ' ' ':' )
  66. net.rrd:
  67. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  68. DS:rbytes:COUNTER:120:0:U \
  69. DS:tbytes:COUNTER:120:0:U \
  70. RRA:LAST:0.5:1:1440 \
  71. RRA:AVERAGE:0.5:420:1440 \
  72. RRA:AVERAGE:0.5:1860:1440 \
  73. RRA:AVERAGE:0.5:21900:1440
  74. update_net: net.rrd
  75. rrdtool update $< $(NOW):$(shell cat /proc/net/dev |grep $(IFACE) |awk '{print $$2,$$10}' |tr ' ' ':' )
  76. disk.rrd:
  77. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  78. DS:mbfsfree:GAUGE:120:0:U \
  79. DS:mbfsused:GAUGE:120:0:U \
  80. RRA:LAST:0.5:1:1440 \
  81. RRA:AVERAGE:0.5:420:1440 \
  82. RRA:AVERAGE:0.5:1860:1440 \
  83. RRA:AVERAGE:0.5:21900:1440
  84. update_disk: disk.rrd
  85. rrdtool update $< $(NOW):$(shell LANG=C sar -F MOUNT --fs=$(FS) 0 -1 |tail -n 1 |awk '{print $$2,$$3}' |tr ' ' ':' )
  86. update: update_cpu update_load update_mem update_net update_disk
  87. run:
  88. while true; do make update; sleep $(STEP); done
  89. $(BUILD_DIR)/cpu-daily$(EXTENSION): cpu.rrd
  90. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  91. --title "Processeur" \
  92. DEF:user=$<:user:AVERAGE \
  93. DEF:nice=$<:nice:AVERAGE \
  94. DEF:sys=$<:sys:AVERAGE \
  95. DEF:iowait=$<:iowait:AVERAGE \
  96. DEF:steal=$<:steal:AVERAGE \
  97. DEF:irq=$<:irq:AVERAGE \
  98. DEF:soft=$<:soft:AVERAGE \
  99. DEF:guest=$<:guest:AVERAGE \
  100. DEF:gnice=$<:gnice:AVERAGE \
  101. DEF:idle=$<:idle:AVERAGE \
  102. AREA:user#$(DANGER1):user:STACK \
  103. AREA:nice#$(DANGER2):nice:STACK \
  104. AREA:sys#$(DANGER3):sys:STACK \
  105. AREA:iowait#$(DANGER4):iowait:STACK \
  106. AREA:steal#$(DANGER5):steal:STACK \
  107. AREA:irq#$(DANGER6):irq:STACK \
  108. AREA:soft#$(DANGER7):soft:STACK \
  109. AREA:guest#$(DANGER8):guest:STACK \
  110. AREA:gnice#$(DANGER9):gnice:STACK \
  111. AREA:idle#$(SUCCESS):idle:STACK
  112. $(BUILD_DIR)/load-daily$(EXTENSION): load.rrd
  113. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  114. --title "Charge système" \
  115. DEF:ldavg-1=$<:ldavg-1:AVERAGE \
  116. DEF:ldavg-5=$<:ldavg-5:AVERAGE \
  117. DEF:ldavg-15=$<:ldavg-15:AVERAGE \
  118. LINE1:ldavg-1#$(INFO1):"sur 1 minute" \
  119. LINE1:ldavg-5#$(INFO2):"sur 5 minutes" \
  120. LINE1:ldavg-15#$(INFO3):"sur 15 minutes"
  121. $(BUILD_DIR)/mem-daily$(EXTENSION): mem.rrd
  122. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  123. --title "Mémoire" \
  124. DEF:kbmemfree=$<:kbmemfree:AVERAGE \
  125. CDEF:memfree=kbmemfree,1024,* \
  126. DEF:kbbuffers=$<:kbbuffers:AVERAGE \
  127. CDEF:buffers=kbbuffers,1024,* \
  128. DEF:kbcached=$<:kbcached:AVERAGE \
  129. CDEF:cached=kbcached,1024,* \
  130. DEF:kbslab=$<:kbslab:AVERAGE \
  131. CDEF:slab=kbslab,1024,* \
  132. AREA:buffers#$(DANGER1):"buffers":STACK \
  133. AREA:cached#$(DANGER2):"cached":STACK \
  134. AREA:slab#$(DANGER3):"slab":STACK \
  135. AREA:memfree#$(SUCCESS):"libre":STACK
  136. $(BUILD_DIR)/net-daily$(EXTENSION): net.rrd
  137. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  138. --title "Réseau" \
  139. DEF:rbytes=$<:rbytes:AVERAGE \
  140. VDEF:rbytesmax=rbytes,MAXIMUM \
  141. DEF:tbytes=$<:tbytes:AVERAGE \
  142. VDEF:tbytesmax=tbytes,MAXIMUM \
  143. CDEF:ntbytes=tbytes,-1,* \
  144. AREA:rbytes#$(DANGER):"reçu" \
  145. GPRINT:rbytesmax:"%6.2lf %Sb" \
  146. AREA:ntbytes#$(SUCCESS):"envoyé" \
  147. GPRINT:tbytesmax:"%6.2lf %Sb"
  148. $(BUILD_DIR)/disk-daily$(EXTENSION): disk.rrd
  149. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  150. --title "Disque" \
  151. --lower-limit 0 \
  152. DEF:mbfsfree=$<:mbfsfree:AVERAGE \
  153. CDEF:bfsfree=mbfsfree,1024,*,1024,* \
  154. DEF:mbfsused=$<:mbfsused:AVERAGE \
  155. CDEF:bfsused=mbfsused,1024,*,1024,* \
  156. AREA:bfsused#$(DANGER):"utilisé":STACK \
  157. AREA:bfsfree#$(SUCCESS):"libre":STACK
  158. $(BUILD_DIR)/%.html: %.php
  159. php $< >$@
  160. 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