add prometheus
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 49s
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 49s
This commit is contained in:
28
main.go
28
main.go
@@ -8,9 +8,20 @@ import (
|
||||
"time"
|
||||
|
||||
messages "git.tornberg.me/go-cart-actor/proto"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
var (
|
||||
opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "cart_grain_spawned_total",
|
||||
Help: "The total number of spawned grains",
|
||||
})
|
||||
)
|
||||
|
||||
func spawn(id CartId) (*CartGrain, error) {
|
||||
opsProcessed.Inc()
|
||||
ret := &CartGrain{
|
||||
Id: id,
|
||||
Items: []CartItem{},
|
||||
@@ -100,9 +111,11 @@ func (s *PoolServer) Serve() *http.ServeMux {
|
||||
return mux
|
||||
}
|
||||
|
||||
var clientName = os.Getenv("NODE_NAME")
|
||||
|
||||
func main() {
|
||||
// Create a new instance of the server
|
||||
storage, err := NewDiskStorage("data/state.gob")
|
||||
storage, err := NewDiskStorage(fmt.Sprintf("data/%s_state.gob", clientName))
|
||||
if err != nil {
|
||||
log.Printf("Error loading state: %v\n", err)
|
||||
}
|
||||
@@ -111,7 +124,13 @@ func main() {
|
||||
storage: storage,
|
||||
}
|
||||
|
||||
syncedPool := NewSyncedPool(app.pool)
|
||||
syncedPool, err := NewSyncedPool(app.pool, clientName)
|
||||
if err != nil {
|
||||
log.Fatalf("Error creating synced pool: %v\n", err)
|
||||
}
|
||||
|
||||
// if local
|
||||
syncedPool.AddRemote("localhost")
|
||||
|
||||
rpcHandler, err := NewGrainHandler(app.pool, ":1337")
|
||||
if err != nil {
|
||||
@@ -123,10 +142,11 @@ func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve()))
|
||||
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {
|
||||
remotePool := NewRemoteGrainPool(fmt.Sprintf("%s:1337", r.PathValue("host")))
|
||||
syncedPool.AddRemote(remotePool)
|
||||
syncedPool.AddRemote(r.PathValue("host"))
|
||||
})
|
||||
mux.HandleFunc("GET /save", app.HandleSave)
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
http.ListenAndServe(":8080", mux)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user