LinuxMonitor


NameLinuxMonitor JSON
Version 1.3.9 PyPI version JSON
download
home_pagehttps://github.com/QuentinCG/Linux-Monitor-Python-Library
SummaryGet information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)
upload_time2024-09-20 17:52:53
maintainerNone
docs_urlNone
authorQuentin Comte-Gaz
requires_python>=3.3
licenseMIT
keywords linux monitor monitoring server service port ping ssl certificate disk folder cpu ram swap usage ip connection
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Linux Monitor (Python library)
[![PyPI version](https://badge.fury.io/py/LinuxMonitor.svg)](https://pypi.org/project/LinuxMonitor/) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/LICENSE.md) [![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/QuentinCG) [![Downloads](https://static.pepy.tech/badge/LinuxMonitor)](https://pepy.tech/project/LinuxMonitor) [![Downloads](https://static.pepy.tech/badge/LinuxMonitor/month)](https://pepy.tech/project/LinuxMonitor)

## What is it

This python library is designed to be integrated in python or shell projects to monitor Linux servers.
It is compatible with python 3+ and usable only on Linux.

It is also designed to be easily integrated in discussion channel bots python scripts (example: [Discord Bot Linux Monitor](https://github.com/QuentinCG/Discord-Bot-Linux-Monitor-Python-Library))

<img src="https://github.com/QuentinCG/Linux-Monitor-Python-Library/raw/master/welcome.png" width="300">

## Functionalities

Most important functionalities:
  - Do all checks bellow in a scheduled tasks and display the results only if there is an issue (only in console if using only the library)
  - Do all checks bellow in a scheduled tasks and display the results every time (only in console if using only the library)

List of 'check' functionalities:
  - Check CPU, RAM, SWAP, Temperature
  - Check disk usage
  - Check folder usage
  - Check websites basic availability (ping)
  - Check websites access with optional authentication (GET request)
  - Check services status and restart them if needed
  - Check certificates expiration and validity
  - Check last user connections IPs
  - Check uptime (to inform if the server has been rebooted)
  - Check custom commands

Additionnal functionalities:
  - Get hostname, OS details, kernel version, server datetime, uptime
  - Get connected users
  - Get processes list (PID and name)
  - Kill a process by PID
  - Reboot server
  - Restart/stop a service
  - Execute custom commands

## How to install (python script and shell)

  - Install package calling `pip install linux-monitor` (or `python setup.py install` from the root of this repository)
  - Copy and edit [config-example.json file](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/config-example.json) depending on your need (on first launch, remove all `restart_command` from config file to prevent potential looping service restart issues on your server in case your config file is not well configured)
  - Add rights to user launching the library depending on what you want it to do
```sh
# Only if this library should be able to reboot the server on demand:
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /sbin/reboot" >> /etc/sudoers.d/USERNAME_HERE
# Only if this library should be able to kill a process on demand:
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/kill" >> /etc/sudoers.d/USERNAME_HERE

# Add also all processes added in your config JSON file you want the library to be able to execute
# Example for the existing config-example.json file:
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNAME_HERE
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
```
  - Check monitor possibilities (you can find it out by calling `python -m linuxmonitor --help` from the root of this repository)
  - Load your shell or python script

## How to use in shell

```sh
# Get help
python3 -m linuxmonitor --help
# Use "--debug" to show more information during command
# Use "--nodebug" to not show any warning information during command



# Start periodic task to show potential issues periodically (will run indefinitely)
# Best is to call this as a service and put the result in a log file or do something of the stdout
python3 -m linuxmonitor --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug

# Start periodic task to show system information periodically (will run indefinitely)
# Best is to call this as a service and put the result in a log file or do something of the stdout
python3 -m linuxmonitor --start_scheduled_task_show_info --config_file config-example.json --nodebug



# View disk space, CPU, RAM, ...
python3 -m linuxmonitor --usage --config_file config-example.json --nodebug

# View basic system information
python3 -m linuxmonitor --os_infos --config_file config-example.json --nodebug

# View connected users
python3 -m linuxmonitor --users --config_file config-example.json --nodebug

# View last user connections
python3 -m linuxmonitor --user_logins --config_file config-example.json --nodebug

# Check websites (ping)
python3 -m linuxmonitor --ping --config_file config-example.json --nodebug

# Check websites access with optional authentication (GET request)
python3 -m linuxmonitor --websites --config_file config-example.json --nodebug

# Check SSL certificates
python3 -m linuxmonitor --certificates --config_file config-example.json --nodebug

# Check if services are running and restart if down
python3 -m linuxmonitor --services_status --config_file config-example.json --nodebug

# List all available services
python3 -m linuxmonitor --list_services --config_file config-example.json --nodebug

# Restart all services
python3 -m linuxmonitor --restart_all --config_file config-example.json --nodebug

# Restart a service
python3 -m linuxmonitor --restart_service SERVICE_NAME_HERE --config_file config-example.json --nodebug

# Stop a service
python3 -m linuxmonitor --stop_service SERVICE_NAME_HERE --config_file config-example.json --nodebug

# Check ports
python3 -m linuxmonitor --ports --config_file config-example.json --nodebug

# List active processes
python3 -m linuxmonitor --list_processes --config_file config-example.json --nodebug

# Stop a process by PID
python3 -m linuxmonitor --kill_process PID_HERE --config_file config-example.json --nodebug

# Restart the entire server
python3 -m linuxmonitor --reboot_server --config_file config-example.json --nodebug

# List all custom commands
python3 -m linuxmonitor --list_commands --config_file config-example.json --nodebug

# Execute a custom commands
python3 -m linuxmonitor --execute_command CUSTOM_COMMAND_HERE --config_file config-example.json --nodebug

# Execute all custom commands
python3 -m linuxmonitor --execute_all_commands --config_file config-example.json --nodebug
```

## How to use in python script

Example of python script using this library:
 - [Discord Bot Linux Monitor](https://github.com/QuentinCG/Discord-Bot-Linux-Monitor-Python-Library)

## License

This project is under MIT license. This means you can use it as you want (just don't delete the library header).

## Contribute

If you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/QuentinCG/Linux-Monitor-Python-Library",
    "name": "LinuxMonitor",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.3",
    "maintainer_email": null,
    "keywords": "linux monitor monitoring server service port ping ssl certificate disk folder cpu ram swap usage ip connection",
    "author": "Quentin Comte-Gaz",
    "author_email": "quentin@comte-gaz.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/cd/67b57f3de5bed2fbb0335ff3480b44963e34f2749abd3ad4cbebabfc9fc3/linuxmonitor-1.3.9.tar.gz",
    "platform": "Linux",
    "description": "# Linux Monitor (Python library)\n[![PyPI version](https://badge.fury.io/py/LinuxMonitor.svg)](https://pypi.org/project/LinuxMonitor/) [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/LICENSE.md) [![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://paypal.me/QuentinCG) [![Downloads](https://static.pepy.tech/badge/LinuxMonitor)](https://pepy.tech/project/LinuxMonitor) [![Downloads](https://static.pepy.tech/badge/LinuxMonitor/month)](https://pepy.tech/project/LinuxMonitor)\n\n## What is it\n\nThis python library is designed to be integrated in python or shell projects to monitor Linux servers.\nIt is compatible with python 3+ and usable only on Linux.\n\nIt is also designed to be easily integrated in discussion channel bots python scripts (example: [Discord Bot Linux Monitor](https://github.com/QuentinCG/Discord-Bot-Linux-Monitor-Python-Library))\n\n<img src=\"https://github.com/QuentinCG/Linux-Monitor-Python-Library/raw/master/welcome.png\" width=\"300\">\n\n## Functionalities\n\nMost important functionalities:\n  - Do all checks bellow in a scheduled tasks and display the results only if there is an issue (only in console if using only the library)\n  - Do all checks bellow in a scheduled tasks and display the results every time (only in console if using only the library)\n\nList of 'check' functionalities:\n  - Check CPU, RAM, SWAP, Temperature\n  - Check disk usage\n  - Check folder usage\n  - Check websites basic availability (ping)\n  - Check websites access with optional authentication (GET request)\n  - Check services status and restart them if needed\n  - Check certificates expiration and validity\n  - Check last user connections IPs\n  - Check uptime (to inform if the server has been rebooted)\n  - Check custom commands\n\nAdditionnal functionalities:\n  - Get hostname, OS details, kernel version, server datetime, uptime\n  - Get connected users\n  - Get processes list (PID and name)\n  - Kill a process by PID\n  - Reboot server\n  - Restart/stop a service\n  - Execute custom commands\n\n## How to install (python script and shell)\n\n  - Install package calling `pip install linux-monitor` (or `python setup.py install` from the root of this repository)\n  - Copy and edit [config-example.json file](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/config-example.json) depending on your need (on first launch, remove all `restart_command` from config file to prevent potential looping service restart issues on your server in case your config file is not well configured)\n  - Add rights to user launching the library depending on what you want it to do\n```sh\n# Only if this library should be able to reboot the server on demand:\necho \"USERNAME_HERE ALL=(ALL) NOPASSWD: /sbin/reboot\" >> /etc/sudoers.d/USERNAME_HERE\n# Only if this library should be able to kill a process on demand:\necho \"USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/kill\" >> /etc/sudoers.d/USERNAME_HERE\n\n# Add also all processes added in your config JSON file you want the library to be able to execute\n# Example for the existing config-example.json file:\necho \"USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl\" >> /etc/sudoers.d/USERNAME_HERE\necho \"USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2\" >> /etc/sudoers.d/USERNAME_HERE\necho \"USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb\" >> /etc/sudoers.d/USERNAME_HERE\n```\n  - Check monitor possibilities (you can find it out by calling `python -m linuxmonitor --help` from the root of this repository)\n  - Load your shell or python script\n\n## How to use in shell\n\n```sh\n# Get help\npython3 -m linuxmonitor --help\n# Use \"--debug\" to show more information during command\n# Use \"--nodebug\" to not show any warning information during command\n\n\n\n# Start periodic task to show potential issues periodically (will run indefinitely)\n# Best is to call this as a service and put the result in a log file or do something of the stdout\npython3 -m linuxmonitor --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug\n\n# Start periodic task to show system information periodically (will run indefinitely)\n# Best is to call this as a service and put the result in a log file or do something of the stdout\npython3 -m linuxmonitor --start_scheduled_task_show_info --config_file config-example.json --nodebug\n\n\n\n# View disk space, CPU, RAM, ...\npython3 -m linuxmonitor --usage --config_file config-example.json --nodebug\n\n# View basic system information\npython3 -m linuxmonitor --os_infos --config_file config-example.json --nodebug\n\n# View connected users\npython3 -m linuxmonitor --users --config_file config-example.json --nodebug\n\n# View last user connections\npython3 -m linuxmonitor --user_logins --config_file config-example.json --nodebug\n\n# Check websites (ping)\npython3 -m linuxmonitor --ping --config_file config-example.json --nodebug\n\n# Check websites access with optional authentication (GET request)\npython3 -m linuxmonitor --websites --config_file config-example.json --nodebug\n\n# Check SSL certificates\npython3 -m linuxmonitor --certificates --config_file config-example.json --nodebug\n\n# Check if services are running and restart if down\npython3 -m linuxmonitor --services_status --config_file config-example.json --nodebug\n\n# List all available services\npython3 -m linuxmonitor --list_services --config_file config-example.json --nodebug\n\n# Restart all services\npython3 -m linuxmonitor --restart_all --config_file config-example.json --nodebug\n\n# Restart a service\npython3 -m linuxmonitor --restart_service SERVICE_NAME_HERE --config_file config-example.json --nodebug\n\n# Stop a service\npython3 -m linuxmonitor --stop_service SERVICE_NAME_HERE --config_file config-example.json --nodebug\n\n# Check ports\npython3 -m linuxmonitor --ports --config_file config-example.json --nodebug\n\n# List active processes\npython3 -m linuxmonitor --list_processes --config_file config-example.json --nodebug\n\n# Stop a process by PID\npython3 -m linuxmonitor --kill_process PID_HERE --config_file config-example.json --nodebug\n\n# Restart the entire server\npython3 -m linuxmonitor --reboot_server --config_file config-example.json --nodebug\n\n# List all custom commands\npython3 -m linuxmonitor --list_commands --config_file config-example.json --nodebug\n\n# Execute a custom commands\npython3 -m linuxmonitor --execute_command CUSTOM_COMMAND_HERE --config_file config-example.json --nodebug\n\n# Execute all custom commands\npython3 -m linuxmonitor --execute_all_commands --config_file config-example.json --nodebug\n```\n\n## How to use in python script\n\nExample of python script using this library:\n - [Discord Bot Linux Monitor](https://github.com/QuentinCG/Discord-Bot-Linux-Monitor-Python-Library)\n\n## License\n\nThis project is under MIT license. This means you can use it as you want (just don't delete the library header).\n\n## Contribute\n\nIf you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Get information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)",
    "version": "1.3.9",
    "project_urls": {
        "Homepage": "https://github.com/QuentinCG/Linux-Monitor-Python-Library"
    },
    "split_keywords": [
        "linux",
        "monitor",
        "monitoring",
        "server",
        "service",
        "port",
        "ping",
        "ssl",
        "certificate",
        "disk",
        "folder",
        "cpu",
        "ram",
        "swap",
        "usage",
        "ip",
        "connection"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3eddfaecde4090d85c71bec35c6b8cfe1d2d85375434e1c318619ee6b778ddea",
                "md5": "0bf308e5b45580a60bd2f62de8af2364",
                "sha256": "5539ec8d1019fd21a247bd054e6c466d55f302b9f1c9917cc3c70a95dcdc4ba6"
            },
            "downloads": -1,
            "filename": "LinuxMonitor-1.3.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0bf308e5b45580a60bd2f62de8af2364",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.3",
            "size": 25005,
            "upload_time": "2024-09-20T17:52:52",
            "upload_time_iso_8601": "2024-09-20T17:52:52.616923Z",
            "url": "https://files.pythonhosted.org/packages/3e/dd/faecde4090d85c71bec35c6b8cfe1d2d85375434e1c318619ee6b778ddea/LinuxMonitor-1.3.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0dcd67b57f3de5bed2fbb0335ff3480b44963e34f2749abd3ad4cbebabfc9fc3",
                "md5": "72a89363cf48703ddfc9733544f9874b",
                "sha256": "726333392cd2248407e40a17d11bb56a6358f3b4378c1a53760d1a94301bedb7"
            },
            "downloads": -1,
            "filename": "linuxmonitor-1.3.9.tar.gz",
            "has_sig": false,
            "md5_digest": "72a89363cf48703ddfc9733544f9874b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.3",
            "size": 24294,
            "upload_time": "2024-09-20T17:52:53",
            "upload_time_iso_8601": "2024-09-20T17:52:53.912934Z",
            "url": "https://files.pythonhosted.org/packages/0d/cd/67b57f3de5bed2fbb0335ff3480b44963e34f2749abd3ad4cbebabfc9fc3/linuxmonitor-1.3.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-20 17:52:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "QuentinCG",
    "github_project": "Linux-Monitor-Python-Library",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "linuxmonitor"
}
        
Elapsed time: 0.42420s