Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit 9f5b387

Browse files
committed
Added some java doc and refactor a couple of methods
1 parent cf49114 commit 9f5b387

File tree

1 file changed

+68
-19
lines changed

1 file changed

+68
-19
lines changed

docker-monitoring-eparest/src/main/java/com/ca/docker/DataPoller.java

Lines changed: 68 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,14 @@ private String translate(final String in)
130130
}
131131

132132
/**
133-
* Deliver the metrics
133+
* This methos is responsible on delivering the metrics from
134+
* MetricFreeBundle
134135
*
135136
* @param mfb
136137
* @throws Exception
137138
*/
138139

139-
public void deliverMetrics(final MetricFeedBundle mfb) throws Exception
140+
private void deliverMetrics(final MetricFeedBundle mfb) throws Exception
140141
{
141142
final String json = mfb.toString();
142143
final HttpURLConnection conn = (HttpURLConnection) dockerMonitor
@@ -181,7 +182,7 @@ private String getPayload(final InputStream is) throws Exception
181182
* @return
182183
* @throws Exception
183184
*/
184-
public MetricFeedBundle makeMetrics(final Object hci, String additionalPath)
185+
private MetricFeedBundle makeMetrics(final Object hci, String additionalPath)
185186
throws Exception
186187
{
187188
String basePath = null;
@@ -220,6 +221,15 @@ private void makeMetrics(MetricFeedBundle mfb, String basePath, Object hci)
220221

221222
}
222223

224+
/**
225+
* Isolate metric types. In case of Double, we will be printing a String
226+
* metrics as well as float metrics This is done because some of the %
227+
* calcualted metrics can make more sense with two precesion levels
228+
*
229+
* @param metricPath
230+
* @param dataObj
231+
* @param mfb
232+
*/
223233
private void makeMetric(final String metricPath,
224234
final Object dataObj,
225235
final MetricFeedBundle mfb)
@@ -263,6 +273,13 @@ private void makeMetric(final String metricPath,
263273
}
264274
}
265275

276+
/**
277+
* Reads the json data from dockerHostInfo String and populate this to
278+
* HostInfo object
279+
*
280+
* @param dockerHostInfo
281+
* @return
282+
*/
266283
private HostInfo readHostInfoJsonFromUrl(String dockerHostInfo)
267284
{
268285
// TODO Auto-generated method stub
@@ -288,6 +305,8 @@ private HostInfo readHostInfoJsonFromUrl(String dockerHostInfo)
288305
}
289306

290307
/**
308+
* Read Containers information and store it under Arraylist of Container.
309+
* This also calculates/determine up/down container
291310
*
292311
* @param relativePath
293312
* @return an ArrayList of Containers
@@ -334,6 +353,12 @@ private ArrayList<Container> readContainerInfoJsonFromUrl(String relativePath)
334353

335354
}
336355

356+
/**
357+
* Populate the container raw data inside ContainerStatInfo
358+
*
359+
* @param id
360+
* @param names
361+
*/
337362
private void resetContainerResourceStats(String id, String names)
338363
{
339364
// TODO Auto-generated method stub
@@ -372,6 +397,12 @@ private void getContainerResourceStats(String id, String names)
372397
readStatInfoJsonFromUrl(resourcePath, names);
373398
}
374399

400+
/**
401+
* Read container Stat information
402+
*
403+
* @param resourcePath
404+
* @param names
405+
*/
375406
private void readStatInfoJsonFromUrl(String resourcePath, String names)
376407
{
377408
try
@@ -382,8 +413,8 @@ private void readStatInfoJsonFromUrl(String resourcePath, String names)
382413
ContainerStatInfo csi = new ContainerStatInfo();
383414
csi.setCpupercentage(this.getCPUPercentage(node, names));
384415
csi.setMemorypercentage(this.getMemoryPercentage(node, names));
385-
csi.setMemporyUsage(this.getMemoryUsage(node));
386-
csi.setTotalMemory(this.getTotalMemory(node));
416+
csi.setMemporyUsage(this.getMemoryData(node, "usage"));
417+
csi.setTotalMemory(this.getMemoryData(node, "limit"));
387418
csi.setNetworkData(getNetWorkData(node));
388419

389420
csi.populateMetricData(csi);
@@ -401,6 +432,12 @@ private void readStatInfoJsonFromUrl(String resourcePath, String names)
401432
return;
402433
}
403434

435+
/**
436+
* Extract data related to Network
437+
*
438+
* @param node
439+
* @return
440+
*/
404441
private NetworkStatInfo getNetWorkData(JsonNode node)
405442
{
406443
// TODO Auto-generated method stub
@@ -442,30 +479,33 @@ private NetworkStatInfo getNetWorkData(JsonNode node)
442479
return null;
443480
}
444481

445-
private Long getTotalMemory(JsonNode node)
446-
{
447-
JsonNode stats = node.get("memory_stats");
448-
if (stats != null)
449-
{
450-
Long limit = ((Double) getValue("limit", stats)).longValue();
451-
452-
return limit / 1000000;
453-
}
454-
return null;
455-
}
482+
/**
483+
* Extract Memory informtaion from Json node based on attr in MB
484+
*
485+
* @param node
486+
* @param attr
487+
* @return
488+
*/
456489

457-
private Long getMemoryUsage(JsonNode node)
490+
private Long getMemoryData(JsonNode node, String attr)
458491
{
459492

460493
JsonNode stats = node.get("memory_stats");
461494
if (stats != null)
462495
{
463-
Long usage = ((Double) getValue("usage", stats)).longValue();
464-
return usage / 1000000;
496+
Long usage = ((Double) getValue(attr, stats)).longValue();
497+
return usage / (1024 * 1024);
465498
}
466499
return null;
467500
}
468501

502+
/**
503+
* This calculates the CPU Utilization (%)
504+
*
505+
* @param node
506+
* @param containerName
507+
* @return
508+
*/
469509
private Double getCPUPercentage(JsonNode node, String containerName)
470510
{
471511

@@ -574,6 +614,15 @@ private Object getValue(String propName, JsonNode node)
574614
return null;
575615
}
576616

617+
/**
618+
* In case of stats query, readfully is set to false as we just want to read
619+
* that snapshot data and don't want to read the entire content
620+
*
621+
* @param urlString
622+
* @param readfully
623+
* @return
624+
* @throws Exception
625+
*/
577626
private String readUrl(String urlString, Boolean readfully)
578627
throws Exception
579628
{

0 commit comments

Comments
 (0)