[SIGAR-36] implement MacOSX file_system.disk metrics

This commit is contained in:
Doug MacEachern 2008-03-16 01:55:51 +00:00
parent 67f94cc5a8
commit abbb5f0208
1 changed files with 27 additions and 2 deletions

View File

@ -1891,12 +1891,35 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name,
io_service_t service; io_service_t service;
CFDictionaryRef props; CFDictionaryRef props;
CFNumberRef number; CFNumberRef number;
sigar_iodev_t *iodev = sigar_iodev_get(sigar, name);
char dname[256], *ptr;
SIGAR_DISK_STATS_INIT(disk); SIGAR_DISK_STATS_INIT(disk);
if (!iodev) {
return ESRCH;
}
/* "/dev/disk0s1" -> "disk0" */ /* XXX better way? */
ptr = &iodev->name[SSTRLEN(SIGAR_DEV_PREFIX)];
SIGAR_SSTRCPY(dname, ptr);
ptr = dname;
if (strnEQ(ptr, "disk", 4)) {
ptr += 4;
if ((ptr = strchr(ptr, 's')) && isdigit(*(ptr+1))) {
*ptr = '\0';
}
}
if (SIGAR_LOG_IS_DEBUG(sigar)) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"[disk_usage] map %s -> %s",
iodev->name, dname);
}
/* e.g. name == "disk0" */ /* e.g. name == "disk0" */
service = IOServiceGetMatchingService(kIOMasterPortDefault, service = IOServiceGetMatchingService(kIOMasterPortDefault,
IOBSDNameMatching(kIOMasterPortDefault, 0, name)); IOBSDNameMatching(kIOMasterPortDefault, 0, dname));
if (!service) { if (!service) {
return errno; return errno;
@ -1964,12 +1987,14 @@ int sigar_file_system_usage_get(sigar_t *sigar,
fsusage->free_files = buf.f_ffree; fsusage->free_files = buf.f_ffree;
fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage); fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage);
#ifdef __FreeBSD__ #if defined(__FreeBSD__)
fsusage->disk_reads = buf.f_syncreads + buf.f_asyncreads; fsusage->disk_reads = buf.f_syncreads + buf.f_asyncreads;
fsusage->disk_writes = buf.f_syncwrites + buf.f_asyncwrites; fsusage->disk_writes = buf.f_syncwrites + buf.f_asyncwrites;
fsusage->disk_read_bytes = SIGAR_FIELD_NOTIMPL; fsusage->disk_read_bytes = SIGAR_FIELD_NOTIMPL;
fsusage->disk_write_bytes = SIGAR_FIELD_NOTIMPL; fsusage->disk_write_bytes = SIGAR_FIELD_NOTIMPL;
fsusage->disk_queue = SIGAR_FIELD_NOTIMPL; fsusage->disk_queue = SIGAR_FIELD_NOTIMPL;
#elif defined(DARWIN)
sigar_disk_usage_get(sigar, dirname, &fsusage->disk);
#else #else
SIGAR_DISK_STATS_INIT(&fsusage->disk); SIGAR_DISK_STATS_INIT(&fsusage->disk);
#endif #endif