def index(self, comp_name, **rest):

        query, data = API.messageListing(comp_name)
        dictofdict = {}
        for id, ev, fro, to, time, delay in data:
            if dictofdict.has_key(str(to)):
                listval = [str(ev), str(fro), str(time), str(delay)]
                dictofdict[str(to)].setdefault(id, listval)
            else:
                tempdict = {id: [str(ev), str(fro), str(time), str(delay)]}
                dictofdict.setdefault(str(to), tempdict)

        if dictofdict.has_key(comp_name):
            html = "<html><body><h2> %s </h2>\n "%("Showing %s message in queue for %s"%(str(len(dictofdict[comp_name])),str(comp_name)))
            html += "<table border='2' cellspacing='2' cellpadding='5'>"
            html += "<tr><th>Message</th><th>From</th><th>Time</th><th>Delay</th></tr>"
            for key, val in dictofdict.iteritems():
                for key2, val2 in val.iteritems():
                    html += "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>"%(val2[0],val2[1],val2[2],val2[3])
            html += """</body></html>"""
        else:
            html = "<html><body><h2> %s </h2>\n "%("%s has no message in queue"%(comp_name))
        return html
    def index(self, **rest):

        query, data = API.messageListing("")
        dictofdict = {}
        for id, ev, fro, to, time, delay in data:
            if dictofdict.has_key(str(to)):
                listval = [str(ev), str(fro), str(time), str(delay)]
                dictofdict[str(to)].setdefault(id, listval)
            else:
                tempdict = {id: [str(ev), str(fro), str(time), str(delay)]}
                dictofdict.setdefault(str(to), tempdict)

        goodone = {}

        for key, val in dictofdict.iteritems():
            goodone.setdefault(key, len(val))

        html = "<html><body><h2> %s </h2>\n "%("Showing message pie chart balance")

        errHtml = "<html><body><h2>No Graph Tools installed!!!</h2>\n "
        errHtml += "</body></html>"
        try:
            from graphtool.graphs.common_graphs import PieGraph
        except ImportError:
            return errHtml

        pngfile = os.path.join(self.workingDir, "MsgBalance.png")
        pngfileUrl = "../%s?filepath=%s" % (self.imageServer, pngfile)
        metadata = {'title':'Message queue balance'}
        Graph = PieGraph()
        coords = Graph( goodone, pngfile, metadata )

        html += "<img src=\"%s\">" % pngfileUrl

        html += """</body></html>"""
        return html
    def index(self, **rest):
        run , not_run = status()
        
        tableHeader = "<tr><th>%s</th><th>Process ID</th><th>Plots<span style=\"color:red\">*</span></th><th>CPU sensor status<span style=\"color:red\">*</span></th></tr>\n"
        plotLink = "<td><small><a href=\"%s/?Component=%s&length=12&span=hours\">last 12h</a></small></td>"
        nameNpid = "<tr><td>%s</td><td><b>%s</b></td>\n"
        sensorFound =  "sensor %s is attached to %s"
        sensorReady = "sensor %s is going to attach %s %s%s"
        sensorMissing = "<b>no CPU sensor found for %s %s...!</b>"
        
        html = """
        <html><head><style type=\"text/css\">
        th, td { text-indent:16px; text-align:left}
        th:first-child, td:first-child {text-indent:0px !important; }
        </style>
        </head>
        """
        html += "<body><h2>Components and Services State<br/>\n"
        html += "<small style=\"color:red; font-weight:normal;\">* Work in progress</small><br/></h2>\n"

        html += '<table Class="Components">\n'
#        html += "<tr><th></th><th></th><th colspan=2><small style=\"color:red;\">work in progress</th></tr>\n"
        html += tableHeader%"Components"

        for r in run:
            comp = str(r[0])
            cpid = str(r[1])
            html += nameNpid%(comp,cpid)
            html += plotLink%(self.compcpu,comp)
            html += "<td><small>"
            sensorOn, spid, cpid = API.isSensorRunning(comp)
            if sensorOn:
                html += sensorFound%(spid,cpid)
            else:
                sensorDaemonOn, spid = API.isSensorDaemonRunning(comp)
                if sensorDaemonOn:
                    html += sensorReady%(spid,"component",comp,"... retry in a minute.")
                else:
                    html += sensorMissing%("component",comp)
            html += "</small></td></tr>\n"

        for n in not_run:
            html  += nameNpid%(str(n),"Not Running")
            html += plotLink%(self.compcpu,str(n))
            html += "<td><small>"
            sensorDaemonOn, spid = API.isSensorDaemonRunning(n)
            if sensorDaemonOn:
                html += sensorReady%(spid,"component",n,"when it will be (re)started")
            else:
                html += sensorMissing%("component",n)
            html += "</small></td></tr>\n"

        html += " <tr><th>&nbsp; </th><th>&nbsp;</th></tr>\n"
        html += tableHeader%"Services"

        for serv in AllServices.keys():
            cpid = API.getPIDof(AllServices[serv])
            spid = API.isSensorRunning(AllServices[serv])
            html += nameNpid%(serv,cpid)
            html += plotLink%(self.compcpu,serv)
            html += "<td><small>"
            sensorOn, spid, cpid = API.isSensorRunning(AllServices[serv])
            if sensorOn:
                html += sensorFound%(spid,cpid)
            else:
                sensorDaemonOn, spid = API.isSensorDaemonRunning(serv)
                if sensorDaemonOn:
                    html += sensorReady%(spid,"service",serv,"... retry in a minute.")
                else:
                    html += sensorMissing%("service",serv)
            html += "</small></td></tr>\n"

        html += "<td></td><td></td>"
        html += "</table>\n"

        html += "<br/><br/> <b>Internal processing status</b><br/>"
        if isDrained() is False:
            html += "<br/> Accepting new submission: <b>YES</b><br/>"
        else:
            html += "<br/> Accepting new submission: <b>NO</b><br/>"

        outqueue = API.getOutputQueue()
        outqueuefail = API.getOutputFailedQueue()
        JTload   = API.jobTrackingLoad()
        dequeued = API.dequeuedJobs()
        jobdistr = API.processStatusDistribution()
        jobbyst = ''
        for couple in jobdistr:
            if len(couple) == 2:
                jobbyst += "<tr><td>&nbsp;&nbsp;%s</td><td>%s</td></tr>"%(str(couple[0]),str(couple[1]))
        table_job = '\n<table Class="Jobs"> %s </table><br/>'%jobbyst

        html += "<br/>Jobs in the GetOutput queue: %s Done + %s Failed = %s"%(str(outqueue[0][0]), str(outqueuefail[0][0]), str(outqueue[0][0]+outqueuefail[0][0]))
        html += "<br/>Jobs being processed by the JobTracking: %s"%str(JTload[0][0])
        html += "<br/>Jobs already processed by the GetOutput: %s"%str(dequeued[0][0])
        html += "<br/>Jobs by processing status: <br/>%s"%table_job

        html += '\n<br/><br/> <b>MySql DB size in MBytes</b><br/>\n<table Class="DBSize" >'

        path=os.environ.get("PRODAGENT_WORKDIR")
        dbsize1 = os.stat(path + "/mysqldata/ibdata1").st_size
        dbsize2 = os.stat(path + "/mysqldata/ibdata2").st_size
        dbsize = (dbsize1 + dbsize2) / 1024 / 1024

        html += "<tr><td>Size : </td><td>%d</td></tr>" % (dbsize)

        html += "<br/></table>"
	

        html += '\n<br/><br/> <b>Disk size in GBytes</b><br/>\n<table Class="DiskSize" >'
        crabhomepath=os.environ.get("HOME")
        stream = os.popen(crabhomepath+"/integration/diskSizePlot.sh").readlines()
        diskSize = float(stream[0]) / 1024/ 1024/ 1024

        html += "<tr><td>Size : </td><td>%d</td></tr>" % (diskSize)

        html += "<br/></table>"
        html += '\n<br/><br/> <b>Messages by destination component</b><br/>\n<table Class="Messages" >'
	
        query, data = API.messageListing("")
        msgs = {}
        for id, ev, fro, to, time, delay in data:
	  if msgs.has_key(str(to)):
	    msgs[str(to)] += 1
	  else:
	    msgs[str(to)] = 1

	for comp in msgs.keys():
	  html += "<tr><td>%s : </td><td>%d</td></tr>" % (comp,msgs[comp])

	html += "<br/></table>"


        html += "</body></html>"

        return html