def update_cpu(rrd): physicals = cpus() cores = cpu_cores() load = cpu_load() print(load) # update all db_all = db_path + rrd['cpu'] load_all = load['all'] update_cpu_db(db_all, load_all) graph(rrd,'cpu') # Check hyper-threading if check_ht() == 1: cores = cores * 2 # update cores db count = 0 while count < cores: core_load = load[str(count)] core_db = db_path + str(count) + rrd['cpu'] update_cpu_db(core_db, core_load) count = count + 1 graph(rrd, 'cpu') graph(rrd, 'cpu_cores')
def create_cpu(rrd): cores = cpu_cores() # Check hyper threading if check_ht() == 1: cores = cores * 2 # Create all load avverage base create_cpu_all(rrd) # Create bases for cores count = 0 while count < cores: db = db_path + str(count) + rrd['cpu'] create_core(db) count = count + 1
def graph_cpu(rrd): png = png_path + "cpu" + ".png" db = rrd # " rrdtool graph /var/www/luci-static/resources/cpu".. i ..".png " .. # " -e now " .. # " -s 'end - 6 hours' " .. # " -S 60" .. # " --title 'CORE-" .. core.." USAGE'" .. # " --vertical-label 'Percents' " .. # " --imgformat PNG".. # " --slope-mode" .. # " --lower-limit 0 " .. # " --upper-limit 100 " .. # " --rigid " .. # " -E " .. # " -i " .. # " --color CANVAS#EEEEEE " .. # " --color SHADEA#FFFFFF " .. # " --color SHADEB#FFFFFF " .. # " --color BACK#CCCCCC" .. # " -w 500 " .. # " -h 300 " .. # " --interlaced" .. # " DEF:c=/var/lib/collectd/rrd/" .. hostname .. "/cpu-"..i.."/cpu-idle.rrd:value:MAX" .. # " DEF:b=/var/lib/collectd/rrd/" .. hostname .. "/cpu-"..i.."/cpu-system.rrd:value:MAX" .. # " DEF:a=/var/lib/collectd/rrd/" .. hostname .. "/cpu-"..i.."/cpu-user.rrd:value:MAX" .. # " DEF:d=/var/lib/collectd/rrd/" .. hostname .. "/cpu-"..i.."/cpu-wait.rrd:value:MAX" .. # " AREA:c#F7FF00:Idle " .. # " LINE1:a#200320: AREA:a#540048:User " .. # " LINE1:b#2cc320: AREA:b#54eb48:System " .. # " LINE1:b#FF0000:Wait " .. # " >>/dev/null 2>>/dev/null;" # rrdtool.graph(png, '--start', '-46000', '--width', '300', '-h', '150', # '--vertical-label=Percents', # '-S 60', # '--slope-mode', # '--rigid', # '--watermark=OpenSAN2', # '--dynamic-labels', # '--lower-limit', '0', '-E', '-i', # #'-r', # '--upper-limit','100', # 'DEF:sys='+db+':sys:AVERAGE', # 'DEF:user='******':user:AVERAGE', # 'CDEF:s=sys,10000000,/', # 'CDEF:u=user,10000000,/', # 'AREA:u#54eb48:System', # 'AREA:s#540048:User' # ) physicals = cpus() cores = get_cores_by_phys() all_load_db = db_path + rrd["cpu"] # Check hyper-threading if check_ht() == 1: cores = cores * 2 # generate all load average graphic png = png_path + "All" + rrd["cpu"] + ".png" generate_cpu(png, all_load_db, "All") # Cores processing # If only one physical CPU in system # we creating only one graphic: # load average by core if physicals == 1: core_db = {} c = 0 while c < cores: num = str(c) core_db[str(c)] = {"db": db_path + str(c) + rrd["cpu"], "png": png_path + str(c) + rrd["cpu"] + ".png"} c += 1 # Generate graph # type(third position) can will be single or smp generate_core(core_db, num, cores, "single") print "Generate core graph"