8
8
import org .apache .logging .log4j .Logger ;
9
9
import org .json .JSONArray ;
10
10
import org .json .JSONObject ;
11
+ import org .json .simple .parser .JSONParser ;
12
+ import org .json .simple .parser .ParseException ;
11
13
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
12
14
import org .springframework .context .annotation .Scope ;
13
15
import org .springframework .stereotype .Service ;
@@ -64,6 +66,7 @@ public String[] containersJson(boolean all, int limit, String filters) {
64
66
.queryString ("all" , all )
65
67
.queryString ("limit" , limit )
66
68
.queryString ("filters" , filters )
69
+ .queryString ("size" ,true )
67
70
.asJson ();
68
71
returnArray [0 ] = String .valueOf (containersResponse .getStatus ());
69
72
returnArray [1 ] = containersResponse .getHeaders ().toString ();
@@ -75,6 +78,33 @@ public String[] containersJson(boolean all, int limit, String filters) {
75
78
}
76
79
}
77
80
81
+ /**
82
+ * https://docs.docker.com/engine/api/v1.39/#operation/SystemInfo
83
+ */
84
+ public String [] getSystemInformation () {
85
+ String [] returnArray = new String [3 ];
86
+ JSONParser parser = new JSONParser ();
87
+ org .json .JSONObject body = new org .json .JSONObject ();
88
+ Object obj = null ;
89
+ try {
90
+ HttpResponse <JsonNode > systemInfo = Unirest .get (DOCKER_SOCKET +"/info" ).asJson ();
91
+ obj = parser .parse (systemInfo .getBody ().toString ());
92
+ org .json .simple .JSONObject jsonObject = (org .json .simple .JSONObject ) obj ;
93
+ body .put ("Containers" ,jsonObject .get ("Containers" ) );
94
+ body .put ("ContainersRunning" ,jsonObject .get ("ContainersRunning" ));
95
+ body .put ("ContainersPaused" ,jsonObject .get ("ContainersPaused" ));
96
+ body .put ("ContainersStopped" ,jsonObject .get ("ContainersStopped" ));
97
+ body .put ("Images" ,jsonObject .get ("Images" ));
98
+ body .put ("MemTotal" ,jsonObject .get ("MemTotal" ));
99
+ returnArray [0 ] = String .valueOf (systemInfo .getStatus ());
100
+ returnArray [1 ] = systemInfo .getHeaders ().toString ();
101
+ returnArray [2 ] = body .toString ();
102
+ return returnArray ;
103
+ } catch ( NullPointerException | ParseException | org .json .JSONException | UnirestException e ) {
104
+ logger .error ("Cannot connect to the server." );
105
+ return ReturnErrors ();
106
+ }
107
+ }
78
108
/**
79
109
* https://docs.docker.com/engine/api/v1.39/#operation/ContainerList
80
110
*/
@@ -89,7 +119,7 @@ public String[] containersIDJson(String id) {
89
119
String [] returnArray = new String [3 ];
90
120
try {
91
121
HttpResponse <JsonNode > containersResponse = Unirest .get (DOCKER_SOCKET + "/containers/" + id + "/json" )
92
- .header ("accept" , "application/json" ).header ("Content-Type" , "application/json" ).asJson ();
122
+ .header ("accept" , "application/json" ).queryString ( "size" , true ). header ("Content-Type" , "application/json" ).asJson ();
93
123
returnArray [0 ] = String .valueOf (containersResponse .getStatus ());
94
124
returnArray [1 ] = containersResponse .getHeaders ().toString ();
95
125
returnArray [2 ] = containersResponse .getBody ().toString ();
@@ -416,19 +446,4 @@ public String[] execStart(String id) {
416
446
}
417
447
}
418
448
419
-
420
- public String shouldReturnStatusOkay () {
421
- HttpResponse <JsonNode > japierdole = null ;
422
- try {
423
- japierdole = Unirest .get (" http://192.168.1.55:2137/containers/json" )
424
- .header ("accept" , "application/json" ).header ("Content-Type" , "application/json" )
425
- .queryString ("apiKey" , "123" ).asJson ();
426
- } catch (Exception e ) {
427
- System .out .println (e );
428
- }
429
- System .out .println (japierdole .getStatus ());
430
- JSONArray jsonObj = new JSONArray (japierdole .getBody ().toString ());
431
- System .out .println (jsonObj .getJSONObject (0 ).getString ("Id" ));
432
- return japierdole .getBody ().toString ();
433
- }
434
449
}
0 commit comments