![](/img/trans.png)
[英]how can i filter data in minute wise or in hour wise or day wise or week wise if data is coming is every 30 seconds ,data is not there for some point
[英]How can I access the number of errors that my App Engine app is returning per hour/day/week?
是否有一個 API 我的 Google App Engine 應用程序可以在以應用程序管理員身份登錄時調用,它會返回有關我的應用程序返回的錯誤數量(404、500 等)的信息?
我想在我的應用程序中設置一個簡單的 cron 作業來計算我的應用程序每隔幾分鍾返回的錯誤數量,如果錯誤率異常高,則向我發送 email。 我想避免必須從 Appspot 儀表板中抓取信息或在我的應用程序之外運行另一個進程。
最接近您需要的可能是LogService API
請注意,它不適用於 Java 運行時(我假設)。
這僅適用於雲並且對 GAE 友好。
你將需要 jsoup。
package some.package
import java.util.HashMap;
import java.util.Map;
import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AppEngineScraperUtil
{
private static final Logger logger = LoggerFactory.getLogger( AppEngineScraperUtil.class );
/**
* @param appId
* in the form of {@code appId}
* @return dashboard in html
*/
public static String fetchDashboard( String appId )
{
return jsoupWay( appId );
}
private static String jsoupWay( String appId )
{
try
{
Connection conn = createGetConn( "https://appengine.google.com" );
Response result = conn.execute();
Document doc = result.parse();
// parse inputs
Elements elements = doc.select( "#dsh, [name=GALX], #service, #continue, #ltmpl" );
Map<String, String> formFields = new HashMap<String, String>();
// build form
for ( Element element: elements )
formFields.put( element.attr( "name" ), element.val() );
formFields.put( "Email", "xxx" );
formFields.put( "Passwd", "xxx" );
String formAction = doc.select( "form" ).first().attr( "action" );
// parse cookies
Map<String, String> cookies = result.cookies();
// build post
conn = createPostConn( formAction );
conn.cookies( cookies );
conn.data( formFields );
conn.header( "Content-Type", "application/x-www-form-urlencoded" );
result = conn.execute();
doc = result.parse();
// get dashboard
conn = createGetConn( "https://appengine.google.com/dashboard?&app_id=" + appId );
conn.cookies( result.cookies() );
result = conn.execute();
// return html
doc = result.parse();
return doc.toString();
}
catch ( Exception e )
{
logger.error( "Error retrieving dashboard.", e );
}
return null;
}
private static Connection createPostConn( String url )
{
Connection conn = Jsoup.connect( url );
conn.method( Method.POST );
return conn;
}
private static Connection createGetConn( String url )
{
Connection conn = Jsoup.connect( url );
conn.method( Method.GET );
return conn;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.