Boot 2.x 普罗米修斯数据采集

为什么80%的码农都做不了架构师?>>>   hot3.png




    io.prometheus
    simpleclient
    0.6.0



    io.prometheus
    simpleclient_hotspot
    0.6.0



    io.prometheus
    simpleclient_httpserver
    0.6.0



    io.prometheus
    simpleclient_pushgateway
    0.6.0


    io.micrometer
    micrometer-registry-prometheus
    1.1.4


    io.micrometer
    micrometer-core
    1.1.4

import io.micrometer.core.instrument.Metrics;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

private PrometheusMetricsUtils() {

}

private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusMetricsUtils.class);


private static final String HTTP_REQUEST_COUNTER_ALL = "http_request_counter_all";
private static final String HTTP_REQUEST_COUNTER_ERROR = "http_request_counter_error";
private static final String HTTP_RESPONSE_RT_MS = "http_response_rt_ms";



private static final String API = "api";
private static final String RC = "rc";


/**
 * 收集api total 埋点数据
 * @param op api名
 */
public static void metricTotalRequest(String op) {
    try {
        Metrics.counter(HTTP_REQUEST_COUNTER_ALL, API, op)
                .increment();
    } catch (Exception e) {
        LOGGER.info("PrometheusMetrics API QPS ERROR ,caused by {}", ExceptionUtils.getFullStackTrace(e));
    }
}

/**
 * 收集api error 埋点数据
 * @param op api名
 */
public static void metricErrorRequest(String op) {
    try {

        Metrics.counter(HTTP_REQUEST_COUNTER_ERROR, API, op)
                .increment();
    } catch (Exception e) {
        LOGGER.info("PrometheusMetrics API ERROR COUNTER ,caused by {}", ExceptionUtils.getFullStackTrace(e));
    }
}

/**
 * 收集接口响应时间
 * @param op 接口标识
 * @param rc 返回码
 * @param rt 返回时间
 */
public static void metricResponseTime(String op, String rc, double rt) {
    Metrics.summary(HTTP_RESPONSE_RT_MS, API, op, RC, rc).record(rt);
}

转载于:https://my.oschina.net/yugj/blog/3053739

你可能感兴趣的:(java,网络,数据库)