monitoring: read tegrastats per scrape
This commit is contained in:
parent
246ed6617e
commit
a7f3d49fea
@ -17,7 +17,7 @@ spec:
|
||||
annotations:
|
||||
prometheus.io/scrape: "true"
|
||||
prometheus.io/port: "9100"
|
||||
monitoring.bstein.dev/restart-rev: "4"
|
||||
monitoring.bstein.dev/restart-rev: "5"
|
||||
spec:
|
||||
serviceAccountName: default
|
||||
hostPID: true
|
||||
|
||||
@ -7,7 +7,6 @@ from time import time
|
||||
|
||||
PORT = int(os.environ.get("JETSON_EXPORTER_PORT", "9100"))
|
||||
NODE_NAME = os.environ.get("NODE_NAME") or os.uname().nodename
|
||||
LOGFILE = "/tmp/tegrastats.log"
|
||||
BASE_METRICS = {
|
||||
"gr3d_freq_percent": 0.0,
|
||||
"gpu_temp_c": 0.0,
|
||||
@ -39,25 +38,21 @@ def parse_line(line: str) -> dict:
|
||||
updates["power_5v_in_mw"] = float(m.group(1))
|
||||
return updates
|
||||
|
||||
def start_tegrastats():
|
||||
subprocess.Popen(
|
||||
["/host/usr/bin/tegrastats", "--interval", "1000", "--logfile", LOGFILE],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
)
|
||||
|
||||
|
||||
def read_latest_line() -> str:
|
||||
if not os.path.exists(LOGFILE):
|
||||
return ""
|
||||
try:
|
||||
with open(LOGFILE, "rb") as handle:
|
||||
handle.seek(0, os.SEEK_END)
|
||||
size = handle.tell()
|
||||
handle.seek(max(size - 4096, 0), os.SEEK_SET)
|
||||
tail = handle.read().decode("utf-8", errors="ignore").splitlines()
|
||||
return tail[-1] if tail else ""
|
||||
proc = subprocess.Popen(
|
||||
["/host/usr/bin/tegrastats", "--interval", "1000"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
text=True,
|
||||
)
|
||||
line = proc.stdout.readline()
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=1)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
return line
|
||||
except OSError:
|
||||
return ""
|
||||
|
||||
@ -88,6 +83,5 @@ class Handler(http.server.BaseHTTPRequestHandler):
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
start_tegrastats()
|
||||
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
||||
httpd.serve_forever()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user