Exemplo n.º 1
0
def defer_fetch(url, cluster_id, is_list=False):

	logging.info('fetching...%s' % url)

	try:
		result = urlfetch.fetch(url)
		status_code = result.status_code
	except Exception as e:
		if is_list:
			logging.error(e)
			#defer_fetch(url, cluster_id, is_list)
			return
		else:
			logging.error(e)
			#taskqueue.add(url='/start_fetch', params={'url': url, 'cluster_id': cluster_id})
			return
			

	if is_list:
		#cluster_attrs = monitor_config[cluster_id]
		#response_dict = api_handler.getApi(cluster_id)
		#appids = response_dict['B_available']
		appids = list_handler.get_list(cluster_id)
		for appid in appids:
			app_url = 'http://%s.appspot.com/2' % appid
			taskqueue.add(url='/start_fetch', params={'url': app_url, 'cluster_id': cluster_id})
	else:
		appid = urlparse.urlparse(url).netloc.split('.')[0]
		if status_code == 503:
			memcache.set(appid, False, 0, 0, cluster_id)
		else:
			memcache.set(appid, True, 0, 0, cluster_id)
Exemplo n.º 2
0
def getApi(cluster_id):
	appids = list_handler.get_list(cluster_id)

	appid_dict = memcache.get_multi(appids,'',cluster_id)

	response_dict = {
		"B_available": [],
		"C_over_quota": [],
	}

	for appid, val in appid_dict.iteritems():
		if val is True:
			response_dict['B_available'].append(appid)
		elif val is False:
			response_dict['C_over_quota'].append(appid)

	response_dict['A_status_msg'] = "今日还剩 %dGB/%dGB 流量" % (len(response_dict['B_available']), len(appids))

	return response_dict
Exemplo n.º 3
0
def getPage(cluster_id):
	PAGE0 = '''
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
'''
	PAGE1 = '''
</title>
<style type="text/css">
<!--
.title {
        color: #9F0000;
        font-weight: bold;
}
.content {font-size: 15px}
body {
        /*background-image: url(images/night.jpg);
        background-repeat: no-repeat;
        background-attachment: fixed;*/
}
-->
</style>
'''
	PAGE2 = '''
</head>
<body>
<center>
  <p>&nbsp;</p>
  <form action="https://www.google.com/search"><input name="ie" type="hidden" value="UTF-8"><input name="oe" type="hidden" value="UTF-8"><input name="aq" type="hidden" value="t"><input name="rls" type="hidden" value="org.mozilla:zh-CN:official"><input name="client" type="hidden" value="firefox-a"><input name="q" type="text"><input value="谷歌搜索" type="submit"></form>
 

<h1> 
'''
	PAGE3 = ''' 
</h1>
<table width="900" border="1" cellpadding="1" cellspacing="0" bordercolor="#000000">
  <tr>
    <td><table width="
'''
	PAGE4 = '''
%" cellpadding="1" cellspacing="0" bgcolor="#00CC00">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
<p>流量会在<a href="https://zh.wikipedia.org/zh-cn/%E5%A4%AA%E5%B9%B3%E6%B4%8B%E6%97%B6%E5%8C%BA">加州时间</a>每日 0:00 重置</p>
<span>现在的加州时间为:</span><div style="position:relative;width:200px;"><iframe src="https://zh.thetimenow.com/clock/united_states/california/san_francisco?t=n&amp;embed=1&amp;text=16&amp;textdate=15&amp;format=24&amp;digitalclock=36&amp;analogclock=60&amp;letter_spacing=-0&amp;bordersize=0&amp;bordercolor=fffffff&amp;bgcolor=FFFFFF&amp;colorloc=ffffff&amp;colordigital=000000&amp;colordate=000000&amp;styleloc=normal&amp;styledigital=normal&amp;styledate=normal&amp;right=0" width="200" height="80"style="border:none;overflow:hidden;" scrolling="no"></iframe></div>
  <tr>
    <td colspan="3" align="center" valign="top">
'''
	PAGE5 = '''
</td>
  </tr>
</table>

</center>

</body>
</html>

'''
	cluster_attrs = monitor_config[cluster_id]
	result = urlfetch.fetch(cluster_attrs['url'])
	urltype = cluster_attrs['urltype']
	name = cluster_attrs['name'].encode('utf8')
	message = cluster_attrs['message'].encode('utf8')
	
	appids = list_handler.get_list(cluster_id)
	
	response_dict = api_handler.getApi(cluster_id)


	PAGE = PAGE0+ name + PAGE1 + google_analytics_code + PAGE2 + name + '	' + response_dict['A_status_msg'] +PAGE3 + '%f'%((float(len(response_dict['B_available']))/float(len(appids)))*100) + PAGE4 + message + PAGE5
	return PAGE