Search in sources :

Example 1 with IndyMetricsException

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();
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) IndyHttpException(org.commonjava.indy.subsys.http.IndyHttpException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) Gauge(com.codahale.metrics.Gauge) Snapshot(com.codahale.metrics.Snapshot) DataObject(org.commonjava.indy.metrics.zabbix.sender.DataObject) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Map(java.util.Map) SortedMap(java.util.SortedMap) SenderResult(org.commonjava.indy.metrics.zabbix.sender.SenderResult) IndyMetricsException(org.commonjava.indy.metrics.exception.IndyMetricsException)

Example 2 with IndyMetricsException

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);
}
Also used : IndyZabbixApi(org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi) URL(java.net.URL) IndyMetricsException(org.commonjava.indy.metrics.exception.IndyMetricsException)

Aggregations

IndyMetricsException (org.commonjava.indy.metrics.exception.IndyMetricsException)2 Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 Snapshot (com.codahale.metrics.Snapshot)1 Timer (com.codahale.metrics.Timer)1 IOException (java.io.IOException)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 IndyZabbixApi (org.commonjava.indy.metrics.zabbix.api.IndyZabbixApi)1 DataObject (org.commonjava.indy.metrics.zabbix.sender.DataObject)1 SenderResult (org.commonjava.indy.metrics.zabbix.sender.SenderResult)1 IndyHttpException (org.commonjava.indy.subsys.http.IndyHttpException)1