private Map getUpdatedStat(String statkey, long[] timePeriod) {
   MonitoringPlugin plugin =
       (MonitoringPlugin)
           XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
   StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
   String[] lowHigh = getLowAndHigh(statkey, timePeriod);
   Map stat = new HashMap();
   stat.put("low", lowHigh[0]);
   stat.put("high", lowHigh[1]);
   stat.put("count", (int) viewer.getCurrentValue(statkey)[0]);
   return stat;
 }
  /**
   * Given a statistic key and a start date, end date and number of datapoints, returns a String[]
   * containing the low and high values (in that order) for the given time period.
   *
   * @param key the name of the statistic to return high and low values for.
   * @param timePeriod start date, end date and number of data points.
   * @return low and high values for the given time period / number of datapoints
   */
  public static String[] getLowAndHigh(String key, long[] timePeriod) {
    MonitoringPlugin plugin =
        (MonitoringPlugin)
            XMPPServer.getInstance().getPluginManager().getPlugin(MonitoringConstants.NAME);
    StatsViewer viewer = (StatsViewer) plugin.getModule(StatsViewer.class);
    Statistic.Type type = viewer.getStatistic(key)[0].getStatType();
    double[] lows = viewer.getMin(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    double[] highs = viewer.getMax(key, timePeriod[0], timePeriod[1], (int) timePeriod[2]);
    String low;
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(0);
    if (lows.length > 0) {
      if (type == Statistic.Type.count) {
        low = String.valueOf((int) lows[0]);
      } else {
        double l = lows[0];
        if (Double.isNaN(l)) {
          l = 0;
        }
        low = format.format(l);
      }
    } else {
      low = String.valueOf(0);
    }
    String high;
    if (highs.length > 0) {
      if (type == Statistic.Type.count) {
        high = String.valueOf((int) highs[0]);
      } else {
        double h = highs[0];
        if (Double.isNaN(h)) {
          h = 0;
        }
        high = format.format(h);
      }

    } else {
      high = String.valueOf(0);
    }

    return new String[] {low, high};
  }