use of io.confluent.ksql.metrics.TopicSensors.Stat in project ksql by confluentinc.
the class Console method printStatistics.
private void printStatistics(final SourceDescription source) {
final List<QueryHostStat> statistics = source.getClusterStatistics();
final List<QueryHostStat> errors = source.getClusterErrorStats();
if (statistics.isEmpty() && errors.isEmpty()) {
writer().println(String.format("%n%-20s%n%s", "Local runtime statistics", "------------------------"));
writer().println(source.getStatistics());
writer().println(source.getErrorStats());
return;
}
final List<String> headers = ImmutableList.of("Host", "Metric", "Value", "Last Message");
final Stream<QueryHostStat> rows = Streams.concat(statistics.stream(), errors.stream());
writer().println(String.format("%n%-20s%n%s", "Runtime statistics by host", "-------------------------"));
final Table statsTable = new Table.Builder().withColumnHeaders(headers).withRows(rows.sorted(Comparator.comparing(QueryHostStat::host).thenComparing(Stat::name)).map((metric) -> {
final String hostCell = metric.host().toString();
final String formattedValue = String.format("%10.0f", metric.getValue());
return ImmutableList.of(hostCell, metric.name(), formattedValue, metric.timestamp());
})).build();
statsTable.print(this);
}
use of io.confluent.ksql.metrics.TopicSensors.Stat in project ksql by confluentinc.
the class ConsoleTest method buildSourceDescription.
private SourceDescription buildSourceDescription(final List<RunningQuery> readQueries, final List<RunningQuery> writeQueries, final List<FieldInfo> fields, final boolean withClusterStats) {
final Stat STAT = new Stat("TEST", 0, 1596644936314L);
final Stat ERROR_STAT = new Stat("ERROR", 0, 1596644936314L);
List<QueryHostStat> statistics = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(STAT, host)).collect(Collectors.toList());
List<QueryHostStat> errors = IntStream.range(1, 5).boxed().map((i) -> new KsqlHostInfoEntity("host" + i, 8000 + i)).map((host) -> QueryHostStat.fromStat(ERROR_STAT, host)).collect(Collectors.toList());
return new SourceDescription("TestSource", Optional.empty(), readQueries, writeQueries, fields, DataSourceType.KTABLE.getKsqlType(), "2000-01-01", "stats", "errors", true, "kafka", "avro", "kafka-topic", 1, 1, "sql statement", Collections.emptyList(), Collections.emptyList(), withClusterStats ? statistics : ImmutableList.of(), withClusterStats ? errors : ImmutableList.of());
}
use of io.confluent.ksql.metrics.TopicSensors.Stat in project ksql by confluentinc.
the class TopicSensorsTest method shouldFormatTimestampInUnambiguousFormatAndUTC.
@Test
public void shouldFormatTimestampInUnambiguousFormatAndUTC() {
// Given:
final Stat stat = new Stat("stat", 5.0, 1538842403035L);
// When:
final String timestamp = stat.timestamp();
// Then:
assertThat(timestamp, is("2018-10-06T16:13:23.035Z"));
}
Aggregations