package net.blackshard.clarity.scribe;
import net.blackshard.clarity.tome.Reading;
import net.blackshard.clarity.tome.ReadingDAOHibernate;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;

import java.io.*;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author Matthew R. Trower
 * abstract class VMStatScribblet
 * 
 * Scribblet to log a subset of vmstat(1) readings.
 */
public abstract class VMStatScribblet implements Runnable {
    protected Logger log;
    protected ReadingDAOHibernate dao;

    protected String name;
    protected VMStatField[] fields;

    protected Reading reading;
    protected Gatherer gatherer;
    protected VMStatParser parser;

    public VMStatScribblet() {
        gatherer = new VMStatGatherer();
        parser = new VMStatParser();
    }

    public void run() {
        log.info(name + ": starting up!");

        while (true)
            try { 
                gatherer.open();

                log.trace(name + ": tick");

                gatherStats();
                writeStats();

                Thread.sleep(1000);
            } catch (InterruptedException ie) {
                break;
            } catch (Exception e) {
                log.error("", e);
                gatherer.close();
            }

        log.info(name + ": shutting down!");

        gatherer.close();
    }

    protected void gatherStats() throws IOException {
        parser.parse(gatherer.read());
        Map<VMStatField, Integer> stats = parser.getStats(fields);

        reading.setMachineId(0);
        reading.setTimestamp(new Date());
        reading.setMetrics(toMetricsMap(stats));
    }

    protected void writeStats() throws IOException {
        log.debug(String.format("%s: %s", name, reading.getMetrics()));
        dao.insert(reading);
    }

    protected abstract LinkedHashMap<String, Integer>
            toMetricsMap(Map<VMStatField, Integer> stats);
}

@@ -325,74 +325,21 @@
 %0A * 
-@author Matthew R. Trower%0A * abstract class VMStatScribblet%0A * %0A *
+Abstract base
  Scr
@@ -384,16 +384,62 @@
 adings.%0A
+ *%0A * @author Matthew R. Trower%0A * @since 1.0%0A
  */%0Apubl
@@ -724,16 +724,84 @@
 arser;%0A%0A
+    /**%0A     * Default Constructor%0A     *%0A     * @since 1.0%0A     */%0A
     publ
@@ -904,24 +904,220 @@
 r();%0A    %7D%0A%0A
+    /**%0A     * Run the scribblet.  It will initialize its gathering method and proceed%0A     * to gather stats at a set interval, writing them out to the database.%0A     *%0A     * @since 1.0%0A     */%0A
     public v
@@ -1650,32 +1650,158 @@
 close();%0A    %7D%0A%0A
+    /**%0A     * Gather and parse stats from the selected gatherer.%0A     *%0A     * @throws IOException%0A     * @since 1.0%0A     */%0A
     protected vo
@@ -2068,32 +2068,162 @@
 stats));%0A    %7D%0A%0A
+    /**%0A     * Write the last set of stats collected to the database.%0A     *%0A     * @throws IOException%0A     * @since 1.0%0A     */%0A
     protected vo
@@ -2363,24 +2363,282 @@
 ng);%0A    %7D%0A%0A
+    /**%0A     * Convert an array of stats (obtained from VMStatParser) into a metrics map that a Reading DTO will understand.%0A     *%0A     * @param stats the output from VMStatParser%0A     * @return a metrics map that can be fed to Reading.setMetrics()%0A     */%0A
     protecte

Add some JavaDoc