diff --git a/API-documentation-tools-functions/monitor-mind-API-reference.md b/API-documentation-tools-functions/monitor-mind-API-reference.md new file mode 100644 index 00000000..44a73388 --- /dev/null +++ b/API-documentation-tools-functions/monitor-mind-API-reference.md @@ -0,0 +1,104 @@ +# Monitormind provides the following functionalities + +- **CPU Monitoring**: Real-time monitoring of CPU usage. +- **Memory Monitoring**: Track RAM and swap usage. +- **Process Tracking**: Monitor and display active system processes. +- **Real-Time Updates**: Frontend updates using polling to display the latest data. + +It does this by using the flask Advance Scheduler to schedule code to be executed whenever the client wants to monitor something. +Monitor mind also uses python system and process utilities (psutils) to retrieve information on running processes and system utilisation. + + +Monitormind also makes use of RESTAPI services which lets it interact the client's software using HTTP request such as GET, POST, PATCH AND HEAD. + + +# The api code or controller + +# starts by importing all necessary packages +from flask import Flask, render_template, jsonify +from flask_apscheduler import APScheduler + +# Import service modules +import services.cpu_service as cpu_service +import services.memory_service as memory_service + + + +# set configuration values. The APScheduler is used here to schedule job which will be executed whenever a get request is recived. +class Config: + SCHEDULER_API_ENABLED = True + + +# create app +app = Flask(__name__) +app.config.from_object(Config()) + +# initialize scheduler +scheduler = APScheduler() +# if you don't wanna use a config, you can set options here: +# scheduler.api_enabled = True +scheduler.init_app(app) +scheduler.start() + +# code bloc to display the home page. +@app.route('/') +def home(): + """Serve the homepage with system metrics.""" + return render_template('index.html') + + +# Code bloc to monitor cpu usage. It uses a get request and then displays data in Java Script Object Notation(JSON) +@app.route('/api/cpu') +def get_cpu(): + """API endpoint to get CPU usage.""" + timestamps, cpu_usage = cpu_service.get_cpu_usage_array() + return jsonify(timestamps=timestamps, cpu_usage=cpu_usage) + +# RAM and swap tracking code +@app.route('/api/memory') +def get_memory(): + """API endpoint to get memory (RAM and Swap) usage.""" + ram_usage, swap_usage = memory_service.get_memory_usage() + return jsonify(ram_usage_history=ram_usage, swap_usage_history=swap_usage) + + +# code bloc to monitor and display system process +@app.route('/api/process') +def get_processes(): + """API endpoint to get active processes.""" + active_processes = process_service.get_active_processes + return jsonify(active_processes=active_processes) + +# Update data and display latest data +@app.route('/api/update') +def updates(): + """API endpoint to geet latest updates" + latest_updates =update_service.get_latest_update + return jsonify(latest_update=latest_updates) + + +@scheduler.task('interval', id='cpu_get_data', seconds=15, misfire_grace_time=1000) +def actualise_cpu_data(): + cpu_service.calculate_cpu_usage() + + +if __name__ == '__main__': + app.run(debug=True, port=2376) + + + +# How it works +# Example + +When a client wants types the url of monitormind on his machine,a +conection is first established between the client'computer and the +monitormind server then a http GET request is sent and the api executes +the bloc of code to display the home page by rendering the home page +html_template. The GEt request is responded and the api enables the monitormind home page is +then displayed on the clients srceen. +To check the cpu usage, the client clicks on cpu usage on the home screen, then a http GET reqest is sent which is taken care of by the api and cpu_usage is displayed on the client's screen. + +# Support + +If you have any questions or run into problems while using monitormind,you can contact monitormind developees at (https://github.com/ADORSYS-GIS/monitor-mind) + diff --git a/API-documentation-tools-functions/monitor-mind-brief.md b/API-documentation-tools-functions/monitor-mind-brief.md new file mode 100644 index 00000000..fd5a3d7b --- /dev/null +++ b/API-documentation-tools-functions/monitor-mind-brief.md @@ -0,0 +1,12 @@ +MonitorMind is an automated system monitoring tool designed to provide real-time insights into various system metrics such as CPU usage, RAM, Swap usage, and system processes. Developed as a Flask web application, MonitorMind utilizes Python's `psutil` library to gather system data, presenting it in a user-friendly web interface. + +Monitormind can be used to do the following; + +# 1.cpu monitoring: +Monitor mind can monitor the how the cpu of a computer is being used and return the info in a sinple form that is easy for users to read and understand. + +# 2. Memory and swap usage +Monitormind can actually be used to monitor memory usage by tracking how the memory is managed and how processes are broght into memory and temporarily copied to a disk after they have been ran for a while. + +# 3. system processes +Monitormind can also monitor and display all running processes in an that is user friendly. \ No newline at end of file diff --git a/API-documentation-tools-functions/monitor-mind-users-guide.md b/API-documentation-tools-functions/monitor-mind-users-guide.md new file mode 100644 index 00000000..255aa756 --- /dev/null +++ b/API-documentation-tools-functions/monitor-mind-users-guide.md @@ -0,0 +1,8 @@ +# Getting Started with Monitormind + +You just have to log into the dashboard using **URL** +Then choose what you want to monitormid to monitor for you by clicking on it. +Click on **CPU Monitoring** to get real-time monitoring of your CPU usage + Select **Memory Monitoring** To track and view infomatioin about your RAM and swap usage. +Select **Process Tracking** To monitor and display active system processes. +And to get latedt updates simply select **Real-Time Updates** on your monitormind home page \ No newline at end of file diff --git a/services/cpu_service.py b/services/cpu_service.py deleted file mode 100644 index aad8f812..00000000 --- a/services/cpu_service.py +++ /dev/null @@ -1,22 +0,0 @@ -import time - -import psutil -import services.time_service as ts - -fake_mem = {} - - -def _collect_cpu_usage(): - cpu_usage = psutil.cpu_percent(interval=1) - timestamp = ts.get_history_time() - return timestamp, cpu_usage - - -def get_cpu_usage_array(): - return [i for i in fake_mem.keys()], [i for i in fake_mem.values()] - - -def calculate_cpu_usage(): - """Calculate the current CPU usage as a percentage.""" - timestamp, cpu_usage = _collect_cpu_usage() - fake_mem[timestamp] = cpu_usage diff --git a/services/memory_service.py b/services/memory_service.py deleted file mode 100644 index 182c487d..00000000 --- a/services/memory_service.py +++ /dev/null @@ -1,4 +0,0 @@ -def get_memory_usage(): - """Get the current memory (RAM and Swap) usage as a percentage.""" - return [], [] - diff --git a/services/time_service.py b/services/time_service.py deleted file mode 100644 index c21150eb..00000000 --- a/services/time_service.py +++ /dev/null @@ -1,7 +0,0 @@ -from time import time - - -def get_history_time(): - """Return the history of time.""" - timestamp = time() - return int(timestamp * 1000)