예제 #1
0
    def import_service(self, base, servicedir):
        service = DataObject()

        sys.path.insert(0, base)
        module = __import__(servicedir)
        sys.path.remove(base)

        service_data = module.init()

        service.ServiceClass = service_data['service_class']
        service.name = service_data.get('name', servicedir)
        service.title = service_data.get('title')
        service.version = service_data.get('version')
        service.model = service_data.get('model')

        service.obj = service.ServiceClass()
        service.status = 'Running'
        service.started = datetime.now()

        service.methods = []

        for m in dir(service.obj):
            member = getattr(service.obj, m)
            if 'webmethodtype' in dir(member):
                t = member.__dict__['webmethodtype']
                service.methods.append(m)
                member = expose(member)

        return service
예제 #2
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)