Commit 1394aa91 authored by Piotr "PHT" Jasiek's avatar Piotr "PHT" Jasiek

add laptop sesnors

parent 8bae8efe
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import datetime
from modules.pcsensors import *
from modules.database import *
####Constant
###Requesting time
request_time = datetime.datetime.now().strftime("%s")
###Requesting sensors
laptop_ram = get_memory_percent()
laptop_hdd = get_disk_percent('/')
laptop_fan_rpm = get_fan_rpm()
laptop_cpu_temp = get_cpu_temp()
##Upload sensor reading
try:
add_record(request_time, 'laptop_ram', laptop_ram)
add_record(request_time, 'laptop_hdd', laptop_hdd)
add_record(request_time, 'laptop_fan_rpm', laptop_fan_rpm)
add_record(request_time, 'laptop_cpu_temp', laptop_cpu_temp)
except:
print "Mysql Errorr"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from psutil import *
from os import *
def get_memory_percent():
ram_percent = virtual_memory().percent
return ram_percent
def get_disk_percent(disk_label):
disk_percent = disk_usage(disk_label).percent
return disk_percent
def get_fan_rpm():
fan_rpm = popen("sensors dell_smm-virtual-0 | grep -i FAN | awk {'print $3'}").read()
return fan_rpm
def get_cpu_temp():
cpu_temp = popen("sensors dell_smm-virtual-0 | grep -i CPU | awk {'print $2'} | sed -e 's/°C//g' | sed -e 's/+//g'").read()
return cpu_temp
#def get_battery_percent():
# battery_percent = sensors_battery().percent
# return battery_percent
#!/usr/bin/env python
import MySQLdb
def add_record(data, sensor, value):
db = MySQLdb.connect("host","user","pass","db" )
cursor = db.cursor()
sql = "INSERT INTO %s (data, value) VALUES ('%s', '%s')" % (sensor, data, value)
try:
cursor.execute(sql)
db.commit()
except:
db.rollback()
db.close()
def get_prev_value(sensor):
db = MySQLdb.connect("host","user","pass","db" )
cursor = db.cursor()
sql = "SELECT value FROM %s ORDER BY id DESC LIMIT 1" % (sensor)
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
prev_temp = row[0]
return prev_temp
print "Error get temp: ", sensor
except:
print "Error: unable to fecth data"
db.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment