Skip to content
Snippets Groups Projects
Unverified Commit fb60fb39 authored by capossele's avatar capossele
Browse files

:construction: WIP

parent afb05103
No related branches found
No related tags found
No related merge requests found
...@@ -43,14 +43,10 @@ func configure(_ *node.Plugin) { ...@@ -43,14 +43,10 @@ func configure(_ *node.Plugin) {
analysisOutboundBytes.Add(amountBytes) analysisOutboundBytes.Add(amountBytes)
})) }))
metrics.Events().CPUUsage.Attach(events.NewClosure(func(cpuPercent float64) { metrics.Events().CPUUsage.Attach(events.NewClosure(func(cpuPercent float64) {
cpuLock.Lock() cpuUsage.Store(cpuPercent)
defer cpuLock.Unlock()
_cpuUsage = cpuPercent
})) }))
metrics.Events().MemUsage.Attach(events.NewClosure(func(memAllocBytes uint64) { metrics.Events().MemUsage.Attach(events.NewClosure(func(memAllocBytes uint64) {
memUsageLock.Lock() memUsageBytes.Store(memAllocBytes)
defer memUsageLock.Unlock()
_memUsageBytes = memAllocBytes
})) }))
metrics.Events().Synced.Attach(events.NewClosure(func(synced bool) { metrics.Events().Synced.Attach(events.NewClosure(func(synced bool) {
syncLock.Lock() syncLock.Lock()
......
...@@ -5,22 +5,18 @@ import ( ...@@ -5,22 +5,18 @@ import (
"time" "time"
"github.com/iotaledger/goshimmer/packages/metrics" "github.com/iotaledger/goshimmer/packages/metrics"
"github.com/iotaledger/hive.go/syncutils"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
"go.uber.org/atomic"
) )
var ( var (
_cpuUsage float64 cpuUsage atomic.Float64
cpuLock syncutils.RWMutex memUsageBytes atomic.Uint64
_memUsageBytes uint64
memUsageLock syncutils.RWMutex
) )
// CpuUsage returns the current cpu usage // CpuUsage returns the current cpu usage
func CpuUsage() float64 { func CpuUsage() float64 {
cpuLock.RLock() return cpuUsage.Load()
defer cpuLock.RUnlock()
return _cpuUsage
} }
func measureCPUUsage() { func measureCPUUsage() {
...@@ -42,7 +38,5 @@ func measureMemUsage() { ...@@ -42,7 +38,5 @@ func measureMemUsage() {
// MemUsage returns the current memory allocated as bytes // MemUsage returns the current memory allocated as bytes
func MemUsage() uint64 { func MemUsage() uint64 {
memUsageLock.RLock() return memUsageBytes.Load()
defer memUsageLock.RUnlock()
return _memUsageBytes
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment