Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1838718
  • 博文数量: 117
  • 博客积分: 2559
  • 博客等级: 少校
  • 技术积分: 4385
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-13 20:08
个人简介

作为初学者,要想取得进步,成为高手,首先应该了解自己的不足之处.

文章分类

全部博文(117)

文章存档

2014年(1)

2013年(25)

2012年(13)

2011年(77)

2010年(1)

分类: 系统运维

2013-06-06 20:33:14


基本的apache,snmp,MySQL,cacti安装过程以及Percona提供的MySQL监控模板设置等问题,这里就不再重复了.可参考文档.下面主要记录了安装过程中遇到的问题.

http://www.percona.com/doc/percona-monitoring-plugins/cacti/customizing-templates.html


URL路径问题

在url中输入
进行初始化,提示404,找不到页面.需要注意以下相关的地方


httpd.conf
DocumentRoot "/www/cacti"
Alias /cacti/ "/www/cacti/"

cacti-include/config.php
$url_path = "/cacti/";
url地址,输入


轮询间隔

将下面两项都设置为1分钟,并且在系统的cron中也设置为1分钟.
poller.php轮询器脚本中有详细的说明.


Poller Interval 
The polling interval in use. This setting will effect how often rrd's are checked and updated.?NOTE: If you change this value, you must re-populate the poller cache. Failure to do so, may result in lost data. 
轮询器间隔,这个设置影响rrd文件的检查和更新 
 
Cron Interval 
The cron interval in use. You need to set this setting to the interval that your cron or scheduled task is currently running. 
Cron执行间隔,在使用时,需要在cron或定时任务中设置. 


ERROR: Spine Timed Out While Processing Hosts Internal

日志报错
当前的轮询任务还没有执行完,下一次任务就开始了.
解决办法:可根据服务器情况适当增加并发数量,主要参数如下:


cacti-Settings-Poller页面下的两个选项


Maximum Threads per Process
Number of PHP Script Servers


ss_get_mysql_stats.php

该脚本中有两个参数,需要额外注意一下


cache_dir
缓存目录(注意权限,要apache用户可写),设置之后,脚本只需要在数据库中执行一次下列命令,而不用每个图形都执行一次.比如现在Percona提供的主机模板有42张图,如果不设置缓存,那么将对数据库执行42次同样的操作.(设置缓存之后,只需要执行1次,但仍然会连接42次数据库)
 210 Connect user@host on 
 210 Query SHOW /*!50002 GLOBAL */ STATUS
 210 Query SHOW VARIABLES
 210 Query SHOW SLAVE STATUS
 210 Query SHOW MASTER LOGS
 210 Query SHOW PROCESSLIST
 210 Query SHOW ENGINES
 210 Query SHOW /*!50000 ENGINE*/ INNODB STATUS
 210 Query SELECT `count`, total * 1000000 AS total FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME WHERE `time` <> 'TOO LONG'
 210 Quit
poll_time
要与轮询器时间匹配,否则会受cache_dir的影响,而取不到想要的数据.脚本中与该变量相关的代码如下;
另外一个问题,不匹配的poll_time会导致监控图"断点",并且数据也不准确.
filectime(), 返回最后一次文件的修改时间戳
time(), 当前时间戳
file(), 把整个文件读入到数组中
如果缓存文件最后修改的时间戳,再加上轮询时间的一半,小于当前时间戳,那么就把缓存数据读到数组,否则在数据库中取数据.


   # First, check the cache.
   $fp = null;
   if ( !isset($options['nocache']) ) {
      if ( $fp = fopen($cache_file, 'a+') ) {
         $locked = flock($fp, 1); # LOCK_SH
         if ( $locked ) {
            if ( filesize($cache_file) > 0
               && filectime($cache_file) + ($poll_time/2) > time()
               && ($arr = file($cache_file))
            ) {# The cache file is good to use.
               debug("Using the cache file");
               fclose($fp);
               return $arr[0];
            }
            else {
               debug("The cache file seems too small or stale");
               # Escalate the lock to exclusive, so we can write to it.
               if ( flock($fp, 2) ) { # LOCK_EX
                  # We might have blocked while waiting for that LOCK_EX, and
                  # another process ran and updated it.  Let's see if we can just
                  # return the data now:
                  if ( filesize($cache_file) > 0
                     && filectime($cache_file) + ($poll_time/2) > time()
                     && ($arr = file($cache_file))
                  ) 

批量添加脚本


  1. #!/bin/bash
  2. # this program is auto add cacti template
  3. # email:
  4. # version 1.0.0
  5. #set -e
  6. set -u
  7. set -x
  8. #
  9. # add_device.php --list-host-templates
  10. #
  11. #host_templates_id=10
  12. host_templates_id=$(php add_device.php --list-host-templates|grep 'Percona MySQL Server HT'|gawk '{print $1}')
  13. #
  14. # check file format,add device
  15. #
  16. add_host() {
  17. for i in $(cat $ft)
  18. do
  19. check_val=$(echo "$i"|gawk -F':' '{print $2}')
  20. : ${check_val:='NULL'}
  21. if [ $check_val == 'NULL' ]; then
  22. echo "[ERROR] file format error."
  23. exit
  24. fi
  25. done
  26. for i in $(cat $ft)
  27. do
  28. desc="$i"
  29. host=$(echo "$i"|gawk -F':' '{print $1}')
  30. # echo "php add_device.php --description='"$desc"' --ip='"$host"' --template=$host_templates_id --avail=ping --ping_method=udp"
  31. echo "php add_device.php --description='"$desc"' --ip='"$host"' --template=$host_templates_id --avail=none"
  32. done
  33. }
  34. #
  35. # hosts and description
  36. #
  37. add_graphs() {
  38. lh_id_names=$(php add_graphs.php --list-hosts|grep -v 'Known Hosts'|gawk '{print $1,$4}')
  39. NAMES=($(echo $lh_id_names))
  40. lg_id=$(php add_graphs.php --list-graph-templates --host-template-id=$host_templates_id|grep -v 'Known Graph Templates'|gawk '{print $1}')
  41. number=${#NAMES[*]}
  42. i=0
  43. while (( i<$number ))
  44. do
  45. hid=${NAMES[i]}
  46. fval=$(echo "${NAMES[i+1]}"|gawk -F':' '{print $2}')
  47. for gtid in $lg_id
  48. do
  49. field=$(php add_graphs.php --list-input-fields --graph-template-id=$gtid|grep -v 'Known Input Fields'|gawk '{print $1}')
  50. php add_graphs.php --graph-type=cg --graph-template-id=$gtid --host-id=$hid --input-fields="$field=$fval"
  51. done
  52. (( i=i+2 ))
  53. echo $i
  54. sleep 1
  55. done
  56. }
  57. append_graphs() {
  58. lh_id_names=$(php add_graphs.php --list-hosts|grep -v 'Known Hosts'|gawk '{print $1,$4}')
  59. NAMES=($(echo $lh_id_names))
  60. lg_id=$(php add_graphs.php --list-graph-templates --host-template-id=$host_templates_id|grep -v 'Known Graph Templates'|gawk '{print $1}')
  61. read first_line < $ft
  62. first_num=
  63. number=${#NAMES[*]}
  64. # Only ben less than ( < )
  65. for (( x=0; x<$number; x++))
  66. do
  67. host_loop=${NAMES[x]}
  68. echo "$x"
  69. if [ "$host_loop" == "$first_line" ]; then
  70. (( first_num=$x-1 ))
  71. # first_num="${NAMES[x]}"
  72. break
  73. fi
  74. done
  75. if [ -z $first_num ]; then
  76. echo "[Error] host: $first_line not found, please check"
  77. exit 0
  78. fi
  79. i=$first_num
  80. # echo $i
  81. while (( i<$number ))
  82. do
  83. hid=${NAMES[i]}
  84. fval=$(echo "${NAMES[i+1]}"|gawk -F':' '{print $2}')
  85. for gtid in $lg_id
  86. do
  87. field=$(php add_graphs.php --list-input-fields --graph-template-id=$gtid|grep -v 'Known Input Fields'|gawk '{print $1}')
  88. php add_graphs.php --graph-type=cg --graph-template-id=$gtid --host-id=$hid --input-fields="$field=$fval"
  89. done
  90. (( i=i+2 ))
  91. echo $i
  92. sleep 1
  93. done
  94. }
  95. while getopts :h:ga: arg
  96. do
  97. case $arg in
  98. h)
  99. ft="$OPTARG"
  100. add_host
  101. ;;
  102. g)
  103. add_graphs
  104. ;;
  105. a)
  106. ft="$OPTARG"
  107. append_graphs
  108. ;;
  109. :)
  110. echo "$arg: 错误参数"
  111. ;;
  112. ?)
  113. echo "$arg: 非法选项"
  114. ;;
  115. esac
  116. done







阅读(5483) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~