private static void autoMonitor(ConnectionRegistry registry)
    {
        System.out.println("Logging system status");
        File gsLogFile = new File("gs.monitor.log");
        File rmLogFile = new File("rm.monitor.log");
        BufferedWriter gsLogWriter;
        BufferedWriter rmLogWriter;
        FileWriter gsLogFileWriter;
        FileWriter rmLogFileWriter;
        try {
            if (!gsLogFile.exists()) {
                gsLogFile.createNewFile();
            }

            if (!rmLogFile.exists()) {
                rmLogFile.createNewFile();
            }

            gsLogFileWriter = new FileWriter(gsLogFile.getAbsoluteFile(), false);
            gsLogWriter = new BufferedWriter(gsLogFileWriter);

            gsLogWriter.write("name,time,t,message_queue,job_queue,rm_count,cpu_percentage,jvm_percentage\n");

            rmLogFileWriter = new FileWriter(rmLogFile.getAbsoluteFile(), false);
            rmLogWriter = new BufferedWriter(rmLogFileWriter);
            rmLogWriter.write("name,time,message_queue,job_queue,max_queue,free_nodes,total_nodes,cpu_percentage,jvm_percentage\n");

            while (true) {
                writeStats(registry, gsLogWriter, rmLogWriter);

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    break;
                }
            }

            gsLogWriter.close();
            gsLogFileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }