metrics: initial commit
This commit is contained in:
@@ -3,6 +3,7 @@ package docker
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/pterodactyl/wings/metrics"
|
||||
"io"
|
||||
"sync"
|
||||
|
||||
@@ -212,5 +213,15 @@ func (e *Environment) SetState(state string) {
|
||||
// If the state changed make sure we update the internal tracking to note that.
|
||||
e.st.Store(state)
|
||||
e.Events().Publish(environment.StateChangeEvent, state)
|
||||
|
||||
if state == environment.ProcessRunningState || state == environment.ProcessOfflineState {
|
||||
val := 0
|
||||
if state == environment.ProcessRunningState {
|
||||
val = 1
|
||||
} else {
|
||||
metrics.ResetServer(e.Id)
|
||||
}
|
||||
metrics.ServerStatus.WithLabelValues(e.Id).Set(float64(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/metrics"
|
||||
"io"
|
||||
"math"
|
||||
)
|
||||
@@ -60,6 +61,11 @@ func (e *Environment) pollResources(ctx context.Context) error {
|
||||
st.Network.TxBytes += nw.TxBytes
|
||||
}
|
||||
|
||||
metrics.ServerCPU.WithLabelValues(e.Id).Set(st.CpuAbsolute)
|
||||
metrics.ServerMemory.WithLabelValues(e.Id).Set(float64(st.Memory))
|
||||
metrics.ServerNetworkRx.WithLabelValues(e.Id).Set(float64(st.Network.RxBytes))
|
||||
metrics.ServerNetworkTx.WithLabelValues(e.Id).Set(float64(st.Network.TxBytes))
|
||||
|
||||
if b, err := json.Marshal(st); err != nil {
|
||||
e.log().WithField("error", err).Warn("error while marshaling stats object for environment")
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user