How to enable WSO2 Carbon metrics in Siddhi extensions

91 Views Asked by At

Can I know how to enable WSO2 carbon metrics in a Siddhi extension when running a test case written for the extension? Currently, when running a test case, metrics are not returned.

Need to know how to make below conditions true

if (MetricsDataHolder.getInstance().getMetricService() != null
                && MetricsDataHolder.getInstance().getMetricManagementService().isEnabled()) {
            try {
                if (MetricsDataHolder.getInstance().getMetricManagementService()
                        .isReporterRunning(SourceConstants.PROMETHEUS_REPORTER_NAME)) {
1

There are 1 best solutions below

0
Anusha Jayasundara On

You can follow this[1] documentation to enable matrics in the Streaming integrator, this enables reporting capability on all the supported extensions.

If you only need to save metrics into a database, then add the following configuration to the deployment.yaml file

 # This is the main configuration for metrics
wso2.metrics:
  # Enable Metrics
  enabled: true
  reporting:
    console:
      - # The name for the Console Reporter
        name: Console

        # Enable Console Reporter
        enabled: false

        # Polling Period in seconds.
        # This is the period for polling metrics from the metric registry and printing in the console
        pollingPeriod: 5

wso2.metrics.jdbc:
  # Data Source Configurations for JDBC Reporters
  dataSource:
    # Default Data Source Configuration
    - &JDBC01
      # JNDI name of the data source to be used by the JDBC Reporter.
      # This data source should be defined under the "wso2.datasources"
      dataSourceName: java:comp/env/jdbc/WSO2MetricsDB
      # Schedule regular deletion of metrics data older than a set number of days.
      # It is recommended that you enable this job to ensure your metrics tables do not get extremely large.
      # Deleting data older than seven days should be sufficient.
      scheduledCleanup:
        # Enable scheduled cleanup to delete Metrics data in the database.
        enabled: true

        # The scheduled job will cleanup all data older than the specified days
        daysToKeep: 3

        # This is the period for each cleanup operation in seconds.
        scheduledCleanupPeriod: 86400

  # The JDBC Reporter is in the Metrics JDBC Core feature
  reporting:
    # The JDBC Reporter configurations will be ignored if the Metrics JDBC Core feature is not available in runtime
    jdbc:
      - # The name for the JDBC Reporter
        name: JDBC

        # Enable JDBC Reporter
        enabled: true

        # Source of Metrics, which will be used to identify each metric in database -->
        # Commented to use the hostname by default
        # source: Carbon

        # Alias referring to the Data Source configuration
        dataSource: *JDBC01

        # Polling Period in seconds.
        # This is the period for polling metrics from the metric registry and updating the database with the values
        pollingPeriod: 60

[1] https://apim.docs.wso2.com/en/4.0.0/observe/streaming-integrator/setting-up-si-statistics-dashboards/