Search in sources :

Example 1 with StatsQuery

use of io.gravitee.rest.api.model.analytics.query.StatsQuery in project gravitee-management-rest-api by gravitee-io.

the class EnvironmentAnalyticsResource method executeStats.

private Analytics executeStats(AnalyticsParam analyticsParam, String extraFilter) {
    final StatsQuery query = new StatsQuery();
    query.setFrom(analyticsParam.getFrom());
    query.setTo(analyticsParam.getTo());
    query.setInterval(analyticsParam.getInterval());
    query.setQuery(analyticsParam.getQuery());
    query.setField(analyticsParam.getField());
    addExtraFilter(query, extraFilter);
    return analyticsService.execute(query);
}
Also used : StatsQuery(io.gravitee.rest.api.model.analytics.query.StatsQuery)

Example 2 with StatsQuery

use of io.gravitee.rest.api.model.analytics.query.StatsQuery in project gravitee-management-rest-api by gravitee-io.

the class ApiMetricsResource method getNbHits.

private Number getNbHits(String apiId) {
    StatsQuery query = new StatsQuery();
    Instant now = Instant.now();
    query.setFrom(now.minus(7, ChronoUnit.DAYS).toEpochMilli());
    query.setTo(now.toEpochMilli());
    query.setInterval(43200000);
    query.setRootField("api");
    query.setRootIdentifier(apiId);
    query.setField("response-time");
    try {
        final StatsAnalytics analytics = analyticsService.execute(query);
        if (analytics != null) {
            return analytics.getCount();
        }
    } catch (final Exception e) {
    // do nothing as the analytics errors should not break the portal
    }
    return null;
}
Also used : Instant(java.time.Instant) StatsQuery(io.gravitee.rest.api.model.analytics.query.StatsQuery) StatsAnalytics(io.gravitee.rest.api.model.analytics.query.StatsAnalytics) ApiNotFoundException(io.gravitee.rest.api.service.exceptions.ApiNotFoundException)

Aggregations

StatsQuery (io.gravitee.rest.api.model.analytics.query.StatsQuery)2 StatsAnalytics (io.gravitee.rest.api.model.analytics.query.StatsAnalytics)1 ApiNotFoundException (io.gravitee.rest.api.service.exceptions.ApiNotFoundException)1 Instant (java.time.Instant)1