LinuxMonitor 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- linuxmonitor-1.0.0/LICENSE.md +21 -0
- linuxmonitor-1.0.0/LinuxMonitor.egg-info/PKG-INFO +157 -0
- linuxmonitor-1.0.0/LinuxMonitor.egg-info/SOURCES.txt +11 -0
- linuxmonitor-1.0.0/LinuxMonitor.egg-info/dependency_links.txt +1 -0
- linuxmonitor-1.0.0/LinuxMonitor.egg-info/requires.txt +3 -0
- linuxmonitor-1.0.0/LinuxMonitor.egg-info/top_level.txt +1 -0
- linuxmonitor-1.0.0/PKG-INFO +157 -0
- linuxmonitor-1.0.0/README.md +129 -0
- linuxmonitor-1.0.0/linuxmonitor/__init__.py +1 -0
- linuxmonitor-1.0.0/linuxmonitor/linuxmonitor.py +2151 -0
- linuxmonitor-1.0.0/setup.cfg +7 -0
- linuxmonitor-1.0.0/setup.py +43 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Quentin Comte-Gaz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: LinuxMonitor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
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)
|
|
5
|
+
Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
|
|
6
|
+
Author: Quentin Comte-Gaz
|
|
7
|
+
Author-email: quentin@comte-gaz.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: linux monitor monitoring server service port ping ssl certificate disk folder cpu ram swap usage ip connection
|
|
10
|
+
Platform: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Topic :: System :: Monitoring
|
|
18
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
19
|
+
Classifier: Topic :: System :: Systems Administration
|
|
20
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
21
|
+
Classifier: Environment :: Console
|
|
22
|
+
Requires-Python: >=3.3
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE.md
|
|
25
|
+
Requires-Dist: psutil
|
|
26
|
+
Requires-Dist: typing
|
|
27
|
+
Requires-Dist: asyncio
|
|
28
|
+
|
|
29
|
+
# Linux Monitor (Python library)
|
|
30
|
+
[](https://badge.fury.io/py/Linux-Monitor) [](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/LICENSE.md) [](https://paypal.me/QuentinCG)
|
|
31
|
+
|
|
32
|
+
## What is it
|
|
33
|
+
|
|
34
|
+
This python library is designed to be integrated in python or shell projects to monitor Linux servers.
|
|
35
|
+
It is compatible with python 3+ and usable only on Linux.
|
|
36
|
+
|
|
37
|
+
It is also designed to be easily integrated in discussion channel bots python scripts (example: [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library))
|
|
38
|
+
|
|
39
|
+
<img src="https://github.com/QuentinCG/Linux-Monitor-Python-Library/raw/master/welcome.png" width="300">
|
|
40
|
+
|
|
41
|
+
## Functionalities
|
|
42
|
+
|
|
43
|
+
Most important functionalities:
|
|
44
|
+
- 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)
|
|
45
|
+
- Do all checks bellow in a scheduled tasks and display the results every time (only in console if using only the library)
|
|
46
|
+
|
|
47
|
+
List of 'check' functionalities:
|
|
48
|
+
- Check CPU, RAM, SWAP, Temperature
|
|
49
|
+
- Check disk usage
|
|
50
|
+
- Check folder usage
|
|
51
|
+
- Check websites basic availability (ping)
|
|
52
|
+
- Check services status and restart them if needed
|
|
53
|
+
- Check certificates expiration and validity
|
|
54
|
+
- Check last user connections IPs
|
|
55
|
+
|
|
56
|
+
Additionnal functionalities:
|
|
57
|
+
- Get hostname, OS details, kernel version, server datetime, uptime
|
|
58
|
+
- Get connected users
|
|
59
|
+
- Get processes list (PID and name)
|
|
60
|
+
- Kill a process by PID
|
|
61
|
+
- Reboot server
|
|
62
|
+
|
|
63
|
+
## How to install (python script and shell)
|
|
64
|
+
|
|
65
|
+
- Install package calling `pip install linux-monitor` (or `python setup.py install` from the root of this repository)
|
|
66
|
+
- 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)
|
|
67
|
+
- Add rights to user launching the library depending on what you want it to do
|
|
68
|
+
```sh
|
|
69
|
+
# Only if this library should be able to reboot the server on demand:
|
|
70
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /sbin/reboot" >> /etc/sudoers.d/USERNAME_HERE
|
|
71
|
+
# Only if this library should be able to kill a process on demand:
|
|
72
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/kill" >> /etc/sudoers.d/USERNAME_HERE
|
|
73
|
+
|
|
74
|
+
# Add also all processes added in your config JSON file you want the library to be able to execute
|
|
75
|
+
# Example for the existing config-example.json file:
|
|
76
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNAME_HERE
|
|
77
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
78
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
79
|
+
```
|
|
80
|
+
- Check monitor possibilities (you can find it out by calling `python linuxmonitor/linuxmonitor.py --help` from the root of this repository)
|
|
81
|
+
- Load your shell or python script
|
|
82
|
+
|
|
83
|
+
## How to use in shell
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
# Get help
|
|
87
|
+
python3 linuxmonitor/linuxmonitor.py --help
|
|
88
|
+
# Use "--debug" to show more information during command
|
|
89
|
+
# Use "--nodebug" to not show any warning information during command
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
94
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
95
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
96
|
+
|
|
97
|
+
# Start periodic task to show system information periodically (will run indefinitely)
|
|
98
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
99
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# View disk space, CPU, RAM, ...
|
|
104
|
+
python3 linuxmonitor/linuxmonitor.py --usage --config_file config-example.json
|
|
105
|
+
|
|
106
|
+
# View basic system information
|
|
107
|
+
python3 linuxmonitor/linuxmonitor.py --os_infos --config_file config-example.json
|
|
108
|
+
|
|
109
|
+
# View connected users
|
|
110
|
+
python3 linuxmonitor/linuxmonitor.py --users --config_file config-example.json
|
|
111
|
+
|
|
112
|
+
# View last user connections
|
|
113
|
+
python3 linuxmonitor/linuxmonitor.py --user_logins --config_file config-example.json
|
|
114
|
+
|
|
115
|
+
# Check websites (ping)
|
|
116
|
+
python3 linuxmonitor/linuxmonitor.py --ping --config_file config-example.json
|
|
117
|
+
|
|
118
|
+
# Check SSL certificates
|
|
119
|
+
python3 linuxmonitor/linuxmonitor.py --certificates --config_file config-example.json
|
|
120
|
+
|
|
121
|
+
# Check if services are running and restart if down
|
|
122
|
+
python3 linuxmonitor/linuxmonitor.py --services_status --config_file config-example.json
|
|
123
|
+
|
|
124
|
+
# List all available services
|
|
125
|
+
python3 linuxmonitor/linuxmonitor.py --list_services --config_file config-example.json
|
|
126
|
+
|
|
127
|
+
# Restart all services
|
|
128
|
+
python3 linuxmonitor/linuxmonitor.py --restart_all --config_file config-example.json
|
|
129
|
+
|
|
130
|
+
# Restart a service
|
|
131
|
+
python3 linuxmonitor/linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
132
|
+
|
|
133
|
+
# Check ports
|
|
134
|
+
python3 linuxmonitor/linuxmonitor.py --ports --config_file config-example.json
|
|
135
|
+
|
|
136
|
+
# List active processes
|
|
137
|
+
python3 linuxmonitor/linuxmonitor.py --list_processes --config_file config-example.json
|
|
138
|
+
|
|
139
|
+
# Stop a process by PID
|
|
140
|
+
python3 linuxmonitor/linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
141
|
+
|
|
142
|
+
# Restart the entire server
|
|
143
|
+
python3 linuxmonitor/linuxmonitor.py --reboot_server --config_file config-example.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## How to use in python script
|
|
147
|
+
|
|
148
|
+
Example of python script using this library:
|
|
149
|
+
- [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
This project is under MIT license. This means you can use it as you want (just don't delete the library header).
|
|
154
|
+
|
|
155
|
+
## Contribute
|
|
156
|
+
|
|
157
|
+
If you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
README.md
|
|
3
|
+
setup.cfg
|
|
4
|
+
setup.py
|
|
5
|
+
LinuxMonitor.egg-info/PKG-INFO
|
|
6
|
+
LinuxMonitor.egg-info/SOURCES.txt
|
|
7
|
+
LinuxMonitor.egg-info/dependency_links.txt
|
|
8
|
+
LinuxMonitor.egg-info/requires.txt
|
|
9
|
+
LinuxMonitor.egg-info/top_level.txt
|
|
10
|
+
linuxmonitor/__init__.py
|
|
11
|
+
linuxmonitor/linuxmonitor.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
linuxmonitor
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: LinuxMonitor
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
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)
|
|
5
|
+
Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
|
|
6
|
+
Author: Quentin Comte-Gaz
|
|
7
|
+
Author-email: quentin@comte-gaz.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: linux monitor monitoring server service port ping ssl certificate disk folder cpu ram swap usage ip connection
|
|
10
|
+
Platform: Linux
|
|
11
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: System Administrators
|
|
17
|
+
Classifier: Topic :: System :: Monitoring
|
|
18
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
19
|
+
Classifier: Topic :: System :: Systems Administration
|
|
20
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
21
|
+
Classifier: Environment :: Console
|
|
22
|
+
Requires-Python: >=3.3
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE.md
|
|
25
|
+
Requires-Dist: psutil
|
|
26
|
+
Requires-Dist: typing
|
|
27
|
+
Requires-Dist: asyncio
|
|
28
|
+
|
|
29
|
+
# Linux Monitor (Python library)
|
|
30
|
+
[](https://badge.fury.io/py/Linux-Monitor) [](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/LICENSE.md) [](https://paypal.me/QuentinCG)
|
|
31
|
+
|
|
32
|
+
## What is it
|
|
33
|
+
|
|
34
|
+
This python library is designed to be integrated in python or shell projects to monitor Linux servers.
|
|
35
|
+
It is compatible with python 3+ and usable only on Linux.
|
|
36
|
+
|
|
37
|
+
It is also designed to be easily integrated in discussion channel bots python scripts (example: [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library))
|
|
38
|
+
|
|
39
|
+
<img src="https://github.com/QuentinCG/Linux-Monitor-Python-Library/raw/master/welcome.png" width="300">
|
|
40
|
+
|
|
41
|
+
## Functionalities
|
|
42
|
+
|
|
43
|
+
Most important functionalities:
|
|
44
|
+
- 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)
|
|
45
|
+
- Do all checks bellow in a scheduled tasks and display the results every time (only in console if using only the library)
|
|
46
|
+
|
|
47
|
+
List of 'check' functionalities:
|
|
48
|
+
- Check CPU, RAM, SWAP, Temperature
|
|
49
|
+
- Check disk usage
|
|
50
|
+
- Check folder usage
|
|
51
|
+
- Check websites basic availability (ping)
|
|
52
|
+
- Check services status and restart them if needed
|
|
53
|
+
- Check certificates expiration and validity
|
|
54
|
+
- Check last user connections IPs
|
|
55
|
+
|
|
56
|
+
Additionnal functionalities:
|
|
57
|
+
- Get hostname, OS details, kernel version, server datetime, uptime
|
|
58
|
+
- Get connected users
|
|
59
|
+
- Get processes list (PID and name)
|
|
60
|
+
- Kill a process by PID
|
|
61
|
+
- Reboot server
|
|
62
|
+
|
|
63
|
+
## How to install (python script and shell)
|
|
64
|
+
|
|
65
|
+
- Install package calling `pip install linux-monitor` (or `python setup.py install` from the root of this repository)
|
|
66
|
+
- 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)
|
|
67
|
+
- Add rights to user launching the library depending on what you want it to do
|
|
68
|
+
```sh
|
|
69
|
+
# Only if this library should be able to reboot the server on demand:
|
|
70
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /sbin/reboot" >> /etc/sudoers.d/USERNAME_HERE
|
|
71
|
+
# Only if this library should be able to kill a process on demand:
|
|
72
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/kill" >> /etc/sudoers.d/USERNAME_HERE
|
|
73
|
+
|
|
74
|
+
# Add also all processes added in your config JSON file you want the library to be able to execute
|
|
75
|
+
# Example for the existing config-example.json file:
|
|
76
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNAME_HERE
|
|
77
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
78
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
79
|
+
```
|
|
80
|
+
- Check monitor possibilities (you can find it out by calling `python linuxmonitor/linuxmonitor.py --help` from the root of this repository)
|
|
81
|
+
- Load your shell or python script
|
|
82
|
+
|
|
83
|
+
## How to use in shell
|
|
84
|
+
|
|
85
|
+
```shell
|
|
86
|
+
# Get help
|
|
87
|
+
python3 linuxmonitor/linuxmonitor.py --help
|
|
88
|
+
# Use "--debug" to show more information during command
|
|
89
|
+
# Use "--nodebug" to not show any warning information during command
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
94
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
95
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
96
|
+
|
|
97
|
+
# Start periodic task to show system information periodically (will run indefinitely)
|
|
98
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
99
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# View disk space, CPU, RAM, ...
|
|
104
|
+
python3 linuxmonitor/linuxmonitor.py --usage --config_file config-example.json
|
|
105
|
+
|
|
106
|
+
# View basic system information
|
|
107
|
+
python3 linuxmonitor/linuxmonitor.py --os_infos --config_file config-example.json
|
|
108
|
+
|
|
109
|
+
# View connected users
|
|
110
|
+
python3 linuxmonitor/linuxmonitor.py --users --config_file config-example.json
|
|
111
|
+
|
|
112
|
+
# View last user connections
|
|
113
|
+
python3 linuxmonitor/linuxmonitor.py --user_logins --config_file config-example.json
|
|
114
|
+
|
|
115
|
+
# Check websites (ping)
|
|
116
|
+
python3 linuxmonitor/linuxmonitor.py --ping --config_file config-example.json
|
|
117
|
+
|
|
118
|
+
# Check SSL certificates
|
|
119
|
+
python3 linuxmonitor/linuxmonitor.py --certificates --config_file config-example.json
|
|
120
|
+
|
|
121
|
+
# Check if services are running and restart if down
|
|
122
|
+
python3 linuxmonitor/linuxmonitor.py --services_status --config_file config-example.json
|
|
123
|
+
|
|
124
|
+
# List all available services
|
|
125
|
+
python3 linuxmonitor/linuxmonitor.py --list_services --config_file config-example.json
|
|
126
|
+
|
|
127
|
+
# Restart all services
|
|
128
|
+
python3 linuxmonitor/linuxmonitor.py --restart_all --config_file config-example.json
|
|
129
|
+
|
|
130
|
+
# Restart a service
|
|
131
|
+
python3 linuxmonitor/linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
132
|
+
|
|
133
|
+
# Check ports
|
|
134
|
+
python3 linuxmonitor/linuxmonitor.py --ports --config_file config-example.json
|
|
135
|
+
|
|
136
|
+
# List active processes
|
|
137
|
+
python3 linuxmonitor/linuxmonitor.py --list_processes --config_file config-example.json
|
|
138
|
+
|
|
139
|
+
# Stop a process by PID
|
|
140
|
+
python3 linuxmonitor/linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
141
|
+
|
|
142
|
+
# Restart the entire server
|
|
143
|
+
python3 linuxmonitor/linuxmonitor.py --reboot_server --config_file config-example.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## How to use in python script
|
|
147
|
+
|
|
148
|
+
Example of python script using this library:
|
|
149
|
+
- [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
This project is under MIT license. This means you can use it as you want (just don't delete the library header).
|
|
154
|
+
|
|
155
|
+
## Contribute
|
|
156
|
+
|
|
157
|
+
If you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# Linux Monitor (Python library)
|
|
2
|
+
[](https://badge.fury.io/py/Linux-Monitor) [](https://github.com/QuentinCG/Linux-Monitor-Python-Library/blob/master/LICENSE.md) [](https://paypal.me/QuentinCG)
|
|
3
|
+
|
|
4
|
+
## What is it
|
|
5
|
+
|
|
6
|
+
This python library is designed to be integrated in python or shell projects to monitor Linux servers.
|
|
7
|
+
It is compatible with python 3+ and usable only on Linux.
|
|
8
|
+
|
|
9
|
+
It is also designed to be easily integrated in discussion channel bots python scripts (example: [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library))
|
|
10
|
+
|
|
11
|
+
<img src="https://github.com/QuentinCG/Linux-Monitor-Python-Library/raw/master/welcome.png" width="300">
|
|
12
|
+
|
|
13
|
+
## Functionalities
|
|
14
|
+
|
|
15
|
+
Most important functionalities:
|
|
16
|
+
- 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)
|
|
17
|
+
- Do all checks bellow in a scheduled tasks and display the results every time (only in console if using only the library)
|
|
18
|
+
|
|
19
|
+
List of 'check' functionalities:
|
|
20
|
+
- Check CPU, RAM, SWAP, Temperature
|
|
21
|
+
- Check disk usage
|
|
22
|
+
- Check folder usage
|
|
23
|
+
- Check websites basic availability (ping)
|
|
24
|
+
- Check services status and restart them if needed
|
|
25
|
+
- Check certificates expiration and validity
|
|
26
|
+
- Check last user connections IPs
|
|
27
|
+
|
|
28
|
+
Additionnal functionalities:
|
|
29
|
+
- Get hostname, OS details, kernel version, server datetime, uptime
|
|
30
|
+
- Get connected users
|
|
31
|
+
- Get processes list (PID and name)
|
|
32
|
+
- Kill a process by PID
|
|
33
|
+
- Reboot server
|
|
34
|
+
|
|
35
|
+
## How to install (python script and shell)
|
|
36
|
+
|
|
37
|
+
- Install package calling `pip install linux-monitor` (or `python setup.py install` from the root of this repository)
|
|
38
|
+
- 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)
|
|
39
|
+
- Add rights to user launching the library depending on what you want it to do
|
|
40
|
+
```sh
|
|
41
|
+
# Only if this library should be able to reboot the server on demand:
|
|
42
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /sbin/reboot" >> /etc/sudoers.d/USERNAME_HERE
|
|
43
|
+
# Only if this library should be able to kill a process on demand:
|
|
44
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/kill" >> /etc/sudoers.d/USERNAME_HERE
|
|
45
|
+
|
|
46
|
+
# Add also all processes added in your config JSON file you want the library to be able to execute
|
|
47
|
+
# Example for the existing config-example.json file:
|
|
48
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNAME_HERE
|
|
49
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
50
|
+
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
51
|
+
```
|
|
52
|
+
- Check monitor possibilities (you can find it out by calling `python linuxmonitor/linuxmonitor.py --help` from the root of this repository)
|
|
53
|
+
- Load your shell or python script
|
|
54
|
+
|
|
55
|
+
## How to use in shell
|
|
56
|
+
|
|
57
|
+
```shell
|
|
58
|
+
# Get help
|
|
59
|
+
python3 linuxmonitor/linuxmonitor.py --help
|
|
60
|
+
# Use "--debug" to show more information during command
|
|
61
|
+
# Use "--nodebug" to not show any warning information during command
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
66
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
67
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
68
|
+
|
|
69
|
+
# Start periodic task to show system information periodically (will run indefinitely)
|
|
70
|
+
# Best is to call this as a service and put the result in a log file or do something of the stdout
|
|
71
|
+
python3 linuxmonitor/linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# View disk space, CPU, RAM, ...
|
|
76
|
+
python3 linuxmonitor/linuxmonitor.py --usage --config_file config-example.json
|
|
77
|
+
|
|
78
|
+
# View basic system information
|
|
79
|
+
python3 linuxmonitor/linuxmonitor.py --os_infos --config_file config-example.json
|
|
80
|
+
|
|
81
|
+
# View connected users
|
|
82
|
+
python3 linuxmonitor/linuxmonitor.py --users --config_file config-example.json
|
|
83
|
+
|
|
84
|
+
# View last user connections
|
|
85
|
+
python3 linuxmonitor/linuxmonitor.py --user_logins --config_file config-example.json
|
|
86
|
+
|
|
87
|
+
# Check websites (ping)
|
|
88
|
+
python3 linuxmonitor/linuxmonitor.py --ping --config_file config-example.json
|
|
89
|
+
|
|
90
|
+
# Check SSL certificates
|
|
91
|
+
python3 linuxmonitor/linuxmonitor.py --certificates --config_file config-example.json
|
|
92
|
+
|
|
93
|
+
# Check if services are running and restart if down
|
|
94
|
+
python3 linuxmonitor/linuxmonitor.py --services_status --config_file config-example.json
|
|
95
|
+
|
|
96
|
+
# List all available services
|
|
97
|
+
python3 linuxmonitor/linuxmonitor.py --list_services --config_file config-example.json
|
|
98
|
+
|
|
99
|
+
# Restart all services
|
|
100
|
+
python3 linuxmonitor/linuxmonitor.py --restart_all --config_file config-example.json
|
|
101
|
+
|
|
102
|
+
# Restart a service
|
|
103
|
+
python3 linuxmonitor/linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
104
|
+
|
|
105
|
+
# Check ports
|
|
106
|
+
python3 linuxmonitor/linuxmonitor.py --ports --config_file config-example.json
|
|
107
|
+
|
|
108
|
+
# List active processes
|
|
109
|
+
python3 linuxmonitor/linuxmonitor.py --list_processes --config_file config-example.json
|
|
110
|
+
|
|
111
|
+
# Stop a process by PID
|
|
112
|
+
python3 linuxmonitor/linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
113
|
+
|
|
114
|
+
# Restart the entire server
|
|
115
|
+
python3 linuxmonitor/linuxmonitor.py --reboot_server --config_file config-example.json
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## How to use in python script
|
|
119
|
+
|
|
120
|
+
Example of python script using this library:
|
|
121
|
+
- [Discord Linux Monitor Bot](https://github.com/QuentinCG/Discord-Linux-Monitor-Bot-Python-Library)
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
This project is under MIT license. This means you can use it as you want (just don't delete the library header).
|
|
126
|
+
|
|
127
|
+
## Contribute
|
|
128
|
+
|
|
129
|
+
If you want to add more examples or improve the library, just create a pull request with proper commit message and right wrapping.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .linuxmonitor import LinuxMonitor
|