def measureDownloadSpeed(IDC, dataCenterIndex, resultArray, speedtestIndex,
                         searchListCount):
    localized_idc = util.getLocalizedIDC(IDC)
    localized_data_center = util.getLocalizedDataCenterArray(
        IDC)[dataCenterIndex]
    print(
        "节点:", localized_idc + " " + localized_data_center +
        "({0}/{1})".format(speedtestIndex + 1, searchListCount))
    url = util.loadUrlByArgs(IDC, dataCenterIndex)
    print("测试文件地址:", url)
    [timeSpent, dataDownload] = getDataCenterSpeed(url)
    resultArray.append([
        localized_idc, localized_data_center,
        dataDownload / timeSpent * downloadSpeedRefreshRate,
        util.getHostFromUrl(url)
    ])
Example #2
0
def handleList():
    if not args.list:
        return
    searchTable = pt.PrettyTable()
    searchTable.field_names = doPackList("服务商", "缩写", "节点位置", "节点编号", "节点域名",
                                         "节点链接")
    searchTable.align = 'l'
    searchTable.align["节点编号"] = 'r'
    for dataCenter in searchList:
        IDC = IDCs[dataCenter[0]]
        dataCenterIndex = dataCenter[1]
        DCUrl = util.loadUrlByArgs(IDC, dataCenterIndex)
        searchTable.add_row(
            doPackList(IDC['localized_idc'], IDC['idc'],
                       IDC['localized_data_center'][dataCenterIndex],
                       dataCenterIndex, util.getHostFromUrl(DCUrl), DCUrl))
    print(searchTable)
Example #3
0
for IDC in IDCs:
    if IDC['idc'] in sys.argv or IDC['localized_idc'] in sys.argv:
        if 'localized_idc' in IDC:
            localized_idc = IDC['localized_idc']
        else:
            localized_idc = IDC['idc']
        print("正在测试:", localized_idc)
        dataCenterCount = len(IDC['prefix'][0])
        for dataCenterIndex in range(0, dataCenterCount):
            if 'localized_data_center' in IDC:
                localized_data_center = IDC['localized_data_center'][
                    dataCenterIndex]
            else:
                localized_data_center = IDC['prefix'][0][dataCenterIndex]
            print("节点:", localized_data_center)
            url = util.loadUrlByArgs(IDC, dataCenterIndex)
            print("测试文件地址:", url)
            [timeSpent, dataDownload] = getDataCenterSpeed(url)
            resultArray.append([
                localized_idc, localized_data_center,
                dataDownload / timeSpent * downloadSpeedRefreshRate,
                util.getHostFromUrl(url)
            ])
resultArray.sort(key=functools.cmp_to_key(compareResultObject), reverse=True)
for row in resultArray:
    row[2] = prettifyUnit(row[2])
    resultTable.add_row(row)
print("\n\n\n\n\n")
print(resultTable)
Example #4
0
        "Ping": [],
        "Smartping": False,
        "Topology": []
    }


smartpingSetting = getServerSettings()
IDCs = util.loadIDC()

for IDC in IDCs:
    if IDC['idc'] in sys.argv or IDC['localized_idc'] in sys.argv:
        if "localized_data_center" in IDC:
            localized_data_center_array = IDC["localized_data_center"]
        else:
            localized_data_center_array = IDC['prefix'][0]
        dataCenterCount = len(IDC['prefix'][0])
        for dataCenterIndex in range(0, dataCenterCount):
            url = util.loadUrlByArgs(IDC, dataCenterIndex)
            localized_idc = IDC[
                'localized_idc'] + ' ' + localized_data_center_array[
                    dataCenterIndex]
            ip = util.getIPFromHost(util.getHostFromUrl(url))
            if ip not in smartpingSetting['Network'] and ip != None:
                smartpingSetting['Network'][ip] = getDefaultEndPoint(
                    localized_idc, ip)
requests.post(smartpingUrl + "/api/saveconfig.json",
              data={
                  "password": smartpingPassword,
                  "config": json.dumps(smartpingSetting)
              })