206 lines
4.1 KiB
Markdown
206 lines
4.1 KiB
Markdown
# 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))
|
|
Server[Server] <----> Client2((Client2))
|
|
Server[Server] <----> Client3((Client3))
|
|
```
|
|
|
|
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.
|
|
|
|
# Screenshot
|
|
|
|
![ScreenShot](./image/Pymonit.PNG)
|
|
|
|
# Install
|
|
|
|
For Debian 12 (and more...)
|
|
|
|
On server :
|
|
```bash
|
|
apt install python3-flask python3-paramiko python3-psutil
|
|
```
|
|
|
|
On nodes (if needed):
|
|
```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
|
|
|
|
python3 -m venv Pymonit --system-site-packages
|
|
. /Pymonit/bin/activate
|
|
pip3 install psutil flask paramiko
|
|
|
|
```
|
|
|
|
|
|
# Configuration
|
|
|
|
## Clients
|
|
|
|
Add your clients in the python list in config.py:
|
|
|
|
```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
|
|
|
|
You have to report these info on config.py :
|
|
|
|
```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
|
|
Configure the flask configuration according to your needs (port,host,...) in config.py
|
|
```bash
|
|
class flask_conf:
|
|
port = 8090
|
|
host = "0.0.0.0"
|
|
thread = True
|
|
debug = False
|
|
reloader = False
|
|
```
|
|
NB: Let thread = True, else this will take a time to switch from node to another node
|
|
|
|
## 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
|
|
```
|
|
|
|
## 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
|
|
|
|
v2.1 On going :
|
|
|
|
- [x] Add Network usage
|
|
|
|
Next:
|
|
|
|
- [ ] Retrieve Process runnning (top ?)
|
|
- [ ] Add alerting (?)
|
|
- [ ] Create admin page for threshold and alert
|
|
- [ ] Manage alert communication (Mail, SMS...)
|