21
21
import javax .servlet .http .HttpServletRequest ;
22
22
import javax .servlet .http .HttpServletResponse ;
23
23
import java .io .*;
24
- import java .util .Collections ;
25
- import java .util .HashMap ;
26
- import java .util .List ;
27
- import java .util .Map ;
24
+ import java .util .*;
28
25
import java .util .logging .Logger ;
26
+ import java .util .stream .Collectors ;
29
27
30
28
/**
31
29
* zhangchang
@@ -71,7 +69,7 @@ public Map isLogin(String kotoken) {
71
69
if (StringUtils .hasText (kotoken )) {
72
70
if (kotoken .equals (Context .getConfig ().getStaticToken ())) {
73
71
checkLogin = true ;
74
- }else {
72
+ } else {
75
73
checkLogin = KoUtil .isLogin (kotoken );
76
74
}
77
75
}
@@ -81,7 +79,7 @@ public Map isLogin(String kotoken) {
81
79
82
80
83
81
@ GetMapping
84
- public void index (String kotoken ,String test , HttpServletResponse response , HttpServletRequest request ) {
82
+ public void index (String kotoken , String test , HttpServletResponse response , HttpServletRequest request ) {
85
83
if (!Context .getConfig ().getEnable ()) {
86
84
return ;
87
85
}
@@ -121,14 +119,14 @@ public void index(String kotoken,String test, HttpServletResponse response, Http
121
119
line = line .replace ("UIKitJs" , uiKitJsText );
122
120
} else if (line .indexOf ("MetricFlowJs" ) > -1 ) {
123
121
line = line .replace ("MetricFlowJs" , metricFlowJsText );
124
- }else if (line .indexOf ("jQueryJs" ) > -1 ) {
122
+ } else if (line .indexOf ("jQueryJs" ) > -1 ) {
125
123
line = line .replace ("jQueryJs" , jQueryJsText );
126
- }else if (line .indexOf ("uiKitIconsJs" ) > -1 ) {
124
+ } else if (line .indexOf ("uiKitIconsJs" ) > -1 ) {
127
125
line = line .replace ("uiKitIconsJs" , uiKitIconsJs );
128
- }else if (line .indexOf ("staticTokenVisitValue" ) > -1 ) {
129
- line = line .replace ("staticTokenVisitValue" , staticTokenVisit + "" );
130
- }else if (line .indexOf ("staticTokenValue" ) > -1 ) {
131
- line = line .replace ("staticTokenValue" , "'" + kotoken + "'" );
126
+ } else if (line .indexOf ("staticTokenVisitValue" ) > -1 ) {
127
+ line = line .replace ("staticTokenVisitValue" , staticTokenVisit + "" );
128
+ } else if (line .indexOf ("staticTokenValue" ) > -1 ) {
129
+ line = line .replace ("staticTokenValue" , "'" + kotoken + "'" );
132
130
}
133
131
stringBuilder .append (line + "\n " );
134
132
}
@@ -139,6 +137,7 @@ public void index(String kotoken,String test, HttpServletResponse response, Http
139
137
e .printStackTrace ();
140
138
}
141
139
}
140
+
142
141
private String getResourceText (String fileName ) {
143
142
ClassPathResource classPathResource = new ClassPathResource (fileName );
144
143
try (InputStream inputStream = classPathResource .getInputStream ();
@@ -229,9 +228,9 @@ public MethodInfo getTree(String methodName) {
229
228
@ GetMapping ("/getMethodsByExceptionId" )
230
229
@ ResponseBody
231
230
@ Auth
232
- public List <ExceptionInfo > getMethodsByExceptionId (String exceptionId ,String message ) {
231
+ public List <ExceptionInfo > getMethodsByExceptionId (String exceptionId , String message ) {
233
232
GraphService graphService = GraphService .getInstance ();
234
- List <ExceptionInfo > exceptionInfos = graphService .getExceptionInfos (exceptionId ,message );
233
+ List <ExceptionInfo > exceptionInfos = graphService .getExceptionInfos (exceptionId , message );
235
234
return exceptionInfos ;
236
235
}
237
236
@@ -257,12 +256,13 @@ public boolean updateConfig(@RequestBody DefaultConfig config) {
257
256
}
258
257
return true ;
259
258
}
259
+
260
260
@ PostMapping ("/updateClass" )
261
261
@ ResponseBody
262
262
@ Auth
263
- public Map updateClass (@ RequestParam ("classFile" ) MultipartFile classFile ,String className ) {
263
+ public Map updateClass (@ RequestParam ("classFile" ) MultipartFile classFile , String className ) {
264
264
Map map = new HashMap ();
265
- if (classFile == null || classFile .isEmpty ()) {
265
+ if (classFile == null || classFile .isEmpty ()) {
266
266
map .put ("state" , 0 );
267
267
map .put ("message" , "文件不能为空" );
268
268
return map ;
@@ -288,15 +288,15 @@ public Map updateClass(@RequestParam("classFile") MultipartFile classFile,String
288
288
map .put ("message" , "请确认类名是否正确" );
289
289
return map ;
290
290
}
291
- file = uploadFile (classFile .getBytes (),filename [0 ]);
291
+ file = uploadFile (classFile .getBytes (), filename [0 ]);
292
292
} catch (IOException e ) {
293
293
log .severe ("Error class file!" );
294
294
map .put ("state" , 0 );
295
295
map .put ("message" , "无法解析文件" );
296
296
return map ;
297
297
}
298
298
final ClassService classService = ClassService .getInstance ();
299
- classService .updateClass (className ,file .getAbsolutePath ());
299
+ classService .updateClass (className , file .getAbsolutePath ());
300
300
file .deleteOnExit ();
301
301
302
302
map .put ("state" , 1 );
@@ -305,19 +305,18 @@ public Map updateClass(@RequestParam("classFile") MultipartFile classFile,String
305
305
}
306
306
307
307
308
-
309
- private static File uploadFile (byte [] file ,String fileName ) throws IOException {
308
+ private static File uploadFile (byte [] file , String fileName ) throws IOException {
310
309
FileOutputStream out = null ;
311
310
try {
312
- File targetFile = File .createTempFile (fileName , ".class" , new File (System .getProperty ("java.io.tmpdir" )));
311
+ File targetFile = File .createTempFile (fileName , ".class" , new File (System .getProperty ("java.io.tmpdir" )));
313
312
out = new FileOutputStream (targetFile .getAbsolutePath ());
314
313
out .write (file );
315
314
out .flush ();
316
315
return targetFile ;
317
316
} catch (Exception e ) {
318
317
log .severe ("" + e );
319
- }finally {
320
- if (out !=null ){
318
+ } finally {
319
+ if (out != null ) {
321
320
out .flush ();
322
321
out .close ();
323
322
}
@@ -342,6 +341,7 @@ public HeapMemoryInfo getHeapMemoryInfo() {
342
341
HeapMemoryInfo heapMemoryInfo = usageService .getHeapMemoryInfo ();
343
342
return heapMemoryInfo ;
344
343
}
344
+
345
345
@ GetMapping ("/getPhysicalMemoryInfo" )
346
346
@ ResponseBody
347
347
@ Auth
@@ -363,9 +363,20 @@ public boolean clearData() {
363
363
@ GetMapping ("/getThreadsInfo" )
364
364
@ ResponseBody
365
365
@ Auth
366
- public List getThreadsInfo () {
366
+ public Map getThreadsInfo (String state ) {
367
367
ThreadUsageService usageService = ThreadUsageService .newInstance ();
368
368
List <ThreadInfo > threads = usageService .getThreads ();
369
- return threads ;
369
+ threads = threads .stream ().sorted (Comparator .comparing (ThreadInfo ::getState )).collect (Collectors .toList ());
370
+
371
+ Map <String , Long > stateCounting = threads .stream ().collect (Collectors .groupingBy (ThreadInfo ::getState , Collectors .counting ()));
372
+ stateCounting .put ("all" ,(long )threads .size ());
373
+
374
+ Map map = new HashMap ();
375
+ map .put ("statistics" , stateCounting );
376
+ if (StringUtils .hasText (state )) {
377
+ threads = threads .stream ().filter (a -> a .getState ().equals (state )).collect (Collectors .toList ());
378
+ }
379
+ map .put ("threads" , threads );
380
+ return map ;
370
381
}
371
382
}
0 commit comments