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.

147 lines
4.3 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. all:
  23. cpu.rrd:
  24. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  25. DS:user:GAUGE:120:0:100 \
  26. DS:nice:GAUGE:120:0:100 \
  27. DS:sys:GAUGE:120:0:100 \
  28. DS:iowait:GAUGE:120:0:100 \
  29. DS:steal:GAUGE:120:0:100 \
  30. DS:irq:GAUGE:120:0:100 \
  31. DS:soft:GAUGE:120:0:100 \
  32. DS:guest:GAUGE:120:0:100 \
  33. DS:gnice:GAUGE:120:0:100 \
  34. DS:idle:GAUGE:120:0:100 \
  35. RRA:LAST:0.5:1:1440 \
  36. RRA:AVERAGE:0.5:420:1440 \
  37. RRA:AVERAGE:0.5:1860:1440 \
  38. RRA:AVERAGE:0.5:21900:1440
  39. update_cpu: cpu.rrd
  40. 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 ' ' ':' )
  41. load.rrd:
  42. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  43. DS:ldavg-1:GAUGE:120:0:U \
  44. DS:ldavg-5:GAUGE:120:0:U \
  45. DS:ldavg-15:GAUGE:120:0:U \
  46. RRA:LAST:0.5:1:1440 \
  47. RRA:AVERAGE:0.5:420:1440 \
  48. RRA:AVERAGE:0.5:1860:1440 \
  49. RRA:AVERAGE:0.5:21900:1440
  50. update_load: load.rrd
  51. rrdtool update $< $(NOW):$(shell LANG=C sar -q LOAD 0 -1 |tail -n1 |awk '{print $$4,$$5,$$6}' |tr ' ' ':' )
  52. mem.rrd:
  53. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  54. DS:kbmemfree:GAUGE:120:0:U \
  55. DS:kbbuffers:GAUGE:120:0:U \
  56. DS:kbcached:GAUGE:120:0:U \
  57. DS:kbslab:GAUGE:120:0:U \
  58. RRA:LAST:0.5:1:1440 \
  59. RRA:AVERAGE:0.5:420:1440 \
  60. RRA:AVERAGE:0.5:1860:1440 \
  61. RRA:AVERAGE:0.5:21900:1440
  62. update_mem: mem.rrd
  63. rrdtool update $< $(NOW):$(shell LANG=C sar -r ALL 0 -1 |tail -n1 |awk '{print $$2,$$6,$$7,$$14}' |tr ' ' ':' )
  64. net.rrd:
  65. rrdtool create $@ --start $$(( $(NOW) - 1 )) --step $(STEP) --no-overwrite \
  66. DS:rbytes:COUNTER:120:0:U \
  67. DS:tbytes:COUNTER:120:0:U \
  68. RRA:LAST:0.5:1:1440 \
  69. RRA:AVERAGE:0.5:420:1440 \
  70. RRA:AVERAGE:0.5:1860:1440 \
  71. RRA:AVERAGE:0.5:21900:1440
  72. update_net: net.rrd
  73. rrdtool update $< $(NOW):$(shell cat /proc/net/dev |grep $(IFACE) |awk '{print $$2,$$10}' |tr ' ' ':' )
  74. update: update_cpu update_load update_mem update_net
  75. run:
  76. while true; do make update; sleep $(STEP); done
  77. cpu-daily$(EXTENSION): cpu.rrd
  78. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  79. DEF:user=$<:user:AVERAGE \
  80. DEF:nice=$<:nice:AVERAGE \
  81. DEF:sys=$<:sys:AVERAGE \
  82. DEF:iowait=$<:iowait:AVERAGE \
  83. DEF:steal=$<:steal:AVERAGE \
  84. DEF:irq=$<:irq:AVERAGE \
  85. DEF:soft=$<:soft:AVERAGE \
  86. DEF:guest=$<:guest:AVERAGE \
  87. DEF:gnice=$<:gnice:AVERAGE \
  88. DEF:idle=$<:idle:AVERAGE \
  89. AREA:user#$(DANGER1):user:STACK \
  90. AREA:nice#$(DANGER2):nice:STACK \
  91. AREA:sys#$(DANGER3):sys:STACK \
  92. AREA:iowait#$(DANGER4):iowait:STACK \
  93. AREA:steal#$(DANGER5):steal:STACK \
  94. AREA:irq#$(DANGER6):irq:STACK \
  95. AREA:soft#$(DANGER7):soft:STACK \
  96. AREA:guest#$(DANGER8):guest:STACK \
  97. AREA:gnice#$(DANGER9):gnice:STACK \
  98. AREA:idle#$(SUCCESS):idle:STACK
  99. load-daily$(EXTENSION): load.rrd
  100. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  101. DEF:ldavg-1=$<:ldavg-1:AVERAGE \
  102. DEF:ldavg-5=$<:ldavg-5:AVERAGE \
  103. DEF:ldavg-15=$<:ldavg-15:AVERAGE \
  104. LINE1:ldavg-1#$(INFO1):ldavg-1 \
  105. LINE1:ldavg-5#$(INFO2):ldavg-5 \
  106. LINE1:ldavg-15#$(INFO3):ldavg-15
  107. mem-daily$(EXTENSION): mem.rrd
  108. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  109. DEF:kbmemfree=$<:kbmemfree:AVERAGE \
  110. DEF:kbbuffers=$<:kbbuffers:AVERAGE \
  111. DEF:kbcached=$<:kbcached:AVERAGE \
  112. DEF:kbslab=$<:kbslab:AVERAGE \
  113. AREA:kbbuffers#$(DANGER1):kbbuffers:STACK \
  114. AREA:kbcached#$(DANGER2):kbcached:STACK \
  115. AREA:kbslab#$(DANGER3):kbslab:STACK \
  116. AREA:kbbuffers#$(DANGER4):kbbuffers:STACK \
  117. AREA:kbmemfree#$(SUCCESS):kbmemfree:STACK
  118. net-daily$(EXTENSION): net.rrd
  119. rrdtool graph $@ --imgformat $(FORMAT) --end now --start end-$(DAY_IN_SECS) \
  120. DEF:rbytes=$<:rbytes:AVERAGE \
  121. DEF:tbytes=$<:tbytes:AVERAGE \
  122. CDEF:ntbytes=tbytes,-1,* \
  123. AREA:rbytes#$(DANGER):rbytes \
  124. AREA:ntbytes#$(SUCCESS):tbytes
  125. graph: cpu-daily$(EXTENSION) load-daily$(EXTENSION) mem-daily$(EXTENSION) net-daily$(EXTENSION)