Skip to content

Commit

Permalink
add applied_cpu_request and applied_memory_request
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Oct 12, 2023
1 parent 88eeb92 commit 5f3e674
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ var (
Help: "hpa maxReplicas that tortoises actually applys to hpa",
}, []string{"tortoise_name", "namespace", "hpa_name"})

AppliedCPURequest = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "applied_cpu_request",
Help: "cpu request (millicore) that tortoises actually applys",
}, []string{"tortoise_name", "namespace", "container_name", "controller_name", "controller_kind"})

AppliedMemoryRequest = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "applied_memory_request",
Help: "memory request (byte) that tortoises actually applys",
}, []string{"tortoise_name", "namespace", "container_name", "controller_name", "controller_kind"})

ProposedHPATargetUtilization = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "proposed_hpa_utilization_target",
Help: "recommended hpa utilization target values that tortoises propose",
Expand Down Expand Up @@ -51,6 +61,10 @@ func init() {
//Register metrics with prometheus
metrics.Registry.MustRegister(
AppliedHPATargetUtilization,
AppliedHPAMaxReplicas,
AppliedHPAMinReplicas,
AppliedCPURequest,
AppliedMemoryRequest,
ProposedHPATargetUtilization,
ProposedHPAMinReplicas,
ProposedHPAMaxReplicas,
Expand Down
2 changes: 2 additions & 0 deletions pkg/vpa/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ func (c *Service) UpdateVPAFromTortoiseRecommendation(ctx context.Context, torto
for resourcename, value := range r.RecommendedResource {
if resourcename == corev1.ResourceCPU {
metrics.ProposedCPURequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.MilliValue()))
metrics.AppliedCPURequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.MilliValue()))
}
if resourcename == corev1.ResourceMemory {
metrics.ProposedMemoryRequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.Value()))
metrics.AppliedMemoryRequest.WithLabelValues(tortoise.Name, tortoise.Namespace, r.ContainerName, tortoise.Spec.TargetRefs.ScaleTargetRef.Name, tortoise.Spec.TargetRefs.ScaleTargetRef.Kind).Set(float64(value.Value()))
}
}
metricsRecorded = true
Expand Down

0 comments on commit 5f3e674

Please sign in to comment.