Create a new Python module named SystemCpuUtilTask with class name SystemCpuUtilTask. This will be in the ./programmingtheiot/cda/system package.
NOTE: The downloaded code repository will a shell implementation of this module for you to work with, or you can create your own if you'd prefer.
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.
If not already part of the template class, import the psutil library and ConfigConst (in addition to logging and BaseSystemUtilTask):
import logging
import psutil
import programmingtheiot.common.ConfigConst as ConfigConst
from programmingtheiot.cda.system.BaseSystemUtilTask import BaseSystemUtilTask
- Create a class within the module named `SystemCpuUtilTask`. This will extend `BaseSystemUtilTask`.
- In the constructor, add the following:
`super(SystemCpuUtilTask, self).__init__(name = ConfigConst.CPU_UTIL_NAME, typeID = ConfigConst.CPU_UTIL_TYPE)`
- BaseSystemUtilTask defines a template method named `getTelemetryValue(self) -> float:`. Implement this in `SystemCpuUtilTask` as follows:
- `return psutil.cpu_percent()`
```python
def __init__(self):
super(SystemCpuUtilTask, self).__init__(name = ConfigConst.CPU_UTIL_NAME, typeID = ConfigConst.CPU_UTIL_TYPE)
def getTelemetryValue(self) -> float:
return psutil.cpu_percent()
Estimate
Small
Tests
Unit tests (in ./src/test/python/programmingtheiot/part01/unit)
Run ./system/SystemCpuUtilTaskTest. The testGetTelemetryValue() unit test should pass.
Description
SystemCpuUtilTask
with class nameSystemCpuUtilTask
. This will be in the ./programmingtheiot/cda/system package.Review the README
Estimated effort may vary greatly
Actions
NOTE: The implementation examples depicted here are only one way to implement the requirements listed. Your own implementation may vary of course.
psutil
library andConfigConst
(in addition tologging
andBaseSystemUtilTask
):import programmingtheiot.common.ConfigConst as ConfigConst
from programmingtheiot.cda.system.BaseSystemUtilTask import BaseSystemUtilTask
Estimate
Tests
testGetTelemetryValue()
unit test should pass.