Search in sources :

Example 1 with Result

use of org.apache.phoenix.pherf.result.Result in project phoenix by apache.

the class MonitorManager method execute.

@Override
public Runnable execute() {
    return new Runnable() {

        @Override
        public void run() {
            try {
                while (!shouldStop()) {
                    isRunning.set(true);
                    List rowValues = new ArrayList<String>();
                    synchronized (resultHandler) {
                        for (MonitorDetails monitorDetails : MONITOR_DETAILS_LIST) {
                            rowValues.clear();
                            try {
                                StandardMBean bean = new StandardMBean(monitorDetails.getMonitor(), Monitor.class);
                                Calendar calendar = new GregorianCalendar();
                                rowValues.add(monitorDetails);
                                rowValues.add(((Monitor) bean.getImplementation()).getStat());
                                rowValues.add(DateUtil.DEFAULT_MS_DATE_FORMATTER.format(calendar.getTime()));
                                Result result = new Result(ResultFileDetails.CSV, ResultFileDetails.CSV_MONITOR.getHeader().toString(), rowValues);
                                resultHandler.write(result);
                            } catch (Exception e) {
                                throw new FileLoaderRuntimeException("Could not log monitor result.", e);
                            }
                            rowCount.getAndIncrement();
                        }
                        try {
                            resultHandler.flush();
                            Thread.sleep(getMonitorFrequency());
                        } catch (Exception e) {
                            Thread.currentThread().interrupt();
                            e.printStackTrace();
                        }
                    }
                }
            } finally {
                try {
                    isRunning.set(false);
                    if (resultHandler != null) {
                        resultHandler.close();
                    }
                } catch (Exception e) {
                    throw new FileLoaderRuntimeException("Could not close monitor results.", e);
                }
            }
        }
    };
}
Also used : FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException) StandardMBean(javax.management.StandardMBean) IOException(java.io.IOException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) FileLoaderRuntimeException(org.apache.phoenix.pherf.exception.FileLoaderRuntimeException) Result(org.apache.phoenix.pherf.result.Result)

Example 2 with Result

use of org.apache.phoenix.pherf.result.Result in project phoenix by apache.

the class CSVFileResultHandler method read.

public synchronized List<Result> read() throws IOException {
    CSVParser parser = null;
    util.ensureBaseResultDirExists();
    try {
        File file = new File(resultFileName);
        parser = CSVParser.parse(file, Charset.defaultCharset(), CSVFormat.DEFAULT);
        List<CSVRecord> records = parser.getRecords();
        List<Result> results = new ArrayList<>();
        String header = null;
        for (CSVRecord record : records) {
            // First record is the CSV Header
            if (record.getRecordNumber() == 1) {
                header = record.toString();
                continue;
            }
            List<ResultValue> resultValues = new ArrayList<>();
            for (String val : record.toString().split(PherfConstants.RESULT_FILE_DELIMETER)) {
                resultValues.add(new ResultValue(val));
            }
            Result result = new Result(resultFileDetails, header, resultValues);
            results.add(result);
        }
        return results;
    } finally {
        parser.close();
    }
}
Also used : CSVParser(org.apache.commons.csv.CSVParser) ArrayList(java.util.ArrayList) CSVRecord(org.apache.commons.csv.CSVRecord) ResultValue(org.apache.phoenix.pherf.result.ResultValue) File(java.io.File) Result(org.apache.phoenix.pherf.result.Result)

Aggregations

Result (org.apache.phoenix.pherf.result.Result)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 StandardMBean (javax.management.StandardMBean)1 CSVParser (org.apache.commons.csv.CSVParser)1 CSVRecord (org.apache.commons.csv.CSVRecord)1 FileLoaderRuntimeException (org.apache.phoenix.pherf.exception.FileLoaderRuntimeException)1 ResultValue (org.apache.phoenix.pherf.result.ResultValue)1