mirror of
https://github.com/prometheus/node_exporter.git
synced 2025-08-20 18:33:52 -07:00
Fix macos filesystem collector cgo memory leak (#3315)
Signed-off-by: Charlie Chiang <charlie_c_0129@outlook.com>
This commit is contained in:
parent
38d32a3977
commit
43fb05c81d
|
@ -21,21 +21,25 @@ package collector
|
||||||
#cgo LDFLAGS: -framework Foundation
|
#cgo LDFLAGS: -framework Foundation
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
Float64 purgeable(char *path) {
|
Float64 purgeable(char *path) {
|
||||||
CFNumberRef tmp;
|
Float64 value = -1.0f;
|
||||||
NSError *error = nil;
|
|
||||||
NSString *str = [NSString stringWithUTF8String:path];
|
@autoreleasepool {
|
||||||
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:str];
|
NSError *error = nil;
|
||||||
NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
|
NSString *str = [NSString stringWithUTF8String:path];
|
||||||
if (results) {
|
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:str];
|
||||||
if ((tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey)) == NULL) {
|
|
||||||
return -1.0f;
|
NSDictionary *results = [fileURL resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:&error];
|
||||||
}
|
if (results) {
|
||||||
Float64 value;
|
CFNumberRef tmp = CFDictionaryGetValue((CFDictionaryRef)results, NSURLVolumeAvailableCapacityForImportantUsageKey);
|
||||||
if (CFNumberGetValue(tmp, kCFNumberFloat64Type, &value)) {
|
if (tmp != NULL) {
|
||||||
return value;
|
CFNumberGetValue(tmp, kCFNumberFloat64Type, &value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[fileURL release];
|
||||||
}
|
}
|
||||||
return -1.0f;
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
@ -88,6 +92,9 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
ro = 1
|
ro = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mountpointCString := C.CString(mountpoint)
|
||||||
|
defer C.free(unsafe.Pointer(mountpointCString))
|
||||||
|
|
||||||
stats = append(stats, filesystemStats{
|
stats = append(stats, filesystemStats{
|
||||||
labels: filesystemLabels{
|
labels: filesystemLabels{
|
||||||
device: device,
|
device: device,
|
||||||
|
@ -99,7 +106,7 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) {
|
||||||
avail: float64(mnt[i].f_bavail) * float64(mnt[i].f_bsize),
|
avail: float64(mnt[i].f_bavail) * float64(mnt[i].f_bsize),
|
||||||
files: float64(mnt[i].f_files),
|
files: float64(mnt[i].f_files),
|
||||||
filesFree: float64(mnt[i].f_ffree),
|
filesFree: float64(mnt[i].f_ffree),
|
||||||
purgeable: float64(C.purgeable(C.CString(mountpoint))),
|
purgeable: float64(C.purgeable(mountpointCString)),
|
||||||
ro: ro,
|
ro: ro,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue