metrics: initial commit

This commit is contained in:
Matthew Penner
2021-03-09 08:45:54 -07:00
parent 08a7ccd175
commit dafbbab2ed
8 changed files with 171 additions and 3 deletions

View File

@@ -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))
}
}
}

View File

@@ -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 {