Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
Initial set of metrics for gitops processing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Emeis committed Nov 13, 2019
1 parent ba63c96 commit f8b6212
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
28 changes: 27 additions & 1 deletion pkg/operations/reconcile/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions pkg/operations/reconcile/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var c *client.Client


func ReconcileManifests(s *manifest.ManifestStorage) {
startMetricsThread()

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f8b6212

Please sign in to comment.