Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions collector/filesystem_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type filesystemStats struct {
labels filesystemLabels
size, free, avail float64
files, filesFree float64
purgeable *float64
purgeable float64
ro, deviceError float64
}

Expand Down Expand Up @@ -232,11 +232,10 @@ func (c *filesystemCollector) Update(ch chan<- prometheus.Metric) error {
c.mountInfoDesc, prometheus.GaugeValue,
1.0, s.labels.device, s.labels.major, s.labels.minor, s.labels.mountPoint,
)
if s.purgeable != nil {
if s.purgeable >= 0 {
ch <- prometheus.MustNewConstMetric(
c.purgeableDesc, prometheus.GaugeValue,
*s.purgeable, s.labels.device, s.labels.mountPoint,
s.labels.fsType, s.labels.deviceError,
s.purgeable, s.labels.device, s.labels.mountPoint, s.labels.fsType, s.labels.deviceError,
)
}
}
Expand Down
17 changes: 8 additions & 9 deletions collector/filesystem_macos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ package collector
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
Float64 *purgeable(char *path) {
Float64 purgeable(char *path) {
CFNumberRef tmp;
Float64 *value;
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 NULL;
value = (Float64 *)malloc(sizeof(Float64));
if (CFNumberGetValue(tmp, kCFNumberFloat64Type, value)) {
if ((tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey)) == NULL) {
return -1.0f;
}
Float64 value;
if (CFNumberGetValue(tmp, kCFNumberFloat64Type, &value)) {
return value;
}
}
free(value);
return NULL;
return -1.0f;
}
*/
import "C"
Expand Down Expand Up @@ -100,7 +99,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(C.CString(mountpoint))),
ro: ro,
})
}
Expand Down
Loading