2022-08-15 03:37:21 +00:00
|
|
|
//go:build !darwin
|
|
|
|
// +build !darwin
|
|
|
|
|
2022-07-01 07:19:16 +00:00
|
|
|
/*
|
|
|
|
* @Author: LinkLeong link@icewhale.com
|
|
|
|
* @Date: 2022-07-01 15:11:36
|
|
|
|
* @LastEditors: LinkLeong
|
2022-09-06 06:28:49 +00:00
|
|
|
* @LastEditTime: 2022-09-05 16:28:46
|
2022-06-08 10:19:45 +00:00
|
|
|
* @FilePath: /CasaOS/route/periodical.go
|
|
|
|
* @Description:
|
|
|
|
* @Website: https://www.casaos.io
|
|
|
|
* Copyright (c) 2022 by icewhale, All Rights Reserved.
|
|
|
|
*/
|
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/IceWhaleTech/CasaOS/model"
|
|
|
|
"github.com/IceWhaleTech/CasaOS/service"
|
|
|
|
)
|
|
|
|
|
2022-06-10 05:33:53 +00:00
|
|
|
func SendAllHardwareStatusBySocket() {
|
|
|
|
netList := service.MyService.System().GetNetInfo()
|
|
|
|
newNet := []model.IOCountersStat{}
|
|
|
|
nets := service.MyService.System().GetNet(true)
|
|
|
|
for _, n := range netList {
|
|
|
|
for _, netCardName := range nets {
|
|
|
|
if n.Name == netCardName {
|
|
|
|
item := *(*model.IOCountersStat)(unsafe.Pointer(&n))
|
2022-06-29 03:09:58 +00:00
|
|
|
item.State = strings.TrimSpace(service.MyService.System().GetNetState(n.Name))
|
2022-06-10 05:33:53 +00:00
|
|
|
item.Time = time.Now().Unix()
|
|
|
|
newNet = append(newNet, item)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cpu := service.MyService.System().GetCpuPercent()
|
2022-11-29 02:25:26 +00:00
|
|
|
|
|
|
|
var cpuModel = "arm"
|
|
|
|
if cpu := service.MyService.System().GetCpuInfo(); len(cpu) > 0 {
|
|
|
|
if strings.Count(strings.ToLower(strings.TrimSpace(cpu[0].ModelName)), "intel") > 0 {
|
|
|
|
cpuModel = "intel"
|
|
|
|
} else if strings.Count(strings.ToLower(strings.TrimSpace(cpu[0].ModelName)), "amd") > 0 {
|
|
|
|
cpuModel = "amd"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-10 05:33:53 +00:00
|
|
|
num := service.MyService.System().GetCpuCoreNum()
|
|
|
|
cpuData := make(map[string]interface{})
|
|
|
|
cpuData["percent"] = cpu
|
|
|
|
cpuData["num"] = num
|
2022-09-06 06:28:49 +00:00
|
|
|
cpuData["temperature"] = service.MyService.System().GetCPUTemperature()
|
|
|
|
cpuData["power"] = service.MyService.System().GetCPUPower()
|
2022-11-29 02:25:26 +00:00
|
|
|
cpuData["model"] = cpuModel
|
2022-06-10 05:33:53 +00:00
|
|
|
|
|
|
|
memInfo := service.MyService.System().GetMemInfo()
|
|
|
|
|
2022-12-20 06:05:16 +00:00
|
|
|
body := make(map[string]interface{})
|
|
|
|
|
|
|
|
body["sys_mem"] = memInfo
|
|
|
|
|
|
|
|
body["sys_cpu"] = cpuData
|
|
|
|
|
|
|
|
body["sys_net"] = newNet
|
|
|
|
systemTempMap := service.MyService.Notify().GetSystemTempMap()
|
2023-02-09 08:10:16 +00:00
|
|
|
systemTempMap.Range(func(key, value interface{}) bool {
|
|
|
|
body[key.(string)] = value
|
|
|
|
return true
|
|
|
|
})
|
2023-02-06 07:47:29 +00:00
|
|
|
service.MyService.Notify().SendNotify("casaos:system:utilization", body)
|
2022-06-10 05:33:53 +00:00
|
|
|
}
|
2022-08-15 03:37:21 +00:00
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
// func MonitoryUSB() {
|
|
|
|
// var matcher netlink.Matcher
|
|
|
|
|
|
|
|
// conn := new(netlink.UEventConn)
|
|
|
|
// if err := conn.Connect(netlink.UdevEvent); err != nil {
|
2022-11-29 17:17:14 +00:00
|
|
|
// logger.Error("udev err", zap.Any("Unable to connect to Netlink Kobject UEvent socket", err))
|
2022-10-20 06:25:26 +00:00
|
|
|
// }
|
|
|
|
// defer conn.Close()
|
|
|
|
|
|
|
|
// queue := make(chan netlink.UEvent)
|
|
|
|
// errors := make(chan error)
|
|
|
|
// quit := conn.Monitor(queue, errors, matcher)
|
|
|
|
|
|
|
|
// signals := make(chan os.Signal, 1)
|
|
|
|
// signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
|
|
|
|
// go func() {
|
|
|
|
// <-signals
|
|
|
|
// close(quit)
|
|
|
|
// os.Exit(0)
|
|
|
|
// }()
|
|
|
|
|
|
|
|
// for {
|
|
|
|
// select {
|
|
|
|
// case uevent := <-queue:
|
|
|
|
// if uevent.Env["DEVTYPE"] == "disk" {
|
|
|
|
// time.Sleep(time.Microsecond * 500)
|
|
|
|
// SendUSBBySocket()
|
|
|
|
// continue
|
|
|
|
// }
|
|
|
|
// case err := <-errors:
|
2022-11-29 17:17:14 +00:00
|
|
|
// logger.Error("udev err", zap.Any("err", err))
|
2022-10-20 06:25:26 +00:00
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|