From a8012ce51d7c94cbf5f4404fa9488e22ff8d90d5 Mon Sep 17 00:00:00 2001 From: Jack Jackson Date: Mon, 20 Feb 2023 19:32:07 -0800 Subject: [PATCH] Add node-name label --- app/main.py | 19 ++++++++++++++++--- helm/templates/daemon-set.yaml | 5 +++++ helm/values.yaml | 18 +----------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/app/main.py b/app/main.py index 3dd406a..342141f 100644 --- a/app/main.py +++ b/app/main.py @@ -2,6 +2,7 @@ # https://pimylifeup.com/raspberry-pi-temperature/ +import os import time import subprocess @@ -11,12 +12,25 @@ REGISTRY.unregister(GC_COLLECTOR) REGISTRY.unregister(PLATFORM_COLLECTOR) REGISTRY.unregister(PROCESS_COLLECTOR) + def setup_gauge(): - g = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature') + g = Gauge(f'sys_cpu_temp_celsius_degrees', 'CPU Temperature', ['node_name']) g.set_function(_get_temp) + g.labels(_get_node_name()) + def _get_temp(): - return float(subprocess.run(['/usr/bin/vcgencmd', 'measure_temp'], capture_output=True).stdout.decode('utf-8').replace('temp=', '').replace("'C\n", '')) + return float(subprocess.run(['/usr/bin/vcgencmd', 'measure_temp'], capture_output=True).stdout.decode('utf-8') + .replace('temp=', '').replace("'C\n", '')) + + +def _get_node_name(): + # https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/ + try: + return os.environ['NODE_NAME'] + except: + return 'unknown-node' + if __name__ == '__main__': setup_gauge() @@ -24,4 +38,3 @@ if __name__ == '__main__': while True: # Stay alive! time.sleep(1) - diff --git a/helm/templates/daemon-set.yaml b/helm/templates/daemon-set.yaml index dd831b0..e44df33 100644 --- a/helm/templates/daemon-set.yaml +++ b/helm/templates/daemon-set.yaml @@ -25,6 +25,11 @@ spec: {{- toYaml .Values.securityContext | nindent 12 }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName ports: - name: prometheus containerPort: 8555 diff --git a/helm/values.yaml b/helm/values.yaml index 76d904a..0827ee8 100644 --- a/helm/values.yaml +++ b/helm/values.yaml @@ -5,7 +5,7 @@ replicaCount: 1 image: - repository: nginx + repository: "gitea.scubbo.org/scubbo/pi-temperature-monitoring" pullPolicy: IfNotPresent # Overrides the image tag whose default is the chart appVersion. tag: "" @@ -14,15 +14,6 @@ imagePullSecrets: [] nameOverride: "" fullnameOverride: "" -serviceAccount: - # Specifies whether a service account should be created - create: true - # Annotations to add to the service account - annotations: {} - # The name of the service account to use. - # If not set and create is true, a name is generated using the fullname template - name: "" - podAnnotations: {} podSecurityContext: {} @@ -68,13 +59,6 @@ resources: {} # cpu: 100m # memory: 128Mi -autoscaling: - enabled: false - minReplicas: 1 - maxReplicas: 100 - targetCPUUtilizationPercentage: 80 - # targetMemoryUtilizationPercentage: 80 - nodeSelector: {} tolerations: []