- 论坛徽章:
- 0
|
通过Agent获取变量的值(小弟写的是一个返回cpu利用百分数的函数 void al_share_mem(int * value),\r\n包含在文件rdm-test3.c中,该函数可动态地返回值)\r\n\r\n然后小弟将MIB文件经过mib2c命令编译成.c和.h文件,并修改.c文件如下:\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不知道怎么样才能获取到实时的值。请指点。 |
|