# services/monitoring/jetson-tegrastats-exporter.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: jetson-tegrastats-exporter
  namespace: monitoring
  labels:
    app: jetson-tegrastats-exporter
spec:
  selector:
    matchLabels:
      app: jetson-tegrastats-exporter
  template:
    metadata:
      labels:
        app: jetson-tegrastats-exporter
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "9100"
        monitoring.bstein.dev/restart-rev: "7"
    spec:
      serviceAccountName: default
      hostPID: true
      tolerations:
        - operator: Exists
      nodeSelector:
        jetson: "true"
      containers:
        - name: exporter
          # Exposes tegrastats output as Prometheus metrics for Jetson devices.
          image: python:3.10-slim
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          ports:
            - name: metrics
              containerPort: 9100
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 200m
              memory: 256Mi
          env:
            - name: JETSON_EXPORTER_PORT
              value: "9100"
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - name: script
              mountPath: /etc/tegrastats-exporter
              readOnly: true
            - name: tegrastats-bin
              mountPath: /host/usr/bin/tegrastats
              readOnly: true
          command:
            - python
            - /etc/tegrastats-exporter/exporter.py
      volumes:
        - name: script
          configMap:
            name: jetson-tegrastats-exporter-script
            defaultMode: 0555
        - name: tegrastats-bin
          hostPath:
            path: /usr/bin/tegrastats
            type: File
---
apiVersion: v1
kind: Service
metadata:
  name: jetson-tegrastats-exporter
  namespace: monitoring
  labels:
    app: jetson-tegrastats-exporter
spec:
  selector:
    app: jetson-tegrastats-exporter
  ports:
    - name: metrics
      port: 9100
      targetPort: metrics
