Debian Codegraph @

contrib/check_load

raw
1 From [email protected] Mon May 6 01:59:29 1996
2 Received: from BOOM.extern.ucsd.edu ([email protected] [132.239.213.10]) by eterna.com.au (8.7.4/8.7.3) with ESMTP id BAA18946 for <[email protected]>; Mon, 6 May 1996 01:59:16 +1000 (EST)
3 Received: from taner@localhost by BOOM.extern.ucsd.edu (8.7.3/BOOM-v1.5 PID 3214) id IAA03214; Sun, 5 May 1996 08:59:07 -0700
4 Message-Id: <[email protected]>
5 Date: Sun, 5 May 1996 08:59:07 -0700
6 From: [email protected]
7 Reply-To: [email protected]
8 To: [email protected]
9 Cc: [email protected]
10 Subject: adds client-level load control (req. by several admins)
11 X-Send-Pr-Version: 3.96
12
13 >Number: 95
14 >Category: change-request
15 >Synopsis: adds client-level load control (req. by several admins)
16 >Confidential: no
17 >Severity: non-critical
18 >Priority: medium
19 >Responsible: mrg-pr (matthew green)
20 >State: open
21 >Class: change-request
22 >Submitter-Id: net
23 >Arrival-Date: Mon May 6 02:17:01 1996
24 >Last-Modified:
25 >Originator: Taner Halicioglu
26 >Organization:
27 San Diego Supercomputer Center
28 >Release: 2.8.15
29 >Environment:
30 i486DX4/100, Linux 1.3.*, gcc2.7.2, libc 5.2.x
31
32 System: Linux BOOM 1.3.94 #22 Tue Apr 23 12:19:20 PDT 1996 i486
33 Architecture: i486
34
35 >Description:
36 This adds a call to /usr/bin/uptime (or wherever it lives) that gets called
37 about once a minute. If the load average is greater than the specified
38 maximum, the user is warned n number of times before being 'removed' from irc.
39 This *may* break on systems with strange 'uptime' outputs - but can be easily
40 changed. Works on Linux, SunOS, OSF/1 and IRIX (at least).
41
42 >How-To-Repeat:
43
44 >Fix:
45
46 Patch is as follows (diff versus 2.8.15):
47 [------------------------------------------------------------------------]
48 diff -N -c -r ircii-2.8.15/ChangeLog.th ircii-2.8.15+th/ChangeLog.th
49 *** ircii-2.8.15/ChangeLog.th Wed Dec 31 16:00:00 1969
50 --- ircii-2.8.15+th/ChangeLog.th Wed Mar 13 16:29:59 1996
51 ***************
52 *** 0 ****
53 --- 1,6 ----
54 + Taner's Changelog:
55 +
56 + * Added #define CHECK_LOAD... for all those sysadmins that want to be
57 + able to disable the use of irc when your system is loaded.
58 + You need to set:
59 + UPTIME_PATH, MAX_LOAD, and MAX_WARN_LOAD in include/config.h
60 diff -N -c -r ircii-2.8.15/include/config.h ircii-2.8.15+th/include/config.h
61 *** ircii-2.8.15/include/config.h Wed Dec 13 15:53:13 1995
62 --- ircii-2.8.15+th/include/config.h Mon Apr 8 23:05:23 1996
63 ***************
64 *** 86,91 ****
65 --- 86,104 ----
66 #define PAUSE_AFTER_MOTD 1
67
68 /*
69 + * Here we define whether or not we want to check system load levels,
70 + * what the max acceptable level is, and how many warnings we will give
71 + * before exiting.
72 + */
73 +
74 + #define CHECK_LOAD
75 + #ifdef CHECK_LOAD
76 + # define UPTIME_PATH "/usr/bin/uptime"
77 + # define MAX_LOAD 5.00
78 + # define MAX_WARN_LOAD 3
79 + #endif /* CHECK_LOAD */
80 +
81 + /*
82 * Below are the IRCII variable defaults. For boolean variables, use 1 for
83 * ON and 0 for OFF. You may set string variable to NULL if you wish them to
84 * have no value. None of these are optional. You may *not* comment out or
85 diff -N -c -r ircii-2.8.15/include/irc.h ircii-2.8.15+th/include/irc.h
86 *** ircii-2.8.15/include/irc.h Wed Dec 6 06:49:16 1995
87 --- ircii-2.8.15+th/include/irc.h Tue Mar 12 17:46:48 1996
88 ***************
89 *** 283,288 ****
90 --- 283,296 ----
91 void parse_notice _((char *, char **));
92 void irc_quit _((unsigned char, char *));
93
94 + /*
95 + * Load average stuff... -Taner
96 + */
97 + #ifdef CHECK_LOAD
98 + extern int load_warnings;
99 + extern float load_AVG;
100 + #endif /* CHECK_LOAD */
101 +
102 typedef struct WhoisStuffStru
103 {
104 char *nick;
105 diff -N -c -r ircii-2.8.15/source/irc.c ircii-2.8.15+th/source/irc.c
106 *** ircii-2.8.15/source/irc.c Fri Mar 1 03:06:18 1996
107 --- ircii-2.8.15+th/source/irc.c Mon Apr 22 21:07:49 1996
108 ***************
109 *** 81,86 ****
110 --- 81,91 ----
111 waiting = 0, /* used by /WAIT command */
112 who_mask = 0; /* keeps track of which /who
113 * switchs are set */
114 + #ifdef CHECK_LOAD
115 + int load_warnings = 0; /* Number of warnings so far */
116 + float load_AVG = 0.0; /* Current load average */
117 + float update_load((int)); /* Get the current load avg */
118 + #endif /* CLIENT_LOAD */
119
120 char *zero = "0";
121 char *one = "1";
122 ***************
123 *** 905,910 ****
124 --- 910,920 ----
125 status_update(1);
126 cursor_to_input();
127 }
128 + #ifdef CHECK_LOAD
129 + load_AVG = update_load(0);
130 + /* We need to update the status bar */
131 + build_status((char *) 0);
132 + #endif /* CHECK_LOAD */
133 if (primary_server != -1)
134 do_notify();
135 }
136 ***************
137 *** 943,948 ****
138 --- 953,961 ----
139 char *channel;
140
141 start_time = time((time_t *)0);
142 + #ifdef CHECK_LOAD
143 + load_AVG = update_load(1);
144 + #endif /* CHECK_LOAD */
145 #ifdef SOCKS
146 SOCKSinit(argv[0]);
147 #endif /* SOCKS */
148 ***************
149 *** 1083,1085 ****
150 --- 1096,1175 ----
151 irc_exit();
152 return;
153 }
154 +
155 + #ifdef CHECK_LOAD
156 + /*
157 + * Check the current system load average. If it is above MAX_LOAD
158 + * then warn the user, and increment the warning counter.
159 + * If we exceed MAX_WARN_LOAD, then exit.
160 + * Added by Taner Halicioglu ([email protected])
161 + */
162 +
163 + float
164 + update_load(int init_load)
165 + {
166 + FILE *fp;
167 + char load[100];
168 + float load_1 = 0.0;
169 + char l1[10], l5[10], l15[10];
170 + int done, fin, tmp;
171 +
172 + /*
173 + * Since this (hopefully) will only err out once (the first time),
174 + * we should use fprintf's to stderr since say(), etc won't work
175 + * yet. Note, man page for popen() says it DOES NOT reliably set errno.
176 + */
177 + if ((fp = popen(UPTIME_PATH,"r")) == NULL) {
178 + fprintf(stderr,"HELP!! Please tell you admins that %s is not",
179 + UPTIME_PATH)
180 + fprintf(stderr,"the correct path to the 'uptime' executable!!");
181 + exit(-1);
182 + }
183 + done = 0;
184 + while (!done) {
185 + fin = fscanf(fp, "%s", load);
186 + done = !strncmp(load, "averag", 6);
187 + done = (done || (fin == EOF));
188 + }
189 + fscanf(fp, "%s %s %s", l1, l5, l15);
190 + if (tmp = (int)index(l1, ',')) l1[tmp - (int)l1] = 0; /* blow away the comma */
191 + pclose(fp);
192 + load_1 = atof(l1);
193 + if (load_1 >= MAX_LOAD) {
194 + if (init_load) {
195 + /*
196 + * Internal IRC functions won't work here - nothing has been initialized
197 + * so use normal fprintf() and exit(). -Taner
198 + */
199 + fprintf(stderr,"Sorry, the system load is currently %.2f, which is greater\n", load_1);
200 + fprintf(stderr,"than the allowed maximum of %.2f.\n", MAX_LOAD);
201 + fprintf(stderr,"Please IRC later, or from another machine.\n");
202 + exit(-1);
203 + }
204 + if (++load_warnings > MAX_WARN_LOAD) {
205 + say("\007\007Sorry, you have been warned %d times about the load",
206 + MAX_WARN_LOAD);
207 + say("average being too high to IRC. Terminating session.");
208 + send_to_server("QUIT :System load average too high %.2f > %.2f",
209 + load_1, MAX_LOAD);
210 + irc_exit();
211 + } else {
212 + say("\007%c* WARNING * WARNING * WARNING * WARNING * WARNING *%c",
213 + REV_TOG, REV_TOG);
214 + say("The system load average is currently %.2f.",load_1);
215 + say("The maximum allowed level is %.2f.",MAX_LOAD);
216 + say("This is warning number %d out of %d.", load_warnings,
217 + MAX_WARN_LOAD);
218 + if (load_warnings == MAX_WARN_LOAD)
219 + say("%cThis is your last warning.%c", BOLD_TOG, BOLD_TOG);
220 + }
221 + } else if (load_warnings) {
222 + say("%c* NOTICE * NOTICE * NOTICE * NOTICE * NOTICE * NOTICE *%c",
223 + BOLD_TOG, BOLD_TOG);
224 + say("The system load average has fallen back down to a level");
225 + say("where IRCing is allowed (%.2f).",load_1);
226 + load_warnings = 0;
227 + }
228 + return load_1;
229 + }
230 + #endif /* CHECK_LOAD */
231 diff -N -c -r ircii-2.8.15/source/status.c ircii-2.8.15+th/source/status.c
232 *** ircii-2.8.15/source/status.c Fri Jan 5 15:14:01 1996
233 --- ircii-2.8.15+th/source/status.c Tue Mar 12 18:41:20 1996
234 ***************
235 *** 385,392 ****
236 --- 385,409 ----
237 char *ptr,
238 *malloc_ptr = (char *) 0;
239 int *cp;
240 + #ifdef CHECK_LOAD
241 + char tmpstr[30];
242 + #endif /* CHECK_LOAD */
243
244 *buffer = (char) 0;
245 + #ifdef CHECK_LOAD
246 + *tmpstr = (char) 0;
247 + /*
248 + * Give them a visual reminder of the load on the status bar
249 + * Put it only in the 'main' status bar.
250 + */
251 + if (k == 0) {
252 + sprintf(tmpstr,"Load: %.2f ", (float)load_AVG);
253 + if (load_warnings) {
254 + strcat(tmpstr, "*TOO HIGH* ");
255 + }
256 + }
257 + strmcat(buffer, tmpstr, BIG_BUFFER_SIZE);
258 + #endif /* CHECK_LOAD */
259 while (format)
260 {
261 if ((ptr = (char *) index(format, '%')) != NULL)
262 [------------------------------------------------------------------------]
263 >Audit-Trail:
264 >Unformatted:
265
266
267