This example demonstrates the use of Apama to monitor CPU and memory usage and calculate what percentage of the time the usage is over 70%. It reports it to the cloud in 5-minute cycles if this percentage is over 70% or once per hour otherwise.
Note that we are not reporting the average CPU and memory usage, but the percentage of time for which CPU or memory usage breached the threshold.
Copyright (c) 2022 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG
Follow the setup and configuration instructions in the README file in the parent directory before running this sample.
Ensure that the thin-edge device has Python 3 installed, that it is on your
$path
, and that you have installed psutil
and paho-mqtt
:
sudo apt-get install python3
pip install psutil
pip install paho-mqtt
Zip the project located in the ResourceMonitoring
directory of this repository. Note that you must use the zip format and not some other compression utility. Then use your tenant to deploy the zipped project to your thin-edge device by following these steps:
resource-monitor.py.py
script in the ResourceMonitoring
directory to the
/etc/tedge/apama/project
directory on the thin-edge device. Run the resource-monitor.py script from this directory using Python 3
with the command python3 resource-monitor.py
.tedge mqtt sub 'tedge/measurements'
.Note: You may need to wait up to an hour for this example to publish a message to the
tedge/measurements
channel. If you want to speed this up, you could alter the thresholds, intervals or CPU and memory usage variables accordingly.