[NEW] refactoring of maintenance_server_monitoring in several modules
This commit is contained in:
2
maintenance_server_monitoring_memory/.gitignore
vendored
Normal file
2
maintenance_server_monitoring_memory/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.*~
|
||||
*pyc
|
44
maintenance_server_monitoring_memory/README.rst
Normal file
44
maintenance_server_monitoring_memory/README.rst
Normal file
@@ -0,0 +1,44 @@
|
||||
======================================
|
||||
maintenance_server_monitoring_memory
|
||||
======================================
|
||||
|
||||
Improve monitoring with ping test
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Use Odoo normal module installation procedure to install
|
||||
``maintenance_server_monitoring_memory``.
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
None yet.
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `our issues website <https://github.com/elabore-coop/maintenance-tools/issues>`_. In case of
|
||||
trouble, please check there if your issue has already been
|
||||
reported. If you spotted it first, help us smashing it by providing a
|
||||
detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Clément Thomas
|
||||
|
||||
Funders
|
||||
-------
|
||||
|
||||
The development of this module has been financially supported by:
|
||||
* Elabore (https://elabore.coop)
|
||||
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
This module is maintained by Elabore.
|
3
maintenance_server_monitoring_memory/__init__.py
Normal file
3
maintenance_server_monitoring_memory/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from . import models
|
37
maintenance_server_monitoring_memory/__manifest__.py
Normal file
37
maintenance_server_monitoring_memory/__manifest__.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# Copyright 2023 Stéphan Sainléger (Elabore)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
{
|
||||
"name": "maintenance_server_monitoring_memory",
|
||||
"version": "14.0.1.0.0",
|
||||
"author": "Elabore",
|
||||
"website": "https://elabore.coop",
|
||||
"maintainer": "Clément Thomas",
|
||||
"license": "AGPL-3",
|
||||
"category": "Tools",
|
||||
"summary": "Monitor memory on remote hosts",
|
||||
# any module necessary for this one to work correctly
|
||||
"depends": [
|
||||
"maintenance_server_monitoring",
|
||||
"maintenance_server_ssh"
|
||||
],
|
||||
"qweb": [
|
||||
# "static/src/xml/*.xml",
|
||||
],
|
||||
"external_dependencies": {
|
||||
"python": [],
|
||||
},
|
||||
# always loaded
|
||||
"data": [
|
||||
|
||||
],
|
||||
# only loaded in demonstration mode
|
||||
"demo": [],
|
||||
"js": [],
|
||||
"css": [],
|
||||
"installable": True,
|
||||
# Install this module automatically if all dependency have been previously
|
||||
# and independently installed. Used for synergetic or glue modules.
|
||||
"auto_install": False,
|
||||
"application": False,
|
||||
}
|
1
maintenance_server_monitoring_memory/models/__init__.py
Normal file
1
maintenance_server_monitoring_memory/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import maintenance_equipment
|
@@ -0,0 +1,51 @@
|
||||
from odoo import fields, models, api
|
||||
|
||||
|
||||
AVAILABLE_MEMORY_PERCENT_COMMAND = "free | grep Mem | awk '{print $3/$2 * 100.0}'"
|
||||
MIN_AVAILABLE_MEMORY_PERCENT_WARNING = 20
|
||||
MIN_AVAILABLE_MEMORY_PERCENT_ERROR = 5
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = 'maintenance.equipment'
|
||||
|
||||
available_memory_percent = fields.Float('Percent of available memory', readonly=True)
|
||||
|
||||
def get_tests(self):
|
||||
res = super(MaintenanceEquipment, self).get_tests()
|
||||
res.append("available_memory_percent")
|
||||
return res
|
||||
|
||||
def test_available_memory_percent(self):
|
||||
"""
|
||||
test available memory with a bash command called by ssh
|
||||
|
||||
Args:
|
||||
ssh (paramiko.SSHClient): ssh client
|
||||
|
||||
Returns:
|
||||
MonitoringTest: representing current test with :
|
||||
* result = -2 if error
|
||||
* result = percent of available memory if no error
|
||||
* error defined with MonitoringTest.ERROR or MonitoringTest.WARNING depending on result comparaison
|
||||
with MIN_AVAILABLE_MEMORY_PERCENT_WARNING and MIN_AVAILABLE_MEMORY_PERCENT_ERROR
|
||||
* log file
|
||||
"""
|
||||
test = self.MonitoringTest("Available memory percent")
|
||||
try:
|
||||
ssh = self.get_ssh_connection()
|
||||
if not ssh:
|
||||
return test.test_error(-2, "No ssh connection")
|
||||
_stdin, stdout, _stderr = ssh.exec_command(AVAILABLE_MEMORY_PERCENT_COMMAND)
|
||||
available_memory_percent = float(stdout.read().decode())
|
||||
if available_memory_percent > MIN_AVAILABLE_MEMORY_PERCENT_WARNING:
|
||||
return test.test_ok(available_memory_percent, f"{available_memory_percent}% available")
|
||||
elif available_memory_percent > MIN_AVAILABLE_MEMORY_PERCENT_ERROR:
|
||||
# memory between warning and error step
|
||||
return test.test_warning(available_memory_percent, f"{available_memory_percent}% available (<{MIN_AVAILABLE_MEMORY_PERCENT_WARNING})")
|
||||
else:
|
||||
# memory available lower than error step
|
||||
return test.test_error(available_memory_percent, f"{available_memory_percent}% available (<{MIN_AVAILABLE_MEMORY_PERCENT_ERROR})")
|
||||
except Exception as e:
|
||||
return test.test_error(-2, f"{e}")
|
||||
|
||||
|
Reference in New Issue
Block a user