mirror of
https://github.com/henrygd/beszel.git
synced 2025-12-17 10:46:16 +01:00
reorganize agent package
This commit is contained in:
30
beszel/internal/agent/utils.go
Normal file
30
beszel/internal/agent/utils.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package agent
|
||||
|
||||
import "math"
|
||||
|
||||
func (a *Agent) acquireSemaphore() {
|
||||
a.sem <- struct{}{}
|
||||
}
|
||||
|
||||
func (a *Agent) releaseSemaphore() {
|
||||
<-a.sem
|
||||
}
|
||||
|
||||
// delete container stats from map using mutex
|
||||
func (a *Agent) deleteContainerStatsSync(id string) {
|
||||
a.containerStatsMutex.Lock()
|
||||
defer a.containerStatsMutex.Unlock()
|
||||
delete(a.containerStatsMap, id)
|
||||
}
|
||||
|
||||
func bytesToMegabytes(b float64) float64 {
|
||||
return twoDecimals(b / 1048576)
|
||||
}
|
||||
|
||||
func bytesToGigabytes(b uint64) float64 {
|
||||
return twoDecimals(float64(b) / 1073741824)
|
||||
}
|
||||
|
||||
func twoDecimals(value float64) float64 {
|
||||
return math.Round(value*100) / 100
|
||||
}
|
||||
Reference in New Issue
Block a user