Search in sources :

Example 1 with StatInfoRevisionCollector

use of com.tencent.polaris.plugins.stat.common.model.StatInfoRevisionCollector in project polaris-java by polarismesh.

the class PrometheusPushHandler method doPush.

private void doPush() {
    try {
        putDataFromContainerInOrder(container.getInsCollector(), container.getInsCollector().getCurrentRevision(), SystemMetricLabelOrder.INSTANCE_GAUGE_LABEL_ORDER);
        putDataFromContainerInOrder(container.getRateLimitCollector(), container.getRateLimitCollector().getCurrentRevision(), SystemMetricLabelOrder.RATELIMIT_GAUGE_LABEL_ORDER);
        putDataFromContainerInOrder(container.getCircuitBreakerCollector(), 0, SystemMetricLabelOrder.CIRCUIT_BREAKER_LABEL_ORDER);
        try {
            if (null == pushAddress && null != addressProvider) {
                setPushAddress(addressProvider.getAddress());
            }
            if (null == pushAddress) {
                return;
            }
            if (getPushGateway() == null) {
                LOG.info("init push-gateway {} ", pushAddress);
                setPushGateway(new PushGateway(pushAddress));
            }
            pushGateway.pushAdd(promRegistry, jobName, Collections.singletonMap(PUSH_GROUP_KEY, instanceName));
            // pushGateway.pushAdd(promRegistry, jobName, Collections.emptyMap());
            LOG.info("push result to push-gateway {} success", pushAddress);
        } catch (IOException exception) {
            LOG.error("push result to push-gateway {} encountered exception, exception:{}", pushAddress, exception.getMessage());
            setPushGateway(null);
            setPushAddress(null);
            return;
        }
        for (StatInfoCollector<?, ? extends StatMetric> s : container.getCollectors()) {
            if (s instanceof StatInfoRevisionCollector<?>) {
                long currentRevision = ((StatInfoRevisionCollector<?>) s).incRevision();
                LOG.debug("RevisionCollector inc current revision to {}", currentRevision);
            }
        }
    } catch (Exception e) {
        LOG.error("push result to push-gateway {} encountered exception, exception:{}", pushAddress, e.getMessage());
        e.printStackTrace();
    }
}
Also used : StatInfoRevisionCollector(com.tencent.polaris.plugins.stat.common.model.StatInfoRevisionCollector) PushGateway(io.prometheus.client.exporter.PushGateway) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

StatInfoRevisionCollector (com.tencent.polaris.plugins.stat.common.model.StatInfoRevisionCollector)1 PushGateway (io.prometheus.client.exporter.PushGateway)1 IOException (java.io.IOException)1