Exemplo n.º 1
0
    def index(self):
        items = sorted(cherrypy.root.services.services.items())
        services = []
        for i in items:
            r = i[1]
            s = DataObject()
            s.title = "%s %s" % (r.title, r.version)
            s.name = r.name
            s.status = r.status
            s.started = r.started.strftime('%Y-%m-%d %H:%M:%S')

            now = datetime.now()
            thismin = datetime(now.year, now.month, now.day, now.hour, 
                now.minute)
            s.avgduration = WebServiceLog.query.filter_by(
                name=s.name).avg(WebServiceLog.c.duration)
            if s.avgduration:
                s.rps = int(1. / s.avgduration)
                load = (WebServiceLog.query.filter(\
                    "name=:name and date>=:date").params(\
                    name=r.name, date=thismin).count() \
                    * 100) / (60 * 100 * s.avgduration)
                if load > 100:
                    load = 100
                s.load = "%.2f" % load
                s.avgduration = "%.4f" % s.avgduration
            else:
                s.rps = '--'
                s.load = '0.00'
                s.avgduration = '--'
            s.requests = WebServiceLog.query.filter_by(name=s.name).count()
            services.append(s)
        return dict(services=services)