102 |
|
} |
103 |
|
|
104 |
|
void display_headings(){ |
105 |
+ |
int line; |
106 |
+ |
|
107 |
|
move(0,0); |
108 |
|
printw("Hostname :"); |
109 |
|
move(0,27); |
179 |
|
move(10,28); |
180 |
|
printw("Write"); |
181 |
|
|
182 |
< |
/* Network IO */ |
183 |
< |
move(10, 42); |
184 |
< |
printw("Network Interface"); |
185 |
< |
move(10, 67); |
186 |
< |
printw("rx"); |
187 |
< |
move(10,77); |
188 |
< |
printw("tx"); |
182 |
> |
line = 10; |
183 |
> |
if (stats.network_stats != NULL) { |
184 |
> |
/* Network IO */ |
185 |
> |
move(line, 42); |
186 |
> |
printw("Network Interface"); |
187 |
> |
move(line, 67); |
188 |
> |
printw("rx"); |
189 |
> |
move(line, 77); |
190 |
> |
printw("tx"); |
191 |
> |
line += 2 + stats.network_entries; |
192 |
> |
} |
193 |
|
|
194 |
< |
move(12+stats.network_entries, 42); |
194 |
> |
move(line, 42); |
195 |
|
printw("Mount Point"); |
196 |
< |
move(12+stats.network_entries, 65); |
196 |
> |
move(line, 65); |
197 |
|
printw("Free"); |
198 |
< |
move(12+stats.network_entries, 75); |
198 |
> |
move(line, 75); |
199 |
|
printw("Used"); |
200 |
|
|
201 |
|
refresh(); |
205 |
|
char cur_time[20]; |
206 |
|
struct tm *tm_time; |
207 |
|
time_t epoc_time; |
208 |
< |
int counter; |
208 |
> |
int counter, line; |
209 |
|
long long r,w; |
210 |
|
long long rt, wt; |
211 |
|
diskio_stat_t *diskio_stat_ptr; |
215 |
|
char hostname[15]; |
216 |
|
char *ptr; |
217 |
|
|
218 |
< |
move(0,12); |
219 |
< |
strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); |
220 |
< |
/* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ |
221 |
< |
hostname[14] = '\0'; |
222 |
< |
ptr=strchr(hostname, '.'); |
223 |
< |
/* Some hosts give back a FQDN for hostname. To avoid this, we'll |
224 |
< |
* just blank out everything after the first "." |
225 |
< |
*/ |
226 |
< |
if (ptr != NULL){ |
227 |
< |
*ptr = '\0'; |
228 |
< |
} |
229 |
< |
printw("%s", hostname); |
230 |
< |
move(0,36); |
231 |
< |
printw("%s", hr_uptime(stats.general_stats->uptime)); |
232 |
< |
epoc_time=time(NULL); |
233 |
< |
tm_time = localtime(&epoc_time); |
234 |
< |
strftime(cur_time, 20, "%Y-%m-%d %T", tm_time); |
235 |
< |
move(0,61); |
236 |
< |
printw("%s", cur_time); |
218 |
> |
if (stats.general_stats != NULL) { |
219 |
> |
move(0,12); |
220 |
> |
strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); |
221 |
> |
/* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ |
222 |
> |
hostname[14] = '\0'; |
223 |
> |
ptr=strchr(hostname, '.'); |
224 |
> |
/* Some hosts give back a FQDN for hostname. To avoid this, we'll |
225 |
> |
* just blank out everything after the first "." |
226 |
> |
*/ |
227 |
> |
if (ptr != NULL){ |
228 |
> |
*ptr = '\0'; |
229 |
> |
} |
230 |
> |
printw("%s", hostname); |
231 |
> |
move(0,36); |
232 |
> |
printw("%s", hr_uptime(stats.general_stats->uptime)); |
233 |
> |
epoc_time=time(NULL); |
234 |
> |
tm_time = localtime(&epoc_time); |
235 |
> |
strftime(cur_time, 20, "%Y-%m-%d %T", tm_time); |
236 |
> |
move(0,61); |
237 |
> |
printw("%s", cur_time); |
238 |
> |
} |
239 |
|
|
240 |
< |
/* Load */ |
241 |
< |
move(2,12); |
242 |
< |
printw("%6.2f", stats.load_stats->min1); |
243 |
< |
move(3,12); |
244 |
< |
printw("%6.2f", stats.load_stats->min5); |
245 |
< |
move(4,12); |
246 |
< |
printw("%6.2f", stats.load_stats->min15); |
240 |
> |
if (stats.load_stats != NULL) { |
241 |
> |
/* Load */ |
242 |
> |
move(2,12); |
243 |
> |
printw("%6.2f", stats.load_stats->min1); |
244 |
> |
move(3,12); |
245 |
> |
printw("%6.2f", stats.load_stats->min5); |
246 |
> |
move(4,12); |
247 |
> |
printw("%6.2f", stats.load_stats->min15); |
248 |
> |
} |
249 |
|
|
250 |
< |
/* CPU */ |
251 |
< |
move(2,33); |
252 |
< |
printw("%6.2f%%", stats.cpu_percents->idle); |
253 |
< |
move(3,33); |
254 |
< |
printw("%6.2f%%", (stats.cpu_percents->kernel + stats.cpu_percents->iowait + stats.cpu_percents->swap)); |
255 |
< |
move(4,33); |
256 |
< |
printw("%6.2f%%", (stats.cpu_percents->user + stats.cpu_percents->nice)); |
250 |
> |
if (stats.cpu_percents != NULL) { |
251 |
> |
/* CPU */ |
252 |
> |
move(2,33); |
253 |
> |
printw("%6.2f%%", stats.cpu_percents->idle); |
254 |
> |
move(3,33); |
255 |
> |
printw("%6.2f%%", (stats.cpu_percents->kernel + stats.cpu_percents->iowait + stats.cpu_percents->swap)); |
256 |
> |
move(4,33); |
257 |
> |
printw("%6.2f%%", (stats.cpu_percents->user + stats.cpu_percents->nice)); |
258 |
> |
} |
259 |
|
|
260 |
< |
/* Process */ |
261 |
< |
move(2, 54); |
262 |
< |
printw("%5d", stats.process_stats->running); |
263 |
< |
move(2,74); |
264 |
< |
printw("%5d", stats.process_stats->zombie); |
265 |
< |
move(3, 54); |
266 |
< |
printw("%5d", stats.process_stats->sleeping); |
267 |
< |
move(3, 74); |
268 |
< |
printw("%5d", stats.process_stats->total); |
269 |
< |
move(4, 54); |
270 |
< |
printw("%5d", stats.process_stats->stopped); |
271 |
< |
move(4,74); |
272 |
< |
printw("%5d", stats.user_stats->num_entries); |
260 |
> |
if (stats.process_stats != NULL) { |
261 |
> |
/* Process */ |
262 |
> |
move(2, 54); |
263 |
> |
printw("%5d", stats.process_stats->running); |
264 |
> |
move(2,74); |
265 |
> |
printw("%5d", stats.process_stats->zombie); |
266 |
> |
move(3, 54); |
267 |
> |
printw("%5d", stats.process_stats->sleeping); |
268 |
> |
move(3, 74); |
269 |
> |
printw("%5d", stats.process_stats->total); |
270 |
> |
move(4, 54); |
271 |
> |
printw("%5d", stats.process_stats->stopped); |
272 |
> |
} |
273 |
> |
if (stats.user_stats != NULL) { |
274 |
> |
move(4,74); |
275 |
> |
printw("%5d", stats.user_stats->num_entries); |
276 |
> |
} |
277 |
|
|
278 |
< |
/* Mem */ |
279 |
< |
move(6, 12); |
280 |
< |
printw("%7s", size_conv(stats.mem_stats->total)); |
281 |
< |
move(7, 12); |
282 |
< |
printw("%7s", size_conv(stats.mem_stats->used)); |
283 |
< |
move(8, 12); |
284 |
< |
printw("%7s", size_conv(stats.mem_stats->free)); |
278 |
> |
if (stats.mem_stats != NULL) { |
279 |
> |
/* Mem */ |
280 |
> |
move(6, 12); |
281 |
> |
printw("%7s", size_conv(stats.mem_stats->total)); |
282 |
> |
move(7, 12); |
283 |
> |
printw("%7s", size_conv(stats.mem_stats->used)); |
284 |
> |
move(8, 12); |
285 |
> |
printw("%7s", size_conv(stats.mem_stats->free)); |
286 |
> |
} |
287 |
|
|
288 |
< |
/* Swap */ |
289 |
< |
move(6, 32); |
290 |
< |
printw("%8s", size_conv(stats.swap_stats->total)); |
291 |
< |
move(7, 32); |
292 |
< |
printw("%8s", size_conv(stats.swap_stats->used)); |
293 |
< |
move(8, 32); |
294 |
< |
printw("%8s", size_conv(stats.swap_stats->free)); |
288 |
> |
if (stats.swap_stats != NULL) { |
289 |
> |
/* Swap */ |
290 |
> |
move(6, 32); |
291 |
> |
printw("%8s", size_conv(stats.swap_stats->total)); |
292 |
> |
move(7, 32); |
293 |
> |
printw("%8s", size_conv(stats.swap_stats->used)); |
294 |
> |
move(8, 32); |
295 |
> |
printw("%8s", size_conv(stats.swap_stats->free)); |
296 |
> |
} |
297 |
|
|
298 |
< |
/* VM */ |
299 |
< |
move(6, 54); |
300 |
< |
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total)); |
301 |
< |
move(7, 54); |
302 |
< |
printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total)); |
303 |
< |
move(8, 54); |
304 |
< |
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total))); |
298 |
> |
if (stats.mem_stats != NULL && stats.swap_stats != NULL) { |
299 |
> |
/* VM */ |
300 |
> |
move(6, 54); |
301 |
> |
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used)/stats.mem_stats->total)); |
302 |
> |
move(7, 54); |
303 |
> |
printw("%5.2f%%", (100.00 * (float)(stats.swap_stats->used)/stats.swap_stats->total)); |
304 |
> |
move(8, 54); |
305 |
> |
printw("%5.2f%%", (100.00 * (float)(stats.mem_stats->used+stats.swap_stats->used)/(stats.mem_stats->total+stats.swap_stats->total))); |
306 |
> |
} |
307 |
|
|
308 |
< |
/* Paging */ |
309 |
< |
move(6, 74); |
310 |
< |
printw("%5d", (stats.page_stats->systime)? (stats.page_stats->pages_pagein / stats.page_stats->systime): stats.page_stats->pages_pagein); |
311 |
< |
move(7, 74); |
312 |
< |
printw("%5d", (stats.page_stats->systime)? (stats.page_stats->pages_pageout / stats.page_stats->systime) : stats.page_stats->pages_pageout); |
308 |
> |
if (stats.page_stats != NULL) { |
309 |
> |
/* Paging */ |
310 |
> |
move(6, 74); |
311 |
> |
printw("%5d", (stats.page_stats->systime)? (stats.page_stats->pages_pagein / stats.page_stats->systime): stats.page_stats->pages_pagein); |
312 |
> |
move(7, 74); |
313 |
> |
printw("%5d", (stats.page_stats->systime)? (stats.page_stats->pages_pageout / stats.page_stats->systime) : stats.page_stats->pages_pageout); |
314 |
> |
} |
315 |
|
|
316 |
< |
/* Disk IO */ |
317 |
< |
diskio_stat_ptr = stats.diskio_stats; |
318 |
< |
r=0; |
319 |
< |
w=0; |
320 |
< |
for(counter=0;counter<stats.diskio_entries;counter++){ |
321 |
< |
move(11+counter, 0); |
322 |
< |
printw("%s", diskio_stat_ptr->disk_name); |
323 |
< |
move(11+counter, 12); |
324 |
< |
rt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->read_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->read_bytes; |
325 |
< |
printw("%7s", size_conv(rt)); |
326 |
< |
r+=rt; |
327 |
< |
move(11+counter, 26); |
328 |
< |
wt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->write_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->write_bytes; |
329 |
< |
printw("%7s", size_conv(wt)); |
330 |
< |
w+=wt; |
331 |
< |
diskio_stat_ptr++; |
316 |
> |
line = 11; |
317 |
> |
if (stats.diskio_stats != NULL) { |
318 |
> |
/* Disk IO */ |
319 |
> |
diskio_stat_ptr = stats.diskio_stats; |
320 |
> |
r=0; |
321 |
> |
w=0; |
322 |
> |
for(counter=0;counter<stats.diskio_entries;counter++){ |
323 |
> |
move(line, 0); |
324 |
> |
printw("%s", diskio_stat_ptr->disk_name); |
325 |
> |
move(line, 12); |
326 |
> |
rt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->read_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->read_bytes; |
327 |
> |
printw("%7s", size_conv(rt)); |
328 |
> |
r+=rt; |
329 |
> |
move(line, 26); |
330 |
> |
wt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->write_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->write_bytes; |
331 |
> |
printw("%7s", size_conv(wt)); |
332 |
> |
w+=wt; |
333 |
> |
diskio_stat_ptr++; |
334 |
> |
line++; |
335 |
> |
} |
336 |
> |
line++; |
337 |
> |
move(line, 0); |
338 |
> |
printw("Total"); |
339 |
> |
move(line, 12); |
340 |
> |
printw("%7s", size_conv(r)); |
341 |
> |
move(line, 26); |
342 |
> |
printw("%7s", size_conv(w)); |
343 |
|
} |
309 |
– |
move(12+counter, 0); |
310 |
– |
printw("Total"); |
311 |
– |
move(12+counter, 12); |
312 |
– |
printw("%7s", size_conv(r)); |
313 |
– |
move(12+counter, 26); |
314 |
– |
printw("%7s", size_conv(w)); |
344 |
|
|
345 |
< |
/* Network */ |
346 |
< |
network_stat_ptr = stats.network_stats; |
347 |
< |
for(counter=0;counter<stats.network_entries;counter++){ |
348 |
< |
move(11+counter, 42); |
349 |
< |
printw("%s", network_stat_ptr->interface_name); |
350 |
< |
move(11+counter, 62); |
351 |
< |
rt = (network_stat_ptr->systime)? (network_stat_ptr->rx / network_stat_ptr->systime): network_stat_ptr->rx; |
352 |
< |
printw("%7s", size_conv(rt)); |
353 |
< |
move(11+counter, 72); |
354 |
< |
wt = (network_stat_ptr->systime)? (network_stat_ptr->tx / network_stat_ptr->systime): network_stat_ptr->tx; |
355 |
< |
printw("%7s", size_conv(wt)); |
356 |
< |
network_stat_ptr++; |
345 |
> |
line = 11; |
346 |
> |
if (stats.network_stats != NULL) { |
347 |
> |
/* Network */ |
348 |
> |
network_stat_ptr = stats.network_stats; |
349 |
> |
for(counter=0;counter<stats.network_entries;counter++){ |
350 |
> |
move(line, 42); |
351 |
> |
printw("%s", network_stat_ptr->interface_name); |
352 |
> |
move(line, 62); |
353 |
> |
rt = (network_stat_ptr->systime)? (network_stat_ptr->rx / network_stat_ptr->systime): network_stat_ptr->rx; |
354 |
> |
printw("%7s", size_conv(rt)); |
355 |
> |
move(line, 72); |
356 |
> |
wt = (network_stat_ptr->systime)? (network_stat_ptr->tx / network_stat_ptr->systime): network_stat_ptr->tx; |
357 |
> |
printw("%7s", size_conv(wt)); |
358 |
> |
network_stat_ptr++; |
359 |
> |
line++; |
360 |
> |
} |
361 |
> |
line += 2; |
362 |
|
} |
363 |
|
|
364 |
< |
/* Disk */ |
365 |
< |
disk_stat_ptr = stats.disk_stats; |
366 |
< |
for(counter=0;counter<stats.disk_entries;counter++){ |
367 |
< |
move(13+stats.network_entries+counter, 42); |
368 |
< |
printw("%s", disk_stat_ptr->mnt_point); |
369 |
< |
move(13+stats.network_entries+counter, 62); |
370 |
< |
printw("%7s", size_conv(disk_stat_ptr->avail)); |
371 |
< |
move(13+stats.network_entries+counter, 73); |
372 |
< |
printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); |
373 |
< |
disk_stat_ptr++; |
364 |
> |
if (stats.disk_stats != NULL) { |
365 |
> |
/* Disk */ |
366 |
> |
disk_stat_ptr = stats.disk_stats; |
367 |
> |
for(counter=0;counter<stats.disk_entries;counter++){ |
368 |
> |
move(line, 42); |
369 |
> |
printw("%s", disk_stat_ptr->mnt_point); |
370 |
> |
move(line, 62); |
371 |
> |
printw("%7s", size_conv(disk_stat_ptr->avail)); |
372 |
> |
move(line, 73); |
373 |
> |
printw("%5.2f%%", 100.00 * ((float) disk_stat_ptr->used / (float) (disk_stat_ptr->used + disk_stat_ptr->avail))); |
374 |
> |
disk_stat_ptr++; |
375 |
> |
line++; |
376 |
> |
} |
377 |
|
} |
378 |
|
|
379 |
|
refresh(); |
387 |
|
} |
388 |
|
|
389 |
|
int get_stats(){ |
390 |
< |
if((stats.cpu_percents = cpu_percent_usage()) == NULL) return 0; |
391 |
< |
if((stats.mem_stats = get_memory_stats()) == NULL) return 0; |
392 |
< |
if((stats.swap_stats = get_swap_stats()) == NULL) return 0; |
393 |
< |
if((stats.load_stats = get_load_stats()) == NULL) return 0; |
394 |
< |
if((stats.process_stats = get_process_stats()) == NULL) return 0; |
395 |
< |
if((stats.page_stats = get_page_stats_diff()) == NULL) return 0; |
396 |
< |
if((stats.network_stats = get_network_stats_diff(&(stats.network_entries))) == NULL) return 0; |
397 |
< |
if((stats.diskio_stats = get_diskio_stats_diff(&(stats.diskio_entries))) == NULL) return 0; |
398 |
< |
if((stats.disk_stats = get_disk_stats(&(stats.disk_entries))) == NULL) return 0; |
399 |
< |
if((stats.general_stats = get_general_stats()) == NULL) return 0; |
400 |
< |
if((stats.user_stats = get_user_stats()) == NULL) return 0; |
390 |
> |
stats.cpu_percents = cpu_percent_usage(); |
391 |
> |
stats.mem_stats = get_memory_stats(); |
392 |
> |
stats.swap_stats = get_swap_stats(); |
393 |
> |
stats.load_stats = get_load_stats(); |
394 |
> |
stats.process_stats = get_process_stats(); |
395 |
> |
stats.page_stats = get_page_stats_diff(); |
396 |
> |
stats.network_stats = get_network_stats_diff(&(stats.network_entries)); |
397 |
> |
stats.diskio_stats = get_diskio_stats_diff(&(stats.diskio_entries)); |
398 |
> |
stats.disk_stats = get_disk_stats(&(stats.disk_entries)); |
399 |
> |
stats.general_stats = get_general_stats(); |
400 |
> |
stats.user_stats = get_user_stats(); |
401 |
|
|
402 |
< |
return 1; |
402 |
> |
return 1; |
403 |
|
} |
404 |
|
|
405 |
|
void version_num(char *progname){ |
415 |
|
fprintf(stderr, " -h Displays this help information.\n"); |
416 |
|
fprintf(stderr, "\nReport bugs to <%s>.\n", PACKAGE_BUGREPORT); |
417 |
|
exit(1); |
381 |
– |
|
418 |
|
} |
419 |
|
|
420 |
|
int main(int argc, char **argv){ |
436 |
|
#ifdef ALLBSD |
437 |
|
gid_t gid; |
438 |
|
#endif |
439 |
< |
if(statgrab_init() != 0){ |
404 |
< |
fprintf(stderr, "statgrab_init failed. Please check the permissions\n"); |
405 |
< |
return 1; |
406 |
< |
} |
439 |
> |
statgrab_init(); |
440 |
|
#ifdef ALLBSD |
441 |
|
if((setegid(getgid())) != 0){ |
442 |
|
fprintf(stderr, "Failed to lose setgid'ness\n"); |
513 |
|
* frequently than once a second. |
514 |
|
*/ |
515 |
|
sleep(1); |
483 |
– |
|
516 |
|
} |
485 |
– |
|
486 |
– |
|
517 |
|
|
518 |
|
endwin(); |
519 |
|
return 0; |