mirror of https://github.com/cjbassi/gotop.git
Merge branch 'temps'
This commit is contained in:
commit
bed05dc425
|
@ -58,7 +58,7 @@
|
|||
"net",
|
||||
"process"
|
||||
]
|
||||
revision = "cd915bdc31582b0a56405ede7fa2f4ab043f851b"
|
||||
revision = "57f370e13068146efe1cb7129f79e5d51da8a242"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
|
|
@ -379,8 +379,8 @@ static kern_return_t read_smc(char *key, smc_return_t *result_smc)
|
|||
|
||||
// Store data for return
|
||||
result_smc->dataSize = outputStruct.keyInfo.dataSize;
|
||||
result_smc->dataType = outputStruct.keyInfo.dataType;
|
||||
|
||||
result_smc->dataType = outputStruct.keyInfo.dataType;
|
||||
|
||||
|
||||
// Second call to AppleSMC - now we can get the data
|
||||
inputStruct.keyInfo.dataSize = outputStruct.keyInfo.dataSize;
|
||||
|
@ -451,10 +451,10 @@ static kern_return_t get_machine_model(io_name_t model)
|
|||
{
|
||||
io_service_t service;
|
||||
kern_return_t result;
|
||||
|
||||
|
||||
service = IOServiceGetMatchingService(kIOMasterPortDefault,
|
||||
IOServiceMatching(IOSERVICE_MODEL));
|
||||
|
||||
|
||||
if (service == 0) {
|
||||
printf("ERROR: %s NOT FOUND\n", IOSERVICE_MODEL);
|
||||
return kIOReturnError;
|
||||
|
@ -465,7 +465,7 @@ static kern_return_t get_machine_model(io_name_t model)
|
|||
IOObjectRelease(service);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -600,7 +600,7 @@ bool get_fan_name(unsigned int fan_num, fan_name_t name)
|
|||
char key[5];
|
||||
kern_return_t result;
|
||||
smc_return_t result_smc;
|
||||
|
||||
|
||||
sprintf(key, "F%dID", fan_num);
|
||||
result = read_smc(key, &result_smc);
|
||||
|
||||
|
@ -610,16 +610,16 @@ bool get_fan_name(unsigned int fan_num, fan_name_t name)
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
We know the data size is 16 bytes and the type is "{fds", a custom
|
||||
struct defined by the AppleSMC.kext. See TMP enum sources for the
|
||||
struct.
|
||||
|
||||
|
||||
The last 12 bytes contain the name of the fan, an array of chars, hence
|
||||
the loop range.
|
||||
*/
|
||||
int index = 0;
|
||||
int index = 0;
|
||||
for (int i = 4; i < 16; i++) {
|
||||
// Check if at the end (name may not be full 12 bytes)
|
||||
// Could check for 0 (null), but instead we check for 32 (space). This
|
||||
|
@ -686,7 +686,7 @@ bool set_fan_min_rpm(unsigned int fan_num, unsigned int rpm, bool auth)
|
|||
|
||||
// TODO: Don't use magic number
|
||||
result_smc.dataSize = 2;
|
||||
result_smc.dataType = to_uint32_t(DATA_TYPE_FPE2);
|
||||
result_smc.dataType = to_uint32_t(DATA_TYPE_FPE2);
|
||||
to_fpe2(rpm, result_smc.data);
|
||||
|
||||
sprintf(key, "F%dMn", fan_num);
|
|
@ -213,7 +213,7 @@ bool is_optical_disk_drive_full(void);
|
|||
|
||||
/**
|
||||
Get the name of a fan.
|
||||
|
||||
|
||||
:param: fanNum The number of the fan to check
|
||||
:param: name The name of the fan. Return will be empty on error.
|
||||
:returns: True if successful, false otherwise.
|
|
@ -6,11 +6,9 @@ package widgets
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ui "github.com/cjbassi/termui"
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
type Temp struct {
|
||||
|
@ -43,18 +41,6 @@ func NewTemp() *Temp {
|
|||
return self
|
||||
}
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
// only sensors with input in their name are giving us live temp info
|
||||
if strings.Contains(sensor.SensorKey, "input") {
|
||||
// removes '_input' from the end of the sensor name
|
||||
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
||||
self.Data[label] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Buffer implements ui.Bufferer interface and renders the widget.
|
||||
func (self *Temp) Buffer() *ui.Buffer {
|
||||
buf := self.Block.Buffer()
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
// +build darwin
|
||||
// +build cgo
|
||||
// TODO do we need to add '+build cgo'?
|
||||
|
||||
package host
|
||||
package widgets
|
||||
|
||||
// #cgo LDFLAGS: -framework IOKit
|
||||
// #include "include/smc.c"
|
||||
import "C"
|
||||
import "context"
|
||||
|
||||
func SensorsTemperatures() ([]TemperatureStat, error) {
|
||||
return SensorsTemperaturesWithContext(context.Background())
|
||||
type TemperatureStat struct {
|
||||
SensorKey string `json:"sensorKey"`
|
||||
Temperature float64 `json:"sensorTemperature"`
|
||||
}
|
||||
|
||||
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
|
||||
func SensorsTemperatures() ([]TemperatureStat, error) {
|
||||
temperatureKeys := []string{
|
||||
C.AMBIENT_AIR_0,
|
||||
C.AMBIENT_AIR_1,
|
||||
|
@ -49,3 +48,10 @@ func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, err
|
|||
}
|
||||
return temperatures, nil
|
||||
}
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package widgets
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
// only sensors with input in their name are giving us live temp info
|
||||
if strings.Contains(sensor.SensorKey, "input") {
|
||||
// removes '_input' from the end of the sensor name
|
||||
label := sensor.SensorKey[:strings.Index(sensor.SensorKey, "_input")]
|
||||
self.Data[label] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package widgets
|
||||
|
||||
import (
|
||||
psHost "github.com/shirou/gopsutil/host"
|
||||
)
|
||||
|
||||
func (self *Temp) update() {
|
||||
sensors, _ := psHost.SensorsTemperatures()
|
||||
for _, sensor := range sensors {
|
||||
self.Data[sensor.SensorKey] = int(sensor.Temperature)
|
||||
}
|
||||
}
|
|
@ -117,6 +117,10 @@ Several methods have been added which are not present in psutil, but will provid
|
|||
- VirtualizationSystem (ex: "LXC")
|
||||
- VirtualizationRole (ex: "guest"/"host")
|
||||
|
||||
- IOCounters
|
||||
|
||||
- Label (linux only) The registered [device mapper name](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm)
|
||||
|
||||
- cpu/CPUInfo() (linux, freebsd)
|
||||
|
||||
- CPU (ex: 0, 1, ...)
|
||||
|
|
|
@ -42,6 +42,7 @@ type IOCountersStat struct {
|
|||
WeightedIO uint64 `json:"weightedIO"`
|
||||
Name string `json:"name"`
|
||||
SerialNumber string `json:"serialNumber"`
|
||||
Label string `json:"label"`
|
||||
}
|
||||
|
||||
func (d UsageStat) String() string {
|
||||
|
|
|
@ -5,6 +5,7 @@ package disk
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
@ -370,6 +371,8 @@ func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOC
|
|||
d.Name = name
|
||||
|
||||
d.SerialNumber = GetDiskSerialNumber(name)
|
||||
d.Label = GetLabel(name)
|
||||
|
||||
ret[name] = d
|
||||
}
|
||||
return ret, nil
|
||||
|
@ -406,6 +409,26 @@ func GetDiskSerialNumberWithContext(ctx context.Context, name string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// GetLabel returns label of given device or empty string on error.
|
||||
// Name of device is expected, eg. /dev/sda
|
||||
// Supports label based on devicemapper name
|
||||
// See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm
|
||||
func GetLabel(name string) string {
|
||||
// Try label based on devicemapper name
|
||||
dmname_filename := common.HostSys(fmt.Sprintf("block/%s/dm/name", name))
|
||||
|
||||
if !common.PathExists(dmname_filename) {
|
||||
return ""
|
||||
}
|
||||
|
||||
dmname, err := ioutil.ReadFile(dmname_filename)
|
||||
if err != nil {
|
||||
return ""
|
||||
} else {
|
||||
return string(dmname)
|
||||
}
|
||||
}
|
||||
|
||||
func getFsType(stat unix.Statfs_t) string {
|
||||
t := int64(stat.Type)
|
||||
ret, ok := fsTypeMap[t]
|
||||
|
|
|
@ -217,3 +217,11 @@ func KernelVersionWithContext(ctx context.Context) (string, error) {
|
|||
_, _, version, err := PlatformInformation()
|
||||
return version, err
|
||||
}
|
||||
|
||||
func SensorsTemperatures() ([]TemperatureStat, error) {
|
||||
return SensorsTemperaturesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
|
||||
return []TemperatureStat{}, common.ErrNotImplementedError
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
// +build darwin
|
||||
// +build !cgo
|
||||
|
||||
package host
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/shirou/gopsutil/internal/common"
|
||||
)
|
||||
|
||||
func SensorsTemperatures() ([]TemperatureStat, error) {
|
||||
return SensorsTemperaturesWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
|
||||
return []TemperatureStat{}, common.ErrNotImplementedError
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs types_linux.go
|
||||
|
||||
package host
|
||||
|
||||
const (
|
||||
sizeofPtr = 0x4
|
||||
sizeofShort = 0x2
|
||||
sizeofInt = 0x4
|
||||
sizeofLong = 0x4
|
||||
sizeofLongLong = 0x8
|
||||
sizeOfUtmp = 0x180
|
||||
)
|
||||
|
||||
type (
|
||||
_C_short int16
|
||||
_C_int int32
|
||||
_C_long int32
|
||||
_C_long_long int64
|
||||
)
|
||||
|
||||
type utmp struct {
|
||||
Type int16
|
||||
Pad_cgo_0 [2]byte
|
||||
Pid int32
|
||||
Line [32]int8
|
||||
Id [4]int8
|
||||
User [32]int8
|
||||
Host [256]int8
|
||||
Exit exit_status
|
||||
Session int32
|
||||
Tv timeval
|
||||
Addr_v6 [4]int32
|
||||
X__unused [20]int8
|
||||
}
|
||||
type exit_status struct {
|
||||
Termination int16
|
||||
Exit int16
|
||||
}
|
||||
type timeval struct {
|
||||
Sec int32
|
||||
Usec int32
|
||||
}
|
|
@ -39,7 +39,7 @@ func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buffers, err := unix.SysctlUint32("vfs.bufspace")
|
||||
buffers, err := unix.SysctlUint64("vfs.bufspace")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue