Index: openacs.org-dev/packages/monitoring/www/top/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs.org-dev/packages/monitoring/www/top/index.tcl,v
diff -u -r1.1.1.1 -r1.1.1.2
--- openacs.org-dev/packages/monitoring/www/top/index.tcl 9 Jul 2002 17:35:09 -0000 1.1.1.1
+++ openacs.org-dev/packages/monitoring/www/top/index.tcl 8 Oct 2002 15:47:14 -0000 1.1.1.2
@@ -3,17 +3,18 @@
ad_page_contract {
Displays reports from saved top statistics.
- @param n_days the # of days over which to average
+ @param n_days the number of days over which to average
@param start_time taken between the given start
@param end_time and end times on each day
@param orderby the field by which to order the procedure-specific data
@param orderbysystem field by which to order the system_avg data
@param showtop show the top of the moment? (boolean)
@param min_cpu_pct procs with CPU below this aren't displayed
- @authors sklein@arsdigita.com, mbryzek@arsdigita.com
+ @author sklein@arsdigita.com
+ @author mbryzek@arsdigita.com
@creation-date May 2000
- @cvs-id index.tcl,v 1.18.2.4 2000/08/02 19:04:34 kevin Exp
+ @cvs-id $Id$
} {
{n_days 1}
{start_time "00"}
@@ -31,25 +32,25 @@
{timestamp "Hour" {} {}}
{threads "Thr" {} {}}
{command "Command" {} \
- {
}}
{count "count" {} {}}
}
@@ -62,69 +63,45 @@
##
## 1. Create the sql to filter by date and time
-set time_clause "where timehour >= :start_time
- and timehour < :end_time"
-
-if { [string compare $n_days "all"] != 0 } {
+set time_clause [db_map time_clause_1]
+if { ![string equal $n_days "all"] } {
# Need to multiply n_days by ($end_time-to_char(sysdate,'HH24'))/24 to
# get 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* } ]
- 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.
- set hour_correction " + (24 - (:end_time - :current_hour)) / 24 "
+ # we correct for the last day in the query if the end time
+ # is later than the current time.
+ set hour_correction [db_map hour_correction]
} else {
- set hour_correction ""
+ set hour_correction ""
}
- append time_clause " and (timestamp + :n_days $hour_correction) > sysdate"
+ append time_clause [db_map time_clause_2]
}
### 2. Create the sql to fill top_proc_avg_table, grouping proc info
### by pid and averaging over each hour(day) that pid was running
### (default to hour). We need to be careful about avging over
### the whole time period b/c the same pid is eventually used by
### distinct processes.
-set hour_sql "to_char(timestamp, 'MM/DD HH24') || ':00'"
-set day_sql "to_char(timestamp, 'Mon DD')"
+set hour_sql [db_map hour_sql]
+set day_sql [db_map day_sql]
##
-set avg_proc_query "
- select pid, command, username,
- count(*) as count,
- $hour_sql as timestamp,
- round(avg(threads)) as threads,
- round(avg(to_number(rtrim(cpu_pct, '%'))), 2) as cpu_pct
- from ( select * from ad_monitoring_top $time_clause ) t,
- ( select * from ad_monitoring_top_proc
- where to_number(rtrim(cpu_pct, '%')) > :min_cpu_pct ) p
- where p.top_id = t.top_id
- group by pid, command, username, $hour_sql
- [ad_order_by_from_sort_spec $orderby $top_proc_avg_table_def]
-"
+# vinodk: FIXME below here 2002-08-17
+set avg_proc_query [db_map avg_proc_query]
+
# [ad_table_orderby_sql $top_proc_avg_table_def $orderby "DESC"]
-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]
## the query to get system averages for each requested day. This is not
## the only query for display in an ad_table; note that "system" is tacked
## onto the end of the orderby variable [and elsewhere as regards this query].
-set avg_system_query "
- select $load_and_memory_averages_sql,
- count(*) as count,
- $day_sql as day
- from ad_monitoring_top
- $time_clause
- group by $day_sql
- [ad_order_by_from_sort_spec $orderbysystem $top_system_avg_table_def]
-"
+set avg_system_query [db_map avg_system_query]
+
# [ad_table_orderby_sql $top_system_avg_table_def $orderbysystem "DESC"]
### Begin returning the page.
@@ -145,22 +122,26 @@
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"
+ 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 "