回転:php+snmpでサーバモニタを実現



  
  
  
  
  1. , , , PHP SNMP 。 MAS , 。 
  2.  
  3. : 
  4.  
  5. 、 net-snmp 
  6.  
  7. centos YUM : 
  8.  
  9. yum -y install net-snmp net-snmp-devel net-snmp-utils net-snmp-perl 
  10.  
  11. redhat net-snmp , , . , 。 
  12.  
  13. :rpm -ihv net-snmp-devel-5.1.2-11.EL4.6.i386.rpm 
  14.  
  15. rpm -qa | grep net-snmp  
  16.  
  17. snmpd.conf: 
  18. # vi /etc/snmp/snmpd.conf 
  19. com2sec notConfigUser default public155 
  20. access notConfigGroup “” any noauth exact all none none 
  21. view all included .1 80 
  22. view systemview included .1.3.6.1.2.1.2 
  23.  
  24. net-snmp 
  25. service snmpd start 
  26.  
  27. : 
  28. snmpget -v 2c -c “public155″ 127.0.0.1 .1.3.6.1.4.1.2021.10.1.3.1 
  29. snmpwalk -v 1 -c “public155″ 127.0.0.1 .1.3.6.1.4.1.2021.10.1.3 
  30.  
  31. : net-snmp-devel,net-snmp-utils , PHP SNMP 。 。 
  32.  
  33. 、 PHP SNMP  
  34. sockets snmp , php  
  35. cd /opt/php-5.2.7/ext/sockets 
  36. /opt/php527/bin/phpize 
  37. ./configure --with-php-config=/opt/php527/bin/php-config 
  38. make 
  39. make install 
  40.  
  41. SNMP 
  42. cd /opt/php-5.2.7/ext/snmp 
  43. /opt/php527/bin/phpize 
  44. ./configure --with-php-config=/opt/php527/bin/php-config 
  45. make 
  46. make install 
  47.  
  48. PHP  
  49. cp /opt/php527/lib/php/extensions/no-debug-non-zts-20060613/sockets.so /opt/php527/etc/ 
  50. cp /opt/php527/lib/php/extensions/no-debug-non-zts-20060613/snmp.so /opt/php527/etc/ 
  51.  
  52. php.ini 
  53. vi /opt/php527/lib/php.ini 
  54.  
  55. extension=sockets.so 
  56. extension=snmp.so 
  57.  
  58. APACHE 
  59. /opt/http2210/bin/apachectl -k graceful 
  60.  
  61. php , snmp , , MAS 。 , 。 
  62.  
  63. ps: , 139 : 139 , 。 
  64.  
  65. 、 PHP  
  66.  
  67. : 
  68.  
  69. function get_server_info($host$community$objectid) { 
  70. $a = snmpget($host$community$objectid); 
  71. $tmp = explode(":"$a); 
  72. if (count($tmp) > 1) { 
  73. $a = trim($tmp[1]); 
  74. return $a
  75. $host="192.168.1.11"
  76. $community="public155"
  77. // $host 1  
  78. $load1 = get_snmp_server($host,$community,".1.3.6.1.4.1.2021.10.1.3.1") ; 
  79. $objectid: 
  80.  
  81. CPU Statistics 
  82.  
  83. Load 
  84. 1 minute Load: .1.3.6.1.4.1.2021.10.1.3.1 
  85. 5 minute Load: .1.3.6.1.4.1.2021.10.1.3.2 
  86. 15 minute Load: .1.3.6.1.4.1.2021.10.1.3.3 
  87.  
  88. CPU 
  89. percentage of user CPU time: .1.3.6.1.4.1.2021.11.9.0 
  90. raw user cpu time: .1.3.6.1.4.1.2021.11.50.0 
  91. percentages of system CPU time: .1.3.6.1.4.1.2021.11.10.0 
  92. raw system cpu time: .1.3.6.1.4.1.2021.11.52.0 
  93. percentages of idle CPU time: .1.3.6.1.4.1.2021.11.11.0 
  94. raw idle cpu time: .1.3.6.1.4.1.2021.11.53.0 
  95. raw nice cpu time: .1.3.6.1.4.1.2021.11.51.0 
  96.  
  97. Memory Statistics 
  98.  
  99. Total Swap Size: .1.3.6.1.4.1.2021.4.3.0 
  100. Available Swap Space: .1.3.6.1.4.1.2021.4.4.0 
  101. Total RAM in machine: .1.3.6.1.4.1.2021.4.5.0 
  102. Total RAM used: .1.3.6.1.4.1.2021.4.6.0 
  103. Total RAM Free: .1.3.6.1.4.1.2021.4.11.0 
  104. Total RAM Shared: .1.3.6.1.4.1.2021.4.13.0 
  105. Total RAM Buffered: .1.3.6.1.4.1.2021.4.14.0 
  106. Total Cached Memory: .1.3.6.1.4.1.2021.4.15.0 
  107.  
  108. Disk Statistics 
  109.  
  110. The snmpd.conf needs to be edited. Add the following (assuming a machine with a single / partition): 
  111.  
  112. disk / 100000 (or
  113.  
  114. includeAllDisks 10% for all partitions and disks 
  115.  
  116. The OIDs are as follows 
  117.  
  118. Path where the disk is mounted: .1.3.6.1.4.1.2021.9.1.2.1 
  119. Path of the device for the partition: .1.3.6.1.4.1.2021.9.1.3.1 
  120. Total size of the disk/partion (kBytes): .1.3.6.1.4.1.2021.9.1.6.1 
  121. Available space on the disk: .1.3.6.1.4.1.2021.9.1.7.1 
  122. Used space on the disk: .1.3.6.1.4.1.2021.9.1.8.1 
  123. Percentage of space used on disk: .1.3.6.1.4.1.2021.9.1.9.1 
  124. Percentage of inodes used on disk: .1.3.6.1.4.1.2021.9.1.10.1 
  125.  
  126. ==============================================