Search in sources :

Example 6 with Metrics

use of com.usthe.common.entity.job.Metrics in project hertzbeat by dromara.

the class WheelTimerTask method initJobMetrics.

/**
 * Initialize job fill information
 * 初始化job填充信息
 *
 * @param job job
 */
private void initJobMetrics(Job job) {
    // 将监控实际参数值对采集字段进行替换
    List<Configmap> config = job.getConfigmap();
    Map<String, Configmap> configmap = config.stream().peek(item -> {
        // 对加密串进行解密
        if (item.getType() == CommonConstants.PARAM_TYPE_PASSWORD && item.getValue() != null) {
            String decodeValue = AesUtil.aesDecode(String.valueOf(item.getValue()));
            if (decodeValue == null) {
                log.error("Aes Decode value {} error.", item.getValue());
            }
            item.setValue(decodeValue);
        } else if (item.getValue() != null && item.getValue() instanceof String) {
            item.setValue(((String) item.getValue()).trim());
        }
    }).collect(Collectors.toMap(Configmap::getKey, item -> item));
    List<Metrics> metrics = job.getMetrics();
    List<Metrics> metricsTmp = new ArrayList<>(metrics.size());
    for (Metrics metric : metrics) {
        JsonElement jsonElement = GSON.toJsonTree(metric);
        jsonElement = replaceSpecialValue(jsonElement, configmap);
        metric = GSON.fromJson(jsonElement, Metrics.class);
        metricsTmp.add(metric);
    }
    job.setMetrics(metricsTmp);
}
Also used : JsonObject(com.google.gson.JsonObject) CommonConstants(com.usthe.common.util.CommonConstants) Iterator(java.util.Iterator) GsonUtil(com.usthe.common.util.GsonUtil) Configmap(com.usthe.common.entity.job.Configmap) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) JsonElement(com.google.gson.JsonElement) JsonArray(com.google.gson.JsonArray) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) SpringContextHolder(com.usthe.collector.util.SpringContextHolder) Job(com.usthe.common.entity.job.Job) Gson(com.google.gson.Gson) Map(java.util.Map) MetricsTaskDispatch(com.usthe.collector.dispatch.MetricsTaskDispatch) AesUtil(com.usthe.common.util.AesUtil) JsonPrimitive(com.google.gson.JsonPrimitive) Metrics(com.usthe.common.entity.job.Metrics) Metrics(com.usthe.common.entity.job.Metrics) Configmap(com.usthe.common.entity.job.Configmap) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList)

Aggregations

Job (com.usthe.common.entity.job.Job)6 Metrics (com.usthe.common.entity.job.Metrics)6 Slf4j (lombok.extern.slf4j.Slf4j)4 WheelTimerTask (com.usthe.collector.dispatch.timer.WheelTimerTask)3 CollectRep (com.usthe.common.entity.message.CollectRep)3 CommonConstants (com.usthe.common.util.CommonConstants)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Timeout (com.usthe.collector.dispatch.timer.Timeout)2 Configmap (com.usthe.common.entity.job.Configmap)2 AesUtil (com.usthe.common.util.AesUtil)2 LinkedList (java.util.LinkedList)2 Data (lombok.Data)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 AviatorEvaluator (com.googlecode.aviator.AviatorEvaluator)1 Expression (com.googlecode.aviator.Expression)1