1 |
|
/* |
2 |
< |
* i-scream central monitoring system |
2 |
> |
* i-scream libstatgrab |
3 |
|
* http://www.i-scream.org |
4 |
|
* Copyright (C) 2000-2004 i-scream |
5 |
|
* |
47 |
|
|
48 |
|
#ifdef LINUX |
49 |
|
#define VALID_FS_TYPES {"adfs", "affs", "befs", "bfs", "efs", "ext2", \ |
50 |
< |
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
51 |
< |
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
52 |
< |
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
53 |
< |
"umsdos", "vfat", "xfs", "jfs"} |
50 |
> |
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
51 |
> |
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
52 |
> |
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
53 |
> |
"umsdos", "vfat", "xfs", "jfs"} |
54 |
|
#endif |
55 |
|
|
56 |
|
#ifdef CYGWIN |
66 |
|
#include <sys/dkstat.h> |
67 |
|
#include <devstat.h> |
68 |
|
#define VALID_FS_TYPES {"hpfs", "msdosfs", "ntfs", "udf", "ext2fs", \ |
69 |
< |
"ufs", "mfs"} |
69 |
> |
"ufs", "mfs"} |
70 |
|
#endif |
71 |
|
#if defined(NETBSD) || defined(OPENBSD) |
72 |
|
#include <sys/param.h> |
73 |
|
#include <sys/sysctl.h> |
74 |
|
#include <sys/disk.h> |
75 |
|
#define VALID_FS_TYPES {"ffs", "mfs", "msdos", "lfs", "adosfs", "ext2fs", \ |
76 |
< |
"ntfs"} |
76 |
> |
"ntfs"} |
77 |
|
#endif |
78 |
|
|
79 |
|
static void disk_stat_init(sg_fs_stats *d) { |
102 |
|
|
103 |
|
sg_fs_stats *sg_get_fs_stats(int *entries){ |
104 |
|
VECTOR_DECLARE_STATIC(disk_stats, sg_fs_stats, 10, |
105 |
< |
disk_stat_init, disk_stat_destroy); |
105 |
> |
disk_stat_init, disk_stat_destroy); |
106 |
|
|
107 |
|
int valid_type; |
108 |
|
int num_disks=0; |
216 |
|
} |
217 |
|
|
218 |
|
if (sg_update_string(&disk_ptr->fs_type, mp.mnt_fstype) < 0) { |
219 |
< |
return NULL; |
220 |
< |
} |
219 |
> |
return NULL; |
220 |
> |
} |
221 |
|
|
222 |
|
if (sg_update_string(&disk_ptr->mnt_point, mp.mnt_mountp) < 0) { |
223 |
< |
return NULL; |
224 |
< |
} |
223 |
> |
return NULL; |
224 |
> |
} |
225 |
|
|
226 |
|
disk_ptr->size = (long long)fs.f_frsize * (long long)fs.f_blocks; |
227 |
|
disk_ptr->avail = (long long)fs.f_frsize * (long long)fs.f_bavail; |
238 |
|
*entries=num_disks; |
239 |
|
|
240 |
|
/* If this fails, there is very little i can do about it, so |
241 |
< |
I'll ignore it :) */ |
241 |
> |
I'll ignore it :) */ |
242 |
|
#if defined(LINUX) || defined(CYGWIN) |
243 |
|
endmntent(f); |
244 |
|
#endif |
259 |
|
} |
260 |
|
|
261 |
|
VECTOR_DECLARE_STATIC(diskio_stats, sg_disk_io_stats, 10, |
262 |
< |
diskio_stat_init, diskio_stat_destroy); |
262 |
> |
diskio_stat_init, diskio_stat_destroy); |
263 |
|
|
264 |
|
#ifdef LINUX |
265 |
|
typedef struct { |
275 |
|
#endif |
276 |
|
|
277 |
|
#ifdef SOLARIS |
278 |
< |
kstat_ctl_t *kc; |
279 |
< |
kstat_t *ksp; |
278 |
> |
kstat_ctl_t *kc; |
279 |
> |
kstat_t *ksp; |
280 |
|
kstat_io_t kios; |
281 |
|
#endif |
282 |
|
#ifdef LINUX |
337 |
|
return NULL; |
338 |
|
} |
339 |
|
|
340 |
< |
disknames = malloc(size); |
340 |
> |
disknames = sg_malloc(size); |
341 |
|
if (disknames == NULL) { |
342 |
|
return NULL; |
343 |
|
} |
346 |
|
return NULL; |
347 |
|
} |
348 |
|
|
349 |
< |
dk_name = calloc(diskcount, sizeof(char *)); |
349 |
> |
dk_name = sg_malloc(diskcount * sizeof(char *)); |
350 |
|
bufpp = disknames; |
351 |
|
for (i = 0; i < diskcount && (name = strsep(&bufpp, ",")) != NULL; i++) { |
352 |
|
dk_name[i] = name; |
370 |
|
num_disks = size / sizeof(struct diskstats); |
371 |
|
#endif |
372 |
|
|
373 |
< |
stats = malloc(size); |
373 |
> |
stats = sg_malloc(size); |
374 |
|
if (stats == NULL) { |
375 |
|
return NULL; |
376 |
|
} |
429 |
|
|
430 |
|
#if defined(FREEBSD) || defined(DFBSD) |
431 |
|
if (!stats_init) { |
432 |
< |
stats.dinfo=malloc(sizeof(struct devinfo)); |
432 |
> |
stats.dinfo=sg_malloc(sizeof(struct devinfo)); |
433 |
|
if(stats.dinfo==NULL) return NULL; |
434 |
|
bzero(stats.dinfo, sizeof(struct devinfo)); |
435 |
|
stats_init = 1; |
488 |
|
#endif |
489 |
|
#ifdef SOLARIS |
490 |
|
if ((kc = kstat_open()) == NULL) { |
491 |
< |
return NULL; |
492 |
< |
} |
491 |
> |
return NULL; |
492 |
> |
} |
493 |
|
|
494 |
|
for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { |
495 |
< |
if (!strcmp(ksp->ks_class, "disk")) { |
495 |
> |
if (!strcmp(ksp->ks_class, "disk")) { |
496 |
|
|
497 |
|
if(ksp->ks_type != KSTAT_TYPE_IO) continue; |
498 |
|
/* We dont want metadevices appearins as num_diskio */ |
499 |
|
if(strcmp(ksp->ks_module, "md")==0) continue; |
500 |
< |
if((kstat_read(kc, ksp, &kios))==-1){ |
500 |
> |
if((kstat_read(kc, ksp, &kios))==-1){ |
501 |
|
} |
502 |
|
|
503 |
|
if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) { |
509 |
|
diskio_stats_ptr->read_bytes=kios.nread; |
510 |
|
diskio_stats_ptr->write_bytes=kios.nwritten; |
511 |
|
if (sg_update_string(&diskio_stats_ptr->disk_name, |
512 |
< |
sg_get_svr_from_bsd(ksp->ks_name)) < 0) { |
512 |
> |
sg_get_svr_from_bsd(ksp->ks_name)) < 0) { |
513 |
|
return NULL; |
514 |
|
} |
515 |
|
diskio_stats_ptr->systime=time(NULL); |
666 |
|
|
667 |
|
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries){ |
668 |
|
VECTOR_DECLARE_STATIC(diff, sg_disk_io_stats, 1, |
669 |
< |
diskio_stat_init, diskio_stat_destroy); |
669 |
> |
diskio_stat_init, diskio_stat_destroy); |
670 |
|
sg_disk_io_stats *src = NULL, *dest; |
671 |
|
int i, j, diff_count, new_count; |
672 |
|
|