Skip to content

Commit

Permalink
Merge pull request #11 from uselagoon/metrics-kilobytes
Browse files Browse the repository at this point in the history
refactor: add lagoon_namespace to metrics, and change naming of bytes to kilobytes
  • Loading branch information
shreddedbacon authored Feb 15, 2024
2 parents 53ac701 + 33c8a77 commit b03c7f3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
16 changes: 10 additions & 6 deletions internal/storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,19 @@ type ActionEvent struct {
func (ae *ActionEvent) ExportMetrics(promStorage *prometheus.GaugeVec) {
for _, claim := range ae.Data.Claims {
promStorage.With(prometheus.Labels{
"claimenv": strconv.Itoa(claim.Environment),
"claimpvc": claim.PersisteStorageClaim,
"project": ae.Meta.Project,
"environment": ae.Meta.Environment,
}).Set(float64(claim.BytesUsed))
"claimenv": strconv.Itoa(claim.Environment),
"claimpvc": claim.PersisteStorageClaim,
"project": ae.Meta.Project,
"environment": ae.Meta.Environment,
"lagoon_namespace": ae.Meta.Namespace,
}).Set(float64(claim.KiloBytesUsed))
}
}

type MetaData struct {
Project string `json:"project"`
Environment string `json:"environment"`
Namespace string `json:"namespace"`
}

type ActionData struct {
Expand All @@ -67,7 +69,9 @@ type ActionData struct {
type StorageClaim struct {
Environment int `json:"environment"`
PersisteStorageClaim string `json:"persistentStorageClaim"`
BytesUsed int `json:"bytesUsed"`
//it is actually kilobytes that du outputs, this should be deprecated
BytesUsed int `json:"bytesUsed"`
KiloBytesUsed int `json:"kiloBytesUsed"`
}

// Calculate will run the storage-calculator job.
Expand Down
3 changes: 3 additions & 0 deletions internal/storage/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func (c *Calculator) createStoragePod(
Environment: environmentID,
PersisteStorageClaim: vol.Name,
BytesUsed: pBytesInt,
KiloBytesUsed: pBytesInt,
})
}

Expand All @@ -187,6 +188,7 @@ func (c *Calculator) createStoragePod(
Environment: environmentID,
PersisteStorageClaim: "mariadb",
BytesUsed: mBytesInt,
KiloBytesUsed: mBytesInt,
})
// and attempt to patch the namespace with the labels
mergePatch, _ := json.Marshal(map[string]interface{}{
Expand Down Expand Up @@ -214,6 +216,7 @@ func (c *Calculator) createStoragePod(
EventType: "environmentStorage",
Data: storData,
Meta: MetaData{
Namespace: namespace.ObjectMeta.Name,
Project: namespace.ObjectMeta.Labels["lagoon.sh/project"],
Environment: namespace.ObjectMeta.Labels["lagoon.sh/environment"],
},
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ func (c *Calculator) checkVolumesCreatePods(
Environment: environmentID,
PersisteStorageClaim: "none",
BytesUsed: 0,
KiloBytesUsed: 0,
})
actionData := ActionEvent{
Type: "updateEnvironmentStorage",
EventType: "environmentStorage",
Data: storData,
Meta: MetaData{
Namespace: namespace.ObjectMeta.Name,
Project: namespace.ObjectMeta.Labels["lagoon.sh/project"],
Environment: namespace.ObjectMeta.Labels["lagoon.sh/environment"],
},
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ var (
setupLog = ctrl.Log.WithName("setup")
prom_storage = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "lagoon_storage_calculator_bytes",
Help: "The lagoon storage calculator bytes",
Name: "lagoon_storage_calculator_kilobytes",
Help: "The lagoon storage calculator kilobytes bytes",
},
[]string{"claimenv", "claimpvc", "project", "environment"},
[]string{"claimenv", "claimpvc", "project", "environment", "lagoon_namespace"},
)
)

Expand Down

0 comments on commit b03c7f3

Please sign in to comment.