我的Google App Engine应用程序在登录时是否可以调用API,而应用程序管理员会返回有关我的应用程序返回的错误数量(404,500等)的信息?
我想在我的应用程序中设置一个简单的cron作业,以计算我的应用每隔几分钟返回的错误数,如果错误率突然变高,则向我发送一封电子邮件。我想避免从Appspot仪表板中删除信息或在我的应用程序之外运行其他进程。
答案 0 :(得分:1)
最接近您需要的是LogService API
请注意,它不适用于Java运行时(但我认为)。
答案 1 :(得分:0)
这仅适用于云,并且对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;
}
}