mysql_info: add support for global status (#63189)

Signed-off-by: Yap Sok Ann <sokann@gmail.com>
This commit is contained in:
Yap Sok Ann 2019-10-10 17:14:49 +07:00 committed by René Moser
parent f2e5e6de23
commit eca33b80f0
2 changed files with 21 additions and 2 deletions

View file

@ -25,8 +25,8 @@ options:
filter: filter:
description: description:
- Limit the collected information by comma separated string or YAML list. - Limit the collected information by comma separated string or YAML list.
- Allowable values are C(version), C(databases), C(settings), C(users), - Allowable values are C(version), C(databases), C(settings), C(global_status),
C(slave_status), C(slave_hosts), C(master_status), C(engines). C(users), C(engines), C(master_status), C(slave_status), C(slave_hosts).
- By default, collects all subsets. - By default, collects all subsets.
- You can use '!' before value (for example, C(!settings)) to exclude it from the information. - You can use '!' before value (for example, C(!settings)) to exclude it from the information.
- If you pass including and excluding values to the filter, for example, I(filter=!settings,version), - If you pass including and excluding values to the filter, for example, I(filter=!settings,version),
@ -129,6 +129,12 @@ settings:
type: dict type: dict
sample: sample:
- { "innodb_open_files": 300, innodb_page_size": 16384 } - { "innodb_open_files": 300, innodb_page_size": 16384 }
global_status:
description: Global status information.
returned: if not excluded by filter
type: dict
sample:
- { "Innodb_buffer_pool_read_requests": 123, "Innodb_buffer_pool_reads": 32 }
users: users:
description: Users information. description: Users information.
returned: if not excluded by filter returned: if not excluded by filter
@ -203,6 +209,7 @@ class MySQL_Info(object):
'version': {}, 'version': {},
'databases': {}, 'databases': {},
'settings': {}, 'settings': {},
'global_status': {},
'engines': {}, 'engines': {},
'users': {}, 'users': {},
'master_status': {}, 'master_status': {},
@ -255,6 +262,7 @@ class MySQL_Info(object):
"""Collect all possible subsets.""" """Collect all possible subsets."""
self.__get_databases() self.__get_databases()
self.__get_global_variables() self.__get_global_variables()
self.__get_global_status()
self.__get_engines() self.__get_engines()
self.__get_users() self.__get_users()
self.__get_master_status() self.__get_master_status()
@ -307,6 +315,14 @@ class MySQL_Info(object):
release=int(release), release=int(release),
) )
def __get_global_status(self):
"""Get global status."""
res = self.__exec_sql('SHOW GLOBAL STATUS')
if res:
for var in res:
self.info['global_status'][var['Variable_name']] = self.__convert(var['Value'])
def __get_master_status(self): def __get_master_status(self):
"""Get master status if the instance is a master.""" """Get master status if the instance is a master."""
res = self.__exec_sql('SHOW MASTER STATUS') res = self.__exec_sql('SHOW MASTER STATUS')

View file

@ -43,6 +43,7 @@
- result.changed == false - result.changed == false
- result.version != {} - result.version != {}
- result.settings != {} - result.settings != {}
- result.global_status != {}
- result.databases != {} - result.databases != {}
- result.engines != {} - result.engines != {}
- result.users != {} - result.users != {}
@ -92,6 +93,7 @@
that: that:
- result.changed == false - result.changed == false
- result.version != {} - result.version != {}
- result.global_status != {}
- result.databases != {} - result.databases != {}
- result.engines != {} - result.engines != {}
- result.settings is not defined - result.settings is not defined
@ -114,4 +116,5 @@
- result.databases != {} - result.databases != {}
- result.engines is not defined - result.engines is not defined
- result.settings is not defined - result.settings is not defined
- result.global_status is not defined
- result.users is not defined - result.users is not defined