Exemplo n.º 1
0
Arquivo: ping.py Projeto: jul/dsat
import sys
from os import path, getpid
from dsat.state import state_wrapper
import psutil

def ping(cnx, arg):
    measure = psutil.network_io_counters().__dict__
    measure["data"] = measure.values()
    return measure

state_wrapper(sys.argv, ping)

Exemplo n.º 2
0
Arquivo: proc.py Projeto: jul/dsat
        key = ( set(x.cmdline()) & interesting) and "me" or "other"
        try:
            procc += dict({key : 1 })
        except:
            pass


        try:
            sum_file += dict({key :x.get_num_fds()})
        except:
            pass

        try:
            sum_connection += dict({ key: sum(x.get_num_ctx_switches())})
        except:
            pass
        try:
            percent_mem += dict({key : x.get_memory_percent() })
        except:
            pass
    ratio = lambda d : min(1,1.0 *d.get("me", 0)/max(.0001,d.get("other",0)))
    absol = lambda d : d.get("me", 0) + d.get("other", 0)
    res=dict(sum_file= sum_file, percent_mem= percent_mem, all_proc =len(all_proc))
    res["data"] = map(ratio, [ sum_file, sum_connection, percent_mem, procc])
    res["data"] += map(absol, [sum_file, sum_connection, percent_mem, procc])
    return res


state_wrapper(sys.argv, proc)

Exemplo n.º 3
0
Arquivo: csvw.py Projeto: jul/dsat
import sys
from dsat.state import state_wrapper

if not len(sys.argv) >= 1:
    raise( Exception("Arg"))

import csv
from os import path


def csvw(cnx, ev, serialization = "simplejson"):
    print ev
    with open(path.join("data", "%(_type)s.csv" % ev ), "a") as f:
        c_write = csv.writer(f)
        c_write.writerow([ int(float(ev["_when"])) ] + ev["data"]  )



state_wrapper(sys.argv, csvw)

Exemplo n.º 4
0
Arquivo: cpu.py Projeto: jul/dsat

def cpu(cnx, arg):
    cpu_f.seek(0)
    _5,_10,_15 = cpu_f.read().split(" ")[:3]
    return { "data" : [ _5,_10,_15], "load" : _5, "5min" : _5, "10min" : _10, "15min" :  _15 }

cntproc = every(60)
cntping = every(30)
cntcsv = every(30)
cntrrd = every(30)
def cpu_clock(ev):
    #try:
    sleep(float(ev['arg']['load']) * .05)
    #except:
    #    pass
    return True

state_wrapper(sys.argv, cpu, bounce_to=["cpu", "proc", "ping"],
    cond_for=dict(
        proc=lambda ev: cntproc.next(),
        csvw = lambda ev: cntcsv.next(),
        rrd = lambda ev: cntrrd.next(),
        ping = lambda ev: cntping.next(),
        cpu = cpu_clock,
    )
)



Exemplo n.º 5
0
Arquivo: rrd.py Projeto: jul/dsat
import json 
from dsat.data import create_rrd_if , open_rrd, write_rrd
from dsat.state import state_wrapper
import sys
cfg = json.load(open("rrd.json"))
rrd_l = dict()

for rrd_db in cfg.keys():
    if rrd_db.startswith("_"):
       continue 
    else:
        print rrd_db
        this_cfg = cfg[rrd_db]
        if isinstance(this_cfg, dict) and cfg[rrd_db].get("source"):
            try:
                create_rrd_if(cfg, rrd_db)
            except IOError:
                pass
            finally:
                print rrd_db
                rrd_l[rrd_db] = lambda : open_rrd(cfg, rrd_db)
last_seen=dict()
def rrd(cnx, ev):
    if last_seen.get(ev["_type"], ev["_when"] ) != ev["_when"]:
        write_rrd(open_rrd(cfg, ev["_type"]), cfg, ev["_type"], ev)
    last_seen[ev["_type"]] = ev["_when"]

state_wrapper(sys.argv, rrd)