免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3520 | 回复: 2
打印 上一主题 下一主题

紧急求助:关于通过SNMP Agent实时获取变量值(net-snmp) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-02-10 12:45 |只看该作者 |倒序浏览
各位大哥:\r\n小弟最近做通过SNMP实时获取变量的值(比如:系统资源利用率)的一个东东。\r\n使用工具为net-snmp。\r\n\r\n做了一个简单的实验,结果Agent编译后通过snmpget总是返回一个固定的值,实际上这个值是在不断变化的。\r\n我贴出我的程序请牛人帮忙分析下,万分感激。。。\r\n\r\n首先写了一个MIB(NET-SNMP-TEST,想得到其中testAgentCpu1的值),\r\n通过mib2c -c  int_watch.conf  testAgentCpu1命令自动生成 testAgentCpu1.c 和.h,现贴出经我修改后的.c\r\n\r\n/*\r\n * Note: this file originally auto-generated by mib2c using\r\n *        : mib2c.int_watch.conf,v 1.3 2005/05/03 14:38:11 dts12 Exp $\r\n */\r\n \r\n#include <net-snmp/net-snmp-config.h>\r\n#include <net-snmp/net-snmp-includes.h>\r\n#include <net-snmp/agent/net-snmp-agent-includes.h>\r\n#include \"testAgentCpu1.h\"\r\n\r\n/*   我加的部分begin  */\r\n#include \"rdm-test3.c\"    /*  这个是我自己写的,将内存利用率写入共享内存并返回值 */\r\n/*   我加的部分end    */\r\n \r\nlong    testAgentCpu1 = 1;  /* XXX: set default value */\r\n \r\n/*\r\n * Our initialization routine, called automatically by the agent\r\n * (Note that the function name must match init_FILENAME())\r\n */\r\nvoid\r\ninit_testAgentCpu1(void)\r\n{\r\n \r\n  int i,j,k;\r\n \r\n  static oid testAgentCpu1_oid[] = { 1,3,6,1,4,1,8072,2,4,1,1,1 };\r\n\r\n/*  我加的部分begin  */\r\n  al_share_mem(&testAgentCpu1);        /*  为rdm-test3.c中的函数,通过读共享内存,\r\n                                           将cpu的利用率百分数赋给testAgentCpu1,\r\n                                           我写了他的测试程序,确实可以动态返回,\r\n                                           每次运行返回值都不同  */\r\n/*  我加的部分end   */ \r\n \r\n \r\n  DEBUGMSGTL((\"testAgentCpu1\",\r\n                \"Initializing testAgentCpu1 scalar integer.  Default value = %d\\n\",\r\n                testAgentCpu1));\r\n  netsnmp_register_int_instance(\"testAgentCpu1\",\r\n                                  testAgentCpu1_oid,\r\n                                  OID_LENGTH(testAgentCpu1_oid),\r\n                                  &testAgentCpu1, NULL);\r\n \r\n  DEBUGMSGTL((\"testAgentCpu1\",\r\n              \"Done initalizing testAgentCpu1 module\\n\"));\r\n}//file ended\r\n\r\n将此文件编入Agent后启动snmpd,执行snmpget localhost -c public -v 1 testAgentCpu1.0\r\n每次都返回相同的值,郁闷。\r\n\r\n如果重新启动snmpd,则又得到新的值,且又保持不变了。。。。\r\n不知道怎么样才能获取到实时的值。请指点。

论坛徽章:
6
2015年迎新春徽章
日期:2015-03-04 09:48:00IT运维版块每日发帖之星
日期:2015-06-11 22:20:00IT运维版块每日发帖之星
日期:2015-08-23 06:20:00数据库技术版块每日发帖之星
日期:2015-10-24 06:20:00IT运维版块每日发帖之星
日期:2015-12-24 06:20:00IT运维版块每日发帖之星
日期:2016-04-15 06:20:00
2 [报告]
发表于 2006-02-11 19:27 |只看该作者
你为什么要自己写Agent,测试的话,先用标准的Agent确定你的读取程序没有问题再做下一步的测试。

论坛徽章:
0
3 [报告]
发表于 2006-02-13 09:35 |只看该作者
标准Agent通过配置snmpd.conf是可以获取的,可是这种方式每获取一次就相当于重新执行一次应用程序。\r\n但是如果是搞成进程通讯的模式,就要想办法去触发应用程序的执行不是吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP