avoiding NPE in Sigar FS
This commit is contained in:
parent
125b33d3dc
commit
a127f2d2e8
|
@ -26,7 +26,9 @@ import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.NodeEnvironment;
|
import org.elasticsearch.env.NodeEnvironment;
|
||||||
import org.elasticsearch.monitor.sigar.SigarService;
|
import org.elasticsearch.monitor.sigar.SigarService;
|
||||||
import org.hyperic.sigar.FileSystem;
|
import org.hyperic.sigar.FileSystem;
|
||||||
|
import org.hyperic.sigar.FileSystemMap;
|
||||||
import org.hyperic.sigar.FileSystemUsage;
|
import org.hyperic.sigar.FileSystemUsage;
|
||||||
|
import org.hyperic.sigar.Sigar;
|
||||||
import org.hyperic.sigar.SigarException;
|
import org.hyperic.sigar.SigarException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -64,14 +66,19 @@ public class SigarFsProbe extends AbstractComponent implements FsProbe {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FileSystem fileSystem = fileSystems.get(dataLocation);
|
FileSystem fileSystem = fileSystems.get(dataLocation);
|
||||||
|
Sigar sigar = sigarService.sigar();
|
||||||
if (fileSystem == null) {
|
if (fileSystem == null) {
|
||||||
fileSystem = sigarService.sigar().getFileSystemMap().getMountPoint(dataLocation.getPath());
|
FileSystemMap fileSystemMap = sigar.getFileSystemMap();
|
||||||
|
if (fileSystemMap != null) {
|
||||||
|
fileSystem = fileSystemMap.getMountPoint(dataLocation.getPath());
|
||||||
fileSystems.put(dataLocation, fileSystem);
|
fileSystems.put(dataLocation, fileSystem);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
FileSystemUsage fileSystemUsage = sigarService.sigar().getFileSystemUsage(fileSystem.getDirName());
|
if (fileSystem != null) {
|
||||||
info.mount = fileSystem.getDirName();
|
info.mount = fileSystem.getDirName();
|
||||||
info.dev = fileSystem.getDevName();
|
info.dev = fileSystem.getDevName();
|
||||||
|
FileSystemUsage fileSystemUsage = sigar.getFileSystemUsage(fileSystem.getDirName());
|
||||||
|
if (fileSystemUsage != null) {
|
||||||
// total/free/available seem to be in megabytes?
|
// total/free/available seem to be in megabytes?
|
||||||
info.total = fileSystemUsage.getTotal() * 1024;
|
info.total = fileSystemUsage.getTotal() * 1024;
|
||||||
info.free = fileSystemUsage.getFree() * 1024;
|
info.free = fileSystemUsage.getFree() * 1024;
|
||||||
|
@ -82,6 +89,8 @@ public class SigarFsProbe extends AbstractComponent implements FsProbe {
|
||||||
info.diskWriteBytes = fileSystemUsage.getDiskWriteBytes();
|
info.diskWriteBytes = fileSystemUsage.getDiskWriteBytes();
|
||||||
info.diskQueue = fileSystemUsage.getDiskQueue();
|
info.diskQueue = fileSystemUsage.getDiskQueue();
|
||||||
info.diskServiceTime = fileSystemUsage.getDiskServiceTime();
|
info.diskServiceTime = fileSystemUsage.getDiskServiceTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SigarException e) {
|
} catch (SigarException e) {
|
||||||
// failed...
|
// failed...
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue