Skip to content

Agent executed on a host that retrieves metrics. Exposes an OAS3 API and is able to send the metrics remotely periodically.

License

Notifications You must be signed in to change notification settings

n0nuser/monitor-agent

Repository files navigation

Monitor: Agent

Computer Science Final Degree Project @ USAL - Host to monitor

Contributors Forks Stargazers Issues GPL License LinkedIn

Built With

Python PSUtils Poetry

FastAPI FastAPI Utils Uvicorn

(back to top)

Getting Started

Installation

First, download the repository into your Home folder or the directory you prefer:

git clone https://github.com/n0nuser/monitor-agent

Install the Python dependencies:

sudo pip3 install -r requirements.txt

Then, create a Systemd service in /etc/systemd/system/ called agent.service.

sudo nano /etc/systemd/system/agent.service:

[Unit]
Description=RESTful web to track agents
After=network.target network-online.target
Requires=network-online.target

[Service]
RemainAfterExit=true
Restart=on-failure
ExecStart=/usr/bin/python3 /home/MYUSER/monitor-agent/monitor_agent/main.py

[Install]
WantedBy=multi-user.target

Modify MYUSER with your user, and DIRECTORY with the path to the main.py. In case you downloaded the repository in your Home folder you wouldn't need to change the directory in the service file.

Once the service is installed, you can enable it to run forever and start on startup:

sudo systemctl enable agent.service
sudo systemctl start agent.service
systemctl status agent.service

Configuration

The user can configure the agent and server settings with the settings.json file:

{
    "alerts": {
        "url": "http://localhost:8000/api/alerts/"
    },
    "auth": {
        "agent_token": "fb79210dd15ea00aeeb4bb21f81b27421a4e11a7",
        "name": "Laptop",
        "user_token": "19fc6e57b8fb0e5a1a7b55976952ab02865aa771"
    },
    "endpoints": {
        "agent_endpoint": "http://localhost:8000/api/agents/",
        "metric_endpoint": "http://localhost:8000/api/metrics/"
    },
    "logging": {
        "filename": "monitor.log",
        "level": "info"
    },
    "metrics": {
        "enable_logfile": false,
        "get_endpoint": false,
        "log_filename": "metrics.json",
        "post_interval": 60
    },
    "thresholds": {
        "cpu_percent": 50,
        "ram_percent": 30
    },
    "uvicorn": {
        "backlog": 2048,
        "debug": false,
        "host": "0.0.0.0",
        "log_level": "trace",
        "port": 8080,
        "reload": true,
        "timeout_keep_alive": 5,
        "workers": 4
    }
}

It's best to use the configurator from the Monitor Web App as it automatically generates it with the approppiate configuration. You can always update the configuration with a form in the Web App.

Once configured, restart the service:

sudo systemctl restart agent.service

Roadmap

Check the Roadmap here.

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the GPL-3.0 License. See LICENSE.txt for more information.

(back to top)

Contact

Pablo González Rubio - @n0nuser_ - gonzrubio.pablo@gmail.com

Project Link: https://github.com/n0nuser/Monitor-Agent

(back to top)

About

Agent executed on a host that retrieves metrics. Exposes an OAS3 API and is able to send the metrics remotely periodically.

Topics

Resources

License

Stars

Watchers

Forks

Languages