423 lines
18 KiB
HTML
423 lines
18 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>Gathering Usage Stats Issue 25</title>
|
|
</HEAD>
|
|
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
|
|
ALINK="#FF0000">
|
|
<!--endcut ============================================================-->
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more fun!</I>"
|
|
</H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
<H2> Gathering Usage Stats</H2>
|
|
<H4>By <a href="mailto:randy@euclid.acs.nmu.edu">Randy Appleton</a></H4>
|
|
</center>
|
|
<P> <HR> <P>
|
|
|
|
<H3>
|
|
Intro</H3>
|
|
Here in the Linux Laboratory at Northern Michigan University, we have quite
|
|
a few users and quite a few computers for them to use. It is important
|
|
for laboratoies like us to quantify usage. This
|
|
data can be used to justify expansion of a computer laboratory, describe
|
|
who is actually using the machines, which machines are being used,
|
|
or just satisfy simple curiosity.
|
|
|
|
<P>Being the curious type, I sat down to write a program that would gather
|
|
usage information. The information I wanted includes:
|
|
<UL>
|
|
<LI>
|
|
How much time each user spends online.</LI>
|
|
|
|
<LI>
|
|
How much time each computer spends being used.</LI>
|
|
|
|
<LI>
|
|
How often the computer is up.</LI>
|
|
|
|
<LI>
|
|
User total usage time divided by weeks (to see long term trends).</LI>
|
|
|
|
<LI>
|
|
User total usage time divided by day for the last couple of days (to see
|
|
current trends).</LI>
|
|
</UL>
|
|
|
|
<H3>
|
|
Methodology</H3>
|
|
My first thought was to just stick my head in at odd times and count users.
|
|
But for such a strategy to work, I would have to count users at various
|
|
times in the day, including times I might not otherwise be inclined to
|
|
visit the lab (like early mornings). Further, I would miss users
|
|
using the lab remotely, over the internet.
|
|
|
|
<P>My second thought was to use the "w" command. This command reads
|
|
a log file (normally /var/log/wtmp) and produces a line of output for every
|
|
logon event in the past, describing who was logged on and for how long.
|
|
My hope was that a summary of this information would provide the usage
|
|
statistics I was looking for. Unfortunately, this command does not
|
|
produce foolproof output. If the machine crashes while someone is
|
|
logged on, then "w" will sometimes produce the wrong total time online.
|
|
Even worse, if a person is logged on but idle, this idle time still counts
|
|
as usage as computed by "w".
|
|
|
|
<P>Counting idle time was unacceptable to me. We have several
|
|
users with computers in their offices, and they are essentially logged
|
|
on 24 hours per day 7 days per week. Their usage is nowhere near
|
|
this level (yes, even college professors go to sleep!)
|
|
|
|
<P>Luckily , there was an alternative to "w". The easiest way to
|
|
find out who is currently logged onto a computer is to use finger, a program
|
|
designed for just this purpose. The command "finger @hostname"
|
|
will describe who is logged on to "hostname", and how long since they actually
|
|
typed a command (i.e. finger knows their idle time).
|
|
|
|
<P>Finger produces a header line, and the one line for every person logged
|
|
on. Eliminating the users with a high idle time will provide a list
|
|
of users who are using the computer at any given moment. A log file
|
|
of such lists, gathered at regular intervals, will describe usage over
|
|
the time the log file was gathered.
|
|
|
|
<P>There is an important statistical assumption here. We assume that
|
|
a set of entries will accurately describe usage over the whole time period,
|
|
not just the precise moments when those entries occur. For
|
|
this assumption to be valid the entries should be gathered at regular intervals.
|
|
<H3>
|
|
Defining Usage</H3>
|
|
The other complicated issue is to define usage. Often a single computer
|
|
will have several users logged on simultaneously, and often a single user
|
|
will be logged on to multiple computers at once (as I am now). It
|
|
becomes important to carefully define usage in these cases. I adopted
|
|
the following definitions.
|
|
<UL>
|
|
<LI>
|
|
A computer is in use if and only if there is at least one user using that
|
|
computer.</LI>
|
|
|
|
<LI>
|
|
A user is logged on if and only if the user is logged onto at least one
|
|
computer.</LI>
|
|
|
|
<LI>
|
|
A computer is up if and only if it responds to the finger command at all,
|
|
and is otherwise down. Note that a computer that is currently running
|
|
Windows will NOT respond, and will therefore be counted as down (which
|
|
makes sense to me!).</LI>
|
|
</UL>
|
|
Given these definition, it becomes important not double count users where
|
|
they are logged in more than once, and to not double count computers when
|
|
they have more than one user. Correct programming eliminates these
|
|
double countings (see the source code below).
|
|
<BR>
|
|
<H3>
|
|
The Log file</H3>
|
|
The log file contains a series of records, each one of which is a description
|
|
of the results of running finger on the set of hosts. The size of
|
|
each entry is minimized, since many entries will be gathered yet the log
|
|
file should remain modest in size. The top of each entry contains the date
|
|
and time the entry was gathered, which is important for gathering time
|
|
and date based statistics. The log file entry below shows that it
|
|
is 11 45 in the evening on 10/11/97, and that I am the only one logged
|
|
in besides root. Root and I are using the computers ogaa and ogimaa.
|
|
Also shown is that the computer nigig is down, since it is not listed at
|
|
all.
|
|
<UL>
|
|
<TABLE BORDER COLS=1 WIDTH="200" NOSAVE >
|
|
<TR NOSAVE>
|
|
<TD NOSAVE>Date 97 10 11 23 45
|
|
<BR>Host ogimaa 1
|
|
<BR>Host bine 0
|
|
<BR>Host gaag 0
|
|
<BR>Host makwa 0
|
|
<BR>Host mooz 0
|
|
<BR>Host zagime 0
|
|
<BR>Host ogaa 1
|
|
<BR>Host euclid 0
|
|
<BR>Host euler 0
|
|
<BR>Host fermat 0
|
|
<BR>User randy
|
|
<BR>User root
|
|
<BR>Total 2 users</TD>
|
|
</TR>
|
|
</TABLE>
|
|
</UL>
|
|
|
|
<H3>
|
|
The Program</H3>
|
|
The program is named fingersummarize, since its job is to summarize a set
|
|
of results from the finger command. It is written in Perl, since
|
|
Perl offers wonderful support for associative arrays (where the usage stats
|
|
are stored) and working with strings (from the log file and the output
|
|
of finger).
|
|
|
|
<P>There are two basic tasks of fingersummarize. These functions could
|
|
easily be done with two separate programs, but I find it easier to have
|
|
one program with options rather than two executables.
|
|
<UL>
|
|
<LI>
|
|
It should gather finger results, and store them in a log file. (fingersummarize
|
|
-probe)</LI>
|
|
|
|
<LI>
|
|
It should read the log file and produce the usage statistics. (fingersummarize
|
|
-print)</LI>
|
|
</UL>
|
|
Fingersummarize can be installed easily. Just follow the instructions
|
|
below.
|
|
<OL>
|
|
<LI>
|
|
Copy the executable to someplace on your system, such as /usr/local/bin.</LI>
|
|
|
|
<BR><TT> cp /tmp/fingersummarize /usr/local/bin;
|
|
chmod 755 /usr/local/bin/fingersummarize</TT>
|
|
<LI>
|
|
Edit the top of the executable so that fingersummarize will probe your
|
|
machines instead of mine. This should be very easy to do.</LI>
|
|
|
|
<BR>
|
|
<TT>vi /usr/local/bin/fingersummarize</TT>
|
|
<LI>
|
|
Make a blank log file and put that log file somewhere. Often /var/log/fingersummarize
|
|
is a reasonable place.</LI>
|
|
|
|
<BR><TT> echo > /var/log/fingersummarize;
|
|
chmod 600 /var/log/fingersummarize</TT>
|
|
<LI>
|
|
Install a line in cron so that fingersummarize will run in probe mode at
|
|
regular intervals. Below is the line I use, which runs fingersummarize
|
|
every fifteen minutes for every hour.</LI>
|
|
|
|
<BR>
|
|
<TT>0,15,30,45 * * * * /usr/local/bin/fingersummarize -probe >> /var/log/fingersummarizelog</TT></OL>
|
|
That's it. Now, whenever you want to see a current summary of the
|
|
usage data, just run
|
|
<BR>
|
|
<TT>fingersummarize -print < /var/log/fingersummarizelog</TT>
|
|
<H3>
|
|
Example Output</H3>
|
|
Here is some sample output. A current example for my lab can he had
|
|
at <A HREF="http://euclid.nmu.edu/fingerprobe.txt">http://euclid.nmu.edu/fingerprobe.txt</A>
|
|
. The executable itself can be had at <A HREF="http://euclid.nmu.edu/~randy/Papers/fingerprobe">http://euclid.nmu.edu/~randy/Papers/fingerprobe</A>
|
|
. Note that the total number of hours computers were in use (12.8
|
|
hours/week) exceeds the total number of hours that people were using computers
|
|
(10.8hours/week). This just means there were times that some person
|
|
was using more than one computer at a time. Also, note that the useage
|
|
spikes at 10am, since a particular class sometimes meets in the lab at
|
|
10am.
|
|
<BR>
|
|
<BR>
|
|
<TABLE BORDER COLS=2 WIDTH="80%" NOSAVE >
|
|
<TR NOSAVE>
|
|
<TD><TT>Stats by user</TT>
|
|
<BR><TT>User Total Usage Hours</TT>
|
|
<BR><TT>Name Observ. Percent /Day</TT>
|
|
<BR><TT>abasosh 47 4
|
|
0.42</TT>
|
|
<BR><TT>agdgdfg 54 4.6
|
|
0.49</TT>
|
|
<BR><TT>arnelso 7 0.6
|
|
0.06</TT>
|
|
<BR><TT>bparton 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>bob 28 2.4
|
|
0.25</TT>
|
|
<BR><TT>brandk 101 8.7
|
|
0.92</TT>
|
|
<BR><TT>btsumda 37 3.2
|
|
0.33</TT>
|
|
<BR><TT>chgijs 1 0
|
|
0</TT>
|
|
<BR><TT>clntudp 1 0
|
|
0</TT>
|
|
<BR><TT>daepke 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>dan 93 8
|
|
0.84</TT>
|
|
<BR><TT>dfliter 17 1.4
|
|
0.15</TT>
|
|
<BR><TT>gclas 43 3.7
|
|
0.39</TT>
|
|
<BR><TT>goofy 15 1.3
|
|
0.13</TT>
|
|
<BR><TT>gypsy 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>jadsjhf 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>jbsdjh 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>jdefgg 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>jeffpat 6 0.5
|
|
0.05</TT>
|
|
<BR><TT>jpaulin 7 0.6
|
|
0.06</TT>
|
|
<BR><TT>jstyle 4 0.3
|
|
0.03</TT>
|
|
<BR><TT>jstamo 17 1.4
|
|
0.15</TT>
|
|
<BR><TT>jwilpin 37 3.2
|
|
0.33</TT>
|
|
<BR><TT>jwilpou 79 6.8
|
|
0.72</TT>
|
|
<BR><TT>kangol 39 3.3
|
|
0.35</TT>
|
|
<BR><TT>matt 58 5
|
|
0.52</TT>
|
|
<BR><TT>mhgihjj 8 0.6
|
|
0.07</TT>
|
|
<BR><TT>randy 187 16.2
|
|
1.7</TT>
|
|
<BR><TT>rbush 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>root 22 1.9
|
|
0.2</TT>
|
|
<BR><TT>rpijj 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>sbeyne 17 1.4
|
|
0.15</TT>
|
|
<BR><TT>sdajani 1 0
|
|
0</TT>
|
|
<BR><TT>sdalma 28 2.4
|
|
0.25</TT>
|
|
<BR><TT>ship 1 0
|
|
0</TT>
|
|
<BR><TT>skinny 48 4.1
|
|
0.43</TT>
|
|
<BR><TT>stacey 2 0.1
|
|
0.01</TT>
|
|
<BR><TT>tbutler 35 3
|
|
0.31</TT>
|
|
<BR><TT>tmarsha 5 0.4
|
|
0.04</TT>
|
|
<BR><TT>tpauls 34 2.9
|
|
0.31</TT>
|
|
<BR><TT>vladami 30 2.6
|
|
0.27</TT>
|
|
<BR><TT>xetroni 26 2.2
|
|
0.23</TT>
|
|
<BR><TT>---------------------------------</TT>
|
|
<BR><TT>Overall 1151
|
|
10.24</TT>
|
|
<BR>
|
|
|
|
<P><TT>Stats by Host</TT>
|
|
<BR><TT>Host Total Percent Percent Hours</TT>
|
|
<BR><TT>Name Observ. Up
|
|
Busy /Day</TT>
|
|
<BR><TT>bine 131 100%
|
|
4.9% 1.194</TT>
|
|
<BR><TT>euclid 152 100%
|
|
5.7% 1.386</TT>
|
|
<BR><TT>euler 7 89.3%
|
|
0.2% 0.068</TT>
|
|
<BR><TT>fermat 52 100%
|
|
2.1% 0.506</TT>
|
|
<BR><TT>gaag 202 36.5%
|
|
7.6% 1.842</TT>
|
|
<BR><TT>maang 118 100%
|
|
4.4% 1.076</TT>
|
|
<BR><TT>makwa 77 100%
|
|
2.9% 0.702</TT>
|
|
<BR><TT>mooz 92 100%
|
|
3.4% 0.839</TT>
|
|
<BR><TT>nigig 81 100%
|
|
3% 0.738</TT>
|
|
<BR><TT>ogaa 48 100%
|
|
1.8% 0.437</TT>
|
|
<BR><TT>ogimaa 374 100%
|
|
14.2% 3.411</TT>
|
|
<BR><TT>waabooz 28 100%
|
|
1% 0.255</TT>
|
|
<BR><TT>zagime 38 100%
|
|
1.4% 0.346</TT>
|
|
<BR><TT>------------------------</TT>
|
|
<BR><TT>Overall 2551 94.2% 4.1%
|
|
12.807</TT></TD>
|
|
|
|
<TD NOSAVE><TT>Stats by the Week</TT>
|
|
<BR><TT>Week
|
|
User</TT>
|
|
<BR><TT>Starting Hours</TT>
|
|
<BR><TT>97 10 04 74.5705816481128</TT>
|
|
<BR><TT>97 09 28 55.9130434782609</TT>
|
|
<BR><TT>97 09 21 64.7</TT>
|
|
<BR><TT>97 09 14 113.023956442831</TT>
|
|
<BR>
|
|
|
|
<P><TT>Last Two Weeks</TT>
|
|
<BR><TT>Day User</TT>
|
|
<BR><TT> Hours</TT>
|
|
<BR><TT>97 10 11 7.05882352941176</TT>
|
|
<BR><TT>97 10 10 16.75</TT>
|
|
<BR><TT>97 10 09 4.25</TT>
|
|
<BR><TT>97 10 08 1.5</TT>
|
|
<BR><TT>97 10 07 5.25</TT>
|
|
<BR><TT>97 10 06 8.25</TT>
|
|
<BR><TT>97 10 05 13.8947368421053</TT>
|
|
<BR><TT>97 10 04 17.6170212765957</TT>
|
|
<BR><TT>97 10 03 9.91304347826087</TT>
|
|
<BR><TT>97 10 02 0.75</TT>
|
|
<BR><TT>97 10 01 1</TT>
|
|
<BR><TT>97 09 31 12</TT>
|
|
<BR><TT>97 09 30 9.75</TT>
|
|
<BR><TT>97 09 29 12.75</TT>
|
|
<BR>
|
|
|
|
<P><TT>Stats by the Hour</TT>
|
|
<BR><TT>Hour Avg Users</TT>
|
|
<BR><TT>00 0.151</TT>
|
|
<BR><TT>01 0.163</TT>
|
|
<BR><TT>02 0.151</TT>
|
|
<BR><TT>03 0.053</TT>
|
|
<BR><TT>04 0.036</TT>
|
|
<BR><TT>06 0.027</TT>
|
|
<BR><TT>07 0.055</TT>
|
|
<BR><TT>08 0.175</TT>
|
|
<BR><TT>09 0.75</TT>
|
|
<BR><TT>10 1.398</TT>
|
|
<BR><TT>11 1.171</TT>
|
|
<BR><TT>12 0.972</TT>
|
|
<BR><TT>13 0.814</TT>
|
|
<BR><TT>14 0.775</TT>
|
|
<BR><TT>15 0.778</TT>
|
|
<BR><TT>16 0.607</TT>
|
|
<BR><TT>17 0.526</TT>
|
|
<BR><TT>18 0.459</TT>
|
|
<BR><TT>19 0.455</TT>
|
|
<BR><TT>20 0.232</TT>
|
|
<BR><TT>21 0.321</TT>
|
|
<BR><TT>22 0.339</TT>
|
|
<BR><TT>23 0.196</TT>
|
|
<P>
|
|
</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1998, Randy Appleton<BR>
|
|
Published in Issue 25 of <i>Linux Gazette</i>, February 1998</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./marsden.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./gm.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|
|
|