mirror of https://github.com/jetkvm/kvm.git
Compare commits
4 Commits
6596671715
...
780120f501
Author | SHA1 | Date |
---|---|---|
|
780120f501 | |
|
bde0a086ab | |
|
9c9335da31 | |
|
315c1c9f57 |
4
Makefile
4
Makefile
|
@ -2,8 +2,8 @@ BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
|
|||
BUILDDATE ?= $(shell date -u +%FT%T%z)
|
||||
BUILDTS ?= $(shell date -u +%s)
|
||||
REVISION ?= $(shell git rev-parse HEAD)
|
||||
VERSION_DEV ?= 0.4.6-dev$(shell date +%Y%m%d%H%M)
|
||||
VERSION ?= 0.4.5
|
||||
VERSION_DEV ?= 0.4.7-dev$(shell date +%Y%m%d%H%M)
|
||||
VERSION ?= 0.4.6
|
||||
|
||||
PROMETHEUS_TAG := github.com/prometheus/common/version
|
||||
KVM_PKG_NAME := github.com/jetkvm/kvm
|
||||
|
|
23
config.go
23
config.go
|
@ -9,6 +9,8 @@ import (
|
|||
"github.com/jetkvm/kvm/internal/logging"
|
||||
"github.com/jetkvm/kvm/internal/network"
|
||||
"github.com/jetkvm/kvm/internal/usbgadget"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
type WakeOnLanDevice struct {
|
||||
|
@ -138,6 +140,21 @@ var (
|
|||
configLock = &sync.Mutex{}
|
||||
)
|
||||
|
||||
var (
|
||||
configSuccess = promauto.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "jetkvm_config_last_reload_successful",
|
||||
Help: "The last configuration load succeeded",
|
||||
},
|
||||
)
|
||||
configSuccessTime = promauto.NewGauge(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "jetkvm_config_last_reload_success_timestamp_seconds",
|
||||
Help: "Timestamp of last successful config load",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
func LoadConfig() {
|
||||
configLock.Lock()
|
||||
defer configLock.Unlock()
|
||||
|
@ -153,6 +170,8 @@ func LoadConfig() {
|
|||
file, err := os.Open(configPath)
|
||||
if err != nil {
|
||||
logger.Debug().Msg("default config file doesn't exist, using default")
|
||||
configSuccess.Set(1.0)
|
||||
configSuccessTime.SetToCurrentTime()
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
@ -161,6 +180,7 @@ func LoadConfig() {
|
|||
loadedConfig := *defaultConfig
|
||||
if err := json.NewDecoder(file).Decode(&loadedConfig); err != nil {
|
||||
logger.Warn().Err(err).Msg("config file JSON parsing failed")
|
||||
configSuccess.Set(0.0)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -181,6 +201,9 @@ func LoadConfig() {
|
|||
|
||||
logging.GetRootLogger().UpdateLogLevel(config.DefaultLogLevel)
|
||||
|
||||
configSuccess.Set(1.0)
|
||||
configSuccessTime.SetToCurrentTime()
|
||||
|
||||
logger.Info().Str("path", configPath).Msg("config loaded")
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ func (u *UsbGadget) listenKeyboardEvents() {
|
|||
default:
|
||||
l.Trace().Msg("reading from keyboard")
|
||||
if u.keyboardHidFile == nil {
|
||||
u.logWithSupression("keyboardHidFileNil", 100, &l, nil, "keyboardHidFile is nil")
|
||||
u.logWithSuppression("keyboardHidFileNil", 100, &l, nil, "keyboardHidFile is nil")
|
||||
// show the error every 100 times to avoid spamming the logs
|
||||
time.Sleep(time.Second)
|
||||
continue
|
||||
|
@ -153,7 +153,7 @@ func (u *UsbGadget) listenKeyboardEvents() {
|
|||
|
||||
n, err := u.keyboardHidFile.Read(buf)
|
||||
if err != nil {
|
||||
u.logWithSupression("keyboardHidFileRead", 100, &l, err, "failed to read")
|
||||
u.logWithSuppression("keyboardHidFileRead", 100, &l, err, "failed to read")
|
||||
continue
|
||||
}
|
||||
u.resetLogSuppressionCounter("keyboardHidFileRead")
|
||||
|
@ -201,7 +201,7 @@ func (u *UsbGadget) keyboardWriteHidFile(data []byte) error {
|
|||
|
||||
_, err := u.keyboardHidFile.Write(data)
|
||||
if err != nil {
|
||||
u.logWithSupression("keyboardWriteHidFile", 100, u.log, err, "failed to write to hidg0")
|
||||
u.logWithSuppression("keyboardWriteHidFile", 100, u.log, err, "failed to write to hidg0")
|
||||
u.keyboardHidFile.Close()
|
||||
u.keyboardHidFile = nil
|
||||
return err
|
||||
|
|
|
@ -75,7 +75,7 @@ func (u *UsbGadget) absMouseWriteHidFile(data []byte) error {
|
|||
|
||||
_, err := u.absMouseHidFile.Write(data)
|
||||
if err != nil {
|
||||
u.logWithSupression("absMouseWriteHidFile", 100, u.log, err, "failed to write to hidg1")
|
||||
u.logWithSuppression("absMouseWriteHidFile", 100, u.log, err, "failed to write to hidg1")
|
||||
u.absMouseHidFile.Close()
|
||||
u.absMouseHidFile = nil
|
||||
return err
|
||||
|
|
|
@ -65,7 +65,7 @@ func (u *UsbGadget) relMouseWriteHidFile(data []byte) error {
|
|||
|
||||
_, err := u.relMouseHidFile.Write(data)
|
||||
if err != nil {
|
||||
u.logWithSupression("relMouseWriteHidFile", 100, u.log, err, "failed to write to hidg2")
|
||||
u.logWithSuppression("relMouseWriteHidFile", 100, u.log, err, "failed to write to hidg2")
|
||||
u.relMouseHidFile.Close()
|
||||
u.relMouseHidFile = nil
|
||||
return err
|
||||
|
|
|
@ -81,7 +81,7 @@ func compareFileContent(oldContent []byte, newContent []byte, looserMatch bool)
|
|||
return false
|
||||
}
|
||||
|
||||
func (u *UsbGadget) logWithSupression(counterName string, every int, logger *zerolog.Logger, err error, msg string, args ...interface{}) {
|
||||
func (u *UsbGadget) logWithSuppression(counterName string, every int, logger *zerolog.Logger, err error, msg string, args ...interface{}) {
|
||||
u.logSuppressionLock.Lock()
|
||||
defer u.logSuppressionLock.Unlock()
|
||||
|
||||
|
|
22
wol.go
22
wol.go
|
@ -4,6 +4,24 @@ import (
|
|||
"bytes"
|
||||
"encoding/binary"
|
||||
"net"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
wolPackets = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "jetkvm_wol_sent_packets_total",
|
||||
Help: "Total number of Wake-on-LAN magic packets sent.",
|
||||
},
|
||||
)
|
||||
wolErrors = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "jetkvm_wol_sent_packet_errors_total",
|
||||
Help: "Total number of Wake-on-LAN magic packets errors.",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
// SendWOLMagicPacket sends a Wake-on-LAN magic packet to the specified MAC address
|
||||
|
@ -11,6 +29,7 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
|||
// Parse the MAC address
|
||||
mac, err := net.ParseMAC(macAddress)
|
||||
if err != nil {
|
||||
wolErrors.Inc()
|
||||
return ErrorfL(wolLogger, "invalid MAC address", err)
|
||||
}
|
||||
|
||||
|
@ -20,6 +39,7 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
|||
// Set up UDP connection
|
||||
conn, err := net.Dial("udp", "255.255.255.255:9")
|
||||
if err != nil {
|
||||
wolErrors.Inc()
|
||||
return ErrorfL(wolLogger, "failed to establish UDP connection", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
@ -27,10 +47,12 @@ func rpcSendWOLMagicPacket(macAddress string) error {
|
|||
// Send the packet
|
||||
_, err = conn.Write(packet)
|
||||
if err != nil {
|
||||
wolErrors.Inc()
|
||||
return ErrorfL(wolLogger, "failed to send WOL packet", err)
|
||||
}
|
||||
|
||||
wolLogger.Info().Str("mac", macAddress).Msg("WOL packet sent")
|
||||
wolPackets.Inc()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue