44 |
|
#endif |
45 |
|
|
46 |
|
typedef struct{ |
47 |
< |
cpu_percent_t *cpu_percents; |
48 |
< |
mem_stat_t *mem_stats; |
49 |
< |
swap_stat_t *swap_stats; |
50 |
< |
load_stat_t *load_stats; |
51 |
< |
process_stat_t *process_stats; |
52 |
< |
page_stat_t *page_stats; |
47 |
> |
sg_cpu_percents *cpu_percents; |
48 |
> |
sg_mem_stats *mem_stats; |
49 |
> |
sg_swap_stats *swap_stats; |
50 |
> |
sg_load_stats *load_stats; |
51 |
> |
sg_process_count *process_count; |
52 |
> |
sg_page_stats *page_stats; |
53 |
|
|
54 |
< |
network_stat_t *network_stats; |
55 |
< |
int network_entries; |
54 |
> |
sg_network_io_stats *network_io_stats; |
55 |
> |
int network_io_entries; |
56 |
|
|
57 |
< |
diskio_stat_t *diskio_stats; |
58 |
< |
int diskio_entries; |
57 |
> |
sg_disk_io_stats *disk_io_stats; |
58 |
> |
int disk_io_entries; |
59 |
|
|
60 |
< |
disk_stat_t *disk_stats; |
61 |
< |
int disk_entries; |
60 |
> |
sg_fs_stats *fs_stats; |
61 |
> |
int fs_entries; |
62 |
|
|
63 |
< |
general_stat_t *general_stats; |
64 |
< |
user_stat_t *user_stats; |
63 |
> |
sg_host_info *host_info; |
64 |
> |
sg_user_stats *user_stats; |
65 |
|
}stats_t; |
66 |
|
|
67 |
|
stats_t stats; |
182 |
|
printw("Write"); |
183 |
|
|
184 |
|
line = 10; |
185 |
< |
if (stats.network_stats != NULL) { |
185 |
> |
if (stats.network_io_stats != NULL) { |
186 |
|
/* Network IO */ |
187 |
|
move(line, 42); |
188 |
|
printw("Network Interface"); |
190 |
|
printw("rx"); |
191 |
|
move(line, 77); |
192 |
|
printw("tx"); |
193 |
< |
line += 2 + stats.network_entries; |
193 |
> |
line += 2 + stats.network_io_entries; |
194 |
|
} |
195 |
|
|
196 |
|
move(line, 42); |
210 |
|
int counter, line; |
211 |
|
long long r,w; |
212 |
|
long long rt, wt; |
213 |
< |
diskio_stat_t *diskio_stat_ptr; |
214 |
< |
network_stat_t *network_stat_ptr; |
215 |
< |
disk_stat_t *disk_stat_ptr; |
213 |
> |
sg_disk_io_stats *disk_io_stat_ptr; |
214 |
> |
sg_network_io_stats *network_stat_ptr; |
215 |
> |
sg_fs_stats *disk_stat_ptr; |
216 |
|
/* Size before it will start overwriting "uptime" */ |
217 |
|
char hostname[15]; |
218 |
|
char *ptr; |
219 |
|
|
220 |
< |
if (stats.general_stats != NULL) { |
220 |
> |
if (stats.host_info != NULL) { |
221 |
|
move(0,12); |
222 |
< |
strncpy(hostname, stats.general_stats->hostname, (sizeof(hostname) - 1)); |
222 |
> |
strncpy(hostname, stats.host_info->hostname, (sizeof(hostname) - 1)); |
223 |
|
/* strncpy does not NULL terminate.. If only strlcpy was on all platforms :) */ |
224 |
|
hostname[14] = '\0'; |
225 |
|
ptr=strchr(hostname, '.'); |
231 |
|
} |
232 |
|
printw("%s", hostname); |
233 |
|
move(0,36); |
234 |
< |
printw("%s", hr_uptime(stats.general_stats->uptime)); |
234 |
> |
printw("%s", hr_uptime(stats.host_info->uptime)); |
235 |
|
epoc_time=time(NULL); |
236 |
|
tm_time = localtime(&epoc_time); |
237 |
|
strftime(cur_time, 20, "%Y-%m-%d %T", tm_time); |
259 |
|
printw("%6.2f%%", (stats.cpu_percents->user + stats.cpu_percents->nice)); |
260 |
|
} |
261 |
|
|
262 |
< |
if (stats.process_stats != NULL) { |
262 |
> |
if (stats.process_count != NULL) { |
263 |
|
/* Process */ |
264 |
|
move(2, 54); |
265 |
< |
printw("%5d", stats.process_stats->running); |
265 |
> |
printw("%5d", stats.process_count->running); |
266 |
|
move(2,74); |
267 |
< |
printw("%5d", stats.process_stats->zombie); |
267 |
> |
printw("%5d", stats.process_count->zombie); |
268 |
|
move(3, 54); |
269 |
< |
printw("%5d", stats.process_stats->sleeping); |
269 |
> |
printw("%5d", stats.process_count->sleeping); |
270 |
|
move(3, 74); |
271 |
< |
printw("%5d", stats.process_stats->total); |
271 |
> |
printw("%5d", stats.process_count->total); |
272 |
|
move(4, 54); |
273 |
< |
printw("%5d", stats.process_stats->stopped); |
273 |
> |
printw("%5d", stats.process_count->stopped); |
274 |
|
} |
275 |
|
if (stats.user_stats != NULL) { |
276 |
|
move(4,74); |
321 |
|
} |
322 |
|
|
323 |
|
line = 11; |
324 |
< |
if (stats.diskio_stats != NULL) { |
324 |
> |
if (stats.disk_io_stats != NULL) { |
325 |
|
/* Disk IO */ |
326 |
< |
diskio_stat_ptr = stats.diskio_stats; |
326 |
> |
disk_io_stat_ptr = stats.disk_io_stats; |
327 |
|
r=0; |
328 |
|
w=0; |
329 |
< |
for(counter=0;counter<stats.diskio_entries;counter++){ |
329 |
> |
for(counter=0;counter<stats.disk_io_entries;counter++){ |
330 |
|
move(line, 0); |
331 |
< |
printw("%s", diskio_stat_ptr->disk_name); |
331 |
> |
printw("%s", disk_io_stat_ptr->disk_name); |
332 |
|
move(line, 12); |
333 |
< |
rt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->read_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->read_bytes; |
333 |
> |
rt = (disk_io_stat_ptr->systime)? (disk_io_stat_ptr->read_bytes/disk_io_stat_ptr->systime): disk_io_stat_ptr->read_bytes; |
334 |
|
printw("%7s", size_conv(rt)); |
335 |
|
r+=rt; |
336 |
|
move(line, 26); |
337 |
< |
wt = (diskio_stat_ptr->systime)? (diskio_stat_ptr->write_bytes/diskio_stat_ptr->systime): diskio_stat_ptr->write_bytes; |
337 |
> |
wt = (disk_io_stat_ptr->systime)? (disk_io_stat_ptr->write_bytes/disk_io_stat_ptr->systime): disk_io_stat_ptr->write_bytes; |
338 |
|
printw("%7s", size_conv(wt)); |
339 |
|
w+=wt; |
340 |
< |
diskio_stat_ptr++; |
340 |
> |
disk_io_stat_ptr++; |
341 |
|
line++; |
342 |
|
} |
343 |
|
line++; |
350 |
|
} |
351 |
|
|
352 |
|
line = 11; |
353 |
< |
if (stats.network_stats != NULL) { |
353 |
> |
if (stats.network_io_stats != NULL) { |
354 |
|
/* Network */ |
355 |
< |
network_stat_ptr = stats.network_stats; |
356 |
< |
for(counter=0;counter<stats.network_entries;counter++){ |
355 |
> |
network_stat_ptr = stats.network_io_stats; |
356 |
> |
for(counter=0;counter<stats.network_io_entries;counter++){ |
357 |
|
move(line, 42); |
358 |
|
printw("%s", network_stat_ptr->interface_name); |
359 |
|
move(line, 62); |
368 |
|
line += 2; |
369 |
|
} |
370 |
|
|
371 |
< |
if (stats.disk_stats != NULL) { |
371 |
> |
if (stats.fs_stats != NULL) { |
372 |
|
/* Disk */ |
373 |
< |
disk_stat_ptr = stats.disk_stats; |
374 |
< |
for(counter=0;counter<stats.disk_entries;counter++){ |
373 |
> |
disk_stat_ptr = stats.fs_stats; |
374 |
> |
for(counter=0;counter<stats.fs_entries;counter++){ |
375 |
|
move(line, 42); |
376 |
|
printw("%s", disk_stat_ptr->mnt_point); |
377 |
|
move(line, 62); |
394 |
|
} |
395 |
|
|
396 |
|
int get_stats(){ |
397 |
< |
stats.cpu_percents = cpu_percent_usage(); |
398 |
< |
stats.mem_stats = get_memory_stats(); |
399 |
< |
stats.swap_stats = get_swap_stats(); |
400 |
< |
stats.load_stats = get_load_stats(); |
401 |
< |
stats.process_stats = get_process_stats(); |
402 |
< |
stats.page_stats = get_page_stats_diff(); |
403 |
< |
stats.network_stats = get_network_stats_diff(&(stats.network_entries)); |
404 |
< |
stats.diskio_stats = get_diskio_stats_diff(&(stats.diskio_entries)); |
405 |
< |
stats.disk_stats = get_disk_stats(&(stats.disk_entries)); |
406 |
< |
stats.general_stats = get_general_stats(); |
407 |
< |
stats.user_stats = get_user_stats(); |
397 |
> |
stats.cpu_percents = sg_get_cpu_percents(); |
398 |
> |
stats.mem_stats = sg_get_mem_stats(); |
399 |
> |
stats.swap_stats = sg_get_swap_stats(); |
400 |
> |
stats.load_stats = sg_get_load_stats(); |
401 |
> |
stats.process_count = sg_get_process_count(); |
402 |
> |
stats.page_stats = sg_get_page_stats_diff(); |
403 |
> |
stats.network_io_stats = sg_get_network_io_stats_diff(&(stats.network_io_entries)); |
404 |
> |
stats.disk_io_stats = sg_get_disk_io_stats_diff(&(stats.disk_io_entries)); |
405 |
> |
stats.fs_stats = sg_get_fs_stats(&(stats.fs_entries)); |
406 |
> |
stats.host_info = sg_get_host_info(); |
407 |
> |
stats.user_stats = sg_get_user_stats(); |
408 |
|
|
409 |
|
return 1; |
410 |
|
} |
437 |
|
|
438 |
|
int delay=2; |
439 |
|
|
440 |
< |
statgrab_init(); |
441 |
< |
if(statgrab_drop_privileges() != 0){ |
440 |
> |
sg_init(); |
441 |
> |
if(sg_drop_privileges() != 0){ |
442 |
|
fprintf(stderr, "Failed to drop setuid/setgid privileges\n"); |
443 |
|
return 1; |
444 |
|
} |