Index: openacs.org-dev/packages/monitoring/www/top/details.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/monitoring/www/top/details.tcl,v diff -u -r1.1.1.1 -r1.1.1.2 --- openacs.org-dev/packages/monitoring/www/top/details.tcl 9 Jul 2002 17:35:09 -0000 1.1.1.1 +++ openacs.org-dev/packages/monitoring/www/top/details.tcl 8 Oct 2002 15:47:14 -0000 1.1.1.2 @@ -4,7 +4,7 @@ Reports details from saved top statistics @author sklein@arsdigita.com - @cvs-id details.tcl,v 1.8.2.4 2000/08/02 19:11:54 kevin Exp + @cvs-id $Id$ @param n_days the # of days over which to average data @param start_time start time on a given day @@ -47,37 +47,37 @@ set top_system_avg_table_def { {time "hour" {} \ - {$time}} + {$time}} {load_average "load" {} {}} {memory_free_average "free mem" {} \ - {[ad_monitor_format_kb $memory_free_average]}} + {[ad_monitor_format_kb $memory_free_average]}} {memory_swap_free_average "free swap" {} \ - {[ad_monitor_format_kb $memory_swap_free_average]}} + {[ad_monitor_format_kb $memory_swap_free_average]}} {memory_swap_in_use_average "used swap" {} \ - {[ad_monitor_format_kb $memory_swap_in_use_average]}} + {[ad_monitor_format_kb $memory_swap_in_use_average]}} {count "count" {} {}} } set top_system_table_def { {time "time" {} {}} {load_average "load" {} {}} {memory_free_average "free mem" {} \ - {[ad_monitor_format_kb $memory_free_average]}} + {[ad_monitor_format_kb $memory_free_average]}} {memory_swap_free_average "free swap" {} \ - {[ad_monitor_format_kb $memory_swap_free_average]}} + {[ad_monitor_format_kb $memory_swap_free_average]}} {memory_swap_in_use_average "used swap" {} \ - {[ad_monitor_format_kb $memory_swap_in_use_average]}} + {[ad_monitor_format_kb $memory_swap_in_use_average]}} } set top_proc_table_def { {time "Time" {} {}} {threads "Thr" {} {}} {command "Command" {} \ - {$command}} + {$command}} {username "Username" {} \ - {$username}} + {$username}} {pid "PID" {} \ - {$pid}} + {$pid}} {cpu_pct "CPU" {} {}} {count "Cnt" {} {}} } @@ -95,27 +95,26 @@ set n_days "all" } if { ![string equal $key "hour"] } { - set time_clause "timehour >= :start_time - and timehour < :end_time" - + set time_clause [db_map time_clause_1] + if { [string compare $n_days "all"] != 0 } { - # Need to multiply n_days by ($end_time-to_char(sysdate,'HH24'))/24 - # for accurate current snapshots. That is, displaying back in time - # needs to be relative to the selected end_time, not to sysdate. - set current_hour [db_string mon_current_hour \ - "select to_char(sysdate,'HH24') from dual"] - if { $end_time > $current_hour } { - # we correct for the last day in the query if the end time - # is later than the current time. - # TODO: need to add this into the query? - set hour_correction " + (24 - (:end_time - :current_hour)) / 24 " - } else { - set hour_correction "" - } + # Need to multiply n_days by ($end_time-to_char(sysdate,'HH24'))/24 + # for accurate current snapshots. That is, displaying back in time + # needs to be relative to the selected end_time, not to sysdate. + set current_hour [db_string mon_current_hour { *SQL* } ] + + if { $end_time > $current_hour } { + # we correct for the last day in the query if the end time + # is later than the current time. + # TODO: need to add this into the query? + set hour_correction [db_map hour_correction] + } else { + set hour_correction "" + } } } else { # we're looking at a specific hour of a specific day, no need to filter - set time_clause "1 = 1" + set time_clause "where 1 = 1" } ### 2. Create the sql to fill the ad_tables, given the detailed constraint. @@ -124,22 +123,25 @@ set proc_time_sql "to_char(timestamp, 'MM/DD HH24') || ':00' as time" switch $key { - day { set details_clause "to_char(timestamp, 'Mon DD') = :value" - set system_time_sql "to_char(timestamp, 'MM/DD HH24') || ':00' as time" - set system_group_by "to_char(timestamp, 'MM/DD HH24')" + day { + set details_clause "to_char(timestamp, 'Mon DD') = :value" + set system_time_sql "to_char(timestamp, 'MM/DD HH24') || ':00' as time" + set system_group_by "to_char(timestamp, 'MM/DD HH24')" } - hour { set details_clause "to_char(timestamp, 'MM/DD HH24') || ':00' = :value" - set system_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" - set system_group_by "timestamp" - # if you want to show every single proc: - if {[string match $showall "t"]} { - set proc_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" - set proc_group_by "timestamp" - } + hour { + set details_clause "to_char(timestamp, 'MM/DD HH24') || ':00' = :value" + set system_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" + set system_group_by "timestamp" + # if you want to show every single proc: + if {[string match $showall "t"]} { + set proc_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" + set proc_group_by "timestamp" + } } - default { set details_clause "$key = :value" - set proc_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" - set proc_group_by "timestamp" + default { + set details_clause "$key = :value" + set proc_time_sql "to_char(timestamp, 'MM/DD HH24:MI') as time" + set proc_group_by "timestamp" } } @@ -148,37 +150,12 @@ ## the $xxx_group_by clause groups either by hour or by second ## (i.e., not at all). -set proc_query " - select pid, command, username, - $proc_time_sql, - count(*) as count, - round(avg(threads),0) as threads, - round(avg(to_number(rtrim(cpu_pct, '%'))),2) as cpu_pct - from (select * from ad_monitoring_top_proc - where to_number(rtrim(cpu_pct, '%')) > :min_cpu_pct) p, - (select * from ad_monitoring_top where $time_clause) t - where p.top_id = t.top_id - and $details_clause - group by pid, command, username, $proc_group_by - [ad_order_by_from_sort_spec $orderby $top_proc_table_def] -" +set proc_query [db_map proc_query] if { [string match $key "hour"] || [string match $key "day"] } { - set load_and_memory_averages_sql "round(nvl(avg(load_avg_1), 0), 2) as load_average, - round(nvl(avg(memory_free),0), -2) as memory_free_average, - round(nvl(avg(memory_swap_free), 0), -2) as memory_swap_free_average, - round(nvl(avg(memory_swap_in_use),0), -2) as memory_swap_in_use_average" + set load_and_memory_averages_sql [db_map load_and_memory_averages_sql] - set system_query " - select $load_and_memory_averages_sql, - count(*) as count, - $system_time_sql - from ad_monitoring_top - where $time_clause - and $details_clause - group by $system_group_by - [ad_order_by_from_sort_spec $orderbysystem $top_system_table_def] - " + set system_query [db_map system_query] } ### Begin returning the page. @@ -201,20 +178,24 @@ set n_days_list [list] foreach n [list 1 2 3 7 14 31 all] { if { $n == $n_days } { - lappend n_days_list "$n" + lappend n_days_list "$n" } else { - lappend n_days_list "$n" } } set start_select "" set end_select "" for { set i 0 } { $i < 25 } { incr i } { - if { $i == 0 || $i == 24} { set text "Midnight" - } elseif { $i == 12 } { set text "Noon" - } elseif { $i > 12 } { set text "[expr {$i - 12}] pm" - } else { set text "$i am" + if { $i == 0 || $i == 24} { + set text "Midnight" + } elseif { $i == 12 } { + set text "Noon" + } elseif { $i > 12 } { + set text "[expr {$i - 12}] pm" + } else { + set text "$i am" } append start_select "