|
@@ -1,13 +1,21 @@
|
|
package com.jjt.task;
|
|
package com.jjt.task;
|
|
|
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import com.jjt.biz.domain.BizObj;
|
|
import com.jjt.biz.service.IBizObjMetricsDataService;
|
|
import com.jjt.biz.service.IBizObjMetricsDataService;
|
|
|
|
+import com.jjt.biz.service.IBizObjService;
|
|
import com.jjt.biz.service.IPinpointService;
|
|
import com.jjt.biz.service.IPinpointService;
|
|
|
|
+import com.jjt.biz.service.IPrometheusService;
|
|
|
|
+import com.jjt.biz.vo.AgentVO;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 定时任务调度测试
|
|
* 定时任务调度测试
|
|
@@ -19,7 +27,11 @@ public class CleanTask {
|
|
@Resource
|
|
@Resource
|
|
private IBizObjMetricsDataService dataService;
|
|
private IBizObjMetricsDataService dataService;
|
|
@Resource
|
|
@Resource
|
|
- private IPinpointService pinpointService;
|
|
|
|
|
|
+ private IPinpointService ppService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IPrometheusService pmService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IBizObjService objService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 清理历史数据
|
|
* 清理历史数据
|
|
@@ -34,8 +46,30 @@ public class CleanTask {
|
|
/**
|
|
/**
|
|
* 清理pinpoint失效agent
|
|
* 清理pinpoint失效agent
|
|
*/
|
|
*/
|
|
- public void ppAgent() {
|
|
|
|
-// dataService.clean(date);
|
|
|
|
|
|
+ public void agent() {
|
|
|
|
+ String exp = "kube_pod_info {namespace=\"default\",exported_pod=~\"${instance}\"}";
|
|
|
|
+ String findKey = "exported_pod";
|
|
|
|
+ BizObj queryObj = new BizObj();
|
|
|
|
+ queryObj.setObjType("1");
|
|
|
|
+ objService.selectBizObjList(new BizObj()).forEach(obj -> {
|
|
|
|
+ String instance = obj.getObjAddr();
|
|
|
|
+ String str = exp.replace("${instance}", instance + ".*");
|
|
|
|
+ JSONObject jsonObject = pmService.find(str);
|
|
|
|
+ List<String> existsAgentIds = new ArrayList<>();
|
|
|
|
+ if (jsonObject != null) {
|
|
|
|
+ JSONArray metric = jsonObject.getByPath("data.result", cn.hutool.json.JSONArray.class);
|
|
|
|
+ for (int i = 0; i < metric.size(); i++) {
|
|
|
|
+ String agentId = metric.getJSONObject(i).getByPath("metric." + findKey, String.class);
|
|
|
|
+ existsAgentIds.add(agentId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<AgentVO> agents = ppService.agentList(instance);
|
|
|
|
+ for (AgentVO vo : agents) {
|
|
|
|
+ if (!existsAgentIds.contains(vo.getAgentId())) {
|
|
|
|
+ ppService.removeAgent(instance, vo.getAgentId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|