Skip to content

Commit

Permalink
通过日志文件中的内存打印信息,分析展示各个租户、CTX、模块的内存使用情况 (#550)
Browse files Browse the repository at this point in the history
* 日志内存分析

* 格式调整

* 支持离线分析
  • Loading branch information
oraclebird authored Nov 14, 2024
1 parent 934c039 commit f48a0b0
Show file tree
Hide file tree
Showing 3 changed files with 880 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from handler.analyzer.analyze_sql_review import AnalyzeSQLReviewHandler
from handler.analyzer.analyze_parameter import AnalyzeParameterHandler
from handler.analyzer.analyze_variable import AnalyzeVariableHandler
from handler.analyzer.analyze_memory import AnalyzeMemoryHandler
from handler.analyzer.analyze_index_space import AnalyzeIndexSpaceHandler
from handler.checker.check_handler import CheckHandler
from handler.checker.check_list import CheckListHandler
Expand Down Expand Up @@ -391,6 +392,10 @@ def analyze_fuction(self, function_type, opt):
self.set_context(function_type, 'analyze', config)
handler = AnalyzeIndexSpaceHandler(self.context)
return handler.handle()
elif function_type == 'analyze_memory':
self.set_context(function_type, 'analyze', config)
handler = AnalyzeMemoryHandler(self.context)
return handler.handle()
else:
self._call_stdio('error', 'Not support analyze function: {0}'.format(function_type))
return ObdiagResult(ObdiagResult.INPUT_ERROR_CODE, error_data='Not support analyze function: {0}'.format(function_type))
Expand Down
29 changes: 29 additions & 0 deletions diag_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,34 @@ def __init__(self):
self.register_command(ObdiagAnalyzeVariableDiffCommand())


class ObdiagAnalyzeMemoryCommand(ObdiagOriginCommand):

def __init__(self):
super(ObdiagAnalyzeMemoryCommand, self).__init__('memory', 'Analyze OceanBase Memory info from online observer machines or offline OceanBase log files')
self.parser.add_option('--from', type='string', help="specify the start of the time range. format: 'yyyy-mm-dd hh:mm:ss'")
self.parser.add_option('--to', type='string', help="specify the end of the time range. format: 'yyyy-mm-dd hh:mm:ss'")
self.parser.add_option('--grep', action="append", type='string', help="specify keywords constrain")
self.parser.add_option('--files', action="append", type='string', help="specify files")
self.parser.add_option('--store_dir', type='string', help='the dir to store gather result, current dir by default.', default='./')
self.parser.add_option('--since', type='string', help="Specify time range that from 'n' [d]ays, 'n' [h]ours or 'n' [m]inutes. before to now. format: <n> <m|h|d>. example: 1h.", default='30m')
self.parser.add_option('--temp_dir', type='string', help='the dir for temporarily storing files on nodes', default='/tmp')
self.parser.add_option('-c', type='string', help='obdiag custom config', default=os.path.expanduser('~/.obdiag/config.yml'))
self.parser.add_option('--config', action="append", type="string", help='config options Format: --config key=value')
self.parser.add_option('--version', type="string", help='specify the OceanBase version of the log file to be analyzed.This option is only used for offline analysis.')

def init(self, cmd, args):
super(ObdiagAnalyzeMemoryCommand, self).init(cmd, args)
self.parser.set_usage('%s [options]' % self.prev_cmd)
return self

def _do_command(self, obdiag):
offline_args_sign = '--files'
if self.args and (offline_args_sign in self.args):
return obdiag.analyze_fuction('analyze_memory', self.opts)
else:
return obdiag.analyze_fuction('analyze_memory', self.opts)


class ObdiagAnalyzeIndexSpaceCommand(ObdiagOriginCommand):
def __init__(self):
super(ObdiagAnalyzeIndexSpaceCommand, self).__init__('index_space', 'Analyze the space of existing or non-existent index and estimate it through the columns included in the index')
Expand Down Expand Up @@ -1194,6 +1222,7 @@ def __init__(self):
self.register_command(ObdiagAnalyzeVariableCommand())
self.register_command(ObdiagAnalyzeQueueCommand())
self.register_command(ObdiagAnalyzeIndexSpaceCommand())
self.register_command(ObdiagAnalyzeMemoryCommand())
# self.register_command(ObdiagAnalyzeSQLCommand())
# self.register_command(ObdiagAnalyzeSQLReviewCommand())

Expand Down
Loading

0 comments on commit f48a0b0

Please sign in to comment.