Search in sources :

Example 1 with GenericRequestDataCollector

use of org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector in project carbon-apimgt by wso2.

the class WebhooksUtils method publishAnalyticsData.

public static void publishAnalyticsData(MessageContext messageContext) {
    org.apache.axis2.context.MessageContext axisCtx = ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    axisCtx.setProperty(PassThroughConstants.SYNAPSE_ARTIFACT_TYPE, APIConstants.API_TYPE_WEBSUB);
    WebhooksAnalyticsDataProvider provider = new WebhooksAnalyticsDataProvider(messageContext);
    GenericRequestDataCollector dataCollector = new GenericRequestDataCollector(provider);
    try {
        dataCollector.collectData();
    } catch (AnalyticsException e) {
        log.error("Error occurred when collecting data", e);
    }
}
Also used : WebhooksAnalyticsDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook.WebhooksAnalyticsDataProvider) GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) AnalyticsException(org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 2 with GenericRequestDataCollector

use of org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector in project carbon-apimgt by wso2.

the class SseResponseStreamInterceptor method publishAnalyticsData.

private void publishAnalyticsData(int eventCount, MessageContext axi2Ctx) throws AnalyticsException {
    Object responseEventProvider = axi2Ctx.getProperty(SSE_ANALYTICS_INFO);
    if (responseEventProvider == null) {
        log.error("SSE Analytics event provider is null.");
        return;
    }
    SseResponseEventDataProvider provider = (SseResponseEventDataProvider) responseEventProvider;
    provider.setResponseCode((int) axi2Ctx.getProperty(SynapseConstants.HTTP_SC));
    GenericRequestDataCollector dataCollector = new GenericRequestDataCollector(provider);
    for (int count = 0; count < eventCount; count++) {
        dataCollector.collectData();
    }
}
Also used : SseResponseEventDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider) GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) JSONObject(org.json.JSONObject)

Example 3 with GenericRequestDataCollector

use of org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector in project carbon-apimgt by wso2.

the class WebSocketAnalyticsMetricsHandler method collectData.

private void collectData(ChannelHandlerContext ctx) {
    AnalyticsDataProvider provider = new WebSocketAnalyticsDataProvider(ctx);
    GenericRequestDataCollector collector = new GenericRequestDataCollector(provider);
    try {
        collector.collectData();
    } catch (AnalyticsException e) {
        log.error("Error Occurred when collecting analytics data", e);
    }
}
Also used : GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) AnalyticsException(org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException) AnalyticsDataProvider(org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider)

Example 4 with GenericRequestDataCollector

use of org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector in project carbon-apimgt by wso2.

the class SubscriberInfoLoader method mediate.

// private final GenericRequestDataCollector dataCollector = null;
@Override
public boolean mediate(MessageContext messageContext) {
    List<WebhooksDTO> subscribersList = (List<WebhooksDTO>) messageContext.getProperty(APIConstants.Webhooks.SUBSCRIBERS_LIST_PROPERTY);
    int index = (Integer) messageContext.getProperty(APIConstants.CLONED_ITERATION_INDEX_PROPERTY);
    WebhooksDTO subscriber = subscribersList.get(index - 1);
    if (subscriber != null) {
        boolean canProceed = handleThrottle(subscriber, messageContext);
        if (!canProceed) {
            return false;
        }
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_CALLBACK_PROPERTY, subscriber.getCallbackURL());
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_SECRET_PROPERTY, subscriber.getSecret());
        messageContext.setProperty(APIConstants.Webhooks.SUBSCRIBER_APPLICATION_ID_PROPERTY, subscriber.getAppID());
    }
    return true;
}
Also used : WebhooksDTO(org.wso2.carbon.apimgt.impl.dto.WebhooksDTO) List(java.util.List)

Example 5 with GenericRequestDataCollector

use of org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector in project carbon-apimgt by wso2.

the class AnalyticsMetricsHandler method handleResponseOutFlow.

@Override
public boolean handleResponseOutFlow(MessageContext messageContext) {
    if (messageContext.getPropertyKeySet().contains(InboundWebsocketConstants.WEBSOCKET_SUBSCRIBER_PATH)) {
        return true;
    }
    AnalyticsDataProvider provider;
    Object skipPublishMetrics = messageContext.getProperty(Constants.SKIP_DEFAULT_METRICS_PUBLISHING);
    if (skipPublishMetrics != null && (Boolean) skipPublishMetrics) {
        provider = new AsyncAnalyticsDataProvider(messageContext);
    } else {
        provider = new SynapseAnalyticsDataProvider(messageContext);
    }
    GenericRequestDataCollector dataCollector = new GenericRequestDataCollector(provider);
    try {
        dataCollector.collectData();
    } catch (Exception e) {
        log.error("Error Occurred when collecting data", e);
    }
    return true;
}
Also used : GenericRequestDataCollector(org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector) AsyncAnalyticsDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider) AnalyticsDataProvider(org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider) AsyncAnalyticsDataProvider(org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider) AnalyticsException(org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException)

Aggregations

GenericRequestDataCollector (org.wso2.carbon.apimgt.common.analytics.collectors.impl.GenericRequestDataCollector)4 AnalyticsException (org.wso2.carbon.apimgt.common.analytics.exceptions.AnalyticsException)3 AnalyticsDataProvider (org.wso2.carbon.apimgt.common.analytics.collectors.AnalyticsDataProvider)2 List (java.util.List)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 JSONObject (org.json.JSONObject)1 AsyncAnalyticsDataProvider (org.wso2.carbon.apimgt.gateway.handlers.streaming.AsyncAnalyticsDataProvider)1 SseResponseEventDataProvider (org.wso2.carbon.apimgt.gateway.handlers.streaming.sse.analytics.SseResponseEventDataProvider)1 WebhooksAnalyticsDataProvider (org.wso2.carbon.apimgt.gateway.handlers.streaming.webhook.WebhooksAnalyticsDataProvider)1 WebhooksDTO (org.wso2.carbon.apimgt.impl.dto.WebhooksDTO)1