Lm sensors monitoring: Skirtumas tarp puslapio versijų

Iš Žinynas.
Jump to navigation Jump to search
 
(Jokio skirtumo)

Dabartinė 19:13, 13 birželio 2019 versija

CPU temperatūrų vidurkis[keisti]

sensors|awk '/^Core /{++r; gsub(/[^[:digit:]]+/, "", $3); s+=$3} END{print s/(10*r) "°C"}'

Network wide scriptas[keisti]

#!/usr/bin/python2.7
# HW Reporting REST API
# (c) 2018-2019 justinas@eofnet.lt
# INSTALL: apt-get install python-pip; pip install python-daemon bottle
import sys, os
from time import sleep
import argparse
import daemon
import logging
import subprocess
import json
import re
from bottle import run, post, request, response, get, route

if not os.getegid() == 0:
      sys.exit('Script must be run as root')

def measure_temp():
        cmd = os.popen("sensors|awk '/^Core /{++r; gsub(/[^[:digit:]]+/, \"\", $3); s+=$3} END{print s/(10*r)}'").read().strip()
        temp = round(float(cmd),2)
        return temp

def daemonize():
            print ("Daemonizing..")
            @route('/temp')
            def returntemp():
               temp = measure_temp()
               respond = { "answer": temp }
               return json.dumps(respond)
            run(host='0.0.0.0', port=1414, debug=False)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='HW info REST API (c) 2019 justinas@eofnet.lt, EOFNET LAB10',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--temp', action='store_true')
    parser.add_argument('--daemonize',action='store_true')
    args = parser.parse_args()
    try:
       if args.temp:
         print measure_temp()
       elif args.daemonize:
         daemonize()
       else:
          print "No arguments specified"
    except KeyboardInterrupt:
        pass

Servisas

[Unit]
Description=Power Switch Relay Network Service
After=network.target


[Service]
Type=simple
ExecStart=/usr/local/bin/hw_info.py --daemonize

[Install]
WantedBy=multi-user.target