Skip to content

Commit

Permalink
small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
first-sportsbook committed Dec 23, 2022
1 parent 21d97ee commit 776b868
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 24 deletions.
3 changes: 0 additions & 3 deletions chart/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ spec:
- containerPort: 8080
protocol: TCP
name: metrics
- containerPort: 80
protocol: TCP
name: web
env:
- name: NODE_NAME
valueFrom:
Expand Down
14 changes: 12 additions & 2 deletions chart/templates/pormonitor.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.podMonitor.isEnabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
Expand All @@ -8,12 +9,21 @@ metadata:
app: kube-prometheus-stack-operator
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: kube-prometheus-stack
{{- range $key, $value := .Values.serviceMonitor.additionalLabels }}
{{- range $key, $value := .Values.podMonitor.additionalLabels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
selector:
matchLabels:
app: {{ include "chart.name" . }}
podMetricsEndpoints:
- port: metrics
- path: "/metrics"
- path: {{ .Values.podMonitor.endpoint }}}}
interval: {{ .Values.podMonitor.interval }}
{{- if .Values.podMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.podMonitor.scrapeTimeout }}
{{- end }}
{{- with .Values.podMonitor.relabelings }}
relabelings: {{ toYaml . | nindent 8 }}
{{- end }}
{{- end }}
17 changes: 16 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
repository: docmarr/kubernetes-multicooker
tag: "1.0.2"
tag: "1.0.3"
pullPolicy: Always

nameOverride: ""
Expand Down Expand Up @@ -30,3 +30,18 @@ nodeSelector: {}
tolerations: []

affinity: {}

podMonitor:
enabled: true
endpoint: "/metrics"
interval: 30s
scrapeTimeout: 10s
namespace: monitoring
additionalLabels:
release: "kube-prometheus-stack"
relabelings:
- sourceLabels: [__meta_kubernetes_pod_node_name]
separator: ;
targetLabel: instance
replacement: $1
action: replace
43 changes: 25 additions & 18 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,55 @@ import (
"k8s.io/client-go/tools/clientcmd"
)

var f config.StartupFlags
var (
prometheusNamespace = "multicooker"
pressureThresholdExceededTotal,
pressureRecoveredTotal,
pressureThresholdExceeded,
pressureEnabled prometheus.Gauge
f config.StartupFlags
)

func init() {
flag.StringVar(&f.KubeConfig, "kubeconfig", "", "file path to kubeconfig")
flag.Float64Var(&f.TaintThreshold, "taint-threshold", 25, "pressure threshold value")
flag.Float64Var(&f.EvictThreshold, "evict-threshold", 50, "pressure threshold value")
flag.StringVar(&f.EvictBackoff, "evict-backoff", "10m", "time to wait between evicting Pods")
flag.StringVar(&f.MinPodAge, "min-pod-age", "5m", "minimum age of Pods to be evicted")
flag.StringVar(&f.NodeName, "node-name", "", "current node name")
flag.IntVar(&f.MetricsPort, "metrics-port", 8080, "port for prometheus metrics endpoint")
flag.IntVar(&f.TargetMetric, "target-metric", 3, "target metric to use / 10,60,300 for pressure; and 1,5,15 for avarage/")
flag.BoolVar(&f.UseAvarage, "use-avarage", false, "use loadavg instead of proc/pressure/cpu")
flag.Parse()

prometheusNamespace := "multicooker"
pressureThresholdExceeded = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: prometheusNamespace,
Name: fmt.Sprintf("pressure_threshold_exceeded_%s", f.NodeName),
Name: "pressure_threshold_exceeded",
Help: "cpu pressure is currently above (1) or below (0) threshold",
})
pressureThresholdExceededTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: prometheusNamespace,
Name: fmt.Sprintf("pressure_threshold_exceeded_total_%s", f.NodeName),
Name: "pressure_threshold_exceeded_total",
Help: "number of times the pressure threshold was exceeded",
})
pressureRecoveredTotal = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: prometheusNamespace,
Name: fmt.Sprintf("pressure_recovered_total_%s", f.NodeName),
Name: "pressure_recovered_total",
Help: "number of times the pressure on the node recovered",
})
pressureEnabled = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: prometheusNamespace,
Name: fmt.Sprintf("enabled_%s", f.NodeName),
Name: "enabled",
Help: "multicooker is enabled (1) or disabled (0)",
})
)
}

func main() {
prometheus.MustRegister(pressureThresholdExceeded)
prometheus.MustRegister(pressureThresholdExceededTotal)
prometheus.MustRegister(pressureRecoveredTotal)
prometheus.MustRegister(pressureEnabled)

flag.StringVar(&f.KubeConfig, "kubeconfig", "", "file path to kubeconfig")
flag.Float64Var(&f.TaintThreshold, "taint-threshold", 25, "pressure threshold value")
flag.Float64Var(&f.EvictThreshold, "evict-threshold", 50, "pressure threshold value")
flag.StringVar(&f.EvictBackoff, "evict-backoff", "10m", "time to wait between evicting Pods")
flag.StringVar(&f.MinPodAge, "min-pod-age", "5m", "minimum age of Pods to be evicted")
flag.StringVar(&f.NodeName, "node-name", "", "current node name")
flag.IntVar(&f.MetricsPort, "metrics-port", 8080, "port for prometheus metrics endpoint")
flag.IntVar(&f.TargetMetric, "target-metric", 3, "target metric to use / 10,60,300 for pressure; and 1,5,15 for avarage/")
flag.BoolVar(&f.UseAvarage, "use-avarage", false, "use loadavg instead of proc/pressure/cpu")
flag.Parse()

if f.NodeName == "" {
panic("-node-name not set")
}
Expand Down

0 comments on commit 776b868

Please sign in to comment.