文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Using Scripts and inetd to provide data to MRTG

Using Scripts and inetd to provide data to MRTG

时间:2006-03-01  来源:mantou

Using Scripts and inetd to provide data to MRTG

   MRTG Will graph anything with numbers. It doesn't have to come from SNMP. Much of my data infact comes from running scripts that output numbers. In a network with multiple systems it is easiest to transform these scripts into servers which spit out the numbers when something connects to them. I prefer xinetd wherever possible as it has more flexible controls. It can bind a service to a specific interface, and it's tcpwrappers implimentation I like much more then regular inetds. So all of my examples will focus on xinetd, converting them to inetd format is not difficult.

Sample

service uptime { socket_type = stream protocol = tcp wait = no user = nobody bind = 127.0.0.1 server = /usr/local/sbin/uptime.pl } 

In order for this to work you need to assign ports to these services in /etc/services, these are the ports I use:

df 9047/tcp # df df2 9048/tcp # df2 smtp-stats 9051/tcp # smtp-stats smtp-stats-bytes 9052/tcp # smtp-stats uptime 9053/tcp # uptime load 9054/tcp # load average processes 9055/tcp # processes sockets 9056/tcp # sockets memory 9057/tcp # memory mysql-stats 9061/tcp # MySQL stats mysql-stats2 9062/tcp # MySQL stats part 2 

This creates a service called uptime, and binds it to the loopback interface. When something connects to it, it changes uid to nobody and executes the script /usr/local/sbin/uptime.pl. Which then spits out some numbers, sample:

[mrtg@portal:~]$ echo "" | nc localhost uptime 10 

I use the command nc(Netcat), the manpage calls it a TCP/IP Swiss Army knife. It's quite flexible but I only use the basic functionality of the command to initiate a connection without the extra output that commands like telnet spit out when initiating a connection. You can download the source of netcat from here. Near the bottom of the page is a link to the source.

Most of the scripts were not written by me, I got them from various places around the net.

 

这里是以守护进程服务方式来提供数据, NC, 有名的瑞士军刀,获取数据,nc localhost 9062('mysql\-stats2'), 其实telnet 也可以获取数据,只是nc直接去数据。

nc -h 中说明 - 要以\-转义。

相关阅读 更多 +
排行榜 更多 +
弓箭手战士酷跑

弓箭手战士酷跑

飞行射击 下载
三角洲行动全面战场攀升A点进攻指南

三角洲行动全面战场攀升A点进攻指南

飞行射击 下载
僵尸射手世界大战

僵尸射手世界大战

飞行射击 下载