db-stats.tcl
- Location:
- /packages/acs-subsite/www/admin/system/db-stats.tcl
- Author:
- Guenter Ernst guenter.ernst@wu-wien.ac.at
- Created:
- 14.09.2007
Related Files
- packages/acs-subsite/www/admin/system/db-stats.tcl
- packages/acs-subsite/www/admin/system/db-stats.adp
[ hide source ] | [ make this the default ]
File Contents
ad_page_contract { @author Guenter Ernst guenter.ernst@wu-wien.ac.at @creation-date 14.09.2007 } { {t:optional {pg_stat_activity}} {c:optional} {orderby:optional } } set tables {pg_stat_activity pg_stat_bgwriter pg_stat_database pg_stat_all_tables pg_stat_sys_tables pg_stat_user_tables pg_stat_all_indexes pg_stat_sys_indexes pg_stat_user_indexes pg_statio_all_tables pg_statio_sys_tables pg_statio_user_tables pg_statio_all_indexes pg_statio_sys_indexes pg_statio_user_indexes pg_statio_all_sequences pg_statio_sys_sequences pg_statio_user_sequences pg_stat_user_functions pg_stat_statements} set cols_sql "select att.attname from pg_attribute att inner join pg_class tab on att.attrelid = tab.relfilenode and tab.relname = :t where att.attnum > 0 order by att.attnum" set columns [db_list get_cols $cols_sql] switch $t { "pg_stat_database" {lappend columns "disk_size"} "pg_stat_activity" {lappend columns "query_run_time"} "pg_stat_user_functions" {lappend columns "avg_total_time" "avg_self_time"} "pg_stat_statements" {lappend columns "avg_total_time" } "pg_stat_all_tables" - "pg_stat_sys_tables" - "pg_stat_user_tables" - "pg_stat_all_indexes" - "pg_stat_sys_indexes" - "pg_stat_user_indexes" {lappend columns "disk_size"} "default" {} } # create table filter & orderby set filters [list] set table_filter [list] foreach table $tables { lappend table_filter [list "$table" "$table" " "] } lappend filters t { label "Statistics View" values $table_filter } set order_by [list] foreach column $columns { lappend order_by $column [list label "$column" orderby $column] } if {([info exists orderby] && $orderby ne "") && [lsearch $columns [lindex [split $orderby ","] 0]] == -1} { unset orderby } ###################################################### ###### Create the list template ###################################################### # create list elements set elements [list] foreach element $columns { lappend elements $element [list label "$element" sub_class "narrow" display_template "<span style='white-space:pre;'>@table.${element}@</span>"] } list::create \ -name "table" \ -multirow "table" \ -no_data "Keine Daten vorhanden" \ -pass_properties {t c return_url} \ -page_flush_p t \ -elements $elements \ -filters $filters \ -orderby $order_by # ###################################################### # ###### Create the sql query string (for the data) # ###################################################### # set sql_str "select * " switch $t { "pg_stat_database" { append sql_str ", pg_size_pretty(pg_database_size(datname)) as disk_size " if {[info exists orderby]} { set disk_size_order_by "order by pg_database_size(datname) [lindex [split $orderby ","] end]" } } "pg_stat_activity" { append sql_str ", now()-xact_start as query_run_time " } "pg_stat_all_tables" - "pg_stat_sys_tables" - "pg_stat_user_tables" { append sql_str ", pg_size_pretty(pg_relation_size(relid)) as disk_size " if {[info exists orderby]} { set disk_size_order_by "order by pg_relation_size(relid) [lindex [split $orderby ","] end]" } } "pg_stat_all_indexes" - "pg_stat_sys_indexes" - "pg_stat_user_indexes" { append sql_str ", pg_size_pretty(pg_relation_size(indexrelid)) as disk_size " if {[info exists orderby]} { set disk_size_order_by "order by pg_relation_size(indexrelid) [lindex [split $orderby ","] end]" } } "pg_stat_user_functions" { append sql_str ", round((total_time/calls)::numeric, 2) as avg_total_time, round((self_time/calls)::numeric, 2) as avg_self_time " } "pg_stat_statements" { append sql_str ", round(total_time::numeric*1000/calls, 2) as avg_total_time " } } append sql_str "from $t" if {[info exists orderby] && [lindex [split $orderby ","] 0] eq "disk_size"} { append sql_str " $disk_size_order_by" } else { append sql_str " [template::list::orderby_clause -orderby -name "table"]" } db_multirow table get_data $sql_str { if {$t eq "pg_stat_statements"} { set query "[wrap_string [string trim $query]]" } } ad_return_template