×

扫描二维码登录本站

QQ登录

只需一步,快速开始

运用nagios监控windows主机

来自:网络



1.说明
在此演示nagios通过check_nt监控windows主机,需要在windows主机上安装NSClient++,下载地址:[ ttp://nsclient.org/nscp/downloads]http://nsclient.org/nscp/downloads[/url]
2.安装NSClient++[ ttp://static.oschina.net/uploads/img/201501/22175458_my9Y.png][ ttp://static.oschina.net/uploads/img/201501/22175459_ii9h.png][/url][/url]
Allowed hosts:nagios server的ip地址
NSClient password:在此设置密码后,在使用check_nt获取主机信息时需要使用-s password指定密码      nagios培训
[ ttp://static.oschina.net/uploads/img/201501/22175459_Bncd.png][ ttp://static.oschina.net/uploads/img/201501/22175500_m4Td.png][/url][/url]
安装完成,启动服务。
NSClient++的配置文件:INSTALLDIR\NSC.ini
[ ttp://static.oschina.net/uploads/img/201501/22175500_FnQS.png][ ttp://static.oschina.net/uploads/img/201501/22175500_aCLB.png][/url][/url]
check_nt端口:12489
NRPE端口:5666
3.关于check_nt命令路径:/usr/local/nagios/libexec/check_nt
查看帮助:/usr/localnagios/libexec/check_nt -h
[ ttp://my.oschina.net/forlinux/blog/370742#]?[/url]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Usage:
check_nt -H host -v variable [-p port] [-w warning] [-c critical]
[-l params] [-d SHOWALL] [-u] [-t timeout]

Options:
-H, --hostname=HOST
   nagios需要监控的主机ip
-p, --port=INTEGER
   指定访问被监控主机的ip地址,默认为1248
-s, --secret=<password>
   指定访问被监控主机需要的密码
-w, --warning=INTEGER
   warning状态的阈值
-c, --critical=INTEGER
   critical状态的阈值
-t, --timeout=INTEGER
   Seconds before connection attempt times out (default:  -l, --params=<parameters>                nagios实施
   Parameters passed to specified check (see below) -d, --display={SHOWALL}
   Display options (currently only SHOWALL works) -u, --unknown-timeout
   Return UNKNOWN on timeouts10)
-v, --variable=STRING
   指定对被监控主机监测哪些指标

可以使用的监测指标:
CLIENTVERSION = 获取NSClient的版本
# ./check_nt -H 10.8.4.23 -p 12489 -v CLIENTVERSION    NSClient++ 0.3.9.328 2011-08-16
如果使用-l <version>指定了一个版本,一旦版本不符,将会返回warning

CPULOAD =
  过去x分钟cpu平均负载
  -l语法:
  -l <minutes range>,<warning threshold>,<critical threshold>.
  <minute range> 要小于 24*60.
  阈值是百分比,而且10个请求可以1次完成
  ie: -l 60,90,95,120,90,95
# ./check_nt -H 10.8.4.23 -p 12489 -v CPULOAD -l 5,80,90 CPU Load 6% (5 min average) |   '5 min avg Load'=6%;80;90;0;100
# ./check_nt -H 10.8.4.23 -p 12489 -v CPULOAD -l 5,80,90,20,85,95 CPU Load 7% (5 min average) 8% (20 min average) |   '5 min avg Load'=7%;80;90;0;100 '20 min avg Load'=8%;85;95;0;100

UPTIME =
  获取主机的运行时间
  -l <unit>  
  <unit> = seconds, minutes, hours, or days. (default: minutes)
  Thresholds will use the unit specified above.
# ./check_nt -H 10.8.4.23 -p 12489 -v UPTIME -l hours System Uptime - 7 day(s) 3 hour(s) 58 minute(s) |uptime=171
# ./check_nt -H 10.8.4.23 -p 12489 -v UPTIME -l days System Uptime - 7 day(s) 3 hour(s) 58 minute(s) |uptime=7

USEDDISKSPACE =
  硬盘大小及使用率.
  -l选项只指定盘符: -l C
  Warning and critical thresholds can be specified with -w and -c.                     监控软件
# ./check_nt -H 10.8.4.23 -p 12489 -w 80 -c 90 -v USEDDISKSPACE -l C C:\ - total: 58.26 Gb - used: 36.94 Gb (63%) - free 21.32 Gb (37%) | 'C:\ Used Space'=36.94Gb;46.61;52.43;0.00;58.26

MEMUSE =
  内存使用率.
  Warning and critical thresholds can be specified with -w and -c.
# ./check_nt -H 10.8.4.23 -p 12489 -w 80 -c 90 -v MEMUSE Memory usage: total:5186.80 MB - used: 3414.76 MB (66%) - free: 1772.04 MB (34%) | 'Memory usage'=3414.76MB;4149.44;4668.12;0.00;5186.80

SERVICESTATE =
  检查一个或多个服务的状态.
  Request a -l parameters with the following syntax:
  -l <service1>,<service2>,<service3>,...
  You can specify -d SHOWALL in case you want to see working services in the returned string.
# ./check_nt -H 10.8.4.23 -p 12489 -v SERVICESTATE -l Spooler Spooler: Stopped

PROCSTATE =
  Check if one or several process are running.
  # ./check_nt -H 10.8.4.23 -p 12489 -v PROCSTATE -l NSClient++.exe   OK: All processes are running.

INSTANCES =
  Some examples:
  check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process



4.配置nagios通过check_nt监控windows主机[ ttp://my.oschina.net/forlinux/blog/370742#]?[/url]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#定义command: [root@nagios1 objects]# vim commands.cfg define command{
    #定义command name,必须全局唯一         command_name    check_nt_1
    #定义command如何获取主机的信息 $$是定义变量         command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$
        }
#定义host和service: [root@nagios1 objects]# vim windows.cfg define host{
    #继承名为windows-server的主机模板         use     windows-server
    #主机名,必须全局唯一         host_name       mywinserver
        alias   My Windows Server
    #被监控主机的ip地址,会传递给上面的$HOSTADDRESS$         address 10.8.4.23               nagios配置
        }

define service{
    #继承名为generic-service的服务模板         use                     generic-service
        host_name               mywinserver
        service_description     NSClient++ Version
    #使用上面定义的command,!后面的是传递给$ARG1$的值,如果传递两个     #值,需要用!隔开,例如check_nt_1!N1!N2         check_command           check_nt_1!CLIENTVERSION
        }
define service{
        use                     generic-service
        host_name               mywinserver
        service_description     Uptime
        check_command           check_nt_1!UPTIME
        }
define service{
        use                     generic-service
        host_name               mywinserver
        service_description     CPU Load
        check_command           check_nt_1!CPULOAD!-l 5,80,90
        }
define service{
        use                     generic-service
        host_name               mywinserver
        service_description     Memory Usage
        check_command           check_nt_1!MEMUSE!-w 80 -c 90
        }
define service{
        use                     generic-service
        host_name               mywinserver
        service_description     C:\ Drive Space
        check_command           check_nt_1!USEDDISKSPACE!-l c -w 80 -c 90
        }
define service{
        use                     generic-service
        host_name               mywinserver
        service_description     Explorer
        check_command           check_nt_1!PROCSTATE!-d SHOWALL -l Explorer.exe                  开源监控软件
        }



[ ttp://my.oschina.net/forlinux/blog/370742#]?[/url]
1
2
3
#启用windows.cfg [root@nagios1 nagios]# vim nagios.cfg cfg_file=/etc/nagios/objects/windows.cfg



[ ttp://my.oschina.net/forlinux/blog/370742#]?[/url]
1
2
3
4
5
#检查语法 [root@nagios1 objects]# /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg  #重启nagios服务 [root@nagios1 objects]#service nagios restart



5.验证[ ttp://static.oschina.net/uploads/img/201501/22175500_aRqr.png][ ttp://static.oschina.net/uploads/img/201501/22175501_wrbQ.png][/url][/url]
[ ttp://static.oschina.net/uploads/img/201501/22175502_5hlp.png][ ttp://static.oschina.net/uploads/img/201501/22175503_iarY.png][/url][/url]
过了一段时间,所有相关信息已获取到:
[ ttp://static.oschina.net/uploads/space/2015/0122/184840_1JuC_225266.png][/url]
我们看到c盘的使用率为63%,我们上面定义-w 80意思为使用率80%以上为WARNING,我们做如下修改:            nagios安装
[ ttp://my.oschina.net/forlinux/blog/370742#]?[/url]
1
2
3
4
5
6
7
8
#vim /etc/nagios/object/windows.cfg define service{
        use                     generic-service
        host_name               mywinserver
        service_description     C:\ Drive Space
        check_command           check_nt_1!USEDDISKSPACE!-l c -w 60 -c 90
        } #service nagios restart



   [ ttp://static.oschina.net/uploads/space/2015/0122/190501_XPx6_225266.png][/url]



想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427





上一篇:Nagios监控磁盘脚本解读
下一篇:安装nagios的方法
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部