import  os
from DBSession import  session_maker
from model import InstanceList, IntfaceList
from utils import count_qps,count_avg_time
from prometheus_client import Gauge,Counter, generate_latest
from prometheus_client.core import CollectorRegistry
registry = CollectorRegistry(auto_describe=False)



def interface_info_count():
    with session_maker() as session:
        intface_infos = session.query(IntfaceList).filter(IntfaceList.app_type == "1").all()
        for i in range(len(intface_infos)):
            url = intface_infos[i].interface_url
            qps = count_qps(url)
            avg_time = count_avg_time(url)
            session.query(IntfaceList).filter(IntfaceList.interface_url == url).update({"qps": qps, "avg_time": avg_time})


if __name__ == '__main__':
    interface_info_count()