private void updateEntityAggValue(GenericMetricEntity entity, HadoopClusterConstants.AggregateFunc aggFunc, double value, double count) { double lastValue = entity.getValue()[0]; switch (aggFunc) { case MAX: entity.setValue(new double[] {Math.max(lastValue, value)}); return; case AVG: long avgValue = (long) ((lastValue * count + value) / (count + 1)); entity.setValue(new double[] {avgValue}); return; default: throw new IllegalArgumentException("Illegal aggregation function: " + aggFunc); } }
private GenericMetricEntity generateMetric(long timestamp, long count) { GenericMetricEntity metricEntity = new GenericMetricEntity(); Map<String, String> tags = new HashMap<>(); tags.put("appId", appId); tags.put("site", site); tags.put("taskId", String.valueOf(taskId)); metricEntity.setTimestamp(timestamp); metricEntity.setTags(tags); metricEntity.setPrefix(HADOOP_LOG_METRIC_NAME); metricEntity.setValue(new double[] {count}); return metricEntity; }
private void createMetric(String metricName, Map<String, String> tags, long timestamp, int value) { String key = metricName + tags.toString() + " " + timestamp; GenericMetricEntity entity = appMetricEntities.get(key); if (entity == null) { entity = new GenericMetricEntity(); entity.setTags(tags); entity.setTimestamp(timestamp); entity.setPrefix(metricName); entity.setValue(new double[] {0.0}); appMetricEntities.put(key, entity); } double lastValue = entity.getValue()[0]; entity.setValue(new double[] {lastValue + value}); }
private GenericMetricEntity buildMetricEntity(long timestamp, String metricFormat, String user, long count, int windowLen) { GenericMetricEntity entity = new GenericMetricEntity(); entity.setTimestamp(timestamp); entity.setValue(new double[]{Double.valueOf(count)}); entity.setPrefix(String.format(metricFormat, windowLen / 60000)); Map<String, String> tags = new HashMap<>(); tags.put("site", config.getString("siteId")); tags.put("user", LogParseUtil.parseUserFromUGI(user)); entity.setTags(tags); return entity; }
private void createMetric(Map<String, GenericMetricEntity> appMetricEntities, long timestamp, Map<String, String> tags, String metricName, int value) { String key = metricName + tags.toString() + " " + timestamp; GenericMetricEntity entity = appMetricEntities.get(key); if (entity == null) { entity = new GenericMetricEntity(); entity.setTags(tags); entity.setTimestamp(timestamp); entity.setPrefix(metricName); entity.setValue(new double[] {0.0}); appMetricEntities.put(key, entity); } double lastValue = entity.getValue()[0]; entity.setValue(new double[] {lastValue + value}); }
private void createMetric(String metricName, Map<String, String> tags, long timestamp, double value) throws Exception { GenericMetricEntity e = new GenericMetricEntity(); e.setPrefix(metricName); e.setTimestamp(timestamp); e.setTags(tags); e.setValue(new double[] {value}); this.metricEntities.add(e); }
private void createMetric(String metricName, long timestamp, double value, HadoopClusterConstants.AggregateFunc aggFunc) { if (timestamp > maxTimestamp) { maxTimestamp = timestamp; } timestamp = timestamp / AGGREGATE_INTERVAL * AGGREGATE_INTERVAL; MetricKey key = new MetricKey(metricName, timestamp); GenericMetricEntity entity = clusterMetricEntities.get(key); if (entity == null) { entity = new GenericMetricEntity(); entity.setTags(buildMetricTags()); entity.setTimestamp(timestamp); entity.setPrefix(metricName); entity.setValue(new double[] {0.0}); clusterMetricEntities.put(key, entity); } clusterMetricCounts.putIfAbsent(key, 0); updateEntityAggValue(entity, aggFunc, value, clusterMetricCounts.get(key)); clusterMetricCounts.put(key, clusterMetricCounts.get(key) + 1); }
metricEntity.setTimestamp(timeStamp); metricEntity.setPrefix(buildMetricName(metric.toLowerCase())); metricEntity.setValue(new double[] {valueByMinute.get(timeStamp)}); metricEntity.setTags(this.baseTags);
metricEntity.setTimestamp(timeStamp); metricEntity.setPrefix(buildMetricName(columnNames)); metricEntity.setValue(new double[] {metricByMin.get(timeStamp)}); metricEntity.setTags(baseTags); entities.add(metricEntity);
private static GenericMetricEntity metricWrapper(Long timestamp, String metricName, double value, Map<String, String> tags) { GenericMetricEntity metricEntity = new GenericMetricEntity(); metricEntity.setTimestamp(timestamp); metricEntity.setTags(tags); metricEntity.setPrefix(metricName); metricEntity.setValue(new double[] {value}); return metricEntity; }
public MetricSender send(String metricName,long timestamp,Map<String,String> tags,double ...values) throws IOException, EagleServiceClientException { GenericMetricEntity metric = new GenericMetricEntity(); metric.setPrefix(metricName); metric.setValue(values); metric.setTimestamp(timestamp); metric.setTags(tags); super.send(metric); return this; }
@Override public GenericMetricEntity map(Map event) { String metricName = metricDescriptor.getMetricNameSelector().getMetricName(event); Preconditions.checkNotNull(metricName, "Metric name is null"); Long timestamp = metricDescriptor.getTimestampSelector().getTimestamp(event); Preconditions.checkNotNull(timestamp, "Timestamp is null"); Map<String, String> tags = new HashMap<>(); for (String dimensionField : metricDescriptor.getDimensionFields()) { Preconditions.checkNotNull(dimensionField, "Dimension field name is null"); tags.put(dimensionField, (String) event.get(dimensionField)); } double[] values; if (event.containsKey(metricDescriptor.getValueField())) { values = new double[] {(double) event.get(metricDescriptor.getValueField())}; } else { LOG.warn("Event has no value field '{}': {}, use 0 by default", metricDescriptor.getValueField(), event); values = new double[] {0}; } GenericMetricEntity entity = new GenericMetricEntity(); entity.setPrefix(metricName); entity.setTimestamp(DateTimeUtil.roundDown(metricDescriptor.getGranularity(), timestamp)); entity.setTags(tags); entity.setValue(values); return entity; } }
public MetricSender send(String metricName,long timestamp,Map<String,String> tags,double ...values) throws IOException, EagleServiceClientException { GenericMetricEntity metric = new GenericMetricEntity(); metric.setPrefix(metricName); metric.setValue(values); metric.setTimestamp(timestamp); metric.setTags(tags); super.send(metric); return this; }
protected GenericMetricEntity metricWrapper(Long timestamp, String field, double[] values, Map<String, String> tags) { String metricName = buildMetricName(field); GenericMetricEntity metricEntity = new GenericMetricEntity(); metricEntity.setTimestamp(timestamp); metricEntity.setTags(tags); metricEntity.setPrefix(metricName); metricEntity.setValue(values); return metricEntity; } }
private GenericMetricEntity generateEntity(GregorianCalendar calendar, String state, int count) { GenericMetricEntity metricEntity = new GenericMetricEntity(); metricEntity.setTimestamp(calendar.getTimeInMillis()); metricEntity.setPrefix(String.format(Constants.HADOOP_HISTORY_TOTAL_METRIC_FORMAT, Constants.JOB_LEVEL, Constants.JOB_COUNT_PER_DAY)); metricEntity.setValue(new double[] {count}); @SuppressWarnings("serial") Map<String, String> baseTags = new HashMap<String, String>() { { put("site", appConfig.getJobHistoryEndpointConfig().site); put(MRJobTagName.JOB_STATUS.toString(), state); } }; metricEntity.setTags(baseTags); return metricEntity; } }
public static GenericMetricEntity convert(String name, Metric metric) { //TODO: add other type metric support EagleMetricKey metricName = MetricKeyCodeDecoder.decodeTSMetricKey(name); if (metric instanceof EagleCounterMetric) { EagleCounterMetric counter = (EagleCounterMetric)metric; GenericMetricEntity entity = new GenericMetricEntity(); entity.setPrefix(metricName.metricName); entity.setValue(new double[]{counter.getValue()}); entity.setTags(metricName.tags); entity.setTimestamp(metricName.timestamp); return entity; } else if (metric instanceof EagleGaugeMetric) { EagleGaugeMetric gauge = (EagleGaugeMetric)metric; GenericMetricEntity entity = new GenericMetricEntity(); entity.setPrefix(metricName.metricName); entity.setValue(new double[]{gauge.getValue()}); entity.setTags(metricName.tags); entity.setTimestamp(metricName.timestamp); return entity; } throw new RuntimeException("Not support this metric type for now!"); } }
public static GenericMetricEntity convert(String name, Metric metric) { //TODO: add other type metric support EagleMetricKey metricName = MetricKeyCodeDecoder.decodeTSMetricKey(name); if (metric instanceof EagleCounterMetric) { EagleCounterMetric counter = (EagleCounterMetric) metric; GenericMetricEntity entity = new GenericMetricEntity(); entity.setPrefix(metricName.metricName); entity.setValue(new double[] {counter.getValue()}); entity.setTags(metricName.tags); entity.setTimestamp(metricName.timestamp); return entity; } else if (metric instanceof EagleGaugeMetric) { EagleGaugeMetric gauge = (EagleGaugeMetric) metric; GenericMetricEntity entity = new GenericMetricEntity(); entity.setPrefix(metricName.metricName); entity.setValue(new double[] {gauge.getValue()}); entity.setTags(metricName.tags); entity.setTimestamp(metricName.timestamp); return entity; } throw new RuntimeException("Not support this metric type for now!"); } }
private GenericMetricEntity newMetric(){ GenericMetricEntity instance = new GenericMetricEntity(); instance.setPrefix(metricName); instance.setTags(new HashMap<String, String>() {{ put("site", "unittest_site"); put("application", "unittest_application"); }}); instance.setValue(new double[]{random.nextDouble()}); instance.setTimestamp(System.currentTimeMillis()); return instance; }
private List<String> prepareMetricEntity(long startTime,int count) throws Exception { List<GenericMetricEntity> list = new ArrayList<GenericMetricEntity>(); EntityDefinition ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(GenericMetricEntity.class); double[] value = new double[60]; for(int i=0;i<60;i++){ value[i] = 1; } for(int i=0;i<count;i++){ GenericMetricEntity e = new GenericMetricEntity(); e.setTimestamp(startTime+i*3600*1000); e.setValue(value); e.setTags(new HashMap<String, String>()); e.getTags().put("cluster", "test4UT"); e.getTags().put("datacenter", "dc1"); e.getTags().put("index", ""+i); e.getTags().put("jobId", "job_"+System.currentTimeMillis()); e.setPrefix("eagle.metric.test"); list.add(e); } GenericEntityWriter writer = new GenericEntityWriter(ed.getService()); List<String> result = writer.write(list); return result; }
@Before public void setUp() throws JsonProcessingException { restURL = "http://localhost:" + RULE.getLocalPort() + EagleMetricResource.METRIC_URL_PATH; List<GenericMetricEntity> entities = new ArrayList<GenericMetricEntity>(); Map<String,String> tags = new HashMap<String, String>() {{ put("cluster", "cluster4ut"); put("datacenter", "datacenter4ut"); }}; for(int i=0;i<100;i++){ GenericMetricEntity entity = new GenericMetricEntity(); entity.setTimestamp(System.currentTimeMillis()); entity.setTags(tags); entity.setValue(new double[]{1.234}); entity.setPrefix("unit.test.metrics"); entities.add(entity); } requestJson = TaggedLogAPIEntity.buildObjectMapper().writeValueAsString(entities); }