Search in sources :

Example 1 with Stat

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);
}
Also used : Table(io.confluent.ksql.cli.console.table.Table) Builder(io.confluent.ksql.cli.console.table.Table.Builder) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat)

Example 2 with Stat

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());
}
Also used : StreamsList(io.confluent.ksql.rest.entity.StreamsList) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) SimpleConnectorPluginInfo(io.confluent.ksql.rest.entity.SimpleConnectorPluginInfo) KsqlQueryType(io.confluent.ksql.util.KsqlConstants.KsqlQueryType) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) StringUtils(org.apache.commons.lang3.StringUtils) Type(io.confluent.ksql.query.QueryError.Type) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) MockitoAnnotations(org.mockito.MockitoAnnotations) SchemaInfo(io.confluent.ksql.rest.entity.SchemaInfo) ConnectorList(io.confluent.ksql.rest.entity.ConnectorList) QueryId(io.confluent.ksql.query.QueryId) ConnectorType(org.apache.kafka.connect.runtime.rest.entities.ConnectorType) ClassRule(org.junit.ClassRule) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) TypeList(io.confluent.ksql.rest.entity.TypeList) EnumMap(java.util.EnumMap) ConnectorState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.ConnectorState) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) Builder(io.confluent.ksql.schema.ksql.LogicalSchema.Builder) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) TopicDescription(io.confluent.ksql.rest.entity.TopicDescription) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) TimezoneRule(io.confluent.ksql.test.util.TimezoneRule) DropConnectorEntity(io.confluent.ksql.rest.entity.DropConnectorEntity) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) FieldInfo(io.confluent.ksql.rest.entity.FieldInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Supplier(java.util.function.Supplier) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) StreamsTaskMetadata(io.confluent.ksql.rest.entity.StreamsTaskMetadata) NoOpRowCaptor(io.confluent.ksql.cli.console.Console.NoOpRowCaptor) FakeException(io.confluent.ksql.FakeException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) CliSpecificCommand(io.confluent.ksql.cli.console.cmd.CliSpecificCommand) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Mockito.never(org.mockito.Mockito.never) ConsumerPartitionOffsets(io.confluent.ksql.rest.entity.ConsumerPartitionOffsets) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) KsqlWarning(io.confluent.ksql.rest.entity.KsqlWarning) ErrorEntity(io.confluent.ksql.rest.entity.ErrorEntity) ConnectorPluginsList(io.confluent.ksql.rest.entity.ConnectorPluginsList) QueryOffsetSummary(io.confluent.ksql.rest.entity.QueryOffsetSummary) TestTerminal(io.confluent.ksql.TestTerminal) TaskState(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo.TaskState) QueryTopicOffsetSummary(io.confluent.ksql.rest.entity.QueryTopicOffsetSummary) CommandId(io.confluent.ksql.rest.entity.CommandId) GenericRow.genericRow(io.confluent.ksql.GenericRow.genericRow) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Approvals(org.approvaltests.Approvals) After(org.junit.After) ExecutionPlan(io.confluent.ksql.rest.entity.ExecutionPlan) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) Parameterized(org.junit.runners.Parameterized) ImmutableSet(com.google.common.collect.ImmutableSet) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) TimeZone(java.util.TimeZone) Collection(java.util.Collection) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) KsqlQueryStatus(io.confluent.ksql.util.KsqlConstants.KsqlQueryStatus) Collectors(java.util.stream.Collectors) ConnectorStateInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo) List(java.util.List) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ConnectorDescription(io.confluent.ksql.rest.entity.ConnectorDescription) Options(org.approvaltests.core.Options) Optional(java.util.Optional) KsqlConstants(io.confluent.ksql.util.KsqlConstants) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IntStream(java.util.stream.IntStream) TerminateQueryEntity(io.confluent.ksql.rest.entity.TerminateQueryEntity) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) SimpleConnectorInfo(io.confluent.ksql.rest.entity.SimpleConnectorInfo) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) QueryError(io.confluent.ksql.query.QueryError) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) ImmutableList(com.google.common.collect.ImmutableList) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) Queries(io.confluent.ksql.rest.entity.Queries) TablesList(io.confluent.ksql.rest.entity.TablesList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Mockito.when(org.mockito.Mockito.when) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) Collections(java.util.Collections) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) Stat(io.confluent.ksql.metrics.TopicSensors.Stat) QueryHostStat(io.confluent.ksql.rest.entity.QueryHostStat) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription)

Example 3 with Stat

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"));
}
Also used : Stat(io.confluent.ksql.metrics.TopicSensors.Stat) Test(org.junit.Test)

Aggregations

Stat (io.confluent.ksql.metrics.TopicSensors.Stat)3 QueryHostStat (io.confluent.ksql.rest.entity.QueryHostStat)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 FakeException (io.confluent.ksql.FakeException)1 GenericRow.genericRow (io.confluent.ksql.GenericRow.genericRow)1 TestTerminal (io.confluent.ksql.TestTerminal)1 NoOpRowCaptor (io.confluent.ksql.cli.console.Console.NoOpRowCaptor)1 CliSpecificCommand (io.confluent.ksql.cli.console.cmd.CliSpecificCommand)1 Table (io.confluent.ksql.cli.console.table.Table)1 Builder (io.confluent.ksql.cli.console.table.Table.Builder)1 DataSourceType (io.confluent.ksql.metastore.model.DataSource.DataSourceType)1 ColumnName (io.confluent.ksql.name.ColumnName)1 QueryError (io.confluent.ksql.query.QueryError)1 Type (io.confluent.ksql.query.QueryError.Type)1 QueryId (io.confluent.ksql.query.QueryId)1