From faf517e12bf1f0558360c77e8fcc7f365617a128 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 14 Oct 2016 17:18:17 -0700 Subject: [PATCH] Include wait information on the activity tab of the dashboards. Fixes #1859 --- web/pgadmin/dashboard/__init__.py | 21 ++++++-- .../dashboard/database_dashboard.html | 2 +- .../templates/dashboard/js/dashboard.js | 50 ++++++++++++++++++- .../templates/dashboard/server_dashboard.html | 2 +- .../dashboard/sql/9.1_plus/activity.sql | 3 +- .../dashboard/sql/9.6_plus/activity.sql | 15 ++++++ .../dashboard/sql/9.6_plus/bio_stats.sql | 3 ++ .../dashboard/sql/9.6_plus/config.sql | 10 ++++ .../dashboard/sql/9.6_plus/locks.sql | 23 +++++++++ .../dashboard/sql/9.6_plus/prepared.sql | 12 +++++ .../dashboard/sql/9.6_plus/session_stats.sql | 4 ++ .../dashboard/sql/9.6_plus/ti_stats.sql | 4 ++ .../dashboard/sql/9.6_plus/to_stats.sql | 3 ++ .../dashboard/sql/9.6_plus/tps_stats.sql | 4 ++ 14 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/activity.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/bio_stats.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/config.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/locks.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/prepared.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/session_stats.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/ti_stats.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/to_stats.sql create mode 100644 web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/tps_stats.sql diff --git a/web/pgadmin/dashboard/__init__.py b/web/pgadmin/dashboard/__init__.py index 7ed761acb..7ccf353c4 100644 --- a/web/pgadmin/dashboard/__init__.py +++ b/web/pgadmin/dashboard/__init__.py @@ -140,7 +140,11 @@ def check_precondition(f): # Set template path for sql scripts g.server_type = g.manager.server_type g.version = g.manager.version - g.template_path = 'dashboard/sql/9.1_plus' + + if g.version < 90600: + g.template_path = 'dashboard/sql/9.1_plus' + else: + g.template_path = 'dashboard/sql/9.6_plus' return f(*args, **kwargs) @@ -174,6 +178,17 @@ def index(sid=None, did=None): prefs = Preferences.module('dashboards') + # Get the server version + if sid is not None: + g.manager = get_driver( + PG_DEFAULT_DRIVER).connection_manager(sid) + g.conn = g.manager.connection() + + g.version = g.manager.version + + if not g.conn.connected(): + g.version = 0 + session_stats_refresh_pref = prefs.preference('session_stats_refresh') rates['session_stats_refresh'] = session_stats_refresh_pref.get() tps_stats_refresh_pref = prefs.preference('tps_stats_refresh') @@ -189,9 +204,9 @@ def index(sid=None, did=None): if sid is None and did is None: return render_template('/dashboard/welcome_dashboard.html') if did is None: - return render_template('/dashboard/server_dashboard.html', sid=sid, rates=rates) + return render_template('/dashboard/server_dashboard.html', sid=sid, rates=rates, version=g.version) else: - return render_template('/dashboard/database_dashboard.html', sid=sid, did=did, rates=rates) + return render_template('/dashboard/database_dashboard.html', sid=sid, did=did, rates=rates, version=g.version) def get_data(sid, did, template): diff --git a/web/pgadmin/dashboard/templates/dashboard/database_dashboard.html b/web/pgadmin/dashboard/templates/dashboard/database_dashboard.html index 0ce92d8ed..f6e9fee86 100644 --- a/web/pgadmin/dashboard/templates/dashboard/database_dashboard.html +++ b/web/pgadmin/dashboard/templates/dashboard/database_dashboard.html @@ -104,6 +104,6 @@ diff --git a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js index 08e7ee077..a50807b73 100644 --- a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js +++ b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js @@ -353,7 +353,7 @@ function(r, $, pgAdmin, _, Backbone) { }, // Rock n' roll on the server dashboard - init_server_dashboard: function(sid, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { + init_server_dashboard: function(sid, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { var div_sessions = document.getElementById('graph-sessions'); var div_tps = document.getElementById('graph-tps'); var div_ti = document.getElementById('graph-ti'); @@ -430,6 +430,29 @@ function(r, $, pgAdmin, _, Backbone) { cell: "string" }]; + if (version < 90600) { + server_activity_columns = server_activity_columns.concat( + [{ + name: "waiting", + label: "{{ _('Waiting?') }}", + editable: false, + cell: "string" + }]); + } else { + server_activity_columns = server_activity_columns.concat( + [{ + name: "wait_event_type", + label: "{{ _('Wait Event Type') }}", + editable: false, + cell: "string" + },{ + name: "wait_event", + label: "{{ _('Wait Event') }}", + editable: false, + cell: "string" + }]); + } + var server_locks_columns = [{ name: "pid", label: "{{ _('Process ID') }}", @@ -616,7 +639,7 @@ function(r, $, pgAdmin, _, Backbone) { }, // Rock n' roll on the database dashboard - init_database_dashboard: function(sid, did, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { + init_database_dashboard: function(sid, did, version, session_stats_refresh, tps_stats_refresh, ti_stats_refresh, to_stats_refresh, bio_stats_refresh) { var div_sessions = document.getElementById('graph-sessions'); var div_tps = document.getElementById('graph-tps'); var div_ti = document.getElementById('graph-ti'); @@ -684,6 +707,29 @@ function(r, $, pgAdmin, _, Backbone) { cell: "string" }]; + if (version < 90600) { + database_activity_columns = database_activity_columns.concat( + [{ + name: "waiting", + label: "{{ _('Waiting?') }}", + editable: false, + cell: "string" + }]); + } else { + database_activity_columns = database_activity_columns.concat( + [{ + name: "wait_event_type", + label: "{{ _('Wait Event Type') }}", + editable: false, + cell: "string" + },{ + name: "wait_event", + label: "{{ _('Wait Event') }}", + editable: false, + cell: "string" + }]); + } + var database_locks_columns = [{ name: "pid", label: "{{ _('Process ID') }}", diff --git a/web/pgadmin/dashboard/templates/dashboard/server_dashboard.html b/web/pgadmin/dashboard/templates/dashboard/server_dashboard.html index 3634d885a..066873c98 100644 --- a/web/pgadmin/dashboard/templates/dashboard/server_dashboard.html +++ b/web/pgadmin/dashboard/templates/dashboard/server_dashboard.html @@ -114,6 +114,6 @@ diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.1_plus/activity.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.1_plus/activity.sql index c31201994..8e03e29b4 100644 --- a/web/pgadmin/dashboard/templates/dashboard/sql/9.1_plus/activity.sql +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.1_plus/activity.sql @@ -5,7 +5,8 @@ SELECT application_name, client_addr, backend_start, - state + state, + CASE WHEN waiting THEN '{{ _('yes') }}' ELSE '{{ _('no') }}' END AS waiting FROM pg_stat_activity {% if did %}WHERE diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/activity.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/activity.sql new file mode 100644 index 000000000..1aec651b3 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/activity.sql @@ -0,0 +1,15 @@ +SELECT + pid, + datname, + usename, + application_name, + client_addr, + backend_start, + state, + wait_event_type, + wait_event +FROM + pg_stat_activity +{% if did %}WHERE + datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %} +ORDER BY pid \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/bio_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/bio_stats.sql new file mode 100644 index 000000000..3572c4c9c --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/bio_stats.sql @@ -0,0 +1,3 @@ +SELECT + (SELECT sum(blks_read) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Reads') }}", + (SELECT sum(blks_hit) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Hits') }}" diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/config.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/config.sql new file mode 100644 index 000000000..654e123f5 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/config.sql @@ -0,0 +1,10 @@ +SELECT + name, + category, + setting, + unit, + short_desc +FROM + pg_settings +ORDER BY + category \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/locks.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/locks.sql new file mode 100644 index 000000000..f02efd241 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/locks.sql @@ -0,0 +1,23 @@ +SELECT + pid, + locktype, + datname, + relation::regclass, + page, + tuple, + virtualxid + transactionid, + classid::regclass, + objid, + objsubid, + virtualtransaction, + mode, + granted, + fastpath +FROM + pg_locks l + LEFT OUTER JOIN pg_database d ON (l.database = d.oid) +{% if did %}WHERE + datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %} +ORDER BY + pid, locktype \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/prepared.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/prepared.sql new file mode 100644 index 000000000..9801e5b32 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/prepared.sql @@ -0,0 +1,12 @@ +SELECT + gid, + database, + owner, + transaction, + prepared +FROM + pg_prepared_xacts +{% if did %}WHERE + database = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %} +ORDER BY + gid, database, owner \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/session_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/session_stats.sql new file mode 100644 index 000000000..5c584c322 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/session_stats.sql @@ -0,0 +1,4 @@ +SELECT + (SELECT count(*) FROM pg_stat_activity{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Total') }}", + (SELECT count(*) FROM pg_stat_activity WHERE state = 'active'{% if did %} AND datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Active') }}", + (SELECT count(*) FROM pg_stat_activity WHERE state = 'idle'{% if did %} AND datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Idle') }}" \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/ti_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/ti_stats.sql new file mode 100644 index 000000000..a92f6da4c --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/ti_stats.sql @@ -0,0 +1,4 @@ +SELECT + (SELECT sum(tup_inserted) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Inserts') }}", + (SELECT sum(tup_updated) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Updates') }}", + (SELECT sum(tup_deleted) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Deletes') }}" \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/to_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/to_stats.sql new file mode 100644 index 000000000..9b085b5ba --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/to_stats.sql @@ -0,0 +1,3 @@ +SELECT + (SELECT sum(tup_fetched) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Fetched') }}", + (SELECT sum(tup_returned) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Returned') }}" \ No newline at end of file diff --git a/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/tps_stats.sql b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/tps_stats.sql new file mode 100644 index 000000000..086a50792 --- /dev/null +++ b/web/pgadmin/dashboard/templates/dashboard/sql/9.6_plus/tps_stats.sql @@ -0,0 +1,4 @@ +SELECT + (SELECT sum(xact_commit) + sum(xact_rollback) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Transactions') }}", + (SELECT sum(xact_commit) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Commits') }}", + (SELECT sum(xact_rollback) FROM pg_stat_database{% if did %} WHERE datname = (SELECT datname FROM pg_database WHERE oid = {{ did }}){% endif %}) AS "{{ _('Rollbacks') }}" \ No newline at end of file