Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIOT-GDA-02-006: Create module - SystemMemUtilTask #46

Open
labbenchstudios opened this issue Jul 15, 2020 · 0 comments
Open

PIOT-GDA-02-006: Create module - SystemMemUtilTask #46

labbenchstudios opened this issue Jul 15, 2020 · 0 comments
Labels
exercise New feature to implement as an exercise
Milestone

Comments

@labbenchstudios
Copy link
Contributor

labbenchstudios commented Jul 15, 2020

Description

  • Create the SystemMemUtilTask module and implement the functionality to retrieve JVM memory utilization.

Review the README

  • Please see README.md for further information on, and use of, this content.
  • License for embedded documentation and source codes: PIOT-DOC-LIC

Estimated effort may vary greatly

  • The estimated level of effort for this exercise shown in the 'Estimate' section below is a very rough approximation. The actual level of effort may vary greatly depending on your development and test environment, experience with the requisite technologies, and many other factors.

Actions

NOTE: The implementation examples depicted here are only one way to implement the requirements listed. Your own implementation may vary of course.

  • Within the programmingtheiot.gda.system package, create a new Java class named SystemMemUtilTask. This should be derived from BaseSystemUtilTask.
  • Import statements should include the following (you may choose to include the Logger for debugging):
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;

import java.util.logging.Logger;

import programmingtheiot.common.ConfigConst;
  • Add in an override for the inherited template method getTelemetryValue(). It will retrieve JVM memory utilization and return the value as a float. Use the @Override annotation and be sure to remove the abstract keyword if you're copying / pasting from the base class. You'll have to perform a simple calculation to derive this, as follows:
MemoryUsage memUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
double memUtil = ((double) memUsage.getUsed() / (double) memUsage.getMax()) * 100.0d;
  • Log the value, then return it as a float (once the value is calculated, for our purposes, it's OK to cast from double to float)
  • Here's one way to implement these requirements (your own implementation may vary from this). Also note that this may not work with all OSes:
public SystemMemUtilTask()
{
	super(ConfigConst.NOT_SET, ConfigConst.DEFAULT_TYPE_ID);
}

@Override
public float getTelemetryValue()
{
	MemoryUsage memUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
	double memUsed = (double) memUsage.getUsed();
	double memMax  = (double) memUsage.getMax();
	
	_Logger.fine("Mem used: " + memUsed + "; Mem Max: " + memMax);
	
	double memUtil = (memUsed / memMax) * 100.0d;
	
	return (float) memUtil;
}

Estimate

  • Small

Tests

  • Unit tests (in ./src/test/java/programmingtheiot/part01/unit)
    • Run ./system/SystemMemUtilTaskTest. The testGetTelemetryValue() unit test should pass while logging values between 0.0% and 100.0%.
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-004 PIOT-GDA-02-004: Create module - SystemMemUtilTask Jul 15, 2020
@labbenchstudios labbenchstudios self-assigned this Jul 15, 2020
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-004: Create module - SystemMemUtilTask PIOT-GDA-02-005: Create module - SystemMemUtilTask Jul 19, 2020
@labbenchstudios labbenchstudios removed their assignment Aug 17, 2020
@labbenchstudios labbenchstudios transferred this issue from programming-the-iot/java-components Sep 7, 2020
@labbenchstudios labbenchstudios added the exercise New feature to implement as an exercise label Sep 7, 2020
@labbenchstudios labbenchstudios added this to the Chapter 02 milestone Sep 7, 2020
@labbenchstudios labbenchstudios changed the title PIOT-GDA-02-005: Create module - SystemMemUtilTask PIOT-GDA-02-006: Create module - SystemMemUtilTask Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exercise New feature to implement as an exercise
Projects
Programming the IoT - Exercises Kanba...
  
Lab Module 02 - Edge Tier Apps
Development

No branches or pull requests

1 participant