Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql表空间查看支持所有的表 #1672

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions sql/db_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ def kill_session(request):
@permission_required('sql.tablespace_view', raise_exception=True)
def tablesapce(request):
instance_name = request.POST.get('instance_name')

offset = int(request.POST.get('offset',0))
limit = int(request.POST.get('limit',14))
try:
instance = user_instances(request.user).get(instance_name=instance_name)
except Instance.DoesNotExist:
Expand All @@ -139,15 +140,17 @@ def tablesapce(request):
if AliyunRdsConfig.objects.filter(instance=instance, is_enable=True).exists():
result = aliyun_sapce_status(request)
else:
query_result = query_engine.tablesapce()
query_result = query_engine.tablesapce(offset,limit)
r = query_engine.tablesapce_num()
total = r.rows[0][0]
else:
result = {'status': 1, 'msg': '暂时不支持{}类型数据库的表空间信息查询'.format(instance.db_type), 'data': []}
return HttpResponse(json.dumps(result), content_type='application/json')

if query_result:
if not query_result.error:
table_space = query_result.to_dict()
result = {'status': 0, 'msg': 'ok', 'rows': table_space}
result = {'status': 0, 'msg': 'ok', 'rows': table_space, 'total':total}
else:
result = {'status': 1, 'msg': query_result.error}
# 返回查询结果
Expand Down
12 changes: 10 additions & 2 deletions sql/engines/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ def kill(self, thread_ids):
kill_sql = kill_sql + row[0]
return self.execute('information_schema', kill_sql)

def tablesapce(self):
def tablesapce(self, offset=0, row_count=14):
"""获取表空间信息"""
sql = '''
SELECT
Expand All @@ -495,7 +495,15 @@ def tablesapce(self):
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql', 'test', 'sys')
ORDER BY total_size DESC
LIMIT 14;'''
LIMIT {},{};'''.format(offset, row_count)
return self.query('information_schema', sql)

def tablesapce_num(self):
"""获取表空间数量"""
sql = '''
SELECT count(*)
FROM information_schema.tables
WHERE table_schema NOT IN ('information_schema', 'performance_schema', 'mysql', 'test', 'sys')'''
return self.query('information_schema', sql)

def trxandlocks(self):
Expand Down
7 changes: 7 additions & 0 deletions sql/engines/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ def test_tablesapce(self, _query):
r = new_engine.tablesapce()
self.assertIsInstance(r, ResultSet)

@patch.object(MysqlEngine, 'query')
def test_tablesapce_num(self, _query):
new_engine = MysqlEngine(instance=self.ins1)
_query.return_value = ResultSet()
r = new_engine.tablesapce_num()
self.assertIsInstance(r, ResultSet)

@patch.object(MysqlEngine, 'query')
@patch('MySQLdb.connect')
def test_trxandlocks(self, _connect, _query):
Expand Down
8 changes: 5 additions & 3 deletions sql/templates/dbdiagnostic.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
sortable: true, //是否启用排序
sortName: 'total_size',
sortOrder: "desc", //排序方式
sidePagination: "client", //分页方式:client客户端分页,server服务端分页(*)
sidePagination: "server", //分页方式:client客户端分页,server服务端分页(*)
pageNumber: 1, //初始化加载第一页,默认第一页,并记录
pageSize: 30, //每页的记录行数(*)
pageList: [20, 30, 50, 100], //可供选择的每页的行数(*)
pageSize: 14, //每页的记录行数(*)
pageList: [14, 30, 50, 100, 500, 2000], //可供选择的每页的行数(*)
search: true, //是否显示表格搜索
strictSearch: false, //是否全匹配搜索
showColumns: true, //是否显示所有的列(选择显示的列)
Expand All @@ -362,6 +362,8 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
//请求服务数据时所传参数
queryParams: function (params) {
return {
offset: params.offset,
limit: params.limit,
instance_name: $("#instance_name").val()
}
},
Expand Down