LinuxMonitor 1.0.2__tar.gz → 1.0.4__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.2 → linuxmonitor-1.0.4/LinuxMonitor.egg-info}/PKG-INFO +19 -19
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/LinuxMonitor.egg-info/SOURCES.txt +1 -0
- {linuxmonitor-1.0.2/LinuxMonitor.egg-info → linuxmonitor-1.0.4}/PKG-INFO +19 -19
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/README.md +18 -18
- linuxmonitor-1.0.4/linuxmonitor/__main__.py +176 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/linuxmonitor/linuxmonitor.py +5 -176
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/setup.py +1 -1
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/LICENSE.md +0 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/LinuxMonitor.egg-info/dependency_links.txt +0 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/LinuxMonitor.egg-info/requires.txt +0 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/LinuxMonitor.egg-info/top_level.txt +0 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/linuxmonitor/__init__.py +0 -0
- {linuxmonitor-1.0.2 → linuxmonitor-1.0.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LinuxMonitor
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
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
5
|
Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
|
|
6
6
|
Author: Quentin Comte-Gaz
|
|
@@ -77,14 +77,14 @@ echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNA
|
|
|
77
77
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
78
78
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
79
79
|
```
|
|
80
|
-
- Check monitor possibilities (you can find it out by calling `python linuxmonitor
|
|
80
|
+
- Check monitor possibilities (you can find it out by calling `python -m linuxmonitor.py --help` from the root of this repository)
|
|
81
81
|
- Load your shell or python script
|
|
82
82
|
|
|
83
83
|
## How to use in shell
|
|
84
84
|
|
|
85
85
|
```shell
|
|
86
86
|
# Get help
|
|
87
|
-
python3 linuxmonitor
|
|
87
|
+
python3 -m linuxmonitor.py --help
|
|
88
88
|
# Use "--debug" to show more information during command
|
|
89
89
|
# Use "--nodebug" to not show any warning information during command
|
|
90
90
|
|
|
@@ -92,55 +92,55 @@ python3 linuxmonitor/linuxmonitor.py --help
|
|
|
92
92
|
|
|
93
93
|
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
94
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
|
|
95
|
+
python3 -m linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
96
96
|
|
|
97
97
|
# Start periodic task to show system information periodically (will run indefinitely)
|
|
98
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
|
|
99
|
+
python3 -m linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
# View disk space, CPU, RAM, ...
|
|
104
|
-
python3 linuxmonitor
|
|
104
|
+
python3 -m linuxmonitor.py --usage --config_file config-example.json
|
|
105
105
|
|
|
106
106
|
# View basic system information
|
|
107
|
-
python3 linuxmonitor
|
|
107
|
+
python3 -m linuxmonitor.py --os_infos --config_file config-example.json
|
|
108
108
|
|
|
109
109
|
# View connected users
|
|
110
|
-
python3 linuxmonitor
|
|
110
|
+
python3 -m linuxmonitor.py --users --config_file config-example.json
|
|
111
111
|
|
|
112
112
|
# View last user connections
|
|
113
|
-
python3 linuxmonitor
|
|
113
|
+
python3 -m linuxmonitor.py --user_logins --config_file config-example.json
|
|
114
114
|
|
|
115
115
|
# Check websites (ping)
|
|
116
|
-
python3 linuxmonitor
|
|
116
|
+
python3 -m linuxmonitor.py --ping --config_file config-example.json
|
|
117
117
|
|
|
118
118
|
# Check SSL certificates
|
|
119
|
-
python3 linuxmonitor
|
|
119
|
+
python3 -m linuxmonitor.py --certificates --config_file config-example.json
|
|
120
120
|
|
|
121
121
|
# Check if services are running and restart if down
|
|
122
|
-
python3 linuxmonitor
|
|
122
|
+
python3 -m linuxmonitor.py --services_status --config_file config-example.json
|
|
123
123
|
|
|
124
124
|
# List all available services
|
|
125
|
-
python3 linuxmonitor
|
|
125
|
+
python3 -m linuxmonitor.py --list_services --config_file config-example.json
|
|
126
126
|
|
|
127
127
|
# Restart all services
|
|
128
|
-
python3 linuxmonitor
|
|
128
|
+
python3 -m linuxmonitor.py --restart_all --config_file config-example.json
|
|
129
129
|
|
|
130
130
|
# Restart a service
|
|
131
|
-
python3 linuxmonitor
|
|
131
|
+
python3 -m linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
132
132
|
|
|
133
133
|
# Check ports
|
|
134
|
-
python3 linuxmonitor
|
|
134
|
+
python3 -m linuxmonitor.py --ports --config_file config-example.json
|
|
135
135
|
|
|
136
136
|
# List active processes
|
|
137
|
-
python3 linuxmonitor
|
|
137
|
+
python3 -m linuxmonitor.py --list_processes --config_file config-example.json
|
|
138
138
|
|
|
139
139
|
# Stop a process by PID
|
|
140
|
-
python3 linuxmonitor
|
|
140
|
+
python3 -m linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
141
141
|
|
|
142
142
|
# Restart the entire server
|
|
143
|
-
python3 linuxmonitor
|
|
143
|
+
python3 -m linuxmonitor.py --reboot_server --config_file config-example.json
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
## How to use in python script
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LinuxMonitor
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
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
5
|
Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
|
|
6
6
|
Author: Quentin Comte-Gaz
|
|
@@ -77,14 +77,14 @@ echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNA
|
|
|
77
77
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
78
78
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
79
79
|
```
|
|
80
|
-
- Check monitor possibilities (you can find it out by calling `python linuxmonitor
|
|
80
|
+
- Check monitor possibilities (you can find it out by calling `python -m linuxmonitor.py --help` from the root of this repository)
|
|
81
81
|
- Load your shell or python script
|
|
82
82
|
|
|
83
83
|
## How to use in shell
|
|
84
84
|
|
|
85
85
|
```shell
|
|
86
86
|
# Get help
|
|
87
|
-
python3 linuxmonitor
|
|
87
|
+
python3 -m linuxmonitor.py --help
|
|
88
88
|
# Use "--debug" to show more information during command
|
|
89
89
|
# Use "--nodebug" to not show any warning information during command
|
|
90
90
|
|
|
@@ -92,55 +92,55 @@ python3 linuxmonitor/linuxmonitor.py --help
|
|
|
92
92
|
|
|
93
93
|
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
94
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
|
|
95
|
+
python3 -m linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
96
96
|
|
|
97
97
|
# Start periodic task to show system information periodically (will run indefinitely)
|
|
98
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
|
|
99
|
+
python3 -m linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
100
100
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
# View disk space, CPU, RAM, ...
|
|
104
|
-
python3 linuxmonitor
|
|
104
|
+
python3 -m linuxmonitor.py --usage --config_file config-example.json
|
|
105
105
|
|
|
106
106
|
# View basic system information
|
|
107
|
-
python3 linuxmonitor
|
|
107
|
+
python3 -m linuxmonitor.py --os_infos --config_file config-example.json
|
|
108
108
|
|
|
109
109
|
# View connected users
|
|
110
|
-
python3 linuxmonitor
|
|
110
|
+
python3 -m linuxmonitor.py --users --config_file config-example.json
|
|
111
111
|
|
|
112
112
|
# View last user connections
|
|
113
|
-
python3 linuxmonitor
|
|
113
|
+
python3 -m linuxmonitor.py --user_logins --config_file config-example.json
|
|
114
114
|
|
|
115
115
|
# Check websites (ping)
|
|
116
|
-
python3 linuxmonitor
|
|
116
|
+
python3 -m linuxmonitor.py --ping --config_file config-example.json
|
|
117
117
|
|
|
118
118
|
# Check SSL certificates
|
|
119
|
-
python3 linuxmonitor
|
|
119
|
+
python3 -m linuxmonitor.py --certificates --config_file config-example.json
|
|
120
120
|
|
|
121
121
|
# Check if services are running and restart if down
|
|
122
|
-
python3 linuxmonitor
|
|
122
|
+
python3 -m linuxmonitor.py --services_status --config_file config-example.json
|
|
123
123
|
|
|
124
124
|
# List all available services
|
|
125
|
-
python3 linuxmonitor
|
|
125
|
+
python3 -m linuxmonitor.py --list_services --config_file config-example.json
|
|
126
126
|
|
|
127
127
|
# Restart all services
|
|
128
|
-
python3 linuxmonitor
|
|
128
|
+
python3 -m linuxmonitor.py --restart_all --config_file config-example.json
|
|
129
129
|
|
|
130
130
|
# Restart a service
|
|
131
|
-
python3 linuxmonitor
|
|
131
|
+
python3 -m linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
132
132
|
|
|
133
133
|
# Check ports
|
|
134
|
-
python3 linuxmonitor
|
|
134
|
+
python3 -m linuxmonitor.py --ports --config_file config-example.json
|
|
135
135
|
|
|
136
136
|
# List active processes
|
|
137
|
-
python3 linuxmonitor
|
|
137
|
+
python3 -m linuxmonitor.py --list_processes --config_file config-example.json
|
|
138
138
|
|
|
139
139
|
# Stop a process by PID
|
|
140
|
-
python3 linuxmonitor
|
|
140
|
+
python3 -m linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
141
141
|
|
|
142
142
|
# Restart the entire server
|
|
143
|
-
python3 linuxmonitor
|
|
143
|
+
python3 -m linuxmonitor.py --reboot_server --config_file config-example.json
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
## How to use in python script
|
|
@@ -49,14 +49,14 @@ echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /bin/systemctl" >> /etc/sudoers.d/USERNA
|
|
|
49
49
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/apache2" >> /etc/sudoers.d/USERNAME_HERE
|
|
50
50
|
echo "USERNAME_HERE ALL=(ALL) NOPASSWD: /etc/init.d/mariadb" >> /etc/sudoers.d/USERNAME_HERE
|
|
51
51
|
```
|
|
52
|
-
- Check monitor possibilities (you can find it out by calling `python linuxmonitor
|
|
52
|
+
- Check monitor possibilities (you can find it out by calling `python -m linuxmonitor.py --help` from the root of this repository)
|
|
53
53
|
- Load your shell or python script
|
|
54
54
|
|
|
55
55
|
## How to use in shell
|
|
56
56
|
|
|
57
57
|
```shell
|
|
58
58
|
# Get help
|
|
59
|
-
python3 linuxmonitor
|
|
59
|
+
python3 -m linuxmonitor.py --help
|
|
60
60
|
# Use "--debug" to show more information during command
|
|
61
61
|
# Use "--nodebug" to not show any warning information during command
|
|
62
62
|
|
|
@@ -64,55 +64,55 @@ python3 linuxmonitor/linuxmonitor.py --help
|
|
|
64
64
|
|
|
65
65
|
# Start periodic task to show potential issues periodically (will run indefinitely)
|
|
66
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
|
|
67
|
+
python3 -m linuxmonitor.py --start_scheduled_task_check_for_issues --config_file config-example.json --nodebug
|
|
68
68
|
|
|
69
69
|
# Start periodic task to show system information periodically (will run indefinitely)
|
|
70
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
|
|
71
|
+
python3 -m linuxmonitor.py --start_scheduled_task_show_info --config_file config-example.json --nodebug
|
|
72
72
|
|
|
73
73
|
|
|
74
74
|
|
|
75
75
|
# View disk space, CPU, RAM, ...
|
|
76
|
-
python3 linuxmonitor
|
|
76
|
+
python3 -m linuxmonitor.py --usage --config_file config-example.json
|
|
77
77
|
|
|
78
78
|
# View basic system information
|
|
79
|
-
python3 linuxmonitor
|
|
79
|
+
python3 -m linuxmonitor.py --os_infos --config_file config-example.json
|
|
80
80
|
|
|
81
81
|
# View connected users
|
|
82
|
-
python3 linuxmonitor
|
|
82
|
+
python3 -m linuxmonitor.py --users --config_file config-example.json
|
|
83
83
|
|
|
84
84
|
# View last user connections
|
|
85
|
-
python3 linuxmonitor
|
|
85
|
+
python3 -m linuxmonitor.py --user_logins --config_file config-example.json
|
|
86
86
|
|
|
87
87
|
# Check websites (ping)
|
|
88
|
-
python3 linuxmonitor
|
|
88
|
+
python3 -m linuxmonitor.py --ping --config_file config-example.json
|
|
89
89
|
|
|
90
90
|
# Check SSL certificates
|
|
91
|
-
python3 linuxmonitor
|
|
91
|
+
python3 -m linuxmonitor.py --certificates --config_file config-example.json
|
|
92
92
|
|
|
93
93
|
# Check if services are running and restart if down
|
|
94
|
-
python3 linuxmonitor
|
|
94
|
+
python3 -m linuxmonitor.py --services_status --config_file config-example.json
|
|
95
95
|
|
|
96
96
|
# List all available services
|
|
97
|
-
python3 linuxmonitor
|
|
97
|
+
python3 -m linuxmonitor.py --list_services --config_file config-example.json
|
|
98
98
|
|
|
99
99
|
# Restart all services
|
|
100
|
-
python3 linuxmonitor
|
|
100
|
+
python3 -m linuxmonitor.py --restart_all --config_file config-example.json
|
|
101
101
|
|
|
102
102
|
# Restart a service
|
|
103
|
-
python3 linuxmonitor
|
|
103
|
+
python3 -m linuxmonitor.py --restart_service SERVICE_NAME_HERE --config_file config-example.json
|
|
104
104
|
|
|
105
105
|
# Check ports
|
|
106
|
-
python3 linuxmonitor
|
|
106
|
+
python3 -m linuxmonitor.py --ports --config_file config-example.json
|
|
107
107
|
|
|
108
108
|
# List active processes
|
|
109
|
-
python3 linuxmonitor
|
|
109
|
+
python3 -m linuxmonitor.py --list_processes --config_file config-example.json
|
|
110
110
|
|
|
111
111
|
# Stop a process by PID
|
|
112
|
-
python3 linuxmonitor
|
|
112
|
+
python3 -m linuxmonitor.py --kill_process PID_HERE --config_file config-example.json
|
|
113
113
|
|
|
114
114
|
# Restart the entire server
|
|
115
|
-
python3 linuxmonitor
|
|
115
|
+
python3 -m linuxmonitor.py --reboot_server --config_file config-example.json
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
## How to use in python script
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
from .linuxmonitor import LinuxMonitor
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
import logging
|
|
6
|
+
import asyncio
|
|
7
|
+
|
|
8
|
+
def main() -> None:
|
|
9
|
+
parser = argparse.ArgumentParser(description='System Management CLI Tool')
|
|
10
|
+
|
|
11
|
+
# Define available arguments
|
|
12
|
+
parser.add_argument('--config_file', type=str, required=True, help='Path to the configuration file (must be a JSON file)')
|
|
13
|
+
parser.add_argument('--start_scheduled_task_check_for_issues', action='store_true', help='Start periodic task to show potential issues periodically (in background, will not stop until you stop the script)')
|
|
14
|
+
parser.add_argument('--start_scheduled_task_show_info', action='store_true', help='Start periodic task to show system information periodically (in background, will not stop until you stop the script)')
|
|
15
|
+
parser.add_argument('--usage', action='store_true', help='📊 View disk space, CPU, RAM, ... 📊')
|
|
16
|
+
parser.add_argument('--os_infos', action='store_true', help='🖥 View basic system information 🖥')
|
|
17
|
+
parser.add_argument('--users', action='store_true', help='👥 View connected users 👥')
|
|
18
|
+
parser.add_argument('--user_logins', action='store_true', help='👥 View last user connections 👥')
|
|
19
|
+
parser.add_argument('--ping', action='store_true', help='🌐 Ping websites 🌐')
|
|
20
|
+
parser.add_argument('--certificates', action='store_true', help='🔒 Check SSL certificates 🔒')
|
|
21
|
+
parser.add_argument('--reboot_server', action='store_true', help='🔄 Restart the entire server 🔄')
|
|
22
|
+
parser.add_argument('--services_status', action='store_true', help='🩺 Check services are running 🩺')
|
|
23
|
+
parser.add_argument('--restart_all', action='store_true', help='🚀 Restart all services 🚀')
|
|
24
|
+
parser.add_argument('--restart_service', type=str, help='🚀 Restart a service 🚀')
|
|
25
|
+
parser.add_argument('--list_services', action='store_true', help='📋 List all available services 📋')
|
|
26
|
+
parser.add_argument('--ports', action='store_true', help='🔒 Check ports 🔒')
|
|
27
|
+
parser.add_argument('--list_processes', action='store_true', help='📋 List active processes 📋')
|
|
28
|
+
parser.add_argument('--kill_process', type=int, help='🚫 Stop a process by PID 🚫')
|
|
29
|
+
|
|
30
|
+
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
|
|
31
|
+
parser.add_argument('--nodebug', action='store_true', help='Disable all logs')
|
|
32
|
+
|
|
33
|
+
# Parse arguments
|
|
34
|
+
args = parser.parse_args()
|
|
35
|
+
|
|
36
|
+
# Enable or disable debug mode
|
|
37
|
+
if args.debug:
|
|
38
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
|
39
|
+
elif args.nodebug:
|
|
40
|
+
logging.getLogger().setLevel(logging.CRITICAL)
|
|
41
|
+
else:
|
|
42
|
+
# Default to warning
|
|
43
|
+
logging.getLogger().setLevel(logging.WARNING)
|
|
44
|
+
|
|
45
|
+
# Ensure the config file is provided
|
|
46
|
+
if not args.config_file:
|
|
47
|
+
print("Error: --config_file is required")
|
|
48
|
+
parser.print_help()
|
|
49
|
+
sys.exit(1)
|
|
50
|
+
|
|
51
|
+
allow_scheduled_tasks_check_for_issues: bool = args.start_scheduled_task_check_for_issues is not None
|
|
52
|
+
allow_scheduled_task_show_info: bool = args.start_scheduled_task_show_info is not None
|
|
53
|
+
monitoring = LinuxMonitor(config_file=args.config_file, allow_scheduled_tasks_check_for_issues=allow_scheduled_tasks_check_for_issues, allow_scheduled_task_show_info=allow_scheduled_task_show_info)
|
|
54
|
+
|
|
55
|
+
# Handle all commands
|
|
56
|
+
handled: bool = False
|
|
57
|
+
|
|
58
|
+
if args.usage:
|
|
59
|
+
handled = True
|
|
60
|
+
print("Viewing disk space, CPU, RAM, ...")
|
|
61
|
+
out_msg: str = monitoring.check_all_disk_usage(is_private=True, display_only_if_critical=False)
|
|
62
|
+
msg: str = monitoring.check_all_folder_usage(is_private=True, display_only_if_critical=False)
|
|
63
|
+
if msg != "":
|
|
64
|
+
if out_msg != "":
|
|
65
|
+
out_msg += "\n"
|
|
66
|
+
out_msg += msg
|
|
67
|
+
|
|
68
|
+
out_msg += "\n"
|
|
69
|
+
out_msg += monitoring.check_cpu_usage(display_only_if_critical=False) + "\n"
|
|
70
|
+
out_msg += monitoring.check_ram_usage(display_only_if_critical=False) + "\n"
|
|
71
|
+
out_msg += monitoring.check_swap_usage(display_only_if_critical=False) + "\n"
|
|
72
|
+
out_msg += monitoring.check_cpu_temperature(display_only_if_critical=False) + "\n"
|
|
73
|
+
out_msg += monitoring.get_network_info()
|
|
74
|
+
print(out_msg)
|
|
75
|
+
|
|
76
|
+
if args.os_infos:
|
|
77
|
+
handled = True
|
|
78
|
+
print("Viewing basic system information...")
|
|
79
|
+
out_msg: str = monitoring.get_hostname() + "\n"
|
|
80
|
+
out_msg += monitoring.get_os_details() + "\n"
|
|
81
|
+
out_msg += monitoring.get_kernel_version() + "\n"
|
|
82
|
+
out_msg += monitoring.get_uptime() + "\n"
|
|
83
|
+
out_msg += monitoring.get_server_datetime()
|
|
84
|
+
print(out_msg)
|
|
85
|
+
|
|
86
|
+
if args.users:
|
|
87
|
+
handled = True
|
|
88
|
+
print("Viewing connected users...")
|
|
89
|
+
out_msg: str = monitoring.get_connected_users()
|
|
90
|
+
print(out_msg)
|
|
91
|
+
|
|
92
|
+
if args.user_logins:
|
|
93
|
+
handled = True
|
|
94
|
+
print("Viewing last user connections...")
|
|
95
|
+
out_msg: str = monitoring.check_all_recent_user_logins(display_only_if_critical=False)
|
|
96
|
+
print(out_msg)
|
|
97
|
+
|
|
98
|
+
if args.ping:
|
|
99
|
+
handled = True
|
|
100
|
+
print("Pinging websites...")
|
|
101
|
+
out_msg: str = monitoring.ping_all_websites(is_private=True, display_only_if_critical=False)
|
|
102
|
+
print(out_msg)
|
|
103
|
+
|
|
104
|
+
if args.certificates:
|
|
105
|
+
handled = True
|
|
106
|
+
print("Checking SSL certificates...")
|
|
107
|
+
out_msg: str = monitoring.check_all_certificates(is_private=True, display_only_if_critical=False)
|
|
108
|
+
print(out_msg)
|
|
109
|
+
|
|
110
|
+
if args.reboot_server:
|
|
111
|
+
handled = True
|
|
112
|
+
print("Restarting the entire server...")
|
|
113
|
+
out_msg: str = monitoring.reboot_server()
|
|
114
|
+
print(out_msg)
|
|
115
|
+
|
|
116
|
+
if args.services_status:
|
|
117
|
+
handled = True
|
|
118
|
+
print("Checking if services are running and restart if down...")
|
|
119
|
+
out_msg: str = monitoring.check_all_services_status_and_restart_if_down(is_private=True)
|
|
120
|
+
print(out_msg)
|
|
121
|
+
|
|
122
|
+
if args.restart_all:
|
|
123
|
+
handled = True
|
|
124
|
+
print("Restarting all services...")
|
|
125
|
+
out_msg: str = monitoring.restart_all_services(is_private=True)
|
|
126
|
+
|
|
127
|
+
if args.restart_service is not None:
|
|
128
|
+
handled = True
|
|
129
|
+
print(f"Restarting service: {args.restart_service}...")
|
|
130
|
+
out_msg: str = monitoring.restart_service(is_private=True, service_name=args.restart_service)
|
|
131
|
+
print(out_msg)
|
|
132
|
+
|
|
133
|
+
if args.list_services:
|
|
134
|
+
handled = True
|
|
135
|
+
print("Listing all available services...")
|
|
136
|
+
out_msg: str = monitoring.get_all_services_allowed_to_restart(is_private=True)
|
|
137
|
+
print(out_msg)
|
|
138
|
+
|
|
139
|
+
if args.ports:
|
|
140
|
+
handled = True
|
|
141
|
+
print("Checking ports...")
|
|
142
|
+
out_msg: str = monitoring.check_all_ports(is_private=True, display_only_if_critical=False, restart_if_down=False)
|
|
143
|
+
print(out_msg)
|
|
144
|
+
|
|
145
|
+
if args.list_processes:
|
|
146
|
+
handled = True
|
|
147
|
+
print("Listing active processes...")
|
|
148
|
+
out_msg: str = monitoring.get_ordered_processes(get_non_consuming_processes=False)
|
|
149
|
+
print(out_msg)
|
|
150
|
+
|
|
151
|
+
if args.kill_process is not None:
|
|
152
|
+
handled = True
|
|
153
|
+
print(f"Stopping process with PID: {args.kill_process}...")
|
|
154
|
+
out_msg: str = monitoring.kill_process(pid=args.kill_process)
|
|
155
|
+
print(out_msg)
|
|
156
|
+
|
|
157
|
+
if args.start_scheduled_task_check_for_issues:
|
|
158
|
+
handled = True
|
|
159
|
+
print("Starting periodic task (will show something only in case of error (or if debug enabled))...")
|
|
160
|
+
async def async_print(msg: str) -> None:
|
|
161
|
+
print(msg)
|
|
162
|
+
asyncio.run(monitoring.schedule_task(handle_error_message=async_print, is_private=True))
|
|
163
|
+
|
|
164
|
+
if args.start_scheduled_task_show_info:
|
|
165
|
+
handled = True
|
|
166
|
+
print("Starting periodic task (will show system information periodically)...")
|
|
167
|
+
async def async_print(msg: str) -> None:
|
|
168
|
+
print(msg)
|
|
169
|
+
asyncio.run(monitoring.schedule_task_show_info(show_message=async_print, is_private=True))
|
|
170
|
+
|
|
171
|
+
# Show help if no command was provided or the command was not recognized
|
|
172
|
+
if not handled:
|
|
173
|
+
parser.print_help()
|
|
174
|
+
|
|
175
|
+
if __name__ == "__main__":
|
|
176
|
+
main()
|
|
@@ -28,7 +28,7 @@ __email__ = "quentin@comte-gaz.com"
|
|
|
28
28
|
__license__ = "MIT License"
|
|
29
29
|
__copyright__ = "Copyright Quentin Comte-Gaz (2024)"
|
|
30
30
|
__python_version__ = "3.+"
|
|
31
|
-
__version__ = "1.0.
|
|
31
|
+
__version__ = "1.0.4 (2024/09/14)"
|
|
32
32
|
__status__ = "Usable for any Linux project"
|
|
33
33
|
|
|
34
34
|
import json
|
|
@@ -45,8 +45,6 @@ import platform
|
|
|
45
45
|
import re
|
|
46
46
|
import logging
|
|
47
47
|
import asyncio
|
|
48
|
-
import argparse
|
|
49
|
-
import sys
|
|
50
48
|
|
|
51
49
|
class LinuxMonitor:
|
|
52
50
|
def __init__(self, config_file: str, allow_scheduled_tasks_check_for_issues: bool, allow_scheduled_task_show_info: bool) -> None:
|
|
@@ -701,7 +699,7 @@ class LinuxMonitor:
|
|
|
701
699
|
|
|
702
700
|
#region Ping Websites
|
|
703
701
|
|
|
704
|
-
def _ping_website(self, website: str, display_name: str, display_only_if_critical: bool=False) -> str:
|
|
702
|
+
def _ping_website(self, website: str, display_name: str, timeout_in_sec: int, display_only_if_critical: bool=False) -> str:
|
|
705
703
|
"""
|
|
706
704
|
Ping a website.
|
|
707
705
|
|
|
@@ -715,7 +713,7 @@ class LinuxMonitor:
|
|
|
715
713
|
display_name = f"[{display_name}](https://{website})"
|
|
716
714
|
|
|
717
715
|
start_time: float = time.time()
|
|
718
|
-
res, out_msg = self.execute_and_verify(command=ping_command, display_name=f"ping {display_name}", timeout_in_sec=
|
|
716
|
+
res, out_msg = self.execute_and_verify(command=ping_command, display_name=f"ping {display_name}", timeout_in_sec=timeout_in_sec, display_only_if_critical=display_only_if_critical)
|
|
719
717
|
end_time: float = time.time()
|
|
720
718
|
|
|
721
719
|
if res == True and not display_only_if_critical:
|
|
@@ -737,7 +735,8 @@ class LinuxMonitor:
|
|
|
737
735
|
out_msg: str = ""
|
|
738
736
|
for ping_config in self.config['pings']:
|
|
739
737
|
if is_private or is_private == ping_config['is_private']:
|
|
740
|
-
|
|
738
|
+
timeout_in_sec: int = ping_config.get('timeout_in_sec', 5)
|
|
739
|
+
result: str = self._ping_website(website=ping_config['website'], display_name=ping_config['display_name'], timeout_in_sec=timeout_in_sec, display_only_if_critical=display_only_if_critical)
|
|
741
740
|
if result:
|
|
742
741
|
if out_msg:
|
|
743
742
|
out_msg += "\n"
|
|
@@ -1993,173 +1992,3 @@ class LinuxMonitor:
|
|
|
1993
1992
|
await asyncio.sleep(delay=self.duration_in_sec_wait_between_each_schedule_task_show_info_execution)
|
|
1994
1993
|
|
|
1995
1994
|
#endregion
|
|
1996
|
-
|
|
1997
|
-
def main() -> None:
|
|
1998
|
-
parser = argparse.ArgumentParser(description='System Management CLI Tool')
|
|
1999
|
-
|
|
2000
|
-
# Define available arguments
|
|
2001
|
-
parser.add_argument('--config_file', type=str, required=True, help='Path to the configuration file (must be a JSON file)')
|
|
2002
|
-
parser.add_argument('--start_scheduled_task_check_for_issues', action='store_true', help='Start periodic task to show potential issues periodically (in background, will not stop until you stop the script)')
|
|
2003
|
-
parser.add_argument('--start_scheduled_task_show_info', action='store_true', help='Start periodic task to show system information periodically (in background, will not stop until you stop the script)')
|
|
2004
|
-
parser.add_argument('--usage', action='store_true', help='📊 View disk space, CPU, RAM, ... 📊')
|
|
2005
|
-
parser.add_argument('--os_infos', action='store_true', help='🖥 View basic system information 🖥')
|
|
2006
|
-
parser.add_argument('--users', action='store_true', help='👥 View connected users 👥')
|
|
2007
|
-
parser.add_argument('--user_logins', action='store_true', help='👥 View last user connections 👥')
|
|
2008
|
-
parser.add_argument('--ping', action='store_true', help='🌐 Ping websites 🌐')
|
|
2009
|
-
parser.add_argument('--certificates', action='store_true', help='🔒 Check SSL certificates 🔒')
|
|
2010
|
-
parser.add_argument('--reboot_server', action='store_true', help='🔄 Restart the entire server 🔄')
|
|
2011
|
-
parser.add_argument('--services_status', action='store_true', help='🩺 Check services are running 🩺')
|
|
2012
|
-
parser.add_argument('--restart_all', action='store_true', help='🚀 Restart all services 🚀')
|
|
2013
|
-
parser.add_argument('--restart_service', type=str, help='🚀 Restart a service 🚀')
|
|
2014
|
-
parser.add_argument('--list_services', action='store_true', help='📋 List all available services 📋')
|
|
2015
|
-
parser.add_argument('--ports', action='store_true', help='🔒 Check ports 🔒')
|
|
2016
|
-
parser.add_argument('--list_processes', action='store_true', help='📋 List active processes 📋')
|
|
2017
|
-
parser.add_argument('--kill_process', type=int, help='🚫 Stop a process by PID 🚫')
|
|
2018
|
-
|
|
2019
|
-
parser.add_argument('--debug', action='store_true', help='Enable debug mode')
|
|
2020
|
-
parser.add_argument('--nodebug', action='store_true', help='Disable all logs')
|
|
2021
|
-
|
|
2022
|
-
# Parse arguments
|
|
2023
|
-
args = parser.parse_args()
|
|
2024
|
-
|
|
2025
|
-
# Enable or disable debug mode
|
|
2026
|
-
if args.debug:
|
|
2027
|
-
logging.getLogger().setLevel(logging.DEBUG)
|
|
2028
|
-
elif args.nodebug:
|
|
2029
|
-
logging.getLogger().setLevel(logging.CRITICAL)
|
|
2030
|
-
else:
|
|
2031
|
-
# Default to warning
|
|
2032
|
-
logging.getLogger().setLevel(logging.WARNING)
|
|
2033
|
-
|
|
2034
|
-
# Ensure the config file is provided
|
|
2035
|
-
if not args.config_file:
|
|
2036
|
-
print("Error: --config_file is required")
|
|
2037
|
-
parser.print_help()
|
|
2038
|
-
sys.exit(1)
|
|
2039
|
-
|
|
2040
|
-
allow_scheduled_tasks_check_for_issues: bool = args.start_scheduled_task_check_for_issues is not None
|
|
2041
|
-
allow_scheduled_task_show_info: bool = args.start_scheduled_task_show_info is not None
|
|
2042
|
-
monitoring = LinuxMonitor(config_file=args.config_file, allow_scheduled_tasks_check_for_issues=allow_scheduled_tasks_check_for_issues, allow_scheduled_task_show_info=allow_scheduled_task_show_info)
|
|
2043
|
-
|
|
2044
|
-
# Handle all commands
|
|
2045
|
-
handled: bool = False
|
|
2046
|
-
|
|
2047
|
-
if args.usage:
|
|
2048
|
-
handled = True
|
|
2049
|
-
print("Viewing disk space, CPU, RAM, ...")
|
|
2050
|
-
out_msg: str = monitoring.check_all_disk_usage(is_private=True, display_only_if_critical=False)
|
|
2051
|
-
msg: str = monitoring.check_all_folder_usage(is_private=True, display_only_if_critical=False)
|
|
2052
|
-
if msg != "":
|
|
2053
|
-
if out_msg != "":
|
|
2054
|
-
out_msg += "\n"
|
|
2055
|
-
out_msg += msg
|
|
2056
|
-
|
|
2057
|
-
out_msg += "\n"
|
|
2058
|
-
out_msg += monitoring.check_cpu_usage(display_only_if_critical=False) + "\n"
|
|
2059
|
-
out_msg += monitoring.check_ram_usage(display_only_if_critical=False) + "\n"
|
|
2060
|
-
out_msg += monitoring.check_swap_usage(display_only_if_critical=False) + "\n"
|
|
2061
|
-
out_msg += monitoring.check_cpu_temperature(display_only_if_critical=False) + "\n"
|
|
2062
|
-
out_msg += monitoring.get_network_info()
|
|
2063
|
-
print(out_msg)
|
|
2064
|
-
|
|
2065
|
-
if args.os_infos:
|
|
2066
|
-
handled = True
|
|
2067
|
-
print("Viewing basic system information...")
|
|
2068
|
-
out_msg: str = monitoring.get_hostname() + "\n"
|
|
2069
|
-
out_msg += monitoring.get_os_details() + "\n"
|
|
2070
|
-
out_msg += monitoring.get_kernel_version() + "\n"
|
|
2071
|
-
out_msg += monitoring.get_uptime() + "\n"
|
|
2072
|
-
out_msg += monitoring.get_server_datetime()
|
|
2073
|
-
print(out_msg)
|
|
2074
|
-
|
|
2075
|
-
if args.users:
|
|
2076
|
-
handled = True
|
|
2077
|
-
print("Viewing connected users...")
|
|
2078
|
-
out_msg: str = monitoring.get_connected_users()
|
|
2079
|
-
print(out_msg)
|
|
2080
|
-
|
|
2081
|
-
if args.user_logins:
|
|
2082
|
-
handled = True
|
|
2083
|
-
print("Viewing last user connections...")
|
|
2084
|
-
out_msg: str = monitoring.check_all_recent_user_logins(display_only_if_critical=False)
|
|
2085
|
-
print(out_msg)
|
|
2086
|
-
|
|
2087
|
-
if args.ping:
|
|
2088
|
-
handled = True
|
|
2089
|
-
print("Pinging websites...")
|
|
2090
|
-
out_msg: str = monitoring.ping_all_websites(is_private=True, display_only_if_critical=False)
|
|
2091
|
-
print(out_msg)
|
|
2092
|
-
|
|
2093
|
-
if args.certificates:
|
|
2094
|
-
handled = True
|
|
2095
|
-
print("Checking SSL certificates...")
|
|
2096
|
-
out_msg: str = monitoring.check_all_certificates(is_private=True, display_only_if_critical=False)
|
|
2097
|
-
print(out_msg)
|
|
2098
|
-
|
|
2099
|
-
if args.reboot_server:
|
|
2100
|
-
handled = True
|
|
2101
|
-
print("Restarting the entire server...")
|
|
2102
|
-
out_msg: str = monitoring.reboot_server()
|
|
2103
|
-
print(out_msg)
|
|
2104
|
-
|
|
2105
|
-
if args.services_status:
|
|
2106
|
-
handled = True
|
|
2107
|
-
print("Checking if services are running and restart if down...")
|
|
2108
|
-
out_msg: str = monitoring.check_all_services_status_and_restart_if_down(is_private=True)
|
|
2109
|
-
print(out_msg)
|
|
2110
|
-
|
|
2111
|
-
if args.restart_all:
|
|
2112
|
-
handled = True
|
|
2113
|
-
print("Restarting all services...")
|
|
2114
|
-
out_msg: str = monitoring.restart_all_services(is_private=True)
|
|
2115
|
-
|
|
2116
|
-
if args.restart_service is not None:
|
|
2117
|
-
handled = True
|
|
2118
|
-
print(f"Restarting service: {args.restart_service}...")
|
|
2119
|
-
out_msg: str = monitoring.restart_service(is_private=True, service_name=args.restart_service)
|
|
2120
|
-
print(out_msg)
|
|
2121
|
-
|
|
2122
|
-
if args.list_services:
|
|
2123
|
-
handled = True
|
|
2124
|
-
print("Listing all available services...")
|
|
2125
|
-
out_msg: str = monitoring.get_all_services_allowed_to_restart(is_private=True)
|
|
2126
|
-
print(out_msg)
|
|
2127
|
-
|
|
2128
|
-
if args.ports:
|
|
2129
|
-
handled = True
|
|
2130
|
-
print("Checking ports...")
|
|
2131
|
-
out_msg: str = monitoring.check_all_ports(is_private=True, display_only_if_critical=False, restart_if_down=False)
|
|
2132
|
-
print(out_msg)
|
|
2133
|
-
|
|
2134
|
-
if args.list_processes:
|
|
2135
|
-
handled = True
|
|
2136
|
-
print("Listing active processes...")
|
|
2137
|
-
out_msg: str = monitoring.get_ordered_processes(get_non_consuming_processes=False)
|
|
2138
|
-
print(out_msg)
|
|
2139
|
-
|
|
2140
|
-
if args.kill_process is not None:
|
|
2141
|
-
handled = True
|
|
2142
|
-
print(f"Stopping process with PID: {args.kill_process}...")
|
|
2143
|
-
out_msg: str = monitoring.kill_process(pid=args.kill_process)
|
|
2144
|
-
print(out_msg)
|
|
2145
|
-
|
|
2146
|
-
if args.start_scheduled_task_check_for_issues:
|
|
2147
|
-
handled = True
|
|
2148
|
-
print("Starting periodic task (will show something only in case of error (or if debug enabled))...")
|
|
2149
|
-
async def async_print(msg: str) -> None:
|
|
2150
|
-
print(msg)
|
|
2151
|
-
asyncio.run(monitoring.schedule_task(handle_error_message=async_print, is_private=True))
|
|
2152
|
-
|
|
2153
|
-
if args.start_scheduled_task_show_info:
|
|
2154
|
-
handled = True
|
|
2155
|
-
print("Starting periodic task (will show system information periodically)...")
|
|
2156
|
-
async def async_print(msg: str) -> None:
|
|
2157
|
-
print(msg)
|
|
2158
|
-
asyncio.run(monitoring.schedule_task_show_info(show_message=async_print, is_private=True))
|
|
2159
|
-
|
|
2160
|
-
# Show help if no command was provided or the command was not recognized
|
|
2161
|
-
if not handled:
|
|
2162
|
-
parser.print_help()
|
|
2163
|
-
|
|
2164
|
-
if __name__ == "__main__":
|
|
2165
|
-
main()
|
|
@@ -6,7 +6,7 @@ with io.open(file='README.md', mode='r', encoding='utf-8') as readme_file:
|
|
|
6
6
|
|
|
7
7
|
setup(
|
|
8
8
|
name="LinuxMonitor",
|
|
9
|
-
version="1.0.
|
|
9
|
+
version="1.0.4",
|
|
10
10
|
description="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)",
|
|
11
11
|
long_description=readme,
|
|
12
12
|
long_description_content_type="text/markdown",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|