Hunter的大杂烩 技术学习笔记

2014-09-11

Bash编程陷阱一

Filed under: 技术话题 — hunter @ 9:28 pm

from:http://www.oenhan.com/bash-pitfalls-1

Bash编程陷阱:bash-pitfalls里面介绍了43条shell陷阱,都是一些很常见的应用场景,新手和老手都有可能犯的错误,为了加深记忆,自己就大致记录下来,英文文章用wiki编辑,条目随时可能增加,建议直接看英文。

如下的内容不完全翻译原文,穿插了一些自己的修改。

1. for i in $(ls *.mp3)

bash编程中最常见的错误之一就是把循环写出如下样子:

1
2
3
4
5
6
7
8
9
for i in $(ls *.mp3); do    # Wrong!
   some command $i          # Wrong!
done
for i in $(ls)              # Wrong!
for i in `ls`               # Wrong!
for i in $(find . -type f)  # Wrong!
for i in `find . -type f`   # Wrong!

(more…)

2014-09-02

ganglia/nagios集成

Filed under: 技术话题 — hunter @ 5:24 pm

1. 用了自带的python client

优点是可以比较精细获取某个指标 ,比如我用这个来判断没有外网IP的机器是否存活:

#!/bin/sh

if [ $# -lt 1 ];then
echo “USAGE: $0 [host]”
exit
fi

retmsg=`/opt/ganglia/bin/ganglia –host=${gmond_ip} –port=${gmond_port}  –alive=$1 |grep True`
if [ -z $retmsg ];
then
echo “CRITICAL: host:” $1 ” is dead!”
exit 2
else
echo “OK:host:” $1 ” is alive”
exit 0
fi
2. 用了ganglia-nagios-bridge

优点是可以批量获取、设置多个指标

安装过程遇到的错误

Filed under: 技术话题 — hunter @ 4:28 pm

1. ganglia python client运行错误

error msg:’cannot connect to ganglia server (gmond) [xxx:yyy]

modify:  vi /opt/ganglia/lib/python/gmon/ganglia.py +412

sock.connect((self.svchost, int(self.svcport)))

^^^^^^^^^

2. nagios 监控出现It appears as though you do not have permission

参考:http://bbs.linuxtone.org/thread-4440-1-1.html

有可能是你的htpasswd里面的用户名不是nagiosadmin,修改 cgi.cfg中相关配置即可

3. contact notification_options里面去掉 u 参数(unkown)

如: service_notification_options    w,c,r,f,s

因为ganglia的python插件会用unkown状态

安装ganglia/nagios集成插件

Filed under: 技术话题 — hunter @ 3:54 pm

url:https://github.com/ganglia/monitor-core/wiki/Integrating-Ganglia-with-Nagios

其中 ganglia-nagios-bridge 需要安装 argparse 模块:

easy_install argparse

check_ganglia_metric 需要 安装NagAconda 模块 或者直接执行 easy_install ceck_ganglia_metric

btw:怎么都没搞定这个check_ganglia_metric的cache问题,回头继续搞 ganglia python client

2014-09-01

gmond的神奇特性

Filed under: 技术话题 — hunter @ 7:00 pm

如果在配置gmond.conf时,没有使用多播,那么必须把自己的ip加入到send_channel里面,否则 gmond不会感知本机的数据!

udp_send_channel {
#bind_hostname = yes # Highly recommended, soon to be default.
# This option tells gmond to use a source address
# that resolves to the machine’s hostname.  Without
# this, the metrics may appear to come from any
# interface and the DNS names associated with
# those IPs will be used to create the RRDs.
#mcast_join = 239.2.11.71
  host = 192.168.1.1

port = 28649
ttl = 1
}

« Newer PostsOlder Posts »

Powered by WordPress