private void saveMetrics(MetricRegistry metricsRegistry, String directoryPath) {
        String directoryName = directoryPath + "/metrics/";
        File file = new File(directoryName);
        if (file.exists()) {
            file.delete();
        }
        file.mkdirs();
        try {
            File outputFile = new File(directoryName + "metrics_counters.data");
            BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile));
            SortedMap<String, Counter> counters = metrics.getCounters();
            for (String counter : counters.keySet()) {
                Counter c = counters.get(counter);
                writer.write(counter + ":" + c.getCount());
                writer.newLine();
                writer.flush();
            }
            writer.flush();
            writer.close();
        } catch (IOException e) {
            logger.error("Unable to save metrics to a file: " + file, e);
        }
    }
Saves the metrics to a file for it to be reloaded when the crawler restarts

@param metricsRegistry
@param directoryPath
@throws IOException
ache/src/main/java/achecrawler/util/MetricsManager.java