diff --git a/pkg/operations/reconcile/metrics.go b/pkg/operations/reconcile/metrics.go index 0af6be852..2a5f5ac51 100644 --- a/pkg/operations/reconcile/metrics.go +++ b/pkg/operations/reconcile/metrics.go @@ -6,10 +6,36 @@ import ( log "github.com/sirupsen/logrus" "github.com/weaveworks/ignite/pkg/constants" "github.com/weaveworks/ignite/pkg/prometheus" + go_prom "github.com/prometheus/client_golang/prometheus" + ) +var ( + vmCreated = go_prom.NewCounter(go_prom.CounterOpts{ + Name: "vm_create_counter", + Help: "The count of VMs created", + }) + vmDeleted = go_prom.NewCounter(go_prom.CounterOpts{ + Name: "vm_delete_counter", + Help: "The count of VMs deleted", + }) + vmStarted = go_prom.NewCounter(go_prom.CounterOpts{ + Name: "vm_start_counter", + Help: "The count of VMs started", + }) + vmStopped = go_prom.NewCounter(go_prom.CounterOpts{ + Name: "vm_stop_counter", + Help: "The count of VMs stopped", + }) + kindIgnored = go_prom.NewCounter(go_prom.CounterOpts{ + Name: "kind_ignored_counter", + Help: "A counter of non-vm manifests ignored", + }) +) func startMetricsThread() { - _, server := prometheus.New() + reg, server := prometheus.New() + reg.MustRegister(vmCreated, vmDeleted, vmStarted, vmStopped, kindIgnored) + go func() { // create a new registry and http.Server. don't register custom metrics to the registry quite yet metricsSocket := path.Join(constants.DATA_DIR, constants.DAEMON_SOCKET) diff --git a/pkg/operations/reconcile/reconcile.go b/pkg/operations/reconcile/reconcile.go index 77664c462..cc08f4f9b 100644 --- a/pkg/operations/reconcile/reconcile.go +++ b/pkg/operations/reconcile/reconcile.go @@ -16,6 +16,7 @@ import ( var c *client.Client + func ReconcileManifests(s *manifest.ManifestStorage) { startMetricsThread() @@ -28,6 +29,7 @@ func ReconcileManifests(s *manifest.ManifestStorage) { // Only care about VMs if upd.APIType.GetKind() != api.KindVM { log.Tracef("GitOps: Ignoring kind %s", upd.APIType.GetKind()) + kindIgnored.Inc() continue } @@ -66,6 +68,7 @@ func ReconcileManifests(s *manifest.ManifestStorage) { runHandle(func() error { return handleChange(vm) }) + case update.ObjectEventDelete: runHandle(func() error { // TODO: Temporary VM Object for removal @@ -108,7 +111,7 @@ func create(vm *api.VM) error { if err := ensureOCIImages(vm); err != nil { return err } - + vmCreated.Inc() // Allocate and populate the overlay file return dmlegacy.AllocateAndPopulateOverlay(vm) } @@ -146,17 +149,19 @@ func start(vm *api.VM) error { } log.Infof("Starting VM %q with name %q...", vm.GetUID(), vm.GetName()) + vmStarted.Inc() return operations.StartVM(vm, true) } func stop(vm *api.VM) error { log.Infof("Stopping VM %q with name %q...", vm.GetUID(), vm.GetName()) + vmStopped.Inc() return operations.StopVM(vm, true, false) } func remove(vm *api.VM) error { log.Infof("Removing VM %q with name %q...", vm.GetUID(), vm.GetName()) - + vmDeleted.Inc() // Object deletion is performed by the SyncStorage, so we just // need to clean up any remaining resources of the VM here return operations.CleanupVM(vm)