use of org.snmp4j.event.ResponseEvent 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.event.ResponseEvent 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.event.ResponseEvent 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;
}
use of org.snmp4j.event.ResponseEvent 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.event.ResponseEvent in project opennms by OpenNMS.
the class MockSnmpAgentIT method sendRequestV1V2.
private PDU sendRequestV1V2(PDU pdu, int version) {
PDU response = null;
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(new UdpAddress(InetAddressUtils.addr("127.0.0.1"), m_agent.getPort()));
target.setVersion(version);
TransportMapping<UdpAddress> transport = null;
Snmp snmp = null;
try {
transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
transport.listen();
ResponseEvent e = snmp.send(pdu, target);
response = e.getResponse();
} catch (final IOException e) {
e.printStackTrace();
} finally {
if (snmp != null) {
try {
snmp.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
if (transport != null) {
try {
transport.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}
return response;
}
Aggregations