做反向代理的squid集群监控,在单机维护时,squidclient mgr:server_list里的OPEN CONNS是经常看的一项数据,不过在开启snmp支持后,在mib里却没有找到相关的数据。还一度怀疑是不是cachePeerKeepAlRecv或者cachePeerKeepSent。今天想起来去src里grep了一把源码,顺利的在squid/src/neighbors.c里看到了OPEN CONNS等数据的来源,如下:
cstatic void
dump_peers(StoreEntry * sentry, peer * peers)
{
peer *e = NULL;
……
for (e = peers; e; e = e->next) {
……
storeAppendPrintf(sentry, "OPEN CONNS : %d\n", e->stats.conn_open);
……
storeAppendPrintf(sentry, "keep-alive ratio: %d%%\n",
percent(e->stats.n_keepalives_recv, e->stats.n_keepalives_sent));
然后在squid/src/snmp_agent.c里看到了这些数据的snmp输出,如下:
cvariable_list *
snmp_meshPtblFn(variable_list * Var, snint * ErrP)
{
variable_list *Answer = NULL;
struct in_addr *laddr;
int loop, index = 0;
char *cp = NULL;
peer *p = NULL;
int cnt = 0;
……
switch (Var->name[LEN_SQ_MESH + 2]) {
case MESH_PTBL_NAME:
cp = p->name;
Answer = snmp_var_new(Var->name, Var->name_length);
……
case MESH_PTBL_KEEPAL_R:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
p->stats.n_keepalives_recv,
SMI_COUNTER32);
break;
case MESH_PTBL_INDEX:
Answer = snmp_var_new_integer(Var->name, Var->name_length,
index,
ASN_INTEGER);
break;
default:
*ErrP = SNMP_ERR_NOSUCHNAME;
break;
}
return Answer;
}
一对比,发现确实没有stats.conn_open输出……
好在这个比较简单,稍微改一下,就能搞出来:
1、修改squid/include/cache_snmp.h如下:
cenum { /* cachePeerTable */
……
MESH_PTBL_CONN_OPEN, /*新增这个*/
MESH_PTBL_HOST,
MESH_PTBL_END
};
2、修改squid/src/snmp_core.c如下:
继续阅读……