oshi.hardware.platform.unix.solaris.SolarisSensors Maven / Gradle / Ivy
/**
* Oshi (https://github.com/dblock/oshi)
*
* Copyright (c) 2010 - 2016 The Oshi Project Team
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Maintainers:
* dblock[at]dblock[dot]org
* widdis[at]gmail[dot]com
* enrico.bianchi[at]gmail[dot]com
*
* Contributors:
* https://github.com/dblock/oshi/graphs/contributors
*/
package oshi.hardware.platform.unix.solaris;
import java.util.ArrayList;
import java.util.List;
import oshi.hardware.Sensors;
import oshi.util.ExecutingCommand;
import oshi.util.ParseUtil;
public class SolarisSensors implements Sensors {
private static final long serialVersionUID = 1L;
/**
* {@inheritDoc}
*/
@Override
public double getCpuTemperature() {
double maxTemp = 0d;
// Return max found temp
for (String line : ExecutingCommand.runNative("/usr/sbin/prtpicl -v -c temperature-sensor")) {
if (line.trim().startsWith("Temperature:")) {
int temp = ParseUtil.parseLastInt(line, 0);
if (temp > maxTemp) {
maxTemp = temp;
}
}
}
// If it's in millidegrees:
if (maxTemp > 1000) {
maxTemp /= 1000;
}
return maxTemp;
}
/**
* {@inheritDoc}
*/
@Override
public int[] getFanSpeeds() {
List speedList = new ArrayList<>();
// Return max found temp
for (String line : ExecutingCommand.runNative("/usr/sbin/prtpicl -v -c fan")) {
if (line.trim().startsWith("Speed:")) {
speedList.add(ParseUtil.parseLastInt(line, 0));
}
}
int[] fans = new int[speedList.size()];
for (int i = 0; i < speedList.size(); i++) {
fans[i] = speedList.get(i);
}
return fans;
}
/**
* {@inheritDoc}
*/
@Override
public double getCpuVoltage() {
double voltage = 0d;
// TODO This is entirely a guess!
for (String line : ExecutingCommand.runNative("/usr/sbin/prtpicl -v -c voltage-sensor")) {
if (line.trim().startsWith("Voltage:")) {
voltage = ParseUtil.parseDoubleOrDefault(line.replace("Voltage:", "").trim(), 0d);
break;
}
}
return voltage;
}
}