logger.error("Type parsing error: {}", q.getResults().get(0).getTypeName());
return;
}
boolean isQueue = m.group(1).equals("q");
RRDToolWriter writer = getWriter(q.getServer().getHost(), exchangeName, isQueue);
ExchangeMetric metric = new ExchangeMetric(q.getServer().getHost(), isQueue ? "queue": "topic", exchangeName, String.format("%s/%s-%s.rrd", outputPath, isQueue ? "queue": "topic", exchangeName));
try {
queryClients(q.getServer().getHost(), q.getResults().get(0).getTypeName(), metric);
}
catch(Exception e) {
logger.error("Cannot obtain consumer and producer information for exchange {} on broker {}", q.getServer().getHost(), exchangeName);
logger.error(e.getMessage(), e);
}
Record lastRecord = lastRecords.get(exchangeName);
long timestamp = System.currentTimeMillis();
long numMsgs = 0;
long totalMsgBytes = 0;
long numMsgsIn = 0;
long numMsgsOut = 0;
long lastConsumed = 0;
long lastProduced = 0;
long lastConsumedSize = 0;
long lastProducedSize = 0;
Record currentRecord = new Record();
currentRecord.setTimestamp(timestamp);
for(Result res : q.getResults()) {
if(res.getAttributeName().equals("NumMsgs")) {
numMsgs = (Long) res.getValues().get("NumMsgs");
metric.addMetric("Pending", res.getValues().get("NumMsgs").toString());
}
else if(res.getAttributeName().equals("NumMsgsIn")) {
numMsgsIn = (Long) res.getValues().get("NumMsgsIn");
metric.addMetric("Enqueue", res.getValues().get("NumMsgsIn").toString());
if(lastRecord == null || lastRecord.getMsgIn() > numMsgsIn) {
res.addValue("NumMsgsIn", "0");
}
else {
lastProduced = numMsgsIn - lastRecord.getMsgIn();
res.addValue("NumMsgsIn", String.valueOf((long) ((float) lastProduced / (timestamp - lastRecord.getTimestamp()) * 1000)));
}
metric.addMetric("Last Enqueue", Long.toString(lastProduced));
currentRecord.setMsgIn(numMsgsIn);
}
else if(res.getAttributeName().equals("NumMsgsOut")) {
numMsgsOut = (Long) res.getValues().get("NumMsgsOut");
metric.addMetric("Dequeue", res.getValues().get("NumMsgsOut").toString());
if(lastRecord == null || lastRecord.getMsgOut() > numMsgsOut) {
res.addValue("NumMsgsOut", "0");
}
else {
lastConsumed = numMsgsOut - lastRecord.getMsgOut();
res.addValue("NumMsgsOut", String.valueOf((long) ((float) lastConsumed / (timestamp - lastRecord.getTimestamp()) * 1000)));
}
metric.addMetric("Last Dequeue", Long.toString(lastConsumed));
currentRecord.setMsgOut(numMsgsOut);
}
else if(res.getAttributeName().equals("NumMsgsPendingAcks")) {
metric.addMetric("Pending ACK", res.getValues().get("NumMsgsPendingAcks").toString());
}
else if(res.getAttributeName().equals("NumConsumers")) {
metric.addMetric("Consumers", res.getValues().get("NumConsumers").toString());
}
else if(res.getAttributeName().equals("NumProducers")) {
metric.addMetric("Producers", res.getValues().get("NumProducers").toString());
}
else if(res.getAttributeName().equals("MsgBytesIn")) {
long numMsgsInSize = (Long) res.getValues().get("MsgBytesIn");
metric.addMetric("Enqueue Size", res.getValues().get("MsgBytesIn").toString());
if(lastRecord == null || lastRecord.getMsgInSize() > numMsgsInSize) {
res.addValue("MsgBytesIn", "0");
}
else {
lastProducedSize = numMsgsInSize - lastRecord.getMsgInSize();
res.addValue("MsgBytesIn", String.valueOf((long) ((float) lastProducedSize / (timestamp - lastRecord.getTimestamp()) * 1000)));
}
metric.addMetric("Last Enqueue Size", Long.toString(lastProducedSize));
currentRecord.setMsgInSize(numMsgsInSize);
}
else if(res.getAttributeName().equals("MsgBytesOut")) {
long numMsgsOutSize = (Long) res.getValues().get("MsgBytesOut");
metric.addMetric("Dequeue Size", res.getValues().get("MsgBytesOut").toString());
if(lastRecord == null || lastRecord.getMsgOutSize() > numMsgsOutSize) {
res.addValue("MsgBytesOut", "0");
}
else {
lastConsumedSize = numMsgsOutSize - lastRecord.getMsgOutSize();
res.addValue("MsgBytesOut", String.valueOf((long) ((float) lastConsumedSize / (timestamp - lastRecord.getTimestamp()) * 1000)));
}
metric.addMetric("Last Dequeue Size", Long.toString(lastConsumedSize));
currentRecord.setMsgOutSize(numMsgsOutSize);
}
else if(res.getAttributeName().equals("TotalMsgBytes")) {
totalMsgBytes = (Long) res.getValues().get("TotalMsgBytes");
metric.addMetric("Pending Size", Long.toString(totalMsgBytes));
}
}
Config c = lastConfigs.get(exchangeName);
if(c != null) {
metric.addMetric("Limit Behavior", c.getLimitBehavior());
metric.addMetric("Max Pending", Long.toString(c.getMaxNumMsgs()));
metric.addMetric("Max Pending Size", Long.toString(c.getMaxTotalMsgBytes()));
}
if(numMsgs > 0 && lastConsumed == 0) {
alert(exchangeName, metric);
}
else {
lastAlertTs.remove(exchangeName);
}
long numMsgsDropped = numMsgsIn - numMsgsOut - numMsgs;
metric.addMetric("Dropped", String.valueOf(numMsgsDropped));
if(lastRecord == null || lastRecord.getMsgDrop() > numMsgsDropped) {
q.getResults().get(0).addValue("NumMsgDropped", "0");
}
else {
q.getResults().get(0).addValue("NumMsgDropped", String.valueOf((long) ((float) (numMsgsDropped - lastRecord.getMsgDrop()) / (timestamp - lastRecord.getTimestamp()) * 1000)));
}
currentRecord.setMsgDrop(numMsgsDropped);
lastRecords.put(exchangeName, currentRecord);
writer.validateSetup(q);
writer.doWrite(q);
File file = new File(String.format("%s/%s-%s.json", outputPath, isQueue ? "queue": "topic", exchangeName));
FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
try {
FileLock lock = channel.lock();