From 9a4336935bf46b033ee93d1ae9fec141e606ee0b Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 9 Aug 2022 01:48:09 +0800 Subject: [PATCH] pgxx4 --- plugins/postgresql/conf/postgresql.conf | 8 +++ plugins/postgresql/index.html | 4 +- plugins/postgresql/index.py | 65 ++++++++++++++++--------- plugins/postgresql/js/postgresql.js | 27 +++++----- 4 files changed, 65 insertions(+), 39 deletions(-) diff --git a/plugins/postgresql/conf/postgresql.conf b/plugins/postgresql/conf/postgresql.conf index 78457a15e..d6bf839b5 100644 --- a/plugins/postgresql/conf/postgresql.conf +++ b/plugins/postgresql/conf/postgresql.conf @@ -10,3 +10,11 @@ log_timezone = 'Asia/Shanghai' datestyle = 'iso, ymd' timezone = 'Asia/Shanghai' default_text_search_config = 'pg_catalog.simple' + + +logging_collector = on +log_destination = 'stderr' +log_directory = '{$APP_PATH}/logs' +log_filename = 'postgresql-%Y-%m-%d.log' +log_statement = all +log_min_duration_statement = 5000 diff --git a/plugins/postgresql/index.html b/plugins/postgresql/index.html index e231893b3..3e0a32f1b 100755 --- a/plugins/postgresql/index.html +++ b/plugins/postgresql/index.html @@ -8,8 +8,8 @@

配置文件

端口

- +

当前状态

+

性能优化

日志

管理列表

diff --git a/plugins/postgresql/index.py b/plugins/postgresql/index.py index c890fb00c..853f34927 100755 --- a/plugins/postgresql/index.py +++ b/plugins/postgresql/index.py @@ -470,30 +470,51 @@ def runInfo(): if status(version) == 'stop': return mw.returnJson(False, 'PG未启动', []) - db = pMysqlDb() - data = db.query('show global status') - gets = ['Max_used_connections', 'Com_commit', 'Com_rollback', 'Questions', 'Innodb_buffer_pool_reads', 'Innodb_buffer_pool_read_requests', 'Key_reads', 'Key_read_requests', 'Key_writes', - 'Key_write_requests', 'Qcache_hits', 'Qcache_inserts', 'Bytes_received', 'Bytes_sent', 'Aborted_clients', 'Aborted_connects', - 'Created_tmp_disk_tables', 'Created_tmp_tables', 'Innodb_buffer_pool_pages_dirty', 'Opened_files', 'Open_tables', 'Opened_tables', 'Select_full_join', - 'Select_range_check', 'Sort_merge_passes', 'Table_locks_waited', 'Threads_cached', 'Threads_connected', 'Threads_created', 'Threads_running', 'Connections', 'Uptime'] - + db = pgDb() + # data = db.query('show global status') + data_directory = getServerDir() + "/data" + port = getPgPort() result = {} - # print(data) - for d in data: - vname = d["Variable_name"] - for g in gets: - if vname == g: - result[g] = d["Value"] - # print(result, int(result['Uptime'])) - result['Run'] = int(time.time()) - int(result['Uptime']) - tmp = db.query('show master status') - try: - result['File'] = tmp[0]["File"] - result['Position'] = tmp[0]["Position"] - except: - result['File'] = 'OFF' - result['Position'] = 'OFF' + result['uptime'] = mw.execShell( + '''cat {}/postmaster.pid |sed -n 3p '''.format(data_directory))[0] + timestamp = result['uptime'] + time_local = time.localtime(int(timestamp)) + dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local) + result['uptime'] = dt + + result['progress_num'] = mw.execShell( + "ps -ef |grep postgres |wc -l")[0].strip() + result['pid'] = mw.execShell( + '''cat {}/postmaster.pid |sed -n 1p '''.format(data_directory))[0].strip() + res = db.query( + 'SELECT count(*) FROM pg_stat_activity WHERE NOT pid=pg_backend_pid()') + result['connections'] = res[0][0] + + res = db.query("select pg_size_pretty(pg_database_size('postgres'))") + result['pg_size'] = res[0][0] + result['pg_mem'] = mw.execShell( + '''cat /proc/%s/status|grep VmRSS|awk -F: '{print $2}' ''' % (result['pid']))[0] + + result['pg_vm_lock'] = mw.execShell( + '''cat /proc/%s/status|grep VmLck|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_high'] = mw.execShell( + '''cat /proc/%s/status|grep VmHWM|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_data_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmData|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_sk_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmStk|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_code_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmExe|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_lib_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmLib|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_swap_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmSwap|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_vm_page_size'] = mw.execShell( + '''cat /proc/%s/status|grep VmPTE|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + result['pg_sigq'] = mw.execShell( + '''cat /proc/%s/status|grep SigQ|awk -F: '{print $2}' ''' % (result['pid'].strip()))[0] + return mw.getJson(result) diff --git a/plugins/postgresql/js/postgresql.js b/plugins/postgresql/js/postgresql.js index ad71f3468..c1320d312 100755 --- a/plugins/postgresql/js/postgresql.js +++ b/plugins/postgresql/js/postgresql.js @@ -81,26 +81,23 @@ function runInfo(){ if (cache_size == 'NaN%') cache_size = 'OFF'; var Con = '
\ \ - \ - \ - \ - \ + \ + \ + \ \
启动时间' + getLocalTime(rdata.Run) + '每秒查询' + parseInt(rdata.Questions / rdata.Uptime) + '
总连接次数' + rdata.Connections + '每秒事务' + parseInt((parseInt(rdata.Com_commit) + parseInt(rdata.Com_rollback)) / rdata.Uptime) + '
发送' + toSize(rdata.Bytes_sent) + 'File' + rdata.File + '
接收' + toSize(rdata.Bytes_received) + 'Position' + rdata.Position + '
启动时间' + rdata.uptime + '进程数' +rdata.progress_num+ '
总连接次数' + rdata.connections + 'PID' +rdata.pid+ '
占用空间' + rdata.pg_size + '占用内存' +rdata.pg_mem+ '
\ \ \ \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ + \ + \ + \ + \ + \ + \ + \ + \ + \ \
活动/峰值连接数' + rdata.Threads_running + '/' + rdata.Max_used_connections + '若值过大,增加max_connections
线程缓存命中率' + ((1 - rdata.Threads_created / rdata.Connections) * 100).toFixed(2) + '%若过低,增加thread_cache_size
索引命中率' + ((1 - rdata.Key_reads / rdata.Key_read_requests) * 100).toFixed(2) + '%若过低,增加key_buffer_size
Innodb索引命中率' + ((1 - rdata.Innodb_buffer_pool_reads / rdata.Innodb_buffer_pool_read_requests) * 100).toFixed(2) + '%若过低,增加innodb_buffer_pool_size
查询缓存命中率' + cache_size + '' + lan.soft.mysql_status_ps5 + '
创建临时表到磁盘' + ((rdata.Created_tmp_disk_tables / rdata.Created_tmp_tables) * 100).toFixed(2) + '%若过大,尝试增加tmp_table_size
已打开的表' + rdata.Open_tables + '若过大,增加table_cache_size
没有使用索引的量' + rdata.Select_full_join + '若不为0,请检查数据表的索引是否合理
没有索引的JOIN量' + rdata.Select_range_check + '若不为0,请检查数据表的索引是否合理
排序后的合并次数' + rdata.Sort_merge_passes + '若值过大,增加sort_buffer_size
锁表次数' + rdata.Table_locks_waited + '若值过大,请考虑增加您的数据库性能
表进程已经锁住的物理内存的大小' + rdata.pg_vm_lock + '
数据库分配到物理内存的峰值' + rdata.pg_vm_high + '
进程数据段的大小' + rdata.pg_vm_data_size + '
进程堆栈段的大小' + rdata.pg_vm_sk_size + '
进程代码的大小' + rdata.pg_vm_code_size + '
进程所使用LIB库的大小' + rdata.pg_vm_lib_size + '
进程占用Swap的大小' + rdata.pg_vm_swap_size + '
占用的页表的大小' + rdata.pg_vm_page_size + '
当前待处理信号的个数' + rdata.pg_sigq + '
'; $(".soft-man-con").html(Con);