com.googlecode.objectify.util.MemcacheStatsServlet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of objectify Show documentation
Show all versions of objectify Show documentation
*** THIS VERSION UPLOADED FOR USE WITH CEDAR-COMMON, TO AVOID DEPENDENCIES ON GOOGLE CODE-BASED MAVEN REPOSITORIES. *** The simplest convenient interface to the Google App Engine datastore
The newest version!
/*
*/
package com.googlecode.objectify.util;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.NumberFormat;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.impl.EntityMemcacheStats;
import com.googlecode.objectify.impl.EntityMemcacheStats.Stat;
/**
* If you are using the ObjectifyService static factory, you can mount this servlet to see the
* memcache stats for an instance. This is nothing fancy, but it should give you an idea of what's
* going on.
*
* @author Jeff Schnitzer
*/
public class MemcacheStatsServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
/**
* If you aren't using ObjectifyService, you can extend the servlet and override this method.
*/
protected EntityMemcacheStats getMemcacheStats()
{
return ObjectifyService.factory().getMemcacheStats();
}
/** */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
Map stats = getMemcacheStats().getStats();
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("");
out.println(" ");
out.println(" "); // css? we don't need no stinkin' css
out.println(" ");
out.println(" Hits Misses Percent Kind ");
out.println(" ");
NumberFormat percentFmt = NumberFormat.getPercentInstance();
percentFmt.setMaximumFractionDigits(2);
for (Map.Entry entry: stats.entrySet())
{
out.println("");
out.println(" " + entry.getValue().getHits() + " ");
out.println(" " + entry.getValue().getMisses() + " ");
out.println(" " + percentFmt.format(entry.getValue().getPercent()) + " ");
out.println(" " + entry.getKey() + " ");
out.println(" ");
}
out.println("
");
out.println(" ");
out.println("");
}
}