CPU Temperaturen auslesen und per Metric Server an InfluxDB übergeben?

InShield

Member
Nov 20, 2020
34
2
13
44
Ja die Überschrift sagt eigentlich alles: Ich möchte gerne die CPU Kern Temperaturen monitoren, diese also mit dem Proxmox Metric Server an meine InfluxDB übergeben.

Xsensors habe ich bereits installiert und dort werden die Kerntemperaturen auch korrekt ausgelesen. Kann ich diese irgendwie zusätzlich an den Metric Server übergeben?

Code:
coretemp-isa-0001
Adapter: ISA adapter
Package id 1:  +64.0°C  (high = +75.0°C, crit = +85.0°C)
Core 0:        +56.0°C  (high = +75.0°C, crit = +85.0°C)
Core 1:        +57.0°C  (high = +75.0°C, crit = +85.0°C)
Core 2:        +55.0°C  (high = +75.0°C, crit = +85.0°C)
Core 3:        +56.0°C  (high = +75.0°C, crit = +85.0°C)
Core 4:        +57.0°C  (high = +75.0°C, crit = +85.0°C)
Core 5:        +55.0°C  (high = +75.0°C, crit = +85.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Package id 0:  +62.0°C  (high = +75.0°C, crit = +85.0°C)
Core 0:        +55.0°C  (high = +75.0°C, crit = +85.0°C)
Core 1:        +54.0°C  (high = +75.0°C, crit = +85.0°C)
Core 2:        +54.0°C  (high = +75.0°C, crit = +85.0°C)
Core 3:        +57.0°C  (high = +75.0°C, crit = +85.0°C)
Core 4:        +56.0°C  (high = +75.0°C, crit = +85.0°C)
Core 5:        +55.0°C  (high = +75.0°C, crit = +85.0°C)

Ich habe eine Telegraf Installation auf einer VM am Laufen aber für das Plugin "LM Sensors Input Plugin" müsste ja dann direkt auf dem Proxmox laufen damit ich die Daten damit ausgelesen bekomme.

Vielleicht hat ja einer ne Idee wie das am Einfachsten klappt :)

Wundert mich ohnehin etwas, dass die CPU Temperatur noch nirgends angezeigt wird im Proxmox. Ist ja keine ganz irrelevante Information.
Scheinbar wurde auch schon mal eine Anfrage zur Integration gestellt, wie ich im Forum irgendwo lesen konnte.
 
Ich denke mal das hat einfach keine hohe Priorität. Im professionellen Umfeld (und da kommen ja wohl die meisten Einnahmen her) werden ja eigentlich Server eingesetzt und die haben dann normal auch ein Fernwartungsmodul und man könnte die CPU Temperatur, Spannungen, Lüfterdrwhzahlen und Co auch remote über IPMI oder SNMP auslesen ohne das der Proxmox Host selbst etwas bereitstellen müsste.
 
Ich denke mal das hat einfach keine hohe Priorität. Im professionellen Umfeld (und da kommen ja wohl die meisten Einnahmen her) werden ja eigentlich Server eingesetzt und die haben dann normal auch ein Fernwartungsmodul und man könnte die CPU Temperatur, Spannungen, Lüfterdrwhzahlen und Co auch remote über IPMI oder SNMP auslesen ohne das der Proxmox Host selbst etwas bereitstellen müsste.
das, und die tatsache das die sensoren sehr hardware und firmware spezifisch sind..
 
Ich denke mal das hat einfach keine hohe Priorität. Im professionellen Umfeld (und da kommen ja wohl die meisten Einnahmen her) werden ja eigentlich Server eingesetzt und die haben dann normal auch ein Fernwartungsmodul und man könnte die CPU Temperatur, Spannungen, Lüfterdrwhzahlen und Co auch remote über IPMI oder SNMP auslesen ohne das der Proxmox Host selbst etwas bereitstellen müsste.
In meinem Fall habe ich auch einen Dell r730xd im Einsatz. Nur ist das SNMP Plugin von Telegraf ziemlich lahm. Daher suche ich nach einer Alternativen Lösung, wie ich die Temperaturen monitoren kann. Geht das mit IPMI vielleicht schneller / einfacher? Oder gibt es noch weitere Wege wie ich die auf nem Dell Server auslesen könnte?

@fabian: Da hast du natürlich Recht, dass dies oft alles sehr unterschiedlich und daher schwerer zu integrieren ist.

@bluesite: Danke für den Link. Ich werde mir das auch mal ansehen, aber sieht nach ziemlich viel Gefrickel aus :-D
 
ich werde es später mal testen wenn ich wieder zu Hause bis von der Arbeit, habe eh schon influxdb und grafana am Laufen als lxc damit monitore ich meinen proxmox, 3 usv und die Fritzbox
ich muss dann nur ne neue db erstellen inkl User und Passwort und dann das Python Script ausführen bzw vielleicht etwas anpassen ob alle Kerne damit überwacht werden
 
Ich habe das hier beschrieben. Du brauchst lm-sensors und eine lokale installation von Telegraf. Ich nutze das auch, um Smart HDD auszulesen bzw. meine APC USV. In dem Paket macht das mehr Sinn als nur die Temperaturen über IPMI zu bekommen.
 
Last edited:
  • Like
Reactions: Vertex and InShield
so ich habe meins nun fertig, es benötigt nur influxdb und grafana und einen cronjob der die Werte einmal pro Minute ausliest
bei mir hat meine CPU 4 Kerne

Cronjob:
Code:
* * * * *            /var/www/temp.php >/dev/null 2>&1

die Datei heißt temp.php

Code:
#!/usr/bin/php
<?php
$command0 = "sensors | grep 'Core 0:' | awk '{print $3}' | cut -c2-3";
$command1 = "sensors | grep 'Core 1:' | awk '{print $3}' | cut -c2-3";
$command2 = "sensors | grep 'Core 2:' | awk '{print $3}' | cut -c2-3";
$command3 = "sensors | grep 'Core 3:' | awk '{print $3}' | cut -c2-3";
$temp0 = shell_exec($command0);
$temp1 = shell_exec($command1);
$temp2 = shell_exec($command2);
$temp3 = shell_exec($command3);
$curl = "curl -i -XPOST 'http://192.168.10.18:8086/write?db=cpu' --data-binary 'cpu,host=pve Temp0=".$temp0."'";
$execsr = exec($curl);
$curl = "curl -i -XPOST 'http://192.168.10.18:8086/write?db=cpu' --data-binary 'cpu,host=pve Temp1=".$temp1."'";
$execsr = exec($curl);
$curl = "curl -i -XPOST 'http://192.168.10.18:8086/write?db=cpu' --data-binary 'cpu,host=pve Temp2=".$temp2."'";
$execsr = exec($curl);
$curl = "curl -i -XPOST 'http://192.168.10.18:8086/write?db=cpu' --data-binary 'cpu,host=pve Temp3=".$temp3."'";
$execsr = exec($curl);
?>

in influx habe ich eine Datenbank erstellt und einen User dazu mit dem Namen cpu

im Grafana dann eine Datenquelle hinzugefügt

der Code von Grafana sieht bei mir so aus:

Code:
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": "-- Grafana --",
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "gnetId": null,
  "graphTooltip": 0,
  "id": 24,
  "links": [],
  "panels": [
    {
      "datasource": "CPUTemp",
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "continuous-RdYlGr"
          },
          "custom": {
            "axisLabel": "",
            "axisPlacement": "auto",
            "barAlignment": 0,
            "drawStyle": "line",
            "fillOpacity": 8,
            "gradientMode": "opacity",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineInterpolation": "smooth",
            "lineStyle": {
              "dash": [
                10,
                10
              ],
              "fill": "dash"
            },
            "lineWidth": 3,
            "pointSize": 6,
            "scaleDistribution": {
              "type": "linear"
            },
            "showPoints": "auto",
            "spanNulls": true,
            "stacking": {
              "group": "A",
              "mode": "none"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "max": 55,
          "min": 35,
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "celsius"
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Core0"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "dark-green",
                  "mode": "fixed"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Core1"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "yellow",
                  "mode": "fixed"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Core2"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "blue",
                  "mode": "fixed"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 32,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 2,
      "options": {
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom"
        },
        "tooltip": {
          "mode": "single"
        }
      },
      "targets": [
        {
          "alias": "Core0",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"Temp0\") FROM \"cpu\" WHERE $timeFilter GROUP BY time($__interval) fill(null)",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "Temp0"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        },
        {
          "alias": "Core1",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "hide": false,
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"Temp1\") FROM \"cpu\" WHERE $timeFilter GROUP BY time($__interval) fill(null)",
          "rawQuery": false,
          "refId": "B",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "Temp1"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        },
        {
          "alias": "Core2",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "hide": false,
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"Temp2\") FROM \"cpu\" WHERE $timeFilter GROUP BY time($__interval) fill(null)",
          "rawQuery": false,
          "refId": "C",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "Temp2"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        },
        {
          "alias": "Core3",
          "groupBy": [
            {
              "params": [
                "$__interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "hide": false,
          "measurement": "cpu",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT mean(\"Temp3\") FROM \"cpu\" WHERE $timeFilter GROUP BY time($__interval) fill(null)",
          "rawQuery": false,
          "refId": "D",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "Temp3"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "CPU Temp",
      "type": "timeseries"
    }
  ],
  "refresh": false,
  "schemaVersion": 30,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "",
  "title": "CPU Temp",
  "uid": "LyjToRvnz",
  "version": 8
}

1633103076647.png
 
Last edited:
  • Like
Reactions: InShield and Dunuin
Hi, ich hab das Grundscript in Python etwas für mich angepasst, damit proxmox mit influxdb2 kommuniziert.
Evtl benötigt das ja mal jemand hier...
Funktioniert, ist aber bestimmt noch nicht die beste lösung. Denke die send commands kann man noch schöner in einer for Schleife oder so abarbeiten.

Python:
#!/usr/bin/env python3
import os
import socket
import subprocess
from datetime import datetime

from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

# You can generate an API token from the "API Tokens Tab" in the UI
token = "<INPUT TOKEN HERE>"
org = "<INPUT ORGANISATION>"
bucket = "<INPUT BUCKET NAME>"

#CORES
cmd00 = "sensors | grep 'Core 0:' | awk '{print $3}' | cut -c2-3"
cmd01 = "sensors | grep 'Core 1:' | awk '{print $3}' | cut -c2-3"
cmd02 = "sensors | grep 'Core 2:' | awk '{print $3}' | cut -c2-3"
cmd03 = "sensors | grep 'Core 3:' | awk '{print $3}' | cut -c2-3"
cmd04 = "sensors | grep 'Core 4:' | awk '{print $3}' | cut -c2-3"
cmd05 = "sensors | grep 'Core 5:' | awk '{print $3}' | cut -c2-3"
#NVME
cmd06 = "sensors | grep 'Composite:' | awk '{print $2}' | cut -c2-5"
#GPU
#cmd07 = "sensors | grep 'GPU core:' | awk '{print $3}' | cut -c1-5"
#cmd08 = "sensors | grep 'fan1:' | awk '{print $2}' | cut -c1-5"
#cmd09 = "sensors | grep 'temp1:' | awk '{print $2}' | cut -c2-5"
#cmd10 = "sensors | grep 'power1:' | awk '{print $2}' | cut -c1-5"
#HDD
#cmd11 = "smartctl -a /dev/sda | grep 'Temperature_Celsius' | awk '{print $10}' | cut -c1-5"
#cmd12 = "smartctl -a /dev/sdb | grep 'Temperature_Celsius' | awk '{print $10}' | cut -c1-5"

output00 = subprocess.run(cmd00, shell=True, capture_output=True)
output01 = subprocess.run(cmd01, shell=True, capture_output=True)
output02 = subprocess.run(cmd02, shell=True, capture_output=True)
output03 = subprocess.run(cmd03, shell=True, capture_output=True)
output04 = subprocess.run(cmd04, shell=True, capture_output=True)
output05 = subprocess.run(cmd05, shell=True, capture_output=True)
output06 = subprocess.run(cmd06, shell=True, capture_output=True)
#output07 = subprocess.run(cmd07, shell=True, capture_output=True)
#output08 = subprocess.run(cmd08, shell=True, capture_output=True)
#output09 = subprocess.run(cmd09, shell=True, capture_output=True)
#output10 = subprocess.run(cmd10, shell=True, capture_output=True)
#output11 = subprocess.run(cmd11, shell=True, capture_output=True)
#output12 = subprocess.run(cmd12, shell=True, capture_output=True)

stdout00 = float(output00.stdout.decode('utf-8'))
stdout01 = float(output01.stdout.decode('utf-8'))
stdout02 = float(output02.stdout.decode('utf-8'))
stdout03 = float(output03.stdout.decode('utf-8'))
stdout04 = float(output04.stdout.decode('utf-8'))
stdout05 = float(output05.stdout.decode('utf-8'))
stdout06 = float(output06.stdout.decode('utf-8'))
#stdout07 = float(output07.stdout.decode('utf-8'))
#stdout08 = float(output08.stdout.decode('utf-8'))
#stdout09 = float(output09.stdout.decode('utf-8'))
#stdout10 = float(output10.stdout.decode('utf-8'))
#stdout11 = float(output11.stdout.decode('utf-8'))
#stdout12 = float(output12.stdout.decode('utf-8'))


with InfluxDBClient(url="http://<INPUT IP-INFLUXDB>:8086", token=token, org=org) as client:
    write_api = client.write_api(write_options=SYNCHRONOUS)

point00 = Point("temp") \
  .tag("host", "value") \
  .field("core0", stdout00) \
  .time(datetime.utcnow(), WritePrecision.NS)

point01 = Point("temp") \
  .tag("host", "value") \
  .field("core1", stdout01) \
  .time(datetime.utcnow(), WritePrecision.NS)

point02 = Point("temp") \
  .tag("host", "value") \
  .field("core2", stdout02) \
  .time(datetime.utcnow(), WritePrecision.NS)

point03 = Point("temp") \
  .tag("host", "value") \
  .field("core3", stdout03) \
  .time(datetime.utcnow(), WritePrecision.NS)

point04 = Point("temp") \
  .tag("host", "value") \
  .field("core4", stdout04) \
  .time(datetime.utcnow(), WritePrecision.NS)

point05 = Point("temp") \
  .tag("host", "value") \
  .field("core5", stdout05) \
  .time(datetime.utcnow(), WritePrecision.NS)

point06 = Point("temp") \
  .tag("host", "value") \
  .field("nvme1", stdout06) \
  .time(datetime.utcnow(), WritePrecision.NS)

write_api.write(bucket, org, point00)
write_api.write(bucket, org, point01)
write_api.write(bucket, org, point02)
write_api.write(bucket, org, point03)
write_api.write(bucket, org, point04)
write_api.write(bucket, org, point05)
write_api.write(bucket, org, point06)

client.close()
 
Last edited:
Hi, ich teste gerade Proxmox auf dem Raspberry Pi4.
Habe dafür den code angepasst:

Python:
#!/usr/bin/env python3

#/usr/temperatures.py

import os

import socket

import subprocess

from datetime import datetime


from influxdb_client import InfluxDBClient, Point, WritePrecision

from influxdb_client.client.write_api import SYNCHRONOUS


# You can generate an API token from the "API Tokens Tab" in the UI

token = "<INPUT TOKEN HERE>"

org = "<INPUT ORGANISATION>"

bucket = "<INPUT BUCKET NAME>"


#CORES

cmd00 = "sensors | grep 'temp1:' | awk '{print $2}' | cut -c2-5"

output00 = subprocess.run(cmd00, shell=True, capture_output=True)


stdout00 = float(output00.stdout.decode('utf-8'))


with InfluxDBClient(url="http://<INPUT IP-INFLUXDB>:8086", token=token, org=org) as client:

        write_api = client.write_api(write_options=SYNCHRONOUS)


point00 = Point("temp") \

  .tag("host", "value") \

  .field("core0", stdout00) \

  .time(datetime.utcnow(), WritePrecision.NS)


write_api.write(bucket, org, point00)



client.close()
 
Hallo zusammen,
ich habe mal chatgpt eine schleife bauen lassen und das ganze etwas CPU freundlicher basteln lassen.
Mein erster versuch hat meine CPU +20°C gekostet^^

Python:
#!/usr/bin/env python3
import subprocess
import time

from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

# InfluxDB Konfiguration
token = "token"
org = "org"
bucket = "bucket"
client = InfluxDBClient(url="http://IP:8086", token=token, org=org)
write_api = client.write_api(write_options=SYNCHRONOUS)

# Sensoren Konfiguration
core_cmds = ["sensors | grep 'Core %d:' | awk '{print $3}' | cut -c2-3" % i for i in range(4)]
package_cmd = "sensors | grep 'Package id 0:' | awk '{print $4}' | cut -c2-3"

while True:
    # Sensorwerte abrufen
    core_temps = [float(subprocess.check_output(cmd, shell=True).decode('utf-8')) for cmd in core_cmds]
    package_temp = float(subprocess.check_output(package_cmd, shell=True).decode('utf-8'))

    # InfluxDB Eintrag erstellen und schreiben
    timestamp = int(time.time() * 1e9) # Nanosekunden seit Epoch
    for i, temp in enumerate(core_temps):
        point = Point("temp") \
            .tag("host", "value") \
            .field(f"core{i}", temp) \
            .time(timestamp, WritePrecision.NS)
        write_api.write(bucket, org, point)
    point = Point("temp") \
        .tag("host", "value") \
        .field("package", package_temp) \
        .time(timestamp, WritePrecision.NS)
    write_api.write(bucket, org, point)

    time.sleep(10) # 10 Sekunden warten

Danach habe ich noch ein service erstellt in /etc/systemd/system/DATEI.service.

Code:
[Unit]
Description=Test Service
After=multi-user.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python3 /PFAD/DATEI.service

[Install]
WantedBy=multi-user.target

Jetzt ein paar befehle:

systemctl daemon-reload

systemctl enable DATEI.service

systemctl start DATEI.service

Zum überprüfen, ob der service läuft.
systemctl status DATEI.service
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!