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

@@ -4,6 +4,7 @@ import (
"crypto/tls"
"errors"
"fmt"
"github.com/pterodactyl/wings/metrics"
log2 "log"
"net/http"
"os"
@@ -137,6 +138,9 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
"gid": config.Get().System.User.Gid,
}).Info("configured system user successfully")
done := make(chan bool)
go metrics.Initialize(done)
pclient := remote.New(
config.Get().PanelLocation,
remote.WithCredentials(config.Get().AuthenticationTokenId, config.Get().AuthenticationToken),
@@ -199,6 +203,12 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
continue
}
if states[s.Id()] == environment.ProcessRunningState {
metrics.ServerStatus.WithLabelValues(s.Id()).Set(1)
} else {
metrics.ServerStatus.WithLabelValues(s.Id()).Set(0)
}
pool.Submit(func() {
s.Log().Info("configuring server environment and restoring to previous state")
var st string
@@ -346,6 +356,7 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
if err := s.ListenAndServe(); err != nil {
log.WithField("error", err).Fatal("failed to configure HTTP server")
}
<-done
}
// Reads the configuration from the disk and then sets up the global singleton