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

Initial set of metrics for gitops processing #494

Merged
merged 1 commit into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion pkg/operations/reconcile/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions pkg/operations/reconcile/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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