Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions collector/filesystem_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ package collector
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
Float64 purgeable(char *path) {
CFNumberRef tmp;
NSError *error = nil;
NSString *str = [NSString stringWithUTF8String:path];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:str];
NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
if (results) {
if ((tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey)) == NULL) {
return -1.0f;
}
Float64 value;
if (CFNumberGetValue(tmp, kCFNumberFloat64Type, &value)) {
return value;
Float64 value = -1.0f;

@autoreleasepool {
NSError *error = nil;
NSString *str = [NSString stringWithUTF8String:path];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:str];

NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
if (results) {
CFNumberRef tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey);
if (tmp != NULL) {
CFNumberGetValue(tmp, kCFNumberFloat64Type, &value);
}
}

[fileURL release];
}
return -1.0f;

return value;
}
*/
import "C"
Expand Down Expand Up @@ -88,6 +92,9 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
ro = 1
}

mountpointCString := C.CString(mountpoint)
defer C.free(unsafe.Pointer(mountpointCString))

stats = append(stats, filesystemStats{
labels: filesystemLabels{
device: device,
Expand All @@ -99,7 +106,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
avail: float64(mnt[i].f_bavail) * float64(mnt[i].f_bsize),
files: float64(mnt[i].f_files),
filesFree: float64(mnt[i].f_ffree),
purgeable: float64(C.purgeable(C.CString(mountpoint))),
purgeable: float64(C.purgeable(mountpointCString)),
ro: ro,
})
}
Expand Down
Loading