panwang %!s(int64=3) %!d(string=hai) anos
achega
03cfb544f0

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/

+ 19 - 0
.idea/devops.iml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="Flask">
+    <option name="enabled" value="true" />
+  </component>
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="TemplatesService">
+    <option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
+    <option name="TEMPLATE_FOLDERS">
+      <list>
+        <option value="$MODULE_DIR$/templates" />
+      </list>
+    </option>
+  </component>
+</module>

+ 6 - 0
.idea/inspectionProfiles/profiles_settings.xml

@@ -0,0 +1,6 @@
+<component name="InspectionProjectProfileManager">
+  <settings>
+    <option name="USE_PROJECT_PROFILE" value="false" />
+    <version value="1.0" />
+  </settings>
+</component>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/devops.iml" filepath="$PROJECT_DIR$/.idea/devops.iml" />
+    </modules>
+  </component>
+</project>

+ 36 - 0
DBSession.py

@@ -0,0 +1,36 @@
+from sqlalchemy import create_engine ,Integer,String,Column
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.ext.declarative import declarative_base
+from contextlib import contextmanager
+
+HOST = 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com'
+PORT = '3306'
+DATABASE = 'devops'
+USERNAME = 'devops'
+PASSWORD = 'devops@123456'
+MYSQL_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8".format(username=USERNAME,
+                                                                                           password=PASSWORD,
+                                                                                           host=HOST, port=PORT,
+                                                                                           db=DATABASE)
+
+Base = declarative_base()
+
+
+engine = create_engine(MYSQL_URI)
+session_factory = sessionmaker(bind=engine)
+
+
+
+@contextmanager
+def session_maker(session=None):
+    try:
+        if session is None:
+            session = session_factory()
+        yield session
+    except:
+        session.rollback()
+        raise
+    else:
+        session.commit()
+    finally:
+        session.close()

+ 39 - 0
DBSession_longvideo.py

@@ -0,0 +1,39 @@
+from sqlalchemy import create_engine ,Integer,String,Column
+from sqlalchemy.orm import sessionmaker
+from sqlalchemy.ext.declarative import declarative_base
+from contextlib import contextmanager
+
+# HOST = 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com'
+
+HOST = 'rr-bp1x9785e8h5452bi157.mysql.rds.aliyuncs.com'
+
+PORT = '3306'
+DATABASE = 'longvideo'
+USERNAME = 'devops'
+PASSWORD = 'devops@123456'
+MYSQL_URI = "mysql+pymysql://{username}:{password}@{host}:{port}/{db}?charset=utf8".format(username=USERNAME,
+                                                                                           password=PASSWORD,
+                                                                                           host=HOST, port=PORT,
+                                                                                           db=DATABASE)
+
+Base = declarative_base()
+
+
+engine = create_engine(MYSQL_URI)
+session_factory = sessionmaker(bind=engine)
+
+
+
+@contextmanager
+def session_maker_longvideo(session=None):
+    try:
+        if session is None:
+            session = session_factory()
+        yield session
+    except:
+        session.rollback()
+        raise
+    else:
+        session.commit()
+    finally:
+        session.close()

+ 0 - 0
DB_sql.py


BIN=BIN
__pycache__/DBSession.cpython-37.pyc


BIN=BIN
__pycache__/DBSession_longvideo.cpython-37.pyc


BIN=BIN
__pycache__/app.cpython-37.pyc


BIN=BIN
__pycache__/ex_response.cpython-37.pyc


BIN=BIN
__pycache__/model.cpython-37.pyc


BIN=BIN
__pycache__/model_longvideo.cpython-37.pyc


BIN=BIN
__pycache__/scheduler_jobs.cpython-37.pyc


BIN=BIN
__pycache__/test.cpython-37.pyc


BIN=BIN
__pycache__/utils.cpython-37.pyc


+ 173 - 0
aliyun-log-exporter.py

@@ -0,0 +1,173 @@
+import prometheus_client
+from prometheus_client import Gauge,start_http_server,Counter
+import time
+import threading
+from io import BytesIO
+from aliyun.log.logclient import LogClient
+from aliyun.log.getlogsrequest import GetLogsRequest
+
+#
+# url_http_code = Counter("url_http_code", "request http_code of the host",['code','url'])
+# url_http_request_time = Counter("url_http_request_time", "request http_request_time of the host",['le','url'])
+# http_request_total = Counter("http_request_total", "request request total of the host",['url'])
+url_http_times_avgs = Gauge("url_http_times_avgs","url  of avgs",['appType', 'url'])
+url_http_qps = Gauge("url_http_qps","url  of qps",['url'])
+
+endpoint = 'cn-hangzhou.log.aliyuncs.com'
+accessKeyId = 'LTAIWYUujJAm7CbH'
+accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+client = LogClient(endpoint, accessKeyId, accessKey)
+start_time = int(time.time())
+end_time = start_time - 60
+
+def count_qps(url):
+
+    logstore = 'request-log'
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         " params.appType=15 and requestUri:'{}' |select requestUri,count(1) as cnt, date_format(logTimestamp/1000,'%Y-%m-%d %H:%i:%S') as date  group by requestUri, date order by cnt desc limit 1".format(url)
+                         , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        print(e)
+        qps = 0
+    else:
+        if res.body:
+            qps = res.body[0]["cnt"]
+        else:
+            qps = 0
+    return  qps
+
+
+def  count_metric(url):
+
+    qps = count_qps(url)
+    # url_http_times_avgs.labels(url).set(avgs)
+
+    url_http_qps.labels(url).set(qps)
+
+def count_threads(url):
+    while True:
+        t = threading.Thread(target=count_metric,args=(url,))
+        t.setDaemon(True)
+        t.start()
+        time.sleep(60)
+if __name__ == '__main__':
+    start_http_server(9092)
+    requestUri_list = [
+        'longvideoapi/sys/config',
+        'longvideoapi/video/played',
+        'longvideoapi/video/shared/weixin/friend',
+        'longvideoapi/user/login/v2',
+        'longvideoapi/user/info/getUserInfoExt',
+        'longvideoapi/user/token/check',
+        'longvideoapi/user/token/refresh',
+        'longvideoapi/user/info/homepageHead',
+        'longvideoapi/user/share/homepage/circle',
+        'longvideoapi/user/idols',
+        'longvideoapi/user/fans',
+        'longvideoapi/user/recommend/list/v4',
+        'longvideoapi/user/outside/subscribeBatch',
+        'longvideoapi/user/info/getBaseUserInfo',
+        'longvideoapi/user/info/getTargetBaseUserInfo',
+        'longvideoapi/user/getWxUserInfoByCode',
+        'longvideoapi/user/follow',
+        'longvideoapi/user/unfollow',
+        'longvideoapi/video/favorite',
+        'longvideoapi/video/unfavorite',
+        'longvideoapi/video/shared/weixin/circle',
+        'longvideoapi/videoCollection/loadUserVideoCollections',
+        'longvideoapi/video/v2/sharePage/queryVideosByCollectionId',
+        'longvideoapi/video/v2/detailPage/queryVideosByCollectionId',
+        'longvideoapi/videoCollection/loadUserVideoCollectionsForShareOrDetailPage',
+        'longvideoapi/video/distribute/getAppInfo',
+        'longvideoapi/video/distribute/category/videoList/v2',
+        'longvideoapi/video/v2/followed',
+        'longvideoapi/video/v2/loadHotVideosByCollectionId',
+        'longvideoapi/video/v2/loadLatelyVideosByCollectionId',
+        'longvideoapi/video/v2/detail',
+        'longvideoapi/video/v2/sharePageDetail',
+        'longvideoapi/video/send',
+        'longvideoapi/video/getCoverImagePaths',
+        'longvideoapi/video/updateVideo',
+        'longvideoapi/video/deleteVideo',
+        'longvideoapi/video/barrage/send',
+        'longvideoapi/video/barrage/switch',
+        'longvideoapi/video/videoActionReport',
+        'longvideoapi/video/barrage/v2/list',
+        'longvideoapi/video/shared/h5"',
+        'longvideoapi/user/share/report',
+        'longvideoapi/oss/signature',
+        'longvideoapi/oss/completeUpload',
+        'longvideoapi/oss/producevideo/getStsToken',
+        'longvideoapi/operate/message/list',
+        'longvideoapi/video/message/list',
+        'longvideoapi/sys/message/list',
+        'longvideoapi/user/station/message/statistics/info',
+        'longvideoapi/user/station/message/statistics/read',
+        'longvideoapi/user/station/message/totalCount/v2',
+        'longvideoapi/user/station/message/totalRead',
+        'longvideoapi/user/station/notice/list',
+        'longvideoapi/user/station/message/share/list',
+        'longvideoapi/user/station/message/prise/list',
+        'longvideoapi/user/station/message/favorite/list',
+        'longvideoapi/user/station/message/comment/list',
+        'longvideoapi/user/station/message/barrage/list',
+        'longvideoapi/operation/message/list',
+        'longvideoapi/search/userandvideo/list',
+        'longvideoapi/search/tips',
+        'longvideoapi/search/user/list',
+        'longvideoapi/search/video/list',
+        'longvideoapi/search/hot/words',
+        'longvideoapi/search/hot/videos',
+        'longvideoapi/video/distribute/search/recommendVideoes/v2',
+        'longvideoapi/comment/top/save',
+        'longvideoapi/comment/top/page',
+        'longvideoapi/comment/praise',
+        'longvideoapi/comment/second/save',
+        'longvideoapi/comment/second/page',
+        'longvideoapi/comment/delete',
+        'longvideoapi/comment/updelete',
+        'longvideoapi/comment/hots',
+        'longvideoapi/bank/withdraw/getBankWithdrawConfig',
+        'longvideoapi/bank/withdraw/getBankWithdrawRecordList',
+        'longvideoapi/bank/withdraw/wxSamllapp/requestWithdraw',
+        'longvideoapi/purchase/video/list',
+        'longvideoapi/profits/myself/head',
+        'longvideoapi/profits/myself/list',
+        'longvideoapi/profits/myself/recordList/v2',
+        'longvideoapi/profits/reward/recordListAccordingToUser',
+        'longvideoapi/profits/reward/recordListAccordingToVideo',
+        'longvideoapi/video/reward/getVideoRewardHeadInfo',
+        'longvideoapi/video/reward/getVideoRewardRecordList',
+        'longvideoapi/video/reward/getVideoRewardConfig',
+        'longvideoapi/video/reward/getVideoRewardConfig/v2',
+        'longvideoapi/order/updateClientPayStatus',
+        'longvideoapi/order/purchase',
+        'longvideoapi/profits/videoPay/head',
+        'longvideoapi/profits/videoPay/list',
+        'longvideoapi/video/getPayedVideoPath',
+        'longvideoapi/order/reward',
+        'longvideoapi/video/reward/getVideoDetailRewardInfo',
+        'longvideoapi/video/recommend/detailPage/list',
+        'longvideoapi/video/recommend/sharePage/list',
+        'longvideoapi/measure/report/view',
+        'longvideoapi/video/validatePwd"',
+        'longvideoapi/video/validatePwdAuth"',
+        'longvideoapi/video/v2/getCutVideo',
+        'longvideoapi/frontConfig/getWxFrontConfig',
+        'longvideoapi/frontConfig/getVideoPlayConfig',
+        'longvideoapi/frontConfig/getUserFrontConfig',
+        'longvideoapi/rhythmapp/homepage/getAllVideos',
+        'longvideoapi/ad/position/info'
+            ]
+    threads = []
+    for url in requestUri_list:
+        t = threading.Thread(target=count_threads,args=(url,))
+        threads.append(t)
+    for thread in threads:
+        thread.setDaemon(True)
+        thread.start()
+    thread.join()

+ 334 - 0
app.py

@@ -0,0 +1,334 @@
+from flask import Flask,Response
+from DBSession import session_maker
+from model import *
+from sqlalchemy.sql import func
+
+from utils import *
+import atexit
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
+from apscheduler.schedulers.background import BackgroundScheduler
+import json
+from model_longvideo import produce_video_task,produce_video_project
+from DBSession_longvideo import session_maker_longvideo
+from prometheus_client import Gauge,Counter, generate_latest
+from prometheus_client.core import CollectorRegistry
+from scheduler_jobs import interface_info_count
+from ex_response import ex_response
+import time
+import  threading
+app = Flask(__name__)
+registry = CollectorRegistry(auto_describe=False)
+
+
+# # 定义后台执行调度器
+# scheduler = BackgroundScheduler()
+# scheduler.add_job(func=interface_info_count, trigger="interval", seconds=120)
+# scheduler.start()
+# atexit.register(lambda: scheduler.shutdown())
+
+client = AcsClient('LTAI4GBWbFvvXoXsSVBe1o9f', 'kRAikWitb4kDxaAyBqNrmLmllMEDO3', 'cn-hangzhou')
+
+
+healthcheck_status = Gauge("healthcheck_status", "ipaddress", ['instance_id','server_name', 'ipaddress'], registry=registry)
+url_http_avgtime = Gauge("url_http_times_avgs", "url  of avgs", ['appType', 'url'], registry=registry)
+url_http_qps = Gauge("url_http_qps", "url  of qps", ['appType','url'], registry=registry)
+url_http_expendtime_summary =  Gauge("url_http_expendtime_summary", "expendtime   summary", ['appType', 'url', 'duration'], registry=registry)
+probe_http_status_code = Gauge("http_status_code", 'h5',['server_name'], registry=registry)
+probe_http_total_time = Gauge("http_total_time", 'h5',['server_name'], registry=registry)
+probe_http_dns_time = Gauge("http_dns_time", 'h5',['server_name'], registry=registry)
+probe_http_connect_time = Gauge("http_connect_time", 'h5',['server_name'], registry=registry)
+probe_http_pretransfer_time = Gauge("http_pretransfer_time", 'h5',['server_name'], registry=registry)
+probe_http_first_byte_time = Gauge("http_first_byte_time", 'h5',['server_name'], registry=registry)
+slb_http_status_code = Gauge("slb_http_status_code", 'slb', ['server_name', 'status'], registry=registry)
+produce_video_task_count = Gauge("produce_video_task_count", 'success_status_count', ['status_count'], registry=registry)
+produce_video_task_rate = Gauge("produce_video_task_rate", 'produce_video_rate', ['produce_video_rate'], registry=registry)
+produce_video_tts_count = Gauge("tts_aliyun_azure", 'success', ['tts_channel'], registry=registry)
+logs_app_recommend_log_cnt_300 = Gauge("logs_app_recommend_log_null_cnt_300", "null cnt", ['cnt'], registry=registry)
+logs_app_recommend_log_cnt_all = Counter("logs_app_recommend_log_null_cnt_all", "all cnt", ['cnt'], registry=registry)
+
+
+
+
+@app.route('/update')
+def update():
+    request = DescribeInstancesRequest()
+    request.set_accept_format('json')
+    request.set_PageSize(100)
+    # request.set_InstanceNetworkType("vpc")
+    request.set_Tags([
+        {
+            "Key": "ecs"
+        }
+    ])
+
+    response = client.do_action_with_exception(request)
+    instance_info = json.loads(response)
+    intances_list_del()
+    count = len(instance_info["Instances"]["Instance"])
+    for i in range(len(instance_info["Instances"]["Instance"])):
+        instance_id = instance_info["Instances"]["Instance"][i]["InstanceId"]
+        if instance_info["Instances"]["Instance"][i]["InstanceNetworkType"] == "vpc":
+            ipaddr = instance_info["Instances"]["Instance"][i]["VpcAttributes"]["PrivateIpAddress"]["IpAddress"][0]
+        if instance_info["Instances"]["Instance"][i]["InstanceNetworkType"] == "classic":
+            ipaddr = instance_info["Instances"]["Instance"][i]["InnerIpAddress"]["IpAddress"][0]
+
+        server_name = instance_info["Instances"]["Instance"][i]["Tags"]["Tag"][0]["TagValue"]
+        status = instance_info["Instances"]["Instance"][i]["Status"]
+        instance_name = instance_info["Instances"]["Instance"][i]["HostName"]
+
+        if status == "Running":
+            status = 1
+        instance_insert(instance_id, ipaddr, instance_name, server_name, status)
+
+
+    return "更新完成"
+@app.route('/app/healthcheck/metrics')
+def app_healthcheck():
+    threads = []
+    with session_maker() as session:
+        instance_infos = session.query(InstanceList).filter(InstanceList.server_name=="longvideoapi.prod").all()
+        for index in range(len(instance_infos)):
+            ipaddr = instance_infos[index].ipadd
+            server_name = instance_infos[index].server_name
+            http_code = healthcheck(ipaddr, server_name)
+            instance_id = instance_infos[index].instance_id
+            healthcheck_status.labels(instance_id, server_name, ipaddr).set(http_code)
+
+    return Response(generate_latest(registry),mimetype="text/plain")
+
+
+
+@app.route('/app/qps/metrics')
+def  qps_avgtime_count():
+    threads = []
+    with session_maker() as session:
+        intface_infos = session.query(IntfaceList.interface_url).all()
+        app_type = session.query(app_info.app_type).all()
+        for i in range(len(intface_infos)):
+            for index  in range(len(app_type)):
+
+                url = intface_infos[i].interface_url
+                appType = app_type[index].app_type
+
+                url_avgtime = count_avg_time(appType, url)
+                url_qps = count_qps(appType, url)
+                url_http_avgtime.labels(appType, url).set(url_avgtime)
+                url_http_qps.labels(appType, url).set(url_qps)
+    return  Response(generate_latest(registry),mimetype="text/plain")
+
+
+@app.route('/h5/metrics')
+def   h5_healthcheck():
+
+
+        # curl_respon = ex_response(
+    share_h5 = "share_h5"
+    download_h5 = "download_h5"
+    share_h5_url = "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=#"
+    download_h5_url = "https://longvideoh5.piaoquantv.com/dist_1_3_4/upload?accessToken=fe8914eb2e99d1fe8ddaa2f753f5ec613eb2dfbb&versionCode=323&galleryId=0&fileType=2&machineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&platform=devtools&system=iOS%2010.0.1&appType=0&appId=wx89e7eb06478361d7&pageSource=vlog-pages%2Fwebview&loginUid=12463024&machineInfo=%7B%22sdkVersion%22%3A%222.4.1%22,%22brand%22%3A%22devtools%22,%22language%22%3A%22zh_CN%22,%22model%22%3A%22iPhone%20X%22,%22platform%22%3A%22devtools%22,%22system%22%3A%22iOS%2010.0.1%22,%22weChatVersion%22%3A%228.0.5%22,%22screenHeight%22%3A812,%22screenWidth%22%3A375,%22windowHeight%22%3A730,%22windowWidth%22%3A375,%22softVersion%22%3A%224.1.168%22%7D&wxHelpPagePath=%2Fpackage-my%2Fhelp-feedback%2Fhelp-feedback&transaction=2065ff98-6f27-4f09-c9eb-d366c99dd5d5&videoBarrageSwitch=true&addMusic=1&eventId=0&fromActivityId=0&sessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&subSessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&projectId=&entranceType=#wechat_redirec"
+    shar_h5_curl_response = ex_response(share_h5_url)
+    share_h5_url_info = shar_h5_curl_response.getinfo()
+    download_h5_curl_response = ex_response(download_h5_url)
+    download_h5_url_info = download_h5_curl_response.getinfo()
+
+    probe_http_status_code.labels(share_h5).set(share_h5_url_info["http_code"])
+    probe_http_status_code.labels(download_h5).set(download_h5_url_info["http_code"])
+
+    probe_http_total_time.labels("share_h5").set(share_h5_url_info["total_time"]*1000)
+    probe_http_total_time.labels("download_h5").set(download_h5_url_info["total_time"]*1000)
+
+    probe_http_dns_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_dns_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+    probe_http_connect_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_connect_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+
+    probe_http_pretransfer_time.labels("share_h5").set(share_h5_url_info["pretransfer_time"]*1000)
+    probe_http_pretransfer_time.labels("download_h5").set(download_h5_url_info["pretransfer_time"]*1000)
+
+    probe_http_first_byte_time.labels("share_h5").set(share_h5_url_info["first_byte_time"]*1000)
+    probe_http_first_byte_time.labels("download_h5").set(download_h5_url_info["first_byte_time"]*1000)
+
+    return Response(generate_latest(registry), mimetype="text/plain")
+
+
+@app.route('/slbStatusCode/metrics')
+def  slb_request_status_metric():
+    svc_name = {'longvideoapi', 'clip', 'speed'}
+    for name in svc_name:
+        res = slb_status_code_count(name)
+        if  res:
+            for i in range(len(res)):
+                status = res[i]['status']
+                cnt = float(res[i]['cnt'])
+                slb_http_status_code.labels(name, status).set(cnt)
+
+
+    return Response(generate_latest(registry), mimetype="text/plain")
+
+@app.route('/metrics')
+def all_metric():
+    with session_maker_longvideo() as  session:
+
+        # video_progress_count = session.query(produce_video_task).filter(produce_video_task.task_status == 1).count()
+        # video_success_count = session.query(produce_video_task).filter(produce_video_task.task_status == 2).count()
+        # video_fail_count = session.query(produce_video_task).filter(produce_video_task.task_status == 3).count()
+        # video_produce_speed =  session.query(produce_video_task).filter(produce_video_task.submit_timestamp)
+        # #视频合成成功率
+        # produce_video_task_count.labels("video_sucess").set(video_success_count)
+        # produce_video_task_count.labels("video_fail").set(video_fail_count)
+        # produce_video_task_count.labels("video_progress").set(video_progress_count)
+        # #合成速度
+        # end_time = int(time.time())
+        # start_time = end_time - (end_time - time.timezone) % 86400
+        # res = session.query(produce_video_task).filter(produce_video_task.task_status==2).order_by(produce_video_task.id.desc()).first()
+        # if  res:
+        #     duration = res.duration
+        #     submit_timestamp = res.submit_timestamp
+        #     complete_timestamp = res.complete_timestamp
+        #     rate = (duration / (complete_timestamp - submit_timestamp) / 1000)
+        #     produce_video_task_rate.labels("produce_video_task_rate").set(round(rate, 3))
+        # else:
+        #     produce_video_task_rate.labels("produce_video_task_rate").set(0)
+        start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
+        end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
+        sql = "select  round(successCount/totalCount * 100,2) as 成功率 from  (select count(*) as totalCount, sum(case when produce_status != 99 then 1 else 0 end) as successCount from produce_video_project where project_id > {} and project_id < {} and app_type not in (13,15)) t1".format(start_time, end_time)
+        res = db_query(sql)
+        if res[0] is not None:
+            produce_video_task_rate.labels("produce_video_task_rate").set(res[0])
+        else:
+            produce_video_task_rate.labels("produce_video_task_rate").set(100)
+
+        sql = "select v1 as 平均合成耗时,v2 as 平均视频时长, round(v2/v1,1) as 时长耗时比 from  (select avg(produce_done_timestamp - submit_timestamp) as v1, avg(video_duration/1000) as v2 from produce_video_project where project_id > {} and project_id < {} and app_type not in (13,15) and produce_status in (5,6,7,8)) as t1".format(start_time, end_time)
+    #tts
+        res = db_query(sql)
+        if res[2] is not None:
+            produce_video_task_count.labels("video_progress").set(res[2])
+        else:
+            produce_video_task_count.labels("video_progress").set(0)
+
+    res = logs_tts_count("aliyun",1)
+    if res is not None:
+        produce_video_tts_count.labels("aliyun_success").set(res[0]["count"])
+    else:
+        produce_video_tts_count.labels("aliyun_success").set(0)
+    res = logs_tts_count("aliyun", 0)
+    if res is not None:
+        produce_video_tts_count.labels("aliyun_fail").set(res[0]["count"])
+    else:
+        produce_video_tts_count.labels("aliyun_fail").set(0)
+    res = logs_tts_count("azure", 1)
+    if res is not None:
+        produce_video_tts_count.labels("azure_success").set(res[0]["count"])
+    else:
+        produce_video_tts_count.labels("azure_success").set(0)
+    res = logs_tts_count("aliyun", 0)
+    if res is not None:
+        produce_video_tts_count.labels("azure_fail").set(res[0]["count"])
+    else:
+        produce_video_tts_count.labels("azure_fail").set(0)
+    #接口qps与返回时长
+    # 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
+    #         url_qps = intface_infos[i].qps
+    #         url_avg_time = intface_infos[i].avg_time
+    #         url_http_avgtime.labels(url).set(url_avg_time)
+    #         url_http_qps.labels(url).set(url_qps)
+
+    #当日负载均衡http_code
+    svc_name = {'longvideoapi', 'clip', 'speed', 'commonapi'}
+    for name in svc_name:
+        res = slb_status_code_count(name)
+        if  res:
+            for i in range(len(res)):
+                status = res[i]['status']
+                cnt = float(res[i]['cnt'])
+                print(cnt)
+                slb_http_status_code.labels(name, status).set(cnt)
+
+    #h5 healthcheck
+    share_h5 = "share_h5"
+    download_h5 = "download_h5"
+    share_h5_url = "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=#"
+    download_h5_url = "https://longvideoh5.piaoquantv.com/dist_1_3_4/upload?accessToken=fe8914eb2e99d1fe8ddaa2f753f5ec613eb2dfbb&versionCode=323&galleryId=0&fileType=2&machineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&platform=devtools&system=iOS%2010.0.1&appType=0&appId=wx89e7eb06478361d7&pageSource=vlog-pages%2Fwebview&loginUid=12463024&machineInfo=%7B%22sdkVersion%22%3A%222.4.1%22,%22brand%22%3A%22devtools%22,%22language%22%3A%22zh_CN%22,%22model%22%3A%22iPhone%20X%22,%22platform%22%3A%22devtools%22,%22system%22%3A%22iOS%2010.0.1%22,%22weChatVersion%22%3A%228.0.5%22,%22screenHeight%22%3A812,%22screenWidth%22%3A375,%22windowHeight%22%3A730,%22windowWidth%22%3A375,%22softVersion%22%3A%224.1.168%22%7D&wxHelpPagePath=%2Fpackage-my%2Fhelp-feedback%2Fhelp-feedback&transaction=2065ff98-6f27-4f09-c9eb-d366c99dd5d5&videoBarrageSwitch=true&addMusic=1&eventId=0&fromActivityId=0&sessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&subSessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&projectId=&entranceType=#wechat_redirec"
+    shar_h5_curl_response = ex_response(share_h5_url)
+    share_h5_url_info = shar_h5_curl_response.getinfo()
+    download_h5_curl_response = ex_response(download_h5_url)
+    download_h5_url_info = download_h5_curl_response.getinfo()
+
+    probe_http_status_code.labels(share_h5).set(share_h5_url_info["http_code"])
+    probe_http_status_code.labels(download_h5).set(download_h5_url_info["http_code"])
+
+    probe_http_total_time.labels("share_h5").set(share_h5_url_info["total_time"]*1000)
+    probe_http_total_time.labels("download_h5").set(download_h5_url_info["total_time"]*1000)
+
+    probe_http_dns_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_dns_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+    probe_http_connect_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_connect_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+
+    probe_http_pretransfer_time.labels("share_h5").set(share_h5_url_info["pretransfer_time"]*1000)
+    probe_http_pretransfer_time.labels("download_h5").set(download_h5_url_info["pretransfer_time"]*1000)
+
+    probe_http_first_byte_time.labels("share_h5").set(share_h5_url_info["first_byte_time"]*1000)
+    probe_http_first_byte_time.labels("download_h5").set(download_h5_url_info["first_byte_time"]*1000)
+
+    #推荐业务
+    res_null_cnt = count_recommend_null()
+    logs_app_recommend_log_cnt_300.labels("recommend").set(res_null_cnt)
+    # # logs_app_recommend_log_cnt_all.labels("recommend").inc(1)
+    # logs_app_recommend_log_cnt_all.inc(res_null_cnt)
+
+    return Response(generate_latest(registry), mimetype="text/plain")
+@app.route('/qps_avgtime/metrics')
+def qps_avgtime_metrics():
+    app_type = ['1', '0', '4', '5', '6', '12', '13']
+    for i in range(len(app_type)):
+        appType = app_type[i]
+        res = count_qps_avgtime(appType)
+        for i in range(len(res.body)):
+            url = res.body[i]["requestUri"]
+
+            qps = int(res.body[i]["cnt"])
+            avgtime = int(float(res.body[i]["avg_time"]))
+            url_http_qps.labels(appType, url).set(qps)
+            url_http_avgtime.labels(appType, url).set(avgtime)
+
+        res = count_rt_less_time_count(appType, 0, 200)
+        for  i in range(len(res.body)):
+            url = res.body[i]["requestUri"]
+            count = res.body[i]["cnt"]
+            url_http_expendtime_summary.labels(appType, url, "0-200").set(count)
+
+        res = count_rt_less_time_count(appType, 200, 500)
+        for  i in range(len(res.body)):
+            url = res.body[i]["requestUri"]
+            count = res.body[i]["cnt"]
+            url_http_expendtime_summary.labels(appType, url, "200-300").set(count)
+
+        res = count_rt_less_time_count(appType, 500, 1000)
+        for  i in range(len(res.body)):
+            url = res.body[i]["requestUri"]
+            count = res.body[i]["cnt"]
+            url_http_expendtime_summary.labels(appType, url, "500-1000").set(count)
+
+        res = count_rt_less_time_count(appType, 1000, 10000)
+        for  i in range(len(res.body)):
+            url = res.body[i]["requestUri"]
+            count = res.body[i]["cnt"]
+            url_http_expendtime_summary.labels(appType, url, ">1000").set(count)
+
+    return Response(generate_latest(registry), mimetype="text/plain")
+
+
+
+
+if __name__ == '__main__':
+    # app.run()
+    app.run(host='192.168.201.1', port=9091)

+ 0 - 0
config.py


+ 40 - 0
ex_response.py

@@ -0,0 +1,40 @@
+import pycurl
+from io import BytesIO
+
+class ex_response(object):
+    def __init__(self,url):
+        self.buffer = BytesIO()
+        self.c = pycurl.Curl()
+        self.c.setopt(pycurl.URL,url)
+        self.c.setopt(pycurl.WRITEDATA, self.buffer)
+        self.c.setopt(pycurl.WRITEHEADER,self.buffer)
+        try:
+            self.c.perform()
+        except Exception as e:
+            print('connection error:' + str(e))
+            self.buffer.close()
+            self.c.close()
+
+    def getinfo(self):
+
+        http_code = self.c.getinfo(pycurl.HTTP_CODE)  # 状态码
+        total_time = self.c.getinfo(pycurl.TOTAL_TIME)  # 传输结束总消耗时间
+        dns_time = self.c.getinfo(pycurl.NAMELOOKUP_TIME)  # DNS解析时间
+        connect_time = self.c.getinfo(pycurl.CONNECT_TIME)  # 建立连接时间
+        pretransfer_time = self.c.getinfo(pycurl.PRETRANSFER_TIME)  # 建立连接到准备传输消耗时间
+        first_byte_time = self.c.getinfo(pycurl.STARTTRANSFER_TIME)  # 从建立连接到传输开始消耗时间
+        info = {"http_code": http_code,
+                "total_time": total_time,
+                "dns_time": dns_time,
+                "connect_time": connect_time,
+                "pretransfer_time": pretransfer_time,
+                "first_byte_time":first_byte_time
+                }
+        return  info
+        self.buffer.close()
+        self.c.close()
+
+if __name__ == '__main__':
+    curl_respon = ex_response("https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=#")
+    http_code, total_time, dns_time, connect_time, pretransfer_time, first_byte_time = curl_respon.getinfo()
+    print(http_code, total_time*1000, dns_time*1000, connect_time*1000, pretransfer_time*1000, first_byte_time*1000)

+ 160 - 0
exporter-wx.py

@@ -0,0 +1,160 @@
+from flask import Flask,Response
+from DBSession import session_maker
+from model import InstanceList
+from utils import *
+import atexit
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
+from apscheduler.schedulers.background import BackgroundScheduler
+import json
+from model_longvideo import produce_video_task
+from DBSession_longvideo import session_maker_longvideo
+from prometheus_client import Gauge,Counter, generate_latest,start_http_server
+from prometheus_client.core import CollectorRegistry
+from scheduler_jobs import interface_info_count
+from ex_response import ex_response
+import time
+import  threading
+app = Flask(__name__)
+registry = CollectorRegistry(auto_describe=False)
+
+
+# 定义后台执行调度器
+scheduler = BackgroundScheduler()
+scheduler.add_job(func=interface_info_count, trigger="interval", seconds=60)
+scheduler.start()
+atexit.register(lambda: scheduler.shutdown())
+
+client = AcsClient('LTAI4GBWbFvvXoXsSVBe1o9f', 'kRAikWitb4kDxaAyBqNrmLmllMEDO3', 'cn-hangzhou')
+
+
+healthcheck_status = Gauge("healthcheck_status", "ipaddress", ['instance_id','server_name', 'ipaddress'], registry=registry)
+url_http_avgtime = Gauge("url_http_times_avgs", "url  of avgs", ['url'], registry=registry)
+url_http_qps = Gauge("url_http_qps", "url  of qps", ['url'], registry=registry)
+probe_http_status_code = Gauge("http_status_code", 'h5',['server_name'], registry=registry)
+probe_http_total_time = Gauge("http_total_time", 'h5',['server_name'], registry=registry)
+probe_http_dns_time = Gauge("http_dns_time", 'h5',['server_name'], registry=registry)
+probe_http_connect_time = Gauge("http_connect_time", 'h5',['server_name'], registry=registry)
+probe_http_pretransfer_time = Gauge("http_pretransfer_time", 'h5',['server_name'], registry=registry)
+probe_http_first_byte_time = Gauge("http_first_byte_time", 'h5',['server_name'], registry=registry)
+slb_http_status_code = Gauge("slb_http_status_code", 'slb', ['server_name', 'status'], registry=registry)
+produce_video_task_success_count = Gauge("produce_video_task_success_count", 'success_status_count', ['success_status_count'], registry=registry)
+produce_video_task_fail_count = Gauge("produce_video_task_fail_count", 'fail_status_count', ['fail_status_count'], registry=registry)
+produce_video_task_progress_count = Gauge("produce_video_task_progress_count", 'progress_status_count', ['progress_status_count'], registry=registry)
+produce_video_task_rate = Gauge("produce_video_task_rate", 'produce_video_rate', ['produce_video_rate'], registry=registry)
+produce_video_tts_count = Gauge("tts_aliyun_azure", 'success', ['tts_channel'], registry=registry)
+
+
+
+def  healthcheck():
+    with session_maker() as session:
+        instance_infos = session.query(InstanceList).filter(InstanceList.server_name=="longvideoapi.prod").all()
+        for index in range(len(instance_infos)):
+            ipaddr = instance_infos[index].ipadd
+            server_name = instance_infos[index].server_name
+            http_code = healthcheck(ipaddr, server_name)
+            instance_id = instance_infos[index].instance_id
+            healthcheck_status.labels(instance_id, server_name, ipaddr).set(http_code)
+
+def interface_qps():
+    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
+            url_qps = intface_infos[i].qps
+            url_avg_time = intface_infos[i].avg_time
+            url_http_avgtime.labels(url).set(url_avg_time)
+            url_http_qps.labels(url).set(url_qps)
+
+def h5_healthcheck():
+    share_h5 = "share_h5"
+    download_h5 = "download_h5"
+    share_h5_url = "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=#"
+    download_h5_url = "https://longvideoh5.piaoquantv.com/dist_1_3_4/upload?accessToken=fe8914eb2e99d1fe8ddaa2f753f5ec613eb2dfbb&versionCode=323&galleryId=0&fileType=2&machineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&platform=devtools&system=iOS%2010.0.1&appType=0&appId=wx89e7eb06478361d7&pageSource=vlog-pages%2Fwebview&loginUid=12463024&machineInfo=%7B%22sdkVersion%22%3A%222.4.1%22,%22brand%22%3A%22devtools%22,%22language%22%3A%22zh_CN%22,%22model%22%3A%22iPhone%20X%22,%22platform%22%3A%22devtools%22,%22system%22%3A%22iOS%2010.0.1%22,%22weChatVersion%22%3A%228.0.5%22,%22screenHeight%22%3A812,%22screenWidth%22%3A375,%22windowHeight%22%3A730,%22windowWidth%22%3A375,%22softVersion%22%3A%224.1.168%22%7D&wxHelpPagePath=%2Fpackage-my%2Fhelp-feedback%2Fhelp-feedback&transaction=2065ff98-6f27-4f09-c9eb-d366c99dd5d5&videoBarrageSwitch=true&addMusic=1&eventId=0&fromActivityId=0&sessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&subSessionId=1626833289618-583a312d-81cd-62f9-cdd4-cf914c682d55&projectId=&entranceType=#wechat_redirec"
+    shar_h5_curl_response = ex_response(share_h5_url)
+    share_h5_url_info = shar_h5_curl_response.getinfo()
+    download_h5_curl_response = ex_response(download_h5_url)
+    download_h5_url_info = download_h5_curl_response.getinfo()
+
+    probe_http_status_code.labels(share_h5).set(share_h5_url_info["http_code"])
+    probe_http_status_code.labels(download_h5).set(download_h5_url_info["http_code"])
+
+    probe_http_total_time.labels("share_h5").set(share_h5_url_info["total_time"]*1000)
+    probe_http_total_time.labels("download_h5").set(download_h5_url_info["total_time"]*1000)
+
+    probe_http_dns_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_dns_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+    probe_http_connect_time.labels("share_h5").set(share_h5_url_info["dns_time"]*1000)
+    probe_http_connect_time.labels("download_h5").set(download_h5_url_info["dns_time"]*1000)
+
+
+    probe_http_pretransfer_time.labels("share_h5").set(share_h5_url_info["pretransfer_time"]*1000)
+    probe_http_pretransfer_time.labels("download_h5").set(download_h5_url_info["pretransfer_time"]*1000)
+
+    probe_http_first_byte_time.labels("share_h5").set(share_h5_url_info["first_byte_time"]*1000)
+    probe_http_first_byte_time.labels("download_h5").set(download_h5_url_info["first_byte_time"]*1000)
+
+
+def produce_video_task_status_count():
+    with session_maker_longvideo() as  session:
+        video_progress_count = session.query(produce_video_task).filter(produce_video_task.task_status == 1).count()
+        video_success_count = session.query(produce_video_task).filter(produce_video_task.task_status == 2).count()
+        video_fail_count = session.query(produce_video_task).filter(produce_video_task.task_status == 3).count()
+        video_produce_speed =  session.query(produce_video_task).filter(produce_video_task.submit_timestamp)
+        #视频合成成功率
+        produce_video_task_success_count.labels("video_sucess_count").set(video_success_count)
+        produce_video_task_fail_count.labels("video_fail_count").set(video_fail_count)
+        produce_video_task_progress_count.labels("video_progress_count").set(video_progress_count)
+        #合成速度
+        end_time = int(time.time())
+        start_time = end_time - (end_time - time.timezone) % 86400
+        res = session.query(produce_video_task).filter(produce_video_task.task_status==2).order_by(produce_video_task.id.desc()).first()
+        if  res:
+            duration = res.duration
+            submit_timestamp = res.submit_timestamp
+            complete_timestamp = res.complete_timestamp
+            rate = (duration / (complete_timestamp - submit_timestamp) / 1000)
+            produce_video_task_rate.labels("produce_video_task_rate").set(round(rate, 3))
+        else:
+            produce_video_task_rate.labels("produce_video_task_rate").set(0)
+
+    #tts
+
+    res = logs_tts_count("aliyun",1)
+    if res[0]["count"]:
+        produce_video_tts_count.labels("aliyun_success").set(res[0]["count"])
+    res = logs_tts_count("aliyun", 0)
+    if res[0]["count"]:
+        produce_video_tts_count.labels("aliyun_fail").set(res[0]["count"])
+    res = logs_tts_count("azure", 1)
+    if res[0]["count"]:
+        produce_video_tts_count.labels("azure_success").set(res[0]["count"])
+    res = logs_tts_count("aliyun", 0)
+    if res[0]["count"]:
+        produce_video_tts_count.labels("azure_fail").set(res[0]["count"])
+
+def  count_metric(url):
+    avgs = count_avg_time(url)
+    qps = count_qps(url)
+    # url_http_times_avgs.labels(url, avgs)
+    url_http_qps.labels(url).set(qps)
+
+def count_threads(url):
+    while True:
+        t = threading.Thread(target=count_metric,args=(url,))
+        t.setDaemon(True)
+        t.start()
+        time.sleep(10)
+
+if __name__ == '__main__':
+    start_http_server(9091)
+    thread_num = 10
+    threads = []
+    for i in range(thread_num):
+        t = threading.Thread(target=count_threads,args=(url,))
+        threads.append(t)
+    for thread in threads:
+        thread.setDaemon(True)
+        thread.start()
+    thread.join()

+ 49 - 0
model.py

@@ -0,0 +1,49 @@
+from sqlalchemy import create_engine ,Integer,String,Column
+from DBSession import Base
+
+
+class InstanceList(Base):
+    __tablename__ = 'instance_list'
+    id = Column(Integer, primary_key=True)
+    instance_id = Column(String(32))
+    instance_name = Column(String(32))
+    ipadd = Column(String(32))
+    server_name = Column(String(32))
+    status = Column(Integer)
+
+
+    def __init__(self):
+        print(self.id)
+
+    def __repr__(self):
+        return '<EAVideoIBPInfo %r>' % self.id
+
+class IntfaceList(Base):
+    __tablename__ = 'interface_list'
+    id = Column(Integer, primary_key=True)
+    app_type = Column(String(32))
+    interface_url = Column(String(32))
+    qps = Column(Integer)
+    avg_time = Column(Integer)
+
+
+
+    def __init__(self):
+        print(self.id)
+
+    def __repr__(self):
+        return '<EAVideoIBPInfo %r>' % self.id
+
+class app_info(Base):
+    __tablename__ = 'app_info'
+    id = Column(Integer, primary_key=True)
+    app_name = Column(String(32))
+    app_type = Column(Integer)
+
+
+
+    def __init__(self):
+        print(self.id)
+
+    def __repr__(self):
+        return '<EAVideoIBPInfo %r>' % self.id

+ 66 - 0
model_longvideo.py

@@ -0,0 +1,66 @@
+from sqlalchemy import create_engine ,Integer,String,Column
+from DBSession import Base
+
+
+class produce_video_task(Base):
+    __tablename__ = 'produce_video_task'
+    id = Column(Integer, primary_key=True)
+    produce_channel = Column(Integer)
+    task_type = Column(Integer)
+    project_id = Column(String(32))
+    section_id = Column(String(32))
+    task_status = Column(Integer)
+    job_id = Column(String(32))
+    submit_timestamp = Column(Integer)
+    submit_result_data = Column(String(32))
+    complete_timestamp = Column(Integer)
+    duration = Column(Integer)
+    error_code = Column(Integer)
+    error_msg = Column(String(32))
+    create_timestamp = Column(Integer)
+
+    def __init__(self):
+        print(self.id)
+
+    def __repr__(self):
+        return '<EAVideoIBPInfo %r>' % self.id
+
+
+class produce_video_project(Base):
+    __tablename__ = "produce_video_project"
+    project_id = Column(String(64))
+    uid = Column(Integer, primary_key=True)
+    app_type = Column(Integer)
+    platform = Column(String(16))
+    title = Column(String(128))
+    draftbox_id = Column(String(64))
+    article_id = Column(String(64))
+    video_width = Column(Integer)
+    video_height = Column(Integer)
+    oss_object_key = Column(String(255))
+    vod_media_id = Column(String(64))
+    ice_media_id = Column(String(64))
+    video_duration = Column(Integer)
+    produce_channel = Column(Integer)
+    produce_status = Column(Integer)
+    submit_timestamp = Column(Integer)
+    produce_done_timestamp = Column(Integer)
+    error_code = Column(Integer)
+    error_msg = Column(Integer)
+    create_timestamp = Column(Integer)
+    update_timestamp = Column(Integer)
+    video_id = Column(Integer)
+    data_status = Column(Integer)
+    sdata_version_code = Column(Integer)
+    parent_project_id = Column(String(64))
+    root_project_id = Column(String(64))
+    reproduce_status = Column(Integer)
+    from_scene = Column(Integer)
+
+
+
+    def __init__(self):
+        print(self.uid)
+
+    def __repr__(self):
+        return '<EAVideoIBPInfo %r>' % self.uid

+ 1 - 0
prometheus.py

@@ -0,0 +1 @@
+

+ 167 - 0
requirement.txt

@@ -0,0 +1,167 @@
+aiocontextvars==0.2.2
+alembic==1.6.5
+alibabacloud-credentials==0.1.4
+alibabacloud-endpoint-util==0.0.3
+alibabacloud-mts20140618==1.0.2
+alibabacloud-openapi-util==0.1.4
+alibabacloud-tea==0.2.6
+alibabacloud-tea-openapi==0.2.5
+alibabacloud-tea-util==0.3.4
+aliyun-log-python-sdk==0.6.53
+aliyun-python-sdk-cms==7.0.11
+aliyun-python-sdk-core==2.13.32
+aliyun-python-sdk-core-v3==2.13.11
+aliyun-python-sdk-cr==3.0.1
+aliyun-python-sdk-ecs==4.19.2
+aliyun-python-sdk-ess==2.3.1
+aliyun-python-sdk-kms==2.14.0
+aliyun-python-sdk-mts==2.7.5
+aliyun-python-sdk-slb==3.2.16
+allure-pytest==2.9.43
+allure-python-commons==2.9.43
+altgraph==0.17
+antiorm==1.2.1
+appdirs==1.4.4
+APScheduler==3.7.0
+asgiref==3.2.7
+astroid==2.5.6
+attrs==21.2.0
+audioread==2.1.9
+autopep8==1.5.7
+bcrypt==3.1.7
+certifi==2020.12.5
+cffi==1.14.5
+chardet==4.0.0
+click==7.1.2
+coinop==0.2.1
+config==0.5.0.post0
+contextvars==2.4
+crcmod==1.7
+cryptography==3.4.7
+dateparser==1.0.0
+db==0.1.1
+DBUtils==2.0
+decorator==4.4.2
+Django==2.0.12
+docker==4.2.0
+docopt==0.6.2
+dominate==2.6.0
+ecdsa==0.17.0
+elasticsearch==7.13.0
+ffmpeg==1.4
+ffmpeg-python==0.2.0
+ffmpy==0.3.0
+flake8==3.9.2
+Flask==2.0.1
+Flask-APScheduler==1.10.1
+Flask-Bootstrap==3.3.7.1
+Flask-Cors==3.0.10
+Flask-Migrate==2.0.0
+Flask-Prometheus==0.0.1
+flask-redis==0.4.0
+Flask-Script==2.0.5
+Flask-SQLAlchemy==2.3.2
+future==0.18.2
+greenlet==1.1.0
+gunicorn==19.9.0
+httpserver==1.1.0
+idna==2.10
+imageio==2.9.0
+imageio-ffmpeg==0.4.3
+immutables==0.15
+importlib-metadata==4.0.1
+iniconfig==1.1.1
+isort==5.8.0
+itsdangerous==2.0.1
+jedi==0.17.2
+Jinja2==3.0.1
+jmespath==0.10.0
+joblib==1.0.1
+lazy-object-proxy==1.6.0
+librosa==0.6.0
+llvmlite==0.31.0
+loguru==0.5.3
+lxml==4.5.1
+macholib==1.14
+Mako==1.1.4
+MarkupSafe==2.0.1
+mccabe==0.6.1
+modulegraph==0.18
+moviepy==1.0.3
+multi-key-dict==2.0.3
+numba==0.48.0
+numpy==1.19.5
+odps==3.5.1
+oss2==2.14.0
+packaging==20.9
+pandas==1.2.4
+paramiko==2.7.1
+parso==0.7.1
+patchboard==0.5.1
+pbkdf2-ctypes==0.99.5
+pbr==5.4.5
+Pillow==8.1.2
+pluggy==0.13.1
+pooch==1.3.0
+PriorityThreadPoolExecutor==0.0.1
+proglog==0.1.9
+prometheus-client==0.11.0
+protobuf==3.17.1
+psutil==5.7.0
+py==1.10.0
+py2app==0.24
+pycodestyle==2.6.0
+pycoin==0.52
+pycparser==2.20
+pycrypto==2.6.1
+pycryptodome==3.10.1
+pycurl==7.43.0.6
+pydocstyle==6.1.1
+pydub==0.25.1
+pyflakes==2.2.0
+pylint==2.8.3
+pymongo==3.11.0
+PyMySQL==0.9.2
+PyNaCl==0.3.0
+pyodps==0.9.5
+pyotp==2.6.0
+pyparsing==2.4.7
+pytest==6.2.4
+python-bitcoinlib==0.4.0
+python-dateutil==2.8.1
+python-editor==1.0.4
+python-jenkins==1.7.0
+python-jsonrpc-server==0.4.0
+python-language-server==0.36.2
+pytz==2021.1
+PyYAML==5.4.1
+redis==3.5.3
+regex==2021.4.4
+requests==2.25.1
+resampy==0.2.2
+rope==0.19.0
+round==0.9.9
+scikit-learn==0.24.1
+scipy==1.5.4
+six==1.15.0
+snowballstemmer==2.1.0
+SoundFile==0.10.3.post1
+SQLAlchemy==1.4.15
+sqlparse==0.3.1
+tabulate==0.8.9
+threadpoolctl==2.1.0
+toml==0.10.2
+tqdm==4.59.0
+typed-ast==1.4.3
+typing-extensions==3.10.0.0
+tzlocal==2.1
+ujson==4.0.2
+urllib3==1.26.4
+visitor==0.1.3
+websocket-client==0.57.0
+Werkzeug==2.0.1
+wrapt==1.12.1
+xlrd==1.2.0
+xlwt==1.3.0
+yapf==0.31.0
+zipp==3.4.1

+ 23 - 0
scheduler_jobs.py

@@ -0,0 +1,23 @@
+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()

+ 184 - 0
test.py

@@ -0,0 +1,184 @@
+from flask import Flask
+import pycurl
+from io import StringIO
+import time
+from DBSession import session_maker
+from model import InstanceList
+app = Flask(__name__)
+from utils import *
+
+def  test():
+
+    return ipaddr
+
+
+def  h5_curl():
+
+        c = pycurl.Curl()
+        c.setopt(pycurl.URL, "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=/")
+        c.setopt(pycurl.HTTPHEADER, ["Accept:"])
+        c.setopt(pycurl.WRITEFUNCTION, StringIO.write)
+        c.setopt(pycurl.FOLLOWLOCATION, 1)
+        c.setopt(pycurl.MAXREDIRS, 5)
+        c.perform()
+
+
+        info = c.getinfo(pycurl.INFO_FILETIME)
+
+        print(info)
+if __name__ == '__main__':
+    # with session_maker() as session:
+    #     instance_info = session.query(InstanceList).filter(InstanceList.status==0).all()
+    #     for index in range(len(instance_info)):
+    #         print( instance_info[index].ipadd)
+
+    requestUri_list = [
+        'longvideoapi/sys/config',
+        'longvideoapi/video/played',
+        'longvideoapi/video/shared/weixin/friend',
+        'longvideoapi/user/login/v2',
+        'longvideoapi/user/info/getUserInfoExt',
+        'longvideoapi/user/token/check',
+        'longvideoapi/user/token/refresh',
+        'longvideoapi/user/info/homepageHead',
+        'longvideoapi/user/share/homepage/circle',
+        'longvideoapi/user/idols',
+        'longvideoapi/user/fans',
+        'longvideoapi/user/recommend/list/v4',
+        'longvideoapi/user/outside/subscribeBatch',
+        'longvideoapi/user/info/getBaseUserInfo',
+        'longvideoapi/user/info/getTargetBaseUserInfo',
+        'longvideoapi/user/getWxUserInfoByCode',
+        'longvideoapi/user/follow',
+        'longvideoapi/user/unfollow',
+        'longvideoapi/video/favorite',
+        'longvideoapi/video/unfavorite',
+        'longvideoapi/video/shared/weixin/circle',
+        'longvideoapi/videoCollection/loadUserVideoCollections',
+        'longvideoapi/video/v2/sharePage/queryVideosByCollectionId',
+        'longvideoapi/video/v2/detailPage/queryVideosByCollectionId',
+        'longvideoapi/videoCollection/loadUserVideoCollectionsForShareOrDetailPage',
+        'longvideoapi/video/distribute/getAppInfo',
+        'longvideoapi/video/distribute/category/videoList/v2',
+        'longvideoapi/video/v2/followed',
+        'longvideoapi/video/v2/loadHotVideosByCollectionId',
+        'longvideoapi/video/v2/loadLatelyVideosByCollectionId',
+        'longvideoapi/video/v2/detail',
+        'longvideoapi/video/v2/sharePageDetail',
+        'longvideoapi/video/send',
+        'longvideoapi/video/getCoverImagePaths',
+        'longvideoapi/video/updateVideo',
+        'longvideoapi/video/deleteVideo',
+        'longvideoapi/video/barrage/send',
+        'longvideoapi/video/barrage/switch',
+        'longvideoapi/video/videoActionReport',
+        'longvideoapi/video/barrage/v2/list',
+        'longvideoapi/video/shared/h5"',
+        'longvideoapi/user/share/report',
+        'longvideoapi/oss/signature',
+        'longvideoapi/oss/completeUpload',
+        'longvideoapi/oss/producevideo/getStsToken',
+        'longvideoapi/operate/message/list',
+        'longvideoapi/video/message/list',
+        'longvideoapi/sys/message/list',
+        'longvideoapi/user/station/message/statistics/info',
+        'longvideoapi/user/station/message/statistics/read',
+        'longvideoapi/user/station/message/totalCount/v2',
+        'longvideoapi/user/station/message/totalRead',
+        'longvideoapi/user/station/notice/list',
+        'longvideoapi/user/station/message/share/list',
+        'longvideoapi/user/station/message/prise/list',
+        'longvideoapi/user/station/message/favorite/list',
+        'longvideoapi/user/station/message/comment/list',
+        'longvideoapi/user/station/message/barrage/list',
+        'longvideoapi/operation/message/list',
+        'longvideoapi/search/userandvideo/list',
+        'longvideoapi/search/tips',
+        'longvideoapi/search/user/list',
+        'longvideoapi/search/video/list',
+        'longvideoapi/search/hot/words',
+        'longvideoapi/search/hot/videos',
+        'longvideoapi/video/distribute/search/recommendVideoes/v2',
+        'longvideoapi/comment/top/save',
+        'longvideoapi/comment/top/page',
+        'longvideoapi/comment/praise',
+        'longvideoapi/comment/second/save',
+        'longvideoapi/comment/second/page',
+        'longvideoapi/comment/delete',
+        'longvideoapi/comment/updelete',
+        'longvideoapi/comment/hots',
+        'longvideoapi/bank/withdraw/getBankWithdrawConfig',
+        'longvideoapi/bank/withdraw/getBankWithdrawRecordList',
+        'longvideoapi/bank/withdraw/wxSamllapp/requestWithdraw',
+        'longvideoapi/purchase/video/list',
+        'longvideoapi/profits/myself/head',
+        'longvideoapi/profits/myself/list',
+        'longvideoapi/profits/myself/recordList/v2',
+        'longvideoapi/profits/reward/recordListAccordingToUser',
+        'longvideoapi/profits/reward/recordListAccordingToVideo',
+        'longvideoapi/video/reward/getVideoRewardHeadInfo',
+        'longvideoapi/video/reward/getVideoRewardRecordList',
+        'longvideoapi/video/reward/getVideoRewardConfig',
+        'longvideoapi/video/reward/getVideoRewardConfig/v2',
+        'longvideoapi/order/updateClientPayStatus',
+        'longvideoapi/order/purchase',
+        'longvideoapi/profits/videoPay/head',
+        'longvideoapi/profits/videoPay/list',
+        'longvideoapi/video/getPayedVideoPath',
+        'longvideoapi/order/reward',
+        'longvideoapi/video/reward/getVideoDetailRewardInfo',
+        'longvideoapi/video/recommend/detailPage/list',
+        'longvideoapi/video/recommend/sharePage/list',
+        'longvideoapi/measure/report/view',
+        'longvideoapi/video/validatePwd"',
+        'longvideoapi/video/validatePwdAuth"',
+        'longvideoapi/video/v2/getCutVideo',
+        'longvideoapi/frontConfig/getWxFrontConfig',
+        'longvideoapi/frontConfig/getVideoPlayConfig',
+        'longvideoapi/frontConfig/getUserFrontConfig',
+        'longvideoapi/rhythmapp/homepage/getAllVideos',
+        'longvideoapi/ad/position/info'
+        ]
+
+    # for i in range(len(instance_info["Instances"]["Instance"])):
+    #     instance_id = instance_info["Instances"]["Instance"][i]["InstanceId"]
+    #     ipaddr = instance_info["Instances"]["Instance"][i]["VpcAttributes"]["PrivateIpAddress"]["IpAddress"][0]
+    #     server_name = instance_info["Instances"]["Instance"][i]["Tags"]["Tag"][0]["TagValue"]
+    #     status = instance_info["Instances"]["Instance"][i]["Status"]
+    #     instance_name = instance_info["Instances"]["Instance"][i]["HostName"]
+    #     if status == "running":
+    # #         status = 1
+    # for url in requestUri_list:
+    #     IntfaceInfo = None
+    #     IntfaceInfo = IntfaceList()
+    #     with session_maker() as session:
+    #             IntfaceInfo.app_type = "1"
+    #             IntfaceInfo.interface_url = url
+    #             session.add(IntfaceInfo)
+    # #
+    # c = pycurl.Curl()
+    # c.setopt(pycurl.URL, "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=/")
+    # c.setopt(pycurl.HTTPHEADER, ["Accept:"])
+    # b = StringIO.StringIO()
+    # c.setopt(pycurl.WRITEFUNCTION, b.write)
+    # c.setopt(pycurl.FOLLOWLOCATION, 1)
+    # c.setopt(pycurl.MAXREDIRS, 5)
+    # c.perform()
+    #
+    #
+    # info = c.getinfo(pycurl.INFO_FILETIME)
+    #
+    # print(info)
+
+    # with open("/t3.txt", "r") as f:  # 打开文件
+    #     data = f.read()  # 读取文件
+    #    #     print(data)
+    # 20210716000000000111111
+    # 20210726200800000000000
+    # start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
+    # end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
+    # print(start_time , end_time)
+    appType = ['0', '4', '5', '6', '12' ,'15']
+    for index in range(len(appType)):
+        # qps = count_qps(url, appType[index])
+        print(appType[index])

+ 357 - 0
utils.py

@@ -0,0 +1,357 @@
+import os
+
+import json
+from aliyunsdkcore.client import AcsClient
+from aliyunsdkecs.request.v20140526.DescribeInstancesRequest import DescribeInstancesRequest
+from model import InstanceList,IntfaceList
+# from DBSession import session_maker
+from model_longvideo import produce_video_task
+from DBSession_longvideo import session_maker_longvideo
+from aliyun.log.logclient import LogClient
+from aliyun.log.getlogsrequest import GetLogsRequest
+import  requests
+import  time
+import  pymysql
+from sqlalchemy.sql import func
+from model_longvideo import produce_video_project
+client = AcsClient('LTAI4GBWbFvvXoXsSVBe1o9f', 'kRAikWitb4kDxaAyBqNrmLmllMEDO3', 'cn-hangzhou')
+
+
+
+def intances_list_update():
+
+    request = DescribeInstancesRequest()
+    request.set_accept_format('json')
+    request.set_PageSize(100)
+    request.set_InstanceNetworkType("vpc")
+    request.set_Tags([
+        {
+            "Key": "ecs"
+        }
+    ])
+
+    response = client.do_action_with_exception(request)
+    instance_info = json.loads(response)
+    intances_list_del()
+    print(len(instance_info["Instances"]["Instance"]))
+    for i in range(len(instance_info["Instances"]["Instance"])):
+        instance_id = instance_info["Instances"]["Instance"][i]["InstanceId"]
+        ipaddr = instance_info["Instances"]["Instance"][i]["VpcAttributes"]["PrivateIpAddress"]["IpAddress"][0]
+        server_name = instance_info["Instances"]["Instance"][i]["Tags"]["Tag"][0]["TagValue"]
+        status = instance_info["Instances"]["Instance"][i]["Status"]
+        instance_name = instance_info["Instances"]["Instance"][i]["HostName"]
+        if status == "running":
+            status = 1
+        instance_insert(instance_id, ipaddr, instance_name, server_name, status)
+
+
+    return "OK"
+
+
+def intances_list_del():
+    with session_maker() as session:
+        session.query(InstanceList).delete()
+
+def instance_insert(instance_id, ipadd, instance_name, server_name, status):
+    InstanceInfo = None
+    InstanceInfo = InstanceList()
+    with session_maker() as session:
+        InstanceInfo.instance_id = instance_id
+        InstanceInfo.ipadd = ipadd
+        InstanceInfo.instance_name = instance_name
+        InstanceInfo.server_name = server_name
+        InstanceInfo.status = status
+        session.add(InstanceInfo)
+
+
+
+
+
+def healthcheck(ipaddr,server_name):
+    """返回容器upload时间,容器运行状态,健康坚持接口返回值,"""
+    svc_name = server_name
+    print(server_name)
+    if svc_name == "longvideoapi.prod" :
+        url = "http://{}:8080/longvideoapi/test".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        print(res.status_code)
+        return res.status_code
+    if svc_name == "commonapi.prod":
+        url = "http://{}:8080/commonapi/test".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+    if svc_name == "speed.prod":
+        url = "http://{}:8080/longvideoapi/test".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+    if svc_name == "clipapi.prod":
+        url = "http://{}:8080/longvideoapi/test".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+    if svc_name == "distribution.prod":
+        url = "http://{}:8080/healthcheck".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+    if svc_name == "manager.prod":
+        url = "http://{}:8971/dev/test/healthcheck".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+    if svc_name == "recommend-queue.prod":
+        url = "http://{}:8080/healthcheck".format(ipaddr)
+        res = requests.post(url, timeout=5)
+        return res.status_code
+
+
+
+# def  healthcheck_metirc(instance_id,ipaddr,server_name,http_code):
+#     healthcheck_status = Gauge("healthcheck_status", "http_code", ['instance_id', 'server_name', 'ipaddress'],
+#                                registry=registry)
+#
+#     healthcheck_status.labels(instance_id, server_name, ipaddr).set(http_code)
+#
+#     return Response(generate_latest(registry),mimetype="text/plain")
+
+
+
+def count_qps(appType, url):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'request-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    end_time = start_time - 60
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         "params.appType={} and requestUri= {} |select requestUri,count(1) as cnt, date_format(logTimestamp/1000,'%Y-%m-%d %H:%i:%S') as date  group by requestUri, date order by cnt desc limit 1".format(appType, url)
+                         , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except :
+        qps = 0
+    else:
+        if res.body:
+            qps = res.body[0]["cnt"]
+        else:
+            qps = 0
+    print(int(time.time())-start_time)
+    return  qps
+
+def  count_avg_time(appType ,url):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'request-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    end_time = start_time - 60
+    # url = '/longvideoapi/user/idolsUpdated'
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         "params.appType=%s and requestUri=%s |select requestUri,round(avg(expendTime)) as  avgs,count(1) as cnt group by requestUri " %(appType, url), 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+    else:
+        if res.body:
+            avgs = res.body[0]["avgs"]
+        else:
+            avgs = 0
+    return  avgs
+
+
+def  slb_status_code_count(server_name):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    if server_name == "longvideoapi":
+        project = 'longvideoapi-slb-log'
+        logstore = 'slb-access-log'
+    if server_name == "speed":
+        project = 'speed-slb-log'
+        logstore = 'access-log'
+    if server_name == "clip":
+        project = 'clips-slb-log'
+        logstore = 'access-log'
+    if server_name == "commonapi":
+        project = 'commonapi-slb-log'
+        logstore = 'slb-access-log'
+
+    topic = ""
+    end_time = int(time.time())
+    start_time = end_time - (end_time - time.timezone)%86400
+    # url = '/longvideoapi/user/idolsUpdated'
+    req = GetLogsRequest(project, logstore, start_time, end_time,  topic,
+                         "* |SELECT  status ,COUNT(*) as  cnt   group by status" , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+    else:
+        if res.body:
+            return  res.body
+
+
+def produce_video_task_status_count():
+    with session_maker_longvideo() as  session:
+        video_progress_count = session.query(produce_video_task).filter(produce_video_task.task_status == 1).count()
+        video_success_count = session.query(produce_video_task).filter(produce_video_task.task_status == 2).count()
+        video_fail_count = session.query(produce_video_task).filter(produce_video_task.task_status == 3).count()
+        end_time = int(time.time())
+        start_time = end_time - (end_time - time.timezone) % 86400
+        res = session.query(produce_video_task).filter(produce_video_task.task_status==2).order_by(produce_video_task.id.desc()).first()
+
+        duration = res.duration
+        submit_timestamp = res.submit_timestamp
+        complete_timestamp = res.complete_timestamp
+        print(res.id,duration,submit_timestamp,complete_timestamp)
+        rate = (duration / (complete_timestamp - submit_timestamp) / 1000)
+
+
+
+def logs_tts_count(tts_channel, tts_status):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-monitor'
+    logstore = 'monitor-log'
+
+    topic = ""
+    end_time = int(time.time())
+    start_time = end_time - (end_time - time.timezone)%86400
+    req = GetLogsRequest(project, logstore, start_time, end_time,  topic,
+                         "* and __topic__: producetts and channel:{} and  produceStatus:{}| select channel,produceStatus,count(*) as count group by channel,produceStatus".format(tts_channel, tts_status) , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+    else:
+        if res.body:
+            return  res.body
+
+
+
+def  count_recommend_null():
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'app-recommend-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    #监控获取时间间隔300s
+    end_time = start_time - 300
+    query_sql = "* and requestUri:'/longvideoapi/video/distribute/category/videoList/v2' | select count(DISTINCT json_extract(params, '$.machineCode')) as cnt where json_array_length(json_extract(result, '$.data')) = 0"
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic, query_sql, 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        print(e)
+        avgs = 0
+    else:
+        if res.body:
+            cnt_300 = res.body[0]["cnt"]
+        else:
+            cnt_300 = 0
+    return  cnt_300
+
+def  db_query(sql):
+    HOST = 'rr-bp1x9785e8h5452bi157.mysql.rds.aliyuncs.com'
+    PORT = '3306'
+    DATABASE = 'longvideo'
+    USERNAME = 'devops'
+    PASSWORD = 'devops@123456'
+    conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
+    cursor = conn.cursor()
+    cursor.execute(sql)
+    res = cursor.fetchone()
+
+    return  res
+
+
+def  count_qps_avgtime(appType):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'request-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    end_time = start_time - 60
+    # url = '/longvideoapi/user/idolsUpdated'
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         "params.appType=%s | select requestUri,count(1) as cnt  , avg(expendTime)  as avg_time group by requestUri  order by requestUri,cnt desc limit  1000" %(appType), 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+
+    return  res
+
+def  count_rt_less_time_count(appType, than, less):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'request-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    end_time = start_time - 60
+    # url = '/longvideoapi/user/idolsUpdated'
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         "params.appType=%s and expendtime >%s and  expendtime <%s| select requestUri,count(1) as cnt group by requestUri  order by requestUri,cnt desc limit  1000" %(appType,than,less), 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+
+    return  res
+
+
+
+if __name__ == '__main__':
+    # slb_status_code_count("clip")
+    # healthcheck_result = []
+    # with session_maker() as session:
+    #     instance_infos = session.query(InstanceList).filter(InstanceList.status==0).all()
+    #     for index in range(len(instance_infos)):
+    #         ipaddr = instance_infos[index].ipadd
+    #         server_name = instance_infos[index].server_name
+    #         http_code = healthcheck(ipaddr,server_name)
+    #         result = {"ipaddr": ipaddr, "server_name": server_name, "http_code": http_code}
+    #         healthcheck_result.append(result)
+    # print(healthcheck_result)
+    # produce_video_task_status_count()
+    # res = logs_tts_count("aliyun",1)
+    # if res[0]["count"]:
+    #     print(res[0]["count"])
+    # res = logs_tts_count("aliyun", 0)
+    # if res[0]["count"]:
+    #     print(res[0]["count"])
+    # res = logs_tts_count("azure", 1)
+    # if res[0]["count"]:
+    #     print(res[0]["count"])
+    # res = logs_tts_count("aliyun", 0)
+    # if res[0]["count"]:
+    #     print(res[0]["count"])
+    # res = count_recommend_nu
+    # res = count_qps_avgtime(appType=0)
+    # print(res.body)
+    # for i in range(len(res.body)):
+    #     url = res.body[i]["requestUri"]
+    #
+    #     qps = res.body[i]["cnt"]
+    #     avgtime = round(float(res.body[i]["avg_time"]), 2)
+    #     print(url,qps ,avgtime)
+
+    res = count_rt_less_time_count(0, 1000, 10000)
+    print(res.body)