2023-06-30 12:33:27 +00:00
|
|
|
# About
|
|
|
|
|
|
|
|
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/) [![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/) [![AGPL License](https://img.shields.io/badge/license-AGPL-blue.svg)](http://www.gnu.org/licenses/agpl-3.0)
|
|
|
|
|
|
|
|
```mermaid
|
|
|
|
graph LR
|
|
|
|
Webpage[Web page] <--Flask--> Server[Server]
|
|
|
|
Server <-- Push agent and execute --> Client((Client))
|
2023-07-03 13:06:50 +00:00
|
|
|
Server[Server] <----> Client2((Client2))
|
|
|
|
Server[Server] <----> Client3((Client3))
|
2023-06-30 12:33:27 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Simple monitoring script.
|
|
|
|
It will push an agent (agent.py) on remote servers to get info about ressources (CPU, Disk, Memories..)
|
|
|
|
And display it on a webpage.
|
|
|
|
|
2023-06-30 12:15:16 +00:00
|
|
|
# Screenshot
|
|
|
|
|
2023-06-30 12:16:07 +00:00
|
|
|
![ScreenShot](./image/Pymonit.PNG)
|
2023-06-30 12:15:16 +00:00
|
|
|
|
2023-06-30 11:40:48 +00:00
|
|
|
# Install
|
|
|
|
|
|
|
|
For Debian 12 (and more...)
|
|
|
|
|
|
|
|
On server :
|
|
|
|
```bash
|
|
|
|
apt install python3-flask python3-paramiko python3-psutil
|
|
|
|
```
|
|
|
|
|
2023-06-30 12:33:27 +00:00
|
|
|
On nodes (if needed):
|
2023-06-30 11:40:48 +00:00
|
|
|
```bash
|
|
|
|
apt install python3-psutil
|
|
|
|
```
|
|
|
|
|
|
|
|
For Debian < 12
|
|
|
|
```bash
|
|
|
|
pip3 install psutil flask paramiko
|
|
|
|
```
|
|
|
|
|
|
|
|
On nodes :
|
|
|
|
```bash
|
|
|
|
pip3 install psutil
|
|
|
|
```
|
|
|
|
If you prefer (recommended), you can run in an python env
|
|
|
|
|
|
|
|
```bash
|
|
|
|
apt install python3-venv
|
|
|
|
|
2023-06-30 12:33:27 +00:00
|
|
|
python3 -m venv Pymonit --system-site-packages
|
2023-06-30 11:40:48 +00:00
|
|
|
. /Pymonit/bin/activate
|
|
|
|
pip3 install psutil flask paramiko
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
# Configuration
|
|
|
|
|
|
|
|
## Clients
|
|
|
|
|
2023-06-30 12:33:27 +00:00
|
|
|
Add your clients in the python list in config.py:
|
2023-06-30 11:40:48 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
client = ['192.168.0.1','server.local','server.mydns']
|
|
|
|
```
|
|
|
|
|
|
|
|
## Generate keys for connection
|
|
|
|
|
|
|
|
Becarrefull, avoid using a root user to start application and connect to client.
|
|
|
|
Use a dedicated user.
|
|
|
|
|
|
|
|
On server, generate a pair of key :
|
|
|
|
```bash
|
|
|
|
ssh-keygen -b 2048 -t rsa
|
|
|
|
```
|
|
|
|
|
|
|
|
And push the public key in your clients :
|
|
|
|
|
|
|
|
```bash
|
|
|
|
ssh-copy-id -i <home_user>/.ssh/id_rsa.pub <user>@<client>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Configuration on application
|
|
|
|
|
2023-06-30 12:33:27 +00:00
|
|
|
You have to report these info on config.py :
|
2023-06-30 11:40:48 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
class ssh_conf:
|
|
|
|
port = 22
|
|
|
|
username = '<user>'
|
|
|
|
password ='<home_user>/.ssh/id_rsa.pub'
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
For testing purpose, but still not recommended, you can use a password in configuration file.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
class ssh_conf:
|
|
|
|
port = 22
|
|
|
|
username = '<user>'
|
|
|
|
password ='<password>'
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## Flask configuration
|
2023-06-30 12:33:27 +00:00
|
|
|
Configure the flask configuration according to your needs (port,host,...) in config.py
|
2023-06-30 11:40:48 +00:00
|
|
|
```bash
|
|
|
|
class flask_conf:
|
|
|
|
port = 8090
|
|
|
|
host = "0.0.0.0"
|
2023-07-02 17:44:37 +00:00
|
|
|
thread = True
|
2023-06-30 11:40:48 +00:00
|
|
|
debug = False
|
|
|
|
reloader = False
|
|
|
|
```
|
2023-07-02 17:44:37 +00:00
|
|
|
NB: Let thread = True, else this will take a time to switch from node to another node
|
2023-06-30 11:40:48 +00:00
|
|
|
|
|
|
|
## Path configuration
|
|
|
|
```bash
|
|
|
|
class paths :
|
|
|
|
basedir = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
agent_path = basedir+'/agent.py'
|
|
|
|
remote_path = '/var/tmp/script.py'
|
|
|
|
```
|
|
|
|
|
|
|
|
remote_path : the location where the agent will be pushed and execute.
|
|
|
|
Take care that your used is able to write and execute in this location.
|
|
|
|
|
|
|
|
## Systemctl (optional)
|
|
|
|
|
|
|
|
To easy start, stop and restart application, you can use the monit.service template.
|
|
|
|
|
|
|
|
Replace the path according to your system in :
|
|
|
|
|
|
|
|
```bash
|
|
|
|
[Unit]
|
|
|
|
Description= Monit service
|
|
|
|
After=multi-user.target
|
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
Restart=always
|
|
|
|
ExecStart=/usr/bin/python3 /application/path/app.py
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
```
|
|
|
|
|
|
|
|
Copy the file in your systemd folder :
|
|
|
|
|
|
|
|
```bash
|
|
|
|
|
|
|
|
cp ./monit.service /etc/systemd/system/
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Then you can start it :
|
|
|
|
```bash
|
|
|
|
systemctl start monit.service
|
|
|
|
```
|
|
|
|
To get it automaticaly start with your system:
|
|
|
|
```bash
|
|
|
|
systemctl enable monit.service
|
|
|
|
```
|
2023-07-03 08:13:22 +00:00
|
|
|
|
|
|
|
## Change log
|
|
|
|
|
|
|
|
v1 :
|
|
|
|
|
|
|
|
- [x] Create Agent:
|
|
|
|
- [x] CPU detail
|
|
|
|
- [x] Memory detail
|
|
|
|
- [x] Swap detail
|
|
|
|
|
|
|
|
- [x] Agent communication :
|
|
|
|
- [x] SSH using Python
|
|
|
|
- [x] Push and Run agents
|
|
|
|
- [x] Retrieve info
|
|
|
|
|
|
|
|
- [x] Interface:
|
|
|
|
- [x] Creation
|
|
|
|
- [x] Bootstap
|
|
|
|
- [x] Delete
|
|
|
|
|
|
|
|
v1.1
|
|
|
|
|
|
|
|
- [x] Adding Disk usage info
|
|
|
|
- [x] Get partitions
|
|
|
|
- [x] Get usage
|
|
|
|
|
|
|
|
- [x] Adding Network info:
|
|
|
|
- [x] Get interfaces
|
|
|
|
- [x] Get info (IP,netmask)
|
|
|
|
|
|
|
|
v2:
|
|
|
|
|
|
|
|
- [x] Create Live view of SWAP,CPU,Memory usage
|
|
|
|
- [x] Adding Chart to interface
|
|
|
|
|
2023-07-03 13:06:50 +00:00
|
|
|
v2.1 On going :
|
|
|
|
|
|
|
|
- [x] Add Network usage
|
2023-07-04 15:54:21 +00:00
|
|
|
- [x] Add boot time
|
|
|
|
- [x] Update dynamically Progress Bar
|
2023-07-03 13:06:50 +00:00
|
|
|
|
2023-07-03 08:13:22 +00:00
|
|
|
Next:
|
|
|
|
|
2023-07-03 13:06:50 +00:00
|
|
|
- [ ] Retrieve Process runnning (top ?)
|
2023-07-03 08:13:22 +00:00
|
|
|
- [ ] Add alerting (?)
|
|
|
|
- [ ] Create admin page for threshold and alert
|
|
|
|
- [ ] Manage alert communication (Mail, SMS...)
|