with '#' will be ignored, and an empty message aborts the commit. Author: Ethan Alicea <64653625+Tech-Gamer@users.noreply.github.com> On branch develop Your branch is up to date with 'origin/develop'. Changes to be committed: modified: .github/workflows/push.yaml modified: .github/workflows/release.yaml modified: CHANGELOG.md modified: Dockerfile modified: Makefile modified: README.md modified: cmd/configure.go modified: cmd/diagnostics.go modified: cmd/root.go modified: config/config.go modified: environment/allocations.go modified: environment/docker.go modified: environment/docker/api.go modified: environment/docker/container.go modified: environment/docker/environment.go modified: environment/docker/power.go modified: environment/docker/stats.go modified: environment/environment.go modified: environment/settings.go modified: events/events.go modified: go.mod modified: internal/cron/activity_cron.go modified: internal/cron/cron.go modified: internal/cron/sftp_cron.go modified: internal/database/database.go modified: internal/progress/progress.go modified: internal/progress/progress_test.go modified: loggers/cli/cli.go new file: oryxBuildBinary modified: parser/parser.go modified: remote/http.go modified: remote/servers.go modified: remote/types.go modified: router/downloader/downloader.go modified: router/middleware.go modified: router/middleware/middleware.go modified: router/middleware/request_error.go modified: router/router.go modified: router/router_download.go modified: router/router_server.go modified: router/router_server_backup.go modified: router/router_server_files.go modified: router/router_server_transfer.go modified: router/router_server_ws.go modified: router/router_system.go modified: router/router_transfer.go modified: router/tokens/parser.go modified: router/websocket/listeners.go modified: router/websocket/websocket.go modified: server/activity.go modified: server/backup.go modified: server/backup/backup.go modified: server/backup/backup_local.go modified: server/backup/backup_s3.go modified: server/configuration.go modified: server/console.go modified: server/crash.go modified: server/events.go modified: server/filesystem/archive.go modified: server/filesystem/filesystem.go modified: server/filesystem/filesystem_test.go modified: server/install.go modified: server/installer/installer.go modified: server/listeners.go modified: server/manager.go modified: server/mounts.go modified: server/power.go modified: server/power_test.go modified: server/resources.go modified: server/server.go modified: server/transfer/archive.go modified: server/transfer/source.go modified: server/transfer/transfer.go modified: server/update.go modified: sftp/event.go modified: sftp/handler.go modified: sftp/server.go modified: wings.go
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package server
|
|
|
|
import (
|
|
"sync"
|
|
"sync/atomic"
|
|
|
|
"github.com/Tech-Gamer/nwy-wings/environment"
|
|
"github.com/Tech-Gamer/nwy-wings/system"
|
|
)
|
|
|
|
// ResourceUsage defines the current resource usage for a given server instance. If a server is offline you
|
|
// should obviously expect memory and CPU usage to be 0. However, disk will always be returned
|
|
// since that is not dependent on the server being running to collect that data.
|
|
type ResourceUsage struct {
|
|
mu sync.RWMutex
|
|
|
|
// Embed the current environment stats into this server specific resource usage struct.
|
|
environment.Stats
|
|
|
|
// The current server status.
|
|
State *system.AtomicString `json:"state"`
|
|
|
|
// The current disk space being used by the server. This value is not guaranteed to be accurate
|
|
// at all times. It is "manually" set whenever server.Proc() is called. This is kind of just a
|
|
// hacky solution for now to avoid passing events all over the place.
|
|
Disk int64 `json:"disk_bytes"`
|
|
}
|
|
|
|
// Proc returns the current resource usage stats for the server instance. This returns
|
|
// a copy of the tracked resources, so making any changes to the response will not
|
|
// have the desired outcome for you most likely.
|
|
func (s *Server) Proc() ResourceUsage {
|
|
s.resources.mu.Lock()
|
|
defer s.resources.mu.Unlock()
|
|
// Store the updated disk usage when requesting process usage.
|
|
atomic.StoreInt64(&s.resources.Disk, s.Filesystem().CachedUsage())
|
|
//goland:noinspection GoVetCopyLock
|
|
return s.resources
|
|
}
|
|
|
|
// UpdateStats updates the current stats for the server's resource usage.
|
|
func (ru *ResourceUsage) UpdateStats(stats environment.Stats) {
|
|
ru.mu.Lock()
|
|
ru.Stats = stats
|
|
ru.mu.Unlock()
|
|
}
|
|
|
|
// Reset resets the usages values to zero, used when a server is stopped to ensure we don't hold
|
|
// onto any values incorrectly.
|
|
func (ru *ResourceUsage) Reset() {
|
|
ru.mu.Lock()
|
|
defer ru.mu.Unlock()
|
|
|
|
ru.Memory = 0
|
|
ru.CpuAbsolute = 0
|
|
ru.Uptime = 0
|
|
ru.Network.TxBytes = 0
|
|
ru.Network.RxBytes = 0
|
|
}
|