diff --git a/pkg/operations/reconcile/metrics.go b/pkg/operations/reconcile/metrics.go index 0af6be852..9d04bb72c 100644 --- a/pkg/operations/reconcile/metrics.go +++ b/pkg/operations/reconcile/metrics.go @@ -3,13 +3,39 @@ package reconcile import ( "path" + go_prom "github.com/prometheus/client_golang/prometheus" log "github.com/sirupsen/logrus" "github.com/weaveworks/ignite/pkg/constants" "github.com/weaveworks/ignite/pkg/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..39d098d0a 100644 --- a/pkg/operations/reconcile/reconcile.go +++ b/pkg/operations/reconcile/reconcile.go @@ -28,6 +28,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 +67,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 +110,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 +148,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)