Пример #1
0
import json
import pycurl
import cStringIO
import devstatus
from mylogger import iotlogger

logger = iotlogger(loggername="Uploader")

def getStatus():
    """
    Obtain device status from `devstatus`
    Returns
    -------
    status_ping
        json dump of dictionary contatining status
        of the device
    """
    try:
        return devstatus.stats()
    except Exception as ex:
        logger.error("Could not obtain Device Status: "+str(ex))

def uploadStatus(status, server="http://localhost:8888/status_upload"):
    """
    Upload Status
    Parameters
    ----------
    status: json dump
        json.dumps(<status_str / dict>)
    server: str
        full uri of the server location to upload to
Пример #2
0
import re
import psutil
import misc
import socket
import datetime
import pytz
from mylogger import iotlogger

logger = iotlogger(loggername="DevStatus")

def handle_exception(function):
    def wrapper_function(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except Exception as e:
            logger.error("Error with " + str(function.func_name) + ":" + str(e), exc_info=True)
            return {}
    return wrapper_function

@handle_exception
def cpuStats():
    logger.debug('Obtaining cpustats')
    cpu_stats = {'cpu_cur_freq': str(psutil.cpu_freq().current).replace('L', ''),
                 'cpu_load': psutil.cpu_percent(percpu=False),
    }
    return cpu_stats

@handle_exception
def memoryStats():
    logger.debug('Obtaining memstats')
    mem = psutil.virtual_memory()
Пример #3
0
import os
import subprocess
from mylogger import iotlogger

logger = iotlogger(loggername="misc")


def execute(command=None,
            std_in=subprocess.PIPE,
            std_out=subprocess.PIPE,
            std_err=subprocess.PIPE):
    """
    Execute shell commands

    Parameters
    ----------
    command: list
        command string should be split at every space
        and be passed as a list
    Returns
    -------
    out: str
        string output of the command
    err: bool
        True if error was raised in executing the command
    """
    logger.debug("Executing: " + " ".join(command))
    out = err = False
    try:
        proc = subprocess.Popen([cmd for cmd in command],
                                stdin=std_in,