private static Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }
private void addMetricToBatch(PreparedStatement upsertStatement, Metric metric, String id) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); int index = 0; upsertStatement.setString(++index, id); upsertStatement.setString(++index, metric.getGroup()); upsertStatement.setString(++index, metric.getName()); upsertStatement.setString(++index, metric.getType().name()); upsertStatement.setString(++index, metric.getValue()); upsertStatement.addBatch(); }
private static boolean existsMetric(Connection connection, String template, String id, Metric metric) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); try (PreparedStatement queryStatement = connection.prepareStatement(template)) { int index = 0; queryStatement.setString(++index, id); queryStatement.setString(++index, metric.getGroup()); queryStatement.setString(++index, metric.getName()); queryStatement.setString(++index, metric.getType().name()); try (ResultSet resultSet = queryStatement.executeQuery()) { return resultSet.next(); } } }
private void assertMetric(Metric actual, Metric expected) { Assert.assertEquals(actual.getGroup(), expected.getGroup()); Assert.assertEquals(actual.getName(), expected.getName()); Assert.assertEquals(actual.getType(), expected.getType()); Assert.assertEquals(actual.getValue(), expected.getValue()); } }
/** * Print out various metrics * @param metrics Metrics to print */ private static void printMetrics(MetricArray metrics) { System.out.println(); if (metrics.size() == 0) { System.out.println("No metrics found."); return; } List<List<String>> data = new ArrayList<>(); List<String> flags = Arrays.asList("", "-"); for (Metric metric : metrics) { data.add(Arrays.asList(metric.getName(), metric.getValue())); } new CliTablePrinter.Builder() .data(data) .flags(flags) .delimiterWidth(2) .build() .printTable(); }
private static void assertMetric(Metric actual, Metric expected) { Assert.assertEquals(actual.getGroup(), expected.getGroup()); Assert.assertEquals(actual.getName(), expected.getName()); Assert.assertEquals(actual.getType(), expected.getType()); Assert.assertEquals(actual.getValue(), expected.getValue()); } }
private static boolean existsMetric(Connection connection, String template, String id, Metric metric) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); try (PreparedStatement queryStatement = connection.prepareStatement(template)) { int index = 0; queryStatement.setString(++index, id); queryStatement.setString(++index, metric.getGroup()); queryStatement.setString(++index, metric.getName()); queryStatement.setString(++index, metric.getType().name()); try (ResultSet resultSet = queryStatement.executeQuery()) { return resultSet.next(); } } }
try { for (Metric metric : metrics) { if (metric.getName().equals(MetricNames.ExtractorMetrics.RECORDS_READ_METER)) { recordsProcessed = Double.parseDouble(metric.getValue()); } else if (metric.getName().equals(MetricNames.ExtractorMetrics.RECORDS_FAILED_METER)) { recordsFailed = Double.parseDouble(metric.getValue());
private Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }
private static void updateMetric(Connection connection, String template, String id, Metric metric, boolean insert) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); try (PreparedStatement updateStatement = connection.prepareStatement(template)) { int index = 0; if (insert) { updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); updateStatement.setString(++index, metric.getValue()); } else { updateStatement.setString(++index, metric.getValue()); updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); } updateStatement.executeUpdate(); } }
/** * Print out various metrics * @param metrics Metrics to print */ private static void printMetrics(MetricArray metrics) { System.out.println(); if (metrics.size() == 0) { System.out.println("No metrics found."); return; } List<List<String>> data = new ArrayList<>(); List<String> flags = Arrays.asList("", "-"); for (Metric metric : metrics) { data.add(Arrays.asList(metric.getName(), metric.getValue())); } new CliTablePrinter.Builder() .data(data) .flags(flags) .delimiterWidth(2) .build() .printTable(); }
Metric counter = new Metric(); counter.setGroup(MetricGroup.JOB.name()); counter.setName(entry.getKey()); counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name())); counter.setValue(Long.toString(((Counter) entry.getValue()).getCount())); metricArray.add(counter); Metric meter = new Metric(); meter.setGroup(MetricGroup.JOB.name()); meter.setName(entry.getKey()); meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name())); meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate())); metricArray.add(meter); Metric gauge = new Metric(); gauge.setGroup(MetricGroup.JOB.name()); gauge.setName(entry.getKey()); gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name())); gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString()); metricArray.add(gauge);
private void addMetricToBatch(PreparedStatement upsertStatement, Metric metric, String id) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); int index = 0; upsertStatement.setString(++index, id); upsertStatement.setString(++index, metric.getGroup()); upsertStatement.setString(++index, metric.getName()); upsertStatement.setString(++index, metric.getType().name()); upsertStatement.setString(++index, metric.getValue()); upsertStatement.addBatch(); }
try { for (Metric metric : metrics) { if (metric.getName().equals(MetricNames.ExtractorMetrics.RECORDS_READ_METER)) { recordsProcessed = Double.parseDouble(metric.getValue()); } else if (metric.getName().equals(MetricNames.ExtractorMetrics.RECORDS_FAILED_METER)) { recordsFailed = Double.parseDouble(metric.getValue());
Metric counter = new Metric(); counter.setGroup(MetricGroup.TASK.name()); counter.setName(entry.getKey()); counter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.COUNTER.name())); counter.setValue(Long.toString(((Counter) entry.getValue()).getCount())); metricArray.add(counter); Metric meter = new Metric(); meter.setGroup(MetricGroup.TASK.name()); meter.setName(entry.getKey()); meter.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.METER.name())); meter.setValue(Double.toString(((Meter) entry.getValue()).getMeanRate())); metricArray.add(meter); Metric gauge = new Metric(); gauge.setGroup(MetricGroup.TASK.name()); gauge.setName(entry.getKey()); gauge.setType(MetricTypeEnum.valueOf(GobblinMetrics.MetricType.GAUGE.name())); gauge.setValue(((Gauge<?>) entry.getValue()).getValue().toString()); metricArray.add(gauge);
private static void updateMetric(Connection connection, String template, String id, Metric metric, boolean insert) throws SQLException { Preconditions.checkArgument(!Strings.isNullOrEmpty(id)); Preconditions.checkArgument(metric.hasGroup()); Preconditions.checkArgument(metric.hasName()); Preconditions.checkArgument(metric.hasType()); Preconditions.checkArgument(metric.hasValue()); try (PreparedStatement updateStatement = connection.prepareStatement(template)) { int index = 0; if (insert) { updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); updateStatement.setString(++index, metric.getValue()); } else { updateStatement.setString(++index, metric.getValue()); updateStatement.setString(++index, id); updateStatement.setString(++index, metric.getGroup()); updateStatement.setString(++index, metric.getName()); updateStatement.setString(++index, metric.getType().name()); } updateStatement.executeUpdate(); } }
Metric jobMetric1 = new Metric(); jobMetric1.setGroup("JOB"); jobMetric1.setName("jm1"); jobMetric1.setType(MetricTypeEnum.COUNTER); jobMetric1.setValue("100"); jobMetrics.add(jobMetric1); jobExecutionInfo.setMetrics(jobMetrics); taskExecutionInfo1.setTable(table1); MetricArray taskMetrics1 = new MetricArray(); Metric taskMetric1 = new Metric(); taskMetric1.setGroup("TASK"); taskMetric1.setName("tm1"); taskMetric1.setType(MetricTypeEnum.COUNTER); taskMetric1.setValue("100"); taskMetrics1.add(taskMetric1); taskExecutionInfo1.setMetrics(taskMetrics1); taskExecutionInfo2.setTable(table2); MetricArray taskMetrics2 = new MetricArray(); Metric taskMetric2 = new Metric(); taskMetric2.setGroup("TASK"); taskMetric2.setName("tm2"); taskMetric2.setType(MetricTypeEnum.COUNTER); taskMetric2.setValue("100"); taskMetrics2.add(taskMetric2); taskExecutionInfo2.setMetrics(taskMetrics2);
Metric jobMetric1 = new Metric(); jobMetric1.setGroup("JOB"); jobMetric1.setName("jm1"); jobMetric1.setType(MetricTypeEnum.COUNTER); jobMetric1.setValue("100"); jobMetrics.add(jobMetric1); jobExecutionInfo.setMetrics(jobMetrics); taskExecutionInfo1.setTable(table1); MetricArray taskMetrics1 = new MetricArray(); Metric taskMetric1 = new Metric(); taskMetric1.setGroup("TASK"); taskMetric1.setName("tm1"); taskMetric1.setType(MetricTypeEnum.COUNTER); taskMetric1.setValue("100"); taskMetrics1.add(taskMetric1); taskExecutionInfo1.setMetrics(taskMetrics1); taskExecutionInfo2.setTable(table2); MetricArray taskMetrics2 = new MetricArray(); Metric taskMetric2 = new Metric(); taskMetric2.setGroup("TASK"); taskMetric2.setName("tm2"); taskMetric2.setType(MetricTypeEnum.COUNTER); taskMetric2.setValue("100"); taskMetrics2.add(taskMetric2); taskExecutionInfo2.setMetrics(taskMetrics2);
private Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }
private static Metric resultSetToMetric(ResultSet rs) throws SQLException { Metric metric = new Metric(); metric.setGroup(rs.getString("metric_group")); metric.setName(rs.getString("metric_name")); metric.setType(MetricTypeEnum.valueOf(rs.getString("metric_type"))); metric.setValue(rs.getString("metric_value")); return metric; }