1 # mash-system.tcl --
2 #
3 # This file contains useful routines for accessing system specific
4 # information (such as CPU load, free disk space etc)
5 #
6 # Copyright (c) 1996-2002 The Regents of the University of California.
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions are met:
11 #
12 # A. Redistributions of source code must retain the above copyright notice,
13 # this list of conditions and the following disclaimer.
14 # B. Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 # C. Neither the names of the copyright holders nor the names of its
18 # contributors may be used to endorse or promote products derived from this
19 # software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
25 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #
32 # @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/common/mash-system.tcl,v 1.1 2002/05/28 19:57:53 weitsang Exp $
33 Class MashSystem
34
35 #-----------------------------------------------------------------------
36 # Method:
37 # MashSystem get_load
38 # Description:
39 # Call uptime and return the current load on this machine.
40 #-----------------------------------------------------------------------
41
42 MashSystem proc get_load {} {
43 set v [catch {open "|uptime"} fd]
44 if { $v != 0 } {
45 return 0
46 }
47 set l [gets $fd]
48 close $fd
49 # Format:
50 # FIXME load averages: 0.00, 0.00, 0.00
51 set n [llength $l]
52 set avg [string trim [lindex $l [expr $n - 3]] ,]
53 return $avg
54 }
55
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.