home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume02 / survey < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  9.3 KB

  1. From mipos3!intelca!oliveb!ames!husc6!necntc!ncoast!allbery Sat Jan 23 19:37:44 PST 1988
  2. Article 259 of comp.sources.misc:
  3. Path: td2cad!mipos3!intelca!oliveb!ames!husc6!necntc!ncoast!allbery
  4. From: dave@sea375.UUCP (David A. Wilson)
  5. Newsgroups: comp.sources.misc
  6. Subject: v02i010: survey - unix system usage profile report(BSD)
  7. Keywords: load average
  8. Message-ID: <7103@ncoast.UUCP>
  9. Date: 20 Jan 88 01:06:36 GMT
  10. Sender: allbery@ncoast.UUCP
  11. Organization: At Home in Seattle, WA
  12. Lines: 345
  13. Approved: allbery@ncoast.UUCP
  14. X-Archive: comp.sources.misc/8801/10
  15. Comp.sources.misc: Volume 2, Issue 10
  16. Submitted-By: David A. Wilson <dave@sea375.UUCP>
  17. Archive-name: survey
  18.  
  19. Comp.sources.misc: Volume 2, Issue 10
  20. Submitted-By: David A. Wilson <dave@sea375.UUCP>
  21. Archive-name: survey
  22.  
  23. [Not portable to System V directly.  /etc/avenrun hook?  ++bsa]
  24.  
  25. Survey, is a utility I use to generate a simple plot of system load
  26. and number of users by time. I find it a very useful system management tool.
  27. Survey requires the BSD uptime(1) command.
  28.  
  29. [I adapted this from a posting several years ago, I do not recall who
  30. the originator was. This is almost a complete rewrite.]
  31.  
  32. Below is a sample of the output:(line width & scale are command line options)
  33. ['L' is load average value, 'U' is number of users logged on.]
  34.  
  35. Tue Nov  3 00:01:02 PST 1987 uptime19871103
  36.          0                1                2                3                4
  37.          |                |                |                |                |
  38.   9:45pm L
  39.  10:00pm L
  40.  10:15pm L
  41.  10:30pm           L      U
  42.  10:45pm               L  U
  43.  11:00pm                 LU
  44.  11:15pm                 LU
  45.  11:30pm                  L
  46.  11:45pm                  L
  47.  
  48. Also included is, namedate(1), which I use to generate the current date
  49. in a numeric, but human readable form. It makes a date of the form
  50. YYYYMMDD, which sorts cronologically. I use it mostly to generate dated
  51. filenames.
  52.  
  53. If you find any problems please tell me about them. If you port it to
  54. any non-BSD system, please send me the changes.
  55.  
  56. David A. Wilson
  57. ...uw-beaver!tikal!slab!sea375!dave  
  58.  
  59. #------- CUT HERE -----
  60. #!/bin/sh
  61. # This is a shell archive, meaning:
  62. # 1. Remove everything above the #!/bin/sh line.
  63. # 2. Save the resulting text in a file.
  64. # 3. Execute the file with /bin/sh (not csh) to create the files:
  65. #    load_chart/README
  66. #    load_chart/survey
  67. #    load_chart/namedate.1
  68. #    load_chart/namedate.c
  69. # This archive created: Sat Nov  7 14:34:21 1987
  70. export PATH; PATH=/bin:$PATH
  71. echo shar: extracting "'README'" '(498 characters)'
  72. if test -f 'README'
  73. then
  74.     echo shar: over-writing existing file "'README'"
  75. fi
  76. sed 's/^X//' << \SHAR_EOF > 'README'
  77. XTo run the cpu load and number of users report:
  78. Xsurvey uptime* > loadyyyymm
  79. X
  80. XUsage: survey [fullscale=#] [width=#] uptime_files
  81. X    fullscale    - max value of scale for data(default:see BEGIN{})
  82. X              if data exceeds fullscale output may exceed width
  83. X    width - number of columns on a line(default:see BEGIN{})
  84. X
  85. XInstall into crontab:
  86. X1 0 * * * date > /usr/local/adm/load_chart/uptime`/usr/local/bin/namedate`
  87. X0,15,30,45 * * * * /usr/ucb/uptime >> /usr/local/adm/load_chart/uptime`/usr/local/bin/namedate`
  88. X
  89. SHAR_EOF
  90. if test 498 -ne "`wc -c 'README'`"
  91. then
  92.     echo shar: error transmitting "'README'" '(should have been 498 characters)'
  93. fi
  94. echo shar: extracting "'survey'" '(3299 characters)'
  95. if test -f 'survey'
  96. then
  97.     echo shar: over-writing existing file "'survey'"
  98. fi
  99. sed 's/^X//' << \SHAR_EOF > 'survey'
  100. X#!/bin/awk -f
  101. X# $Header: survey,v 1.7 87/11/07 14:12:42 dave Exp $
  102. XBEGIN {
  103. X    FS = ",";
  104. X    ff = 12;
  105. X    max = 0;
  106. X    fullscale = 4;
  107. X    width = 79;
  108. X    unit = -1;
  109. X    old_filename = "------";
  110. X    blanks = "                                                                                ";
  111. X}
  112. X
  113. X#skip blank lines
  114. X/^$/    { next; }
  115. X
  116. X#dates start in first column and first letter is always a CAP
  117. X/^[A-Z]/    { date = $1; next; }
  118. X
  119. X# Page break on a new file
  120. X{
  121. X    if ( FILENAME != old_filename )
  122. X    {
  123. X        # compute units here
  124. X        # so user can set fullscale an width on command line
  125. X        if ( unit < 0 )
  126. X        {
  127. X            unit = int((width-10)/fullscale);
  128. X        }
  129. X        old_filename = FILENAME;
  130. X        printf( "%c\n%s %s\n", ff, date, FILENAME );
  131. X        printf( "         0" );
  132. X        for ( i=1; i<=fullscale; i++ )
  133. X        {
  134. X            numstr = sprintf( "%d", i );
  135. X            printf( "%s%s", \
  136. X                substr( blanks, 1, (unit-length(numstr)) ), \
  137. X                numstr );
  138. X        }
  139. X        printf( "\n         |" );
  140. X        for ( i=0; i<fullscale; i++ )
  141. X        {
  142. X            printf( "%s|", substr( blanks, 1, unit-1 ) );
  143. X        }
  144. X        printf( "\n" );
  145. X    } 
  146. X
  147. X    # the load average for the last 15min period is always the last field
  148. X    if ( NF == 5 )
  149. X    {
  150. X        avg = $NF;
  151. X        user_field = $2;
  152. X    }
  153. X    else
  154. X    {
  155. X        avg = $NF;
  156. X        user_field = $3;
  157. X    }
  158. X    time = substr($0, 1, 8);
  159. X    if ( exist[time] != 1 )
  160. X    {
  161. X        exist[time] = 1;
  162. X        t[++max] = time;
  163. X    }
  164. X    # compute position for user & loadavg
  165. X    nsplit = split( user_field, xusers, " " );
  166. X    pusers = int( unit * xusers[1] );
  167. X    lavg = int(avg * unit);
  168. X
  169. X    sum[time] += avg;
  170. X    count[time]++;
  171. X    users_sum[ time ] += xusers[1];
  172. X
  173. X    # test for max users and max average
  174. X    if ( avg > max_avg )
  175. X    {
  176. X        max_avg = avg;
  177. X        max_avg_date = date;
  178. X        max_avg_time = time;
  179. X    }
  180. X    if ( xusers[1] > max_users )
  181. X    {
  182. X        max_users = xusers[1];
  183. X        max_users_date = date;
  184. X        max_users_time = time;
  185. X    }
  186. X
  187. X    #find max of pusers and lavg
  188. X    if ( pusers > lavg )
  189. X    {
  190. X        printf( "%8s %s%s%s%s\n", \
  191. X            time, substr( blanks, 1, lavg ), "L", \
  192. X            substr( blanks, 0, pusers-lavg-1 ), "U" );
  193. X    }
  194. X    else if ( pusers < lavg )
  195. X    {
  196. X        printf( "%8s %s%s%s%s\n", \
  197. X            time, substr( blanks, 1, pusers ), \
  198. X            "U", substr( blanks, 0, lavg-pusers-1 ), "L" );
  199. X    }
  200. X    else
  201. X    {
  202. X        printf( "%8s %s%s\n", time, substr( blanks, 1, lavg ), "L" );
  203. X    }
  204. X}
  205. X
  206. XEND {
  207. X    printf( "%c\nAVERAGE\n", ff );
  208. X    printf( "         0" );
  209. X    for ( i=1; i<=fullscale; i++ )
  210. X    {
  211. X        numstr = sprintf( "%d", i );
  212. X        printf( "%s%s", substr( blanks, 1, (unit-length(numstr)) ), \
  213. X            numstr );
  214. X    }
  215. X    printf( "\n         |" );
  216. X    for ( i=0; i<fullscale; i++ )
  217. X    {
  218. X        printf( "%s|", substr( blanks, 1, unit-1 ) );
  219. X    }
  220. X    printf( "\n" );
  221. X
  222. X    for ( j = 1; j <= max; j++ )
  223. X    {
  224. X        time = t[j];
  225. X        if (count[time] == 0)
  226. X        {
  227. X            avg = 0;
  228. X            user_avg = 0;
  229. X        }
  230. X        else
  231. X        {
  232. X            avg = sum[time]/count[time];
  233. X            user_avg = users_sum[time]/count[time];
  234. X        }
  235. X        pusers = int( unit * user_avg );
  236. X        lavg = int(avg * unit);
  237. X        #find max of pusers and lavg
  238. X        if ( pusers > lavg )
  239. X        {
  240. X            printf( "%8s %s%s%s%s\n", \
  241. X                time, substr( blanks, 1, lavg ), "L", \
  242. X                substr( blanks, 0, pusers-lavg-1 ), "U" );
  243. X        }
  244. X        else if ( pusers < lavg )
  245. X        {
  246. X            printf( "%8s %s%s%s%s\n", \
  247. X                time, substr( blanks, 1, pusers ), "U", \
  248. X                substr( blanks, 0, lavg-pusers-1 ), "L" );
  249. X        }
  250. X        else
  251. X        {
  252. X            printf( "%8s %s%s\n", \
  253. X                time, substr( blanks, 1, lavg ), "L" );
  254. X        }
  255. X    }
  256. X    print "";
  257. X    print "max_load = ", max_avg, max_avg_date, max_avg_time;
  258. X    print "max_users = ", max_users, max_users_date, max_users_time;
  259. X}
  260. SHAR_EOF
  261. if test 3299 -ne "`wc -c 'survey'`"
  262. then
  263.     echo shar: error transmitting "'survey'" '(should have been 3299 characters)'
  264. fi
  265. chmod +x 'survey'
  266. echo shar: extracting "'namedate.1'" '(604 characters)'
  267. if test -f 'namedate.1'
  268. then
  269.     echo shar: over-writing existing file "'namedate.1'"
  270. fi
  271. sed 's/^X//' << \SHAR_EOF > 'namedate.1'
  272. X.TH NAMEDATE 1 VAX/11
  273. X.UC 4
  274. X.SH NAME
  275. Xnamedate \- print a string followed by current date
  276. X.SH SYNOPSIS
  277. X.B namedate
  278. X.RB "[ name ]"
  279. X.SH DESCRIPTION
  280. XIf no argument is given, the current date is printed.
  281. XIf an argument is given, the argument followed immediately by
  282. Xthe current date is printed. The format of the date is:
  283. X.I 'yyyymmdd'
  284. X, where
  285. X.I yyyy
  286. Xis the four digits of the year;
  287. X.I mm
  288. Xis the month number; and
  289. X.I dd
  290. Xis the day number in the month.
  291. XFor example:
  292. X.IP
  293. X.B
  294. Xnamedate junk
  295. X.PP
  296. Xprints
  297. X.B junk19820429.
  298. X.PP
  299. X.B namedate
  300. Xwith no argument is equivalent to 
  301. X.B namedate
  302. X"".
  303. X.SH AUTHOR
  304. XDavid A. Wilson
  305. SHAR_EOF
  306. if test 604 -ne "`wc -c 'namedate.1'`"
  307. then
  308.     echo shar: error transmitting "'namedate.1'" '(should have been 604 characters)'
  309. fi
  310. echo shar: extracting "'namedate.c'" '(1052 characters)'
  311. if test -f 'namedate.c'
  312. then
  313.     echo shar: over-writing existing file "'namedate.c'"
  314. fi
  315. sed 's/^X//' << \SHAR_EOF > 'namedate.c'
  316. X#include <stdio.h>
  317. X#include <sys/time.h>
  318. X/* namedate ---
  319. X *    Given a string as the parameter, it writes to stdout a string
  320. X *    composed of the input string with a the current date appended
  321. X *    to the end of the string. The format of the output string is:
  322. X *        'namestringYYYYMMDD'
  323. X *    where 'namestring' is the first parameter to namedate, 'YYYY'
  324. X *    is the full year number, 'MM' is the month number, 'DD' is the
  325. X *    day of the month number.
  326. X*/
  327. Xmain( ac, av )
  328. Xint ac;
  329. Xchar *av[];
  330. X{
  331. X    char *name;            /* name string */
  332. X    long    c;            /* time counter value */
  333. X    struct tm *s;        /* decoded time structure */
  334. X
  335. X    /* check for valid number of args */
  336. X    switch ( ac )
  337. X    {
  338. X    case 0:
  339. X    case 1: name = (char *)0; break;    /* null name */
  340. X    case 2: name = av[1]; break;        /* use arg 1 string */
  341. X    default: fprintf( stderr, "Usage: namedate name\n" ); exit(1);
  342. X    }
  343. X
  344. X    /* get time counter */
  345. X    c = time(0);
  346. X
  347. X    /* decode into time structure */
  348. X    s = localtime( &c );
  349. X
  350. X    /* print out the name parameter and date */
  351. X    printf( "%s%04d%02d%02d\n",
  352. X        name, s->tm_year+1900, s->tm_mon+1, s->tm_mday );
  353. X}
  354. SHAR_EOF
  355. if test 1052 -ne "`wc -c 'namedate.c'`"
  356. then
  357.     echo shar: error transmitting "'namedate.c'" '(should have been 1052 characters)'
  358. fi
  359. #    End of shell archive
  360. exit 0
  361. -- 
  362.     David A. Wilson
  363.     uw-beaver!tikal!slab!sea375!dave  
  364.  
  365.  
  366.