From 73283db4f095629d7d09f84e190680259456ab89 Mon Sep 17 00:00:00 2001 From: Rongfeng Fu Date: Mon, 28 Jun 2021 15:49:14 +0800 Subject: [PATCH] 1.0.2 (#17) * memory and disk check * 1.0.2 --- _cmd.py | 2 +- ob-deploy.spec | 6 ++++-- plugins/mysqltest/3.1.0/init.py | 2 +- plugins/oceanbase/3.1.0/start_check.py | 28 ++++++++++---------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/_cmd.py b/_cmd.py index d119fd2..3c2d084 100644 --- a/_cmd.py +++ b/_cmd.py @@ -35,7 +35,7 @@ from tool import DirectoryUtil, FileUtil ROOT_IO = IO(1) -VERSION = '1.0.1' +VERSION = '1.0.2' REVISION = '' BUILD_BRANCH = '' BUILD_TIME = '' diff --git a/ob-deploy.spec b/ob-deploy.spec index 29501c5..5e972e6 100644 --- a/ob-deploy.spec +++ b/ob-deploy.spec @@ -1,5 +1,5 @@ Name: ob-deploy -Version: 1.0.1 +Version: 1.0.2 Release: 1%{?dist} # if you want use the parameter of rpm_create on build time, # uncomment below @@ -105,4 +105,6 @@ echo -e 'Installation of obd finished successfully\nPlease source /etc/profile.d - new features: obd update - cancel the timeout limit for waiting for the cluster to initialize - new configuration item for store log - - support SUSE, Ubuntu etc. \ No newline at end of file + - support SUSE, Ubuntu etc. +* Mon Jun 28 2021 obd 1.0.2 + - fix memory and disk check bug \ No newline at end of file diff --git a/plugins/mysqltest/3.1.0/init.py b/plugins/mysqltest/3.1.0/init.py index d6eeb19..4b420fb 100644 --- a/plugins/mysqltest/3.1.0/init.py +++ b/plugins/mysqltest/3.1.0/init.py @@ -31,7 +31,7 @@ def parse_size(size): _bytes = int(size) else: units = {"B": 1, "K": 1<<10, "M": 1<<20, "G": 1<<30, "T": 1<<40} - match = re.match(r'([1-9][0-9]*)([B,K,M,G,T])', size) + match = re.match(r'([1-9][0-9]*)\s*([B,K,M,G,T])', size.upper()) _bytes = int(match.group(1)) * units[match.group(2)] return _bytes diff --git a/plugins/oceanbase/3.1.0/start_check.py b/plugins/oceanbase/3.1.0/start_check.py index f3ce6a4..bfc658a 100644 --- a/plugins/oceanbase/3.1.0/start_check.py +++ b/plugins/oceanbase/3.1.0/start_check.py @@ -20,6 +20,7 @@ from __future__ import absolute_import, division, print_function +import os import re @@ -27,17 +28,6 @@ stdio = None success = True -def parse_size(size): - _bytes = 0 - if not isinstance(size, str) or size.isdigit(): - _bytes = int(size) - else: - units = {"B": 1, "K": 1<<10, "M": 1<<20, "G": 1<<30, "T": 1<<40} - match = re.match(r'([1-9][0-9]*)([B,K,M,G,T])', size) - _bytes = int(match.group(1)) * units[match.group(2)] - return _bytes - - def get_port_socket_inode(client, port): port = hex(port)[2:].zfill(4).upper() cmd = "bash -c 'cat /proc/net/{tcp,udp}' | awk -F' ' '{print $2,$10}' | grep '00000000:%s' | awk -F' ' '{print $2}' | uniq" % port @@ -54,7 +44,7 @@ def parse_size(size): _bytes = int(size) else: units = {"B": 1, "K": 1<<10, "M": 1<<20, "G": 1<<30, "T": 1<<40} - match = re.match(r'([1-9][0-9]*)([B,K,M,G,T])', size) + match = re.match(r'([1-9][0-9]*)\s*([B,K,M,G,T])', size.upper()) _bytes = int(match.group(1)) * units[match.group(2)] return _bytes @@ -127,7 +117,7 @@ def start_check(plugin_context, strict_check=False, *args, **kwargs): memory['percentage'] += int(parse_size(server_config['memory_limit_percentage'])) else: memory['percentage'] += 80 - data_path = server_config['data_dir'] if 'data_dir' in server_config else server_config['home_path'] + data_path = server_config['data_dir'] if 'data_dir' in server_config else os.path.join(server_config['home_path'], 'store') if not client.execute_command('ls %s/sstable/block_file' % data_path): if data_path in disk: critical('Same Path: %s in %s and %s' % (data_path, server, disk[data_path]['server'])) @@ -171,11 +161,15 @@ def start_check(plugin_context, strict_check=False, *args, **kwargs): alert('(%s) The recommended number of open files is 655350 (Current value: %s)' % (ip, max_of)) # memory - ret = client.execute_command("free -b | grep Mem | awk -F' ' '{print $2, $4}'") + ret = client.execute_command('cat /proc/meminfo') if ret: - total_memory, free_memory = ret.stdout.split(' ') - total_memory = int(total_memory) - free_memory = int(free_memory) + total_memory = 0 + free_memory = 0 + for k, v in re.findall('(\w+)\s*:\s*(\d+\s*\w+)', ret.stdout): + if k == 'MemTotal': + total_memory = parse_size(str(v)) + elif k == 'MemAvailable': + free_memory = parse_size(str(v)) total_use = servers_memory[ip]['percentage'] * total_memory / 100 + servers_memory[ip]['num'] if total_use > free_memory: critical('(%s) not enough memory. (Free: %s, Need: %s)' % (ip, formate_size(free_memory), formate_size(total_use))) -- GitLab