protected void execute(String[] command, long timestamp) throws ValidationException, DatastoreException { Validator.validateNotNullOrEmpty("metricName", command[1]); String metricName = command[1]; DataPoint dp; try { if (command[3].contains(".")) dp = m_doubleFactory.createDataPoint(timestamp, Double.parseDouble(command[3])); else dp = m_longFactory.createDataPoint(timestamp, Util.parseLong(command[3])); } catch (NumberFormatException e) { throw new ValidationException(e.getMessage()); } ImmutableSortedMap.Builder<String, String> tags = Tags.create(); int tagCount = 0; for (int i = 4; i < command.length; i++) { String[] tag = command[i].split("="); validateTag(tagCount, tag); tags.put(tag[0], tag[1]); tagCount++; } if (tagCount == 0) tags.put("add", "tag"); m_counter.incrementAndGet(); m_datastore.putDataPoint(metricName, tags.build(), dp); }
@Override public List<DataPointSet> getMetrics(long now) { DataPointSet dps = new DataPointSet(REPORTING_METRIC_NAME); dps.addTag("host", m_hostName); dps.addTag("method", "putm"); dps.addDataPoint(m_longFactory.createDataPoint(now, m_counter.getAndSet(0))); return (Collections.singletonList(dps)); }
public void sendData() throws IOException { synchronized (m_sendLock) { String oldDataFile = m_dataFileName; long now = System.currentTimeMillis(); long fileSize = (new File(m_dataFileName)).length(); ImmutableSortedMap<String, String> tags = ImmutableSortedMap.<String, String>naturalOrder().put("host", m_hostName).build(); synchronized (m_dataFileLock) { closeDataFile(); openDataFile(); } long zipSize = zipFile(oldDataFile); sendAllZipfiles(); long timeToSend = System.currentTimeMillis() - now; try { putDataPoint( FILE_SIZE_METRIC, tags, m_longDataPointFactory.createDataPoint(now, fileSize), 0); putDataPoint( WRITE_SIZE_METRIC, tags, m_longDataPointFactory.createDataPoint(now, m_dataPointCounter), 0); putDataPoint( ZIP_FILE_SIZE_METRIC, tags, m_longDataPointFactory.createDataPoint(now, zipSize), 0); putDataPoint( TIME_TO_SEND_METRIC, tags, m_longDataPointFactory.createDataPoint(now, timeToSend), 0); } catch (DatastoreException e) { logger.error("Error writing remote metrics", e); } } }