Pymonit/README.md

167 lines
3.4 KiB
Markdown
Raw Normal View History

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))
Server[Square Rect] <----> Client2((Client2))
Server[Square Rect] <----> 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.
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"
thread = False
debug = False
reloader = False
ssl = 'adhoc'
```
NB: the parameter ssl = 'adhoc' will activate the HTTPS with a self certificate.
If you get an error, you should add this package :
```bash
pip3 install pyopenssl
```
## 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
```