Skip to content
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ evaluations.

This setup expects Prometheus to be running in the cluster and configured to scrape pod resource metrics. The address
for Prometheus can be passed through `-prometheus-url` flag.

## Compatibility

#### Tested on the following environment:

- Kubernetes v1.17 with Docker v19.03
- Prometheus v2.20
- Kube-state-metrics v1.8
2 changes: 1 addition & 1 deletion deploy/scaler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
serviceAccountName: system
containers:
- name: scaler
image: arjunrn/simple-scaler:ca121dd
image: denisjd/simple-scaler:v2.0
args:
- -prometheus-url=http://prometheus
resources:
Expand Down
7 changes: 4 additions & 3 deletions pkg/replicacalculator/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
)

const (
prometheusQuery = `sum(rate(container_cpu_usage_seconds_total{pod_name=~"%s", namespace="%s"}[1m])) by(pod_name) /
sum(kube_pod_container_resource_requests_cpu_cores{pod_name=~"%s", namespace="%s"}) by (pod_name)`
prometheusQuery = `sum(rate(container_cpu_usage_seconds_total{job="kubernetes-cadvisor",image!="",container!="POD",pod=~"%s",namespace="%s"}[1m])) by(pod) /
sum(kube_pod_container_resource_requests_cpu_cores{job="kube-state-metrics",pod=~"%s",namespace="%s"}) by (pod)`
)

type MetricsSource interface {
Expand Down Expand Up @@ -55,8 +55,9 @@ func (m *prometheusMetricsSource) GetPodMetrics(namespace string, podIDs []strin
return nil, fmt.Errorf("unexpected return type from the prometheus api call: %v", results.Type())
}
mapResults := make(map[string][]int)
log.Debugf("matrixResult ----: %v", matrixResult)
for _, r := range matrixResult {
podName := string(r.Metric["pod_name"])
podName := string(r.Metric["pod"])
mapResults[podName] = make([]int, len(r.Values))
for i, v := range r.Values {
mapResults[podName][i] = int(v.Value * 100)
Expand Down