HttpSequenceServiceImpl.java
3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.ecar.apm.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ecar.apm.dao.HttpSequenceLogMapper;
import com.ecar.apm.dao.HttpSequenceMapper;
import com.ecar.apm.model.HttpSequence;
import com.ecar.apm.model.HttpSequenceLog;
import com.ecar.apm.model.HttpSystem;
import com.ecar.apm.model.MonitorFrequency;
import com.ecar.apm.service.HttpSequenceService;
import com.ecar.apm.util.GuidGenerator;
import com.ecar.apm.util.MathUtil;
import com.github.pagehelper.StringUtil;
@Service
public class HttpSequenceServiceImpl implements HttpSequenceService{
@Autowired
private HttpSequenceMapper httpSequenceMapper;
@Autowired
private HttpSequenceLogMapper httpSequenceLogMapper;
@Override
public HttpSequence getByGuid(String guid){
return httpSequenceMapper.getByGuid(guid);
}
@Override
public void archived(String guid){
httpSequenceMapper.archived(guid);
}
@Override
public void updateEnabled(HttpSequence httpSequence){
httpSequenceMapper.updateEnabled(httpSequence);
}
@Override
public void insert(HttpSequence httpSequence){
if(StringUtil.isEmpty(httpSequence.getGuid())){
httpSequence.setGuid(GuidGenerator.generate());
}
httpSequenceMapper.insert(httpSequence);
}
@Override
public void update(HttpSequence httpSequence){
httpSequenceMapper.update(httpSequence);
}
@Override
public List<Map<String, Object>> getMonitorList(){
List<Map<String, Object>> list = httpSequenceMapper.selectMonitorList();
for(Map<String,Object> item : list){
item.put("frequency", MonitorFrequency.valueOf(item.get("frequency").toString()).getLabel());
item.put("type", HttpSequence.getMonitorTypeName(String.valueOf(item.get("type"))));
String guid = String.valueOf(item.get("guid"));
//启动监控
if((boolean)item.get("enabled")){
//平均响应时间
Object avgCostTime = httpSequenceLogMapper.selectAvgCostTimeByPguid(guid);
item.put("avgCostTime", avgCostTime);
//最近一次请求状态
Object recentStatus = httpSequenceLogMapper.selectRecentStatusByPguid(guid);
if(recentStatus == null){
item.put("status", "未监控");
item.put("textColor", "text-muted");
}else{
item.put("status", (boolean)recentStatus == true ? "正常" : "故障");
item.put("textColor", (boolean)recentStatus == true ? "text-green" : "text-red");
}
//可用率
List<Map<String, Object>> usabilityList = httpSequenceLogMapper.selectUsabilityByPguid(guid);
long count = 0;
long uCount = 0;
for(Map<String,Object> u : usabilityList){
count += (long)u.get("count");
if((boolean)u.get("status")){
uCount+=(long)u.get("count");
}
}
item.put("usability", MathUtil.percent(uCount, count));
}else{
//未启动
item.put("status", "未监控");
item.put("textColor", "text-muted");
item.put("usability", "0%");
item.put("avgCostTime", "0");
}
}
return list;
}
@Override
public List<Map<String, Object>> getLogByGuid(String guid){
List<Map<String, Object>> list = httpSequenceLogMapper.selectLogByPguid(guid);
for(Map<String,Object> item : list){
}
return list;
}
@Override
public boolean addHttpSystem(String group){
HttpSystem httpSystem = new HttpSystem();
httpSystem.setName(group);
try{
httpSequenceMapper.insertSystem(httpSystem);
return true;
}catch(Exception e){
return false;
}
}
@Override
public List<HttpSystem> getAllSystem(){
return httpSequenceMapper.selectAllSystem();
}
@Override
public void insertLog(HttpSequenceLog httpSequenceLog){
httpSequenceLogMapper.insert(httpSequenceLog);
}
@Override
public void deleteLog(String pguid){
httpSequenceLogMapper.delete(pguid);
}
@Override
public void cleanLog(int day){
httpSequenceLogMapper.cleanLogByDay(day);
}
}