apim_4xx_support_multiple_analytics_publishers APIM manage workflow with multiple roles APIM 3.0.0 per API based subscription workflow Logging internal HTTP requests Log APIM analytics events to a file Monetization and sample with WSO2 API Manager 2.6.0 Share application and subscription among a set of specific groups or roles WSO2 APIM Correlating analytics event with correlationID APIM analytics distinguish production and sandbox traffic APIM 2.x.x analytics internal and analytics tuneup Configure APIM(Next release) Key Manager User stores APIM(Next release) working with key manager DAS 3.x Parse system variables to Spark Context Revoke OAuth application In APIM 2.1.0 Next WSO2 APIM powered by WSO2 Ballerina Configure WSO2 APIM Analytics on Cluster environment Configure WSO2 DAS 3.1.0 for WSO2 APIM 2.0.0 Analytics WSO2 APIM publishing custom statistics WSO2 APIM Error codes Working with WSO2 message tracer Use DAS admin service to query using Spark SQL Configure WSO2 APIM Analytics using XML WSO2 APIM Generating and Retrieving Custom Statistics Understanding WSO2 APIM Statistics Model Publishing WSO2 APIM 1.10.x Runtime Statistics to DAS with RDBMS Publishing_APIM_1100_Runtime_Statistics_to_DAS Aggregate functions with WSO2 DAS REST API Create a cApp for WSO2 DAS Debugging WSO2 Products using OSGI console. Publishing APIM Runtime Statistics to DAS Deploy cApp on WSO2 DAS How to configure and start the Accumulo minicluster How to setup DNS server on Ubuntu and Ubuntu server How to use Java Reflection how to install apache web server on ubuntu and ubuntu server How to install Mail server on Ubuntu and Ubuntu server How to install squirrelmail webmail client on Ubuntu and Ubuntu Server Pass and return String value to JNI method Pass and return numeric value to JNI method Calling a C Function from the Java Programming Language using JNI AXIS 2 Sample web service Client with maven and eclipse How to setup AXIS 2 with Apache Tomcat AXIS 2 Sample web service with maven and eclipse Robot framework Sample with Selenium Robot framework Custom Library Sample Behaviour-Driven Development with JBehave and Eclipse Play Audio with Netbeans and linking with LibVLC Implement LibVLC based player with QT-part2 Simple Audio playing sample with LibVLC How to install LibVLC on Ubuntu Implement LibVLC based player with QT-part1
apim_4xx_support_multiple_analytics_publishers
  1. Introduction

    There can be requirements to publish analytics data to multiple endpoints. Ex: ELK, Choreo, Google Analytics, etc. But there is no direct way to define multiple publishers(Reporters) in APIM. The solution for this is to use a custom reporter. The most common requirement was to use choreo analytics and ELK analytics. Both ELK and Choreo reporters are available in the APIM 400 onwards by default. But the limitation was only one at a time can be used.

    With this custom publisher, APIM can use to publish analytics to two endpoints choreo and ELK. For this, we need to implement a custom reporter and counter metric.

    • Workflow executor
    • Customize the BPEL process
    • Customize HumanTask
  2. Prerequisites
    • WSO2 API Manager 4.x.x
  3. Workflow executor Implementation
    package com.rukspot.sample.custompublisher;
    
    import org.wso2.am.analytics.publisher.exception.MetricCreationException;
    import org.wso2.am.analytics.publisher.reporter.CounterMetric;
    import org.wso2.am.analytics.publisher.reporter.MetricReporter;
    import org.wso2.am.analytics.publisher.reporter.MetricSchema;
    import org.wso2.am.analytics.publisher.reporter.TimerMetric;
    import org.wso2.am.analytics.publisher.reporter.cloud.DefaultAnalyticsMetricReporter;
    import org.wso2.am.analytics.publisher.reporter.elk.ELKMetricReporter;
    
    import java.util.Map;
    
    /**
     *
     */
    public class CustomMetricReporter implements MetricReporter {
        private final DefaultAnalyticsMetricReporter defaultAnalyticsMetricReporter;
        private final ELKMetricReporter elkMetricReporter;
        private final Map<String, String> properties;
    
        public CustomMetricReporter(Map<String, String> properties) throws MetricCreationException {
            this.properties = properties;
            this.defaultAnalyticsMetricReporter = new DefaultAnalyticsMetricReporter(properties);
            this.elkMetricReporter = new ELKMetricReporter(properties);
        }
    
        @Override
        public CounterMetric createCounterMetric(String name, MetricSchema schema) throws MetricCreationException {
            CounterMetric defaultCounterMetric = this.defaultAnalyticsMetricReporter.createCounterMetric(name, schema);
            CounterMetric elkCounterMetric = this.elkMetricReporter.createCounterMetric(name, schema);
            CustomCounterMetric customCounterMetric = new CustomCounterMetric(defaultCounterMetric, elkCounterMetric,
                    schema);
            return customCounterMetric;
        }
    
        @Override
        public TimerMetric createTimerMetric(String name) {
            return null;
        }
    
        @Override
        public Map<String, String> getConfiguration() {
            return this.properties;
        }
    }
    
    =
  4. customer counter metric
    package com.rukspot.sample.custompublisher;
    
    import org.wso2.am.analytics.publisher.exception.MetricReportingException;
    import org.wso2.am.analytics.publisher.reporter.CounterMetric;
    import org.wso2.am.analytics.publisher.reporter.MetricEventBuilder;
    import org.wso2.am.analytics.publisher.reporter.MetricSchema;
    import org.wso2.am.analytics.publisher.reporter.cloud.DefaultFaultMetricEventBuilder;
    import org.wso2.am.analytics.publisher.reporter.cloud.DefaultResponseMetricEventBuilder;
    
    /**
     *
     */
    public class CustomCounterMetric implements CounterMetric {
        private CounterMetric defaultCounterMetric;
        private CounterMetric elkCounterMetric;
        private MetricSchema schema;
    
        public CustomCounterMetric(CounterMetric defaultCounterMetric, CounterMetric elkCounterMetric,
                MetricSchema schema) {
            this.defaultCounterMetric = defaultCounterMetric;
            this.elkCounterMetric = elkCounterMetric;
            this.schema = schema;
        }
    
        @Override
        public int incrementCount(MetricEventBuilder metricEventBuilder) throws MetricReportingException {
            metricEventBuilder.build(); // build before sending events
            this.defaultCounterMetric.incrementCount(metricEventBuilder);
            this.elkCounterMetric.incrementCount(metricEventBuilder);
            return 0;
        }
    
        @Override
        public String getName() {
            return defaultCounterMetric.getName();
        }
    
        @Override
        public MetricSchema getSchema() {
            return defaultCounterMetric.getSchema();
        }
    
        @Override
        public MetricEventBuilder getEventBuilder() {
            switch (schema) {
            case RESPONSE:
                return new DefaultResponseMetricEventBuilder();
            case ERROR:
                return new DefaultFaultMetricEventBuilder();
            default:
                // will not happen
                return null;
            }
        }
    }
    
  5. Registering the custom reporter in deployment.toml
          [apim.analytics]
    enable = true
    auth_token = ""
    config_endpoint = "https://analytics-event-auth.choreo.dev/auth/v1"
    properties."publisher.reporter.class" = "com.rukspot.sample.custompublisher.CustomMetricReporter"
    
  6. Code Sample

    Please find the sample code from GitHub

Add Comment

* Required information
1000
Powered by Commentics

Comments (0)

No comments yet. Be the first!