use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getProcessData.
public List<SNMPTriple> getProcessData(String processName) throws IOException {
List<SNMPTriple> resList = new ArrayList<SNMPTriple>();
List<Integer> prIndexes = this.getProcessIndexes(processName);
if (prIndexes == null || prIndexes.size() == 0)
return resList;
logger.fine("Query process stats");
PDU pdu = createPDU();
for (Integer idx : prIndexes) {
for (int i = 1; i < PROCESS_PERF_TABLE_ENTRIES.length; i++) {
if (PROCESS_PERF_TABLE_ENTRIES[i].length() == 0)
continue;
pdu.add(new VariableBinding(new OID("." + PROCESS_PERF_TABLE_OID + "." + i + "." + idx)));
// logger.info("Adding " + "."+PROCESS_PERF_TABLE_OID+"."+i+"."+idx);
}
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(prIndexes.size() * 2);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
VariableBinding[] binds = event.getResponse().toArray();
for (VariableBinding b : binds) {
res.put(b.getOid().toString(), b.getVariable().toString());
// logger.info(b.getOid().toString() +", "+ b.getVariable().toString());
}
}
// logger.info("result: "+res);
for (int i = 1; i < PROCESS_PERF_TABLE_ENTRIES.length; i++) {
if (PROCESS_PERF_TABLE_ENTRIES[i].length() == 0)
continue;
BigDecimal data = new BigDecimal(0);
for (Integer idx : prIndexes) {
data = data.add(new BigDecimal(res.get(PROCESS_PERF_TABLE_OID + "." + i + "." + idx)));
}
resList.add(new SNMPTriple("", PROCESS_PERF_TABLE_ENTRIES[i], data.toString()));
}
return resList;
}
use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getProcessIndexes.
// 1.3.6.1.2.1.25.4.2.1.2.
/**
* Query index for given process name. Note the parameter only provides 128 characters,
* so it could be difficult for us to differentiate each other if multi processes with same name exist.
* So we will return this list and use the sum from all processes for our metrics
* @param process
* @return
* @throws IOException
*/
private List<Integer> getProcessIndexes(String process) throws IOException {
List<Integer> indexes = new ArrayList<Integer>();
if (process == null || process.isEmpty())
return indexes;
TableUtils tUtils = new TableUtils(snmp, new DefaultPDUFactory());
logger.fine("Query " + this.address + " for process " + process);
@SuppressWarnings("unchecked") List<TableEvent> events = tUtils.getTable(getTarget(), new OID[] { new OID("." + PROCESS_TABLE_OID) }, null, null);
for (TableEvent event : events) {
if (event.isError()) {
logger.warning(this.address + ": SNMP event error: " + event.getErrorMessage());
continue;
// throw new RuntimeException(event.getErrorMessage());
}
for (VariableBinding vb : event.getColumns()) {
String key = vb.getOid().toString();
String value = vb.getVariable().toString();
if (process != null && !process.isEmpty() && !value.equalsIgnoreCase(process))
continue;
if (value != null) {
logger.fine("Find process OID entry: " + key);
int index = -1;
String[] strs = key.split("\\.");
try {
index = Integer.parseInt(strs[strs.length - 1]);
indexes.add(index);
} catch (Exception ex) {
}
}
}
}
return indexes;
}
use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getEvent.
public ResponseEvent getEvent(OID[] oids) throws IOException {
PDU pdu = createPDU();
for (OID oid : oids) {
pdu.add(new VariableBinding(oid));
}
pdu.setType(PDU.GET);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
return event;
}
throw new RuntimeException("GET timed out");
}
use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getDiskData.
public List<SNMPTriple> getDiskData(String device) throws IOException {
int index = this.getDiskIndex(device);
if (index < 0) {
return new ArrayList<SNMPTriple>();
}
logger.fine("Query disk stats for " + index);
PDU pdu = createPDU();
for (int i = 1; i < DISK_TABLE_ENTRIES.length; i++) {
if (DISK_TABLE_ENTRIES[i].length() == 0)
continue;
pdu.add(new VariableBinding(new OID("." + DISK_TABLE_OID + "." + i + "." + index)));
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(13);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
VariableBinding[] binds = event.getResponse().toArray();
for (VariableBinding b : binds) res.put(b.getOid().toString(), b.getVariable().toString());
// logger.info(res.toString());
}
List<SNMPTriple> resList = new ArrayList<SNMPTriple>(res.size());
for (int i = 1; i < DISK_TABLE_ENTRIES.length; i++) {
if (DISK_TABLE_ENTRIES[i].length() == 0)
continue;
resList.add(new SNMPTriple("." + DISK_TABLE_OID + "." + i + "." + index, DISK_TABLE_ENTRIES[i], res.get(DISK_TABLE_OID + "." + i + "." + index)));
}
return resList;
}
use of org.snmp4j.smi.VariableBinding in project mysql_perf_analyzer by yahoo.
the class SNMPClient method getNetIfData3.
public Map<String, List<SNMPTriple>> getNetIfData3(String device) throws IOException {
Map<String, List<SNMPTriple>> resMap = new HashMap<String, List<SNMPTriple>>();
Map<Integer, String> indexMap = this.getNetIfIndexes(device);
if (indexMap == null || indexMap.size() == 0) {
logger.warning("Cannot find network interfaces ");
return resMap;
}
logger.fine("Query net if stats for network");
PDU pdu = createPDU();
for (Map.Entry<Integer, String> entry : indexMap.entrySet()) for (int i = 1; i < IF_TABLE_ENTRIES.length; i++) {
if (IF_TABLE_ENTRIES[i].length() == 0)
continue;
pdu.add(new VariableBinding(new OID("." + IF_TABLE_OID + "." + i + "." + entry.getKey())));
}
pdu.setType(PDU.GET);
Map<String, String> res = new HashMap<String, String>(IF_TABLE_ENTRIES.length * indexMap.size());
ResponseEvent event = snmp.send(pdu, getTarget(), null);
if (event != null) {
VariableBinding[] binds = event.getResponse().toArray();
for (VariableBinding b : binds) res.put(b.getOid().toString(), b.getVariable().toString());
// logger.info(res.toString());
}
for (Map.Entry<Integer, String> entry : indexMap.entrySet()) {
int index = entry.getKey();
String ifName = entry.getValue();
// ignore the case with no incoming and no outgoing traffic
if ("0".equals(res.get(IF_TABLE_OID + ".6." + index)) && "0".equals(res.get(IF_TABLE_OID + ".10." + index)))
continue;
resMap.put(ifName, new ArrayList<SNMPTriple>(IF_TABLE_ENTRIES.length));
for (int i = 1; i < IF_TABLE_ENTRIES.length; i++) {
if (IF_TABLE_ENTRIES[i].length() == 0)
continue;
resMap.get(ifName).add(new SNMPTriple("." + IF_TABLE_OID + "." + i + "." + index, IF_TABLE_ENTRIES[i], res.get(IF_TABLE_OID + "." + i + "." + index)));
}
}
return resMap;
}
Aggregations