Exemple #1
0
def draw():
    os.environ['TZ'] = 'Asia/Shanghai'
    type = request.args.get('type')
    region = request.args.get('region')
    hostname = request.args.get('host')
    if type == 'ali_ecs': 
        dir = r"/data/apps/rrd_db"
        rpath = os.path.join(dir, 'ali_'+region, hostname)
    if type == 'ali_rds': 
        dir = r"/data/apps/rrd_db/rds"
        rpath = os.path.join(dir, region, hostname)
    #pngdir = r"/data/apps/rrd_db/static/images/rrdpng"
    pngdir = r"static/images/rrdpng"
    strtime = str(int(time.time()- 86400))
    gdatas = []
    pngs = []
    graph_q = db.session.query(DrawTree.graphname).filter_by(type=type).filter_by(region=region).filter_by(hostname=hostname).all()
    for graph in graph_q:
        graphname = graph[0]
        ppath = os.path.join(pngdir, hostname)
        if not os.path.exists(ppath):
            os.makedirs(ppath)
        graphs = graphname.split(',')
        for dsname in graphs:
            item_q = db.session.query(DrawGraphs.itemname,DrawGraphs.units).filter_by(dsname=dsname).all()
            for item in item_q:
                dss = item[:-1][0]
                unit = item[-1:][0]
                ds = dss.split(',')
            rfile = os.path.join(rpath, dsname+'.rrd')
            pfile = 'images/rrdpng/'+hostname+'/'+dsname+'.png'
            pname = os.path.join(ppath, dsname+'.png')
            gdata = {'pname':pname, 'gname':dsname, 'rrdpath':rfile, 'pitem':ds, 'flag':'Daily', 'stime':strtime, 'host':hostname, 'cols':'', 'itypes':'','unit':unit}
            url_img = url_for('static', filename=pfile)
            pngs.append({'pngpath':url_img, 'drawal':type+'&'+region+'&'+hostname+'&'+dsname})
            print "----graphing ",rfile
            if len(gdata['pitem']) == 1: graphsub.dItem01(gdata)
            if len(gdata['pitem']) == 2: graphsub.dItem02(gdata)
            if len(gdata['pitem']) == 3: graphsub.dItem03(gdata)
            if len(gdata['pitem']) == 4: graphsub.dItem04(gdata)
            if len(gdata['pitem']) == 5: graphsub.dItem05(gdata)
            if len(gdata['pitem']) == 6: graphsub.dItem06(gdata)
            if len(gdata['pitem']) == 7: graphsub.dItem07(gdata)
        #graphsub.dmanage(gdata)
    return render_template('drawgraph.html', pngs=pngs)
def graph():
    #services = ['est_tcp', 'total_processes', 'memory_usage', 'root_partition', 'load_5min', 'ping_package_loss','network_eth0']
    #date = time.strftime('%Y-%m-%d',time.localtime(time.time()))
    strtime = str(int(time.time()- 86400))
    DSS = {"est_tcp":"DS:est_tcp:GAUGE:600:0:U",
          "total_processes":"DS:total_processes:GAUGE:600:0:U",
          "memory":"DS:memory_free:GAUGE:600:0:U,DS:memory_used:GAUGE:600:0:U",
          "disk_free":"DS:root:GAUGE:600:0:U,DS:root_dev_shm:GAUGE:600:0:U,DS:root_data:GAUGE:600:0:U",
          "load":"DS:load_1min:GAUGE:600:0:U,DS:load_5min:GAUGE:600:0:U,DS:load_15min:GAUGE:600:0:U",
          "ping":"DS:ping_rta:GAUGE:600:0:U",
          "network_eth0":"DS:network_rx:GAUGE:600:0:U,DS:network_tx:GAUGE:600:0:U",
          "memory_percent":"DS:memory_percent:GAUGE:120:0:100",
          "disk_percent":"DS:root_percent:GAUGE:120:0:100,DS:data_percent:GAUGE:120:0:100",
          "ping_percent":"DS:ping_percent:GAUGE:120:0:100",
          "api_ops":"DS:api_ops:GAUGE:60:0:U"}
    for host in os.listdir(BASE_RRD):
        data = {}
        #pitem = []
        rrddir = os.path.join(BASE_RRD, host)
        pngdir = os.path.join(BASE_PNG, host)
        if not os.path.exists(pngdir):
    	        os.mkdir(pngdir)
        for rrdfile in os.listdir(rrddir):
            rrdpath = os.path.join(rrddir, rrdfile)
            service = rrdfile.split('.')[0]
            DS = DSS[service]
                
            pitem = [i.split(':')[1] for i in DS.split(',') ]
                #for d in ds:
                    
            pngfile = os.path.join(pngdir, service + '.png')
            #title="%s for %s  (update:%s)" % (service, host, date)
            #if service == 'est_tcp':
                
            gdata = {'pname':pngfile, 'gname':service, 'rrdpath':rrdpath, 'pitem':pitem, 'flag':'Daily', 'stime':strtime, 'host':host, 'cols':'', 'itypes':''}
            if len(pitem) == 1: graphsub.dItem01(gdata)
            if len(pitem) == 2: graphsub.dItem02(gdata)
            if len(pitem) == 3: graphsub.dItem03(gdata)
            if len(pitem) == 4: graphsub.dItem04(gdata)
Exemple #3
0
def drawall(drawal):
    os.environ['TZ'] = 'Asia/Shanghai'
    gdatas = []
    pngs = []
    dir_tmp = "/data/apps/rrd_db"
    pngdir = "images/rrdpng/cache"
    png_tmp = drawal.split('&')
    type = png_tmp[0]
    region = png_tmp[1]
    hostname = png_tmp[2]
    dsname = png_tmp[3]
    if type == 'ali_ecs':
        rpath = os.path.join(dir_tmp, 'ali_' + region, hostname,
                             dsname + ".rrd")
    if type == 'ali_rds':
        rpath = os.path.join(dir_tmp, 'rds', region, hostname, dsname + ".rrd")
    ppath = os.path.join('static/' + pngdir, hostname)
    fdir = os.path.join(pngdir, hostname)
    if not os.path.exists(ppath):
        os.makedirs(ppath)
    png2d = os.path.join(ppath, dsname + "_2d.png")
    f2d = os.path.join(fdir, dsname + "_2d.png")
    url2d = url_for('static', filename=f2d)
    pngs.append(url2d)
    png1w = os.path.join(ppath, dsname + "_1w.png")
    f1w = os.path.join(fdir, dsname + "_1w.png")
    url1w = url_for('static', filename=f1w)
    pngs.append(url1w)
    png1m = os.path.join(ppath, dsname + "_1m.png")
    f1m = os.path.join(fdir, dsname + "_1m.png")
    url1m = url_for('static', filename=f1m)
    pngs.append(url1m)
    png1y = os.path.join(ppath, dsname + "_1y.png")
    f1y = os.path.join(fdir, dsname + "_1y.png")
    url1y = url_for('static', filename=f1y)
    pngs.append(url1y)
    #    #######################################################
    item_q = db.session.query(DrawGraphs.itemname,
                              DrawGraphs.units).filter_by(dsname=dsname).all()
    for item in item_q:
        dss = item[:-1][0].split(',')
        unit = item[-1:][0]


#    ###########################
    strtime = str(int(time.time() - 172800))
    gdata = {
        'pname': png2d,
        'gname': dsname,
        'rrdpath': rpath,
        'pitem': dss,
        'unit': unit,
        'cols': '',
        'itypes': '',
        'host': hostname,
        'stime': strtime,
        'flag': '2 Days'
    }
    gdatas.append(gdata)
    #    ###########################
    strtime = str(int(time.time() - 604800))
    gdata = {
        'pname': png1w,
        'gname': dsname,
        'rrdpath': rpath,
        'pitem': dss,
        'unit': unit,
        'cols': '',
        'itypes': '',
        'host': hostname,
        'stime': strtime,
        'flag': 'Weekly'
    }
    gdatas.append(gdata)
    ###########################
    strtime = str(int(time.time() - 2592000))
    gdata = {
        'pname': png1m,
        'gname': dsname,
        'rrdpath': rpath,
        'pitem': dss,
        'unit': unit,
        'cols': '',
        'itypes': '',
        'host': hostname,
        'stime': strtime,
        'flag': 'Monthly'
    }
    gdatas.append(gdata)
    ###########################
    strtime = str(int(time.time() - 31536000))
    gdata = {
        'pname': png1y,
        'gname': dsname,
        'rrdpath': rpath,
        'pitem': dss,
        'unit': unit,
        'cols': '',
        'itypes': '',
        'host': hostname,
        'stime': strtime,
        'flag': 'Yearly'
    }
    gdatas.append(gdata)
    ##########################
    #print gdatas,'---',pngs
    for gdata in gdatas:
        #if os.path.isfile(gdata['pname']): os.remove(gdata['pname'])
        print "----graphing ", gdata['pname']
        if len(gdata['pitem']) == 1: graphsub.dItem01(gdata)
        if len(gdata['pitem']) == 2: graphsub.dItem02(gdata)
        if len(gdata['pitem']) == 3: graphsub.dItem03(gdata)
        if len(gdata['pitem']) == 4: graphsub.dItem04(gdata)
        if len(gdata['pitem']) == 5: graphsub.dItem05(gdata)
        if len(gdata['pitem']) == 6: graphsub.dItem06(gdata)
        if len(gdata['pitem']) == 7: graphsub.dItem07(gdata)
    return render_template('drawall.html', pngs=pngs)
Exemple #4
0
def draw():
    os.environ['TZ'] = 'Asia/Shanghai'
    type = request.args.get('type')
    region = request.args.get('region')
    hostname = request.args.get('host')
    if type == 'ali_ecs':
        dir = r"/data/apps/rrd_db"
        rpath = os.path.join(dir, 'ali_' + region, hostname)
    if type == 'ali_rds':
        dir = r"/data/apps/rrd_db/rds"
        rpath = os.path.join(dir, region, hostname)
    #pngdir = r"/data/apps/rrd_db/static/images/rrdpng"
    pngdir = r"static/images/rrdpng"
    strtime = str(int(time.time() - 86400))
    gdatas = []
    pngs = []
    graph_q = db.session.query(DrawTree.graphname).filter_by(
        type=type).filter_by(region=region).filter_by(hostname=hostname).all()
    for graph in graph_q:
        graphname = graph[0]
        ppath = os.path.join(pngdir, hostname)
        if not os.path.exists(ppath):
            os.makedirs(ppath)
        graphs = graphname.split(',')
        for dsname in graphs:
            item_q = db.session.query(
                DrawGraphs.itemname,
                DrawGraphs.units).filter_by(dsname=dsname).all()
            for item in item_q:
                dss = item[:-1][0]
                unit = item[-1:][0]
                ds = dss.split(',')
            rfile = os.path.join(rpath, dsname + '.rrd')
            pfile = 'images/rrdpng/' + hostname + '/' + dsname + '.png'
            pname = os.path.join(ppath, dsname + '.png')
            gdata = {
                'pname': pname,
                'gname': dsname,
                'rrdpath': rfile,
                'pitem': ds,
                'flag': 'Daily',
                'stime': strtime,
                'host': hostname,
                'cols': '',
                'itypes': '',
                'unit': unit
            }
            url_img = url_for('static', filename=pfile)
            pngs.append({
                'pngpath':
                url_img,
                'drawal':
                type + '&' + region + '&' + hostname + '&' + dsname
            })
            print "----graphing ", rfile
            if len(gdata['pitem']) == 1: graphsub.dItem01(gdata)
            if len(gdata['pitem']) == 2: graphsub.dItem02(gdata)
            if len(gdata['pitem']) == 3: graphsub.dItem03(gdata)
            if len(gdata['pitem']) == 4: graphsub.dItem04(gdata)
            if len(gdata['pitem']) == 5: graphsub.dItem05(gdata)
            if len(gdata['pitem']) == 6: graphsub.dItem06(gdata)
            if len(gdata['pitem']) == 7: graphsub.dItem07(gdata)
        #graphsub.dmanage(gdata)
    return render_template('drawgraph.html', pngs=pngs)
Exemple #5
0
def drawall(drawal):
    os.environ['TZ'] = 'Asia/Shanghai'
    gdatas = []
    pngs = []
    dir_tmp = "/data/apps/rrd_db"
    pngdir = "images/rrdpng/cache"
    png_tmp = drawal.split('&')
    type = png_tmp[0]
    region = png_tmp[1]
    hostname = png_tmp[2]
    dsname = png_tmp[3]
    if type == 'ali_ecs':
        rpath = os.path.join(dir_tmp, 'ali_'+region, hostname, dsname+".rrd")
    if type == 'ali_rds':
        rpath = os.path.join(dir_tmp, 'rds', region, hostname, dsname+".rrd")
    ppath = os.path.join('static/'+pngdir, hostname)
    fdir = os.path.join(pngdir, hostname)
    if not os.path.exists(ppath):
        os.makedirs(ppath)
    png2d = os.path.join(ppath, dsname+"_2d.png")
    f2d = os.path.join(fdir, dsname+"_2d.png")
    url2d = url_for('static', filename=f2d)
    pngs.append(url2d)
    png1w = os.path.join(ppath, dsname+"_1w.png")
    f1w = os.path.join(fdir, dsname+"_1w.png")
    url1w = url_for('static', filename=f1w)
    pngs.append(url1w)
    png1m = os.path.join(ppath, dsname+"_1m.png")
    f1m = os.path.join(fdir, dsname+"_1m.png")
    url1m = url_for('static', filename=f1m)
    pngs.append(url1m)
    png1y = os.path.join(ppath, dsname+"_1y.png")
    f1y = os.path.join(fdir, dsname+"_1y.png")
    url1y = url_for('static', filename=f1y)
    pngs.append(url1y)
#    #######################################################
    item_q = db.session.query(DrawGraphs.itemname,DrawGraphs.units).filter_by(dsname=dsname).all()
    for item in item_q:
        dss = item[:-1][0].split(',')
        unit = item[-1:][0]
#    ###########################
    strtime = str(int(time.time()- 172800))
    gdata = {'pname':png2d, 'gname':dsname, 'rrdpath':rpath, 'pitem':dss, 'unit':unit,
            'cols':'', 'itypes':'', 'host':hostname, 'stime':strtime, 'flag':'2 Days'}
    gdatas.append(gdata)
#    ###########################
    strtime = str(int(time.time()- 604800))
    gdata = {'pname':png1w, 'gname':dsname, 'rrdpath':rpath, 'pitem':dss, 'unit':unit,
            'cols':'', 'itypes':'', 'host':hostname, 'stime':strtime, 'flag':'Weekly'}
    gdatas.append(gdata)
    ###########################
    strtime = str(int(time.time()- 2592000))
    gdata = {'pname':png1m, 'gname':dsname, 'rrdpath':rpath, 'pitem':dss, 'unit':unit,
            'cols':'', 'itypes':'', 'host':hostname, 'stime':strtime, 'flag':'Monthly'}
    gdatas.append(gdata)
    ###########################
    strtime = str(int(time.time()- 31536000))
    gdata = {'pname':png1y, 'gname':dsname, 'rrdpath':rpath, 'pitem':dss, 'unit':unit,
            'cols':'', 'itypes':'', 'host':hostname, 'stime':strtime, 'flag':'Yearly'}
    gdatas.append(gdata)
    ##########################
    #print gdatas,'---',pngs
    for gdata in gdatas:
        #if os.path.isfile(gdata['pname']): os.remove(gdata['pname'])
        print "----graphing ",gdata['pname']
        if len(gdata['pitem']) == 1: graphsub.dItem01(gdata)
        if len(gdata['pitem']) == 2: graphsub.dItem02(gdata)
        if len(gdata['pitem']) == 3: graphsub.dItem03(gdata)
        if len(gdata['pitem']) == 4: graphsub.dItem04(gdata)
        if len(gdata['pitem']) == 5: graphsub.dItem05(gdata)
        if len(gdata['pitem']) == 6: graphsub.dItem06(gdata)
        if len(gdata['pitem']) == 7: graphsub.dItem07(gdata)
    return render_template('drawall.html', pngs=pngs)