use of org.commonjava.indy.metrics.exception.IndyMetricsException in project indy by Commonjava.
the class IndyZabbixReporter method report.
@SuppressWarnings("rawtypes")
@Override
public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) {
final long clock = System.currentTimeMillis() / 1000;
List<DataObject> dataObjectList = new LinkedList<DataObject>();
for (Map.Entry<String, Gauge> entry : gauges.entrySet()) {
DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getValue()), clock);
dataObjectList.add(dataObject);
}
for (Map.Entry<String, Counter> entry : counters.entrySet()) {
DataObject dataObject = toDataObject(entry.getKey(), "", String.valueOf(entry.getValue().getCount()), clock);
dataObjectList.add(dataObject);
}
for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
Histogram histogram = entry.getValue();
Snapshot snapshot = histogram.getSnapshot();
addSnapshotDataObject(entry.getKey(), snapshot, clock, dataObjectList);
}
for (Map.Entry<String, Meter> entry : meters.entrySet()) {
Meter meter = entry.getValue();
addMeterDataObject(entry.getKey(), meter, clock, dataObjectList);
}
for (Map.Entry<String, Timer> entry : timers.entrySet()) {
Timer timer = entry.getValue();
addMeterDataObject(entry.getKey(), timer, clock, dataObjectList);
addSnapshotDataObjectWithConvertDuration(entry.getKey(), timer.getSnapshot(), clock, dataObjectList);
}
try {
SenderResult senderResult = indyZabbixSender.send(dataObjectList, clock);
if (!senderResult.success()) {
logger.warn("report metrics to zabbix not success!" + senderResult);
} else if (logger.isDebugEnabled()) {
logger.info("report metrics to zabbix success. " + senderResult);
}
} catch (IOException e) {
logger.error("report metrics to zabbix error! " + e);
e.printStackTrace();
} catch (IndyMetricsException e) {
logger.error("Indy metrics config error " + e);
e.printStackTrace();
} catch (IndyHttpException e) {
logger.error("Indy http client error " + e);
e.printStackTrace();
}
}
use of org.commonjava.indy.metrics.exception.IndyMetricsException in project indy by Commonjava.
the class IndyZabbixSender method zabbixApiInit.
private void zabbixApiInit() throws IndyMetricsException, IOException, IndyHttpException {
if (!bCreateNotExistZabbixApi) {
return;
}
if (this.zabbixHostUrl == null || "".equals(this.zabbixHostUrl)) {
throw new IndyMetricsException("can not find Zabbix's Host");
}
zabbixApi = new IndyZabbixApi(this.zabbixHostUrl, indyHttpProvider.createClient(new URL(zabbixHostUrl).getHost()));
zabbixApi.init();
if (this.zabbixUserName == null || "".equals(this.zabbixUserName) || this.zabbixUserPwd == null || "".equals(this.zabbixUserPwd)) {
throw new IndyMetricsException("can not find Zabbix's username or password");
}
boolean login = zabbixApi.login(this.zabbixUserName, this.zabbixUserPwd);
logger.info("User:" + this.zabbixUserName + " login is " + login);
}
Aggregations