@Override
  public void run() {
    Checker checker = SmartRestart.getInstance().getChecker();

    if (checker.getTicks() < 0) {
      return;
    }

    float memoryusage = ((float) checker.getMemoryUsed() / (float) checker.getMemoryTotal()) * 100;
    float freememory = ((float) checker.getMemoryFree() / (float) checker.getMemoryTotal()) * 100;

    // Build message.
    final StringBuilder nowmsg = new StringBuilder(telemetrytemplate);
    replace(nowmsg, TICK_TOKEN, Integer.toString(checker.getTicks()));
    replace(nowmsg, MEMORY_USAGE_TOKEN, Float.toString(memoryusage));
    replace(nowmsg, FREE_MEMORY_TOKEN, Float.toString(freememory));
    replace(nowmsg, AVG_MILLIS_TOKEN, getAvgTimePerTick(checker.getRecords()));

    for (Map.Entry<UUID, Long> en : receivers.entrySet()) {
      if (checker.getTicks() % en.getValue() == 0) {
        Player p = Bukkit.getPlayer(en.getKey());
        if (p == null) {
          continue;
        }
        p.sendMessage(nowmsg.toString());
      }
    }
  }
  @Override
  public boolean isCriteriaViolated() {
    if (memoryLog.isEmpty()
        || memoryLog.firstKey()
            > System.currentTimeMillis()
                - SmartRestart.getInstance().getConf().getTickSamplePeriod()) {
      return false;
    }

    float val = 0;
    SortedMap<Long, Float> subset =
        memoryLog.tailMap(
            System.currentTimeMillis()
                - SmartRestart.getInstance().getConf().getMemorySamplePeriod());
    for (Float f : subset.values()) {
      val += f;
    }

    val /= subset.size();

    return MemoryInterface.getUsedMemoryPercent() >= val;
  }
  @Override
  public void tick() {
    memoryLog.put(System.currentTimeMillis(), MemoryInterface.getUsedMemoryPercent());

    if (memoryLog.size() % 200 == 0) {
      // Clear out our data to clear memory.
      Iterator<Long> it = memoryLog.keySet().iterator();
      while (it.hasNext()) {
        if (it.next() < SmartRestart.getInstance().getConf().getMemorySamplePeriod()) {
          it.remove();
        } else {
          break;
        }
      }
    }
  }