Monitor the Nomad events

and send all Nomad events to Influxdb.
This commit is contained in:
Maximilian Paß
2023-05-06 21:18:21 +01:00
parent bc479fcf1e
commit 42efebc194
3 changed files with 15 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
nomadApi "github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/nomad/structs"
influxdb2 "github.com/influxdata/influxdb-client-go/v2"
"github.com/influxdata/influxdb-client-go/v2/api/write"
"github.com/openHPI/poseidon/internal/config"
"github.com/openHPI/poseidon/pkg/dto"
@ -207,6 +208,7 @@ func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationP
}
handler := func(event *nomadApi.Event) (bool, error) {
dumpNomadEventToInflux(event)
switch event.Topic {
case nomadApi.TopicEvaluation:
return false, handleEvaluationEvent(a.evaluations, event)
@ -223,6 +225,15 @@ func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationP
return err
}
func dumpNomadEventToInflux(event *nomadApi.Event) {
p := influxdb2.NewPointWithMeasurement(monitoring.MeasurementNomadEvents)
p.AddTag("topic", event.Topic.String())
p.AddTag("type", event.Type)
p.AddTag("key", event.Key)
p.AddField("payload", event.Payload)
monitoring.WriteInfluxPoint(p)
}
func (a *APIClient) initializeAllocations() {
allocationStubs, err := a.listAllocations()
if err != nil {