Java Code Examples for io.siddhi.core.config.SiddhiAppContext#getStatisticsManager()

The following examples show how to use io.siddhi.core.config.SiddhiAppContext#getStatisticsManager() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Window.java    From siddhi with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a Window object.
 *
 * @param windowDefinition definition of the window
 * @param siddhiAppContext siddhi app context of Siddhi
 */
public Window(WindowDefinition windowDefinition, SiddhiAppContext siddhiAppContext) {
    this.windowDefinition = windowDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.lockWrapper = new LockWrapper(windowDefinition.getId());
    this.lockWrapper.setLock(new ReentrantLock());
    if (siddhiAppContext.getStatisticsManager() != null) {
        latencyTrackerFind = QueryParserHelper.createLatencyTracker(siddhiAppContext, windowDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_WINDOWS, SiddhiConstants.METRIC_TYPE_FIND);
        latencyTrackerInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext, windowDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_WINDOWS, SiddhiConstants.METRIC_TYPE_INSERT);

        throughputTrackerFind = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                windowDefinition.getId(), SiddhiConstants.METRIC_INFIX_WINDOWS, SiddhiConstants.METRIC_TYPE_FIND);
        throughputTrackerInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                windowDefinition.getId(), SiddhiConstants.METRIC_INFIX_WINDOWS, SiddhiConstants.METRIC_TYPE_INSERT);
    }
}
 
Example 2
Source File: SourceMapper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public final void init(StreamDefinition streamDefinition, String mapType, OptionHolder mapOptionHolder,
                       List<AttributeMapping> attributeMappings, String sourceType,
                       SourceSyncCallback sourceSyncCallback, List<AttributeMapping> transportMappings,
                       SourceHandler sourceHandler, OptionHolder sourceOptionHolder, ConfigReader configReader,
                       SiddhiAppContext siddhiAppContext) {

    this.streamDefinition = streamDefinition;
    this.mapType = mapType;
    this.sourceType = sourceType;
    this.transportMappings = transportMappings;
    this.sourceOptionHolder = sourceOptionHolder;
    if (sourceHandler != null) {
        sourceHandler.initSourceHandler(siddhiAppContext.getName(), sourceSyncCallback, streamDefinition,
                siddhiAppContext);
    }
    this.sourceHandler = sourceHandler;
    this.siddhiAppContext = siddhiAppContext;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SOURCES, sourceType);
        this.mapperLatencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SOURCE_MAPPERS,
                sourceType + SiddhiConstants.METRIC_DELIMITER + mapType);
    }
    if (configReader != null && configReader.getAllConfigs().size() != 0) {
        if (configReader.getAllConfigs().containsKey(ENABLE_EVENT_COUNT_LOGGER) &&
                configReader.getAllConfigs().get(ENABLE_EVENT_COUNT_LOGGER).toLowerCase().equals(TRUE)) {
            logEventCount = true;
            this.receivedEventCounter = new ReceivedEventCounter();
            if (configReader.getAllConfigs().containsKey(LOGGING_DURATION)) {
                loggingDuration = Integer.parseInt(configReader.getAllConfigs().get(LOGGING_DURATION));
            }
            receivedEventCounter.init(siddhiAppContext, streamDefinition, loggingDuration);
        }
    }
    init(streamDefinition, mapOptionHolder, attributeMappings, configReader, siddhiAppContext);
}
 
Example 3
Source File: Table.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public void initTable(TableDefinition tableDefinition, StreamEventFactory storeEventPool,
                      StreamEventCloner storeEventCloner,
                      ConfigReader configReader, SiddhiAppContext siddhiAppContext,
                      RecordTableHandler recordTableHandler) {
    this.tableDefinition = tableDefinition;
    this.scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    this.siddhiAppContext = siddhiAppContext;
    this.recordTableHandler = recordTableHandler;
    if (siddhiAppContext.getStatisticsManager() != null) {
        latencyTrackerFind = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
        latencyTrackerInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
        latencyTrackerUpdate = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
        latencyTrackerDelete = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
        latencyTrackerUpdateOrInsert = QueryParserHelper.createLatencyTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES,
                SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
        latencyTrackerContains = QueryParserHelper.createLatencyTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);

        throughputTrackerFind = QueryParserHelper.createThroughputTracker(siddhiAppContext, tableDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_FIND);
        throughputTrackerInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_INSERT);
        throughputTrackerUpdate = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_UPDATE);
        throughputTrackerDelete = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_DELETE);
        throughputTrackerUpdateOrInsert = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES,
                SiddhiConstants.METRIC_TYPE_UPDATE_OR_INSERT);
        throughputTrackerContains = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                tableDefinition.getId(), SiddhiConstants.METRIC_INFIX_TABLES, SiddhiConstants.METRIC_TYPE_CONTAINS);

    }
    init(tableDefinition, storeEventPool, storeEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
 
Example 4
Source File: QueryParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static LatencyTracker createLatencyTracker(SiddhiAppContext siddhiAppContext, String name, String type,
                                                  String function) {
    LatencyTracker latencyTracker = null;
    if (siddhiAppContext.getStatisticsManager() != null) {
        String metricName =
                siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getMetricPrefix() +
                        SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS +
                        SiddhiConstants.METRIC_DELIMITER + siddhiAppContext.getName() +
                        SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI +
                        SiddhiConstants.METRIC_DELIMITER + type +
                        SiddhiConstants.METRIC_DELIMITER + name;
        if (function != null) {
            metricName += SiddhiConstants.METRIC_DELIMITER + function;
        }
        metricName += SiddhiConstants.METRIC_DELIMITER + "latency";
        boolean matchExist = false;
        for (String regex : siddhiAppContext.getIncludedMetrics()) {
            if (metricName.matches(regex)) {
                matchExist = true;
                break;
            }
        }
        if (matchExist) {
            latencyTracker = siddhiAppContext.getSiddhiContext()
                    .getStatisticsConfiguration()
                    .getFactory()
                    .createLatencyTracker(metricName, siddhiAppContext.getStatisticsManager());
        }
    }
    return latencyTracker;
}
 
Example 5
Source File: QueryParserHelper.java    From siddhi with Apache License 2.0 5 votes vote down vote up
public static ThroughputTracker createThroughputTracker(SiddhiAppContext siddhiAppContext, String name,
                                                        String type, String function) {
    ThroughputTracker throughputTracker = null;
    if (siddhiAppContext.getStatisticsManager() != null) {
        String metricName =
                siddhiAppContext.getSiddhiContext().getStatisticsConfiguration().getMetricPrefix() +
                        SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI_APPS +
                        SiddhiConstants.METRIC_DELIMITER + siddhiAppContext.getName() +
                        SiddhiConstants.METRIC_DELIMITER + SiddhiConstants.METRIC_INFIX_SIDDHI +
                        SiddhiConstants.METRIC_DELIMITER + type +
                        SiddhiConstants.METRIC_DELIMITER + name;
        if (function != null) {
            metricName += SiddhiConstants.METRIC_DELIMITER + function;
        }
        metricName += SiddhiConstants.METRIC_DELIMITER + "throughput";
        boolean matchExist = false;
        for (String regex : siddhiAppContext.getIncludedMetrics()) {
            if (metricName.matches(regex)) {
                matchExist = true;
                break;
            }
        }
        if (matchExist) {
            throughputTracker = siddhiAppContext
                    .getSiddhiContext()
                    .getStatisticsConfiguration()
                    .getFactory()
                    .createThroughputTracker(metricName, siddhiAppContext.getStatisticsManager());
        }
    }
    return throughputTracker;
}
 
Example 6
Source File: PeriodicTrigger.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TriggerDefinition triggerDefinition, SiddhiAppContext siddhiAppContext, StreamJunction
        streamJunction) {
    this.triggerDefinition = triggerDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.streamJunction = streamJunction;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                triggerDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TRIGGERS, null);
    }
}
 
Example 7
Source File: CronTrigger.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TriggerDefinition triggerDefinition, SiddhiAppContext siddhiAppContext,
                 StreamJunction streamJunction) {
    this.triggerDefinition = triggerDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.streamJunction = streamJunction;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                triggerDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TRIGGERS, null);
    }
}
 
Example 8
Source File: StartTrigger.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Override
public void init(TriggerDefinition triggerDefinition, SiddhiAppContext siddhiAppContext, StreamJunction
        streamJunction) {
    this.triggerDefinition = triggerDefinition;
    this.siddhiAppContext = siddhiAppContext;
    this.streamJunction = streamJunction;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                triggerDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_TRIGGERS, null);
    }
}
 
Example 9
Source File: StreamJunction.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public StreamJunction(StreamDefinition streamDefinition, ExecutorService executorService, int bufferSize,
                      StreamJunction faultStreamJunction, SiddhiAppContext siddhiAppContext) {
    this.streamDefinition = streamDefinition;
    this.bufferSize = bufferSize;
    this.batchSize = bufferSize;
    this.executorService = executorService;
    this.siddhiAppContext = siddhiAppContext;
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_STREAMS, null);
    }
    this.faultStreamJunction = faultStreamJunction;
    if (faultStreamJunction != null) {
        StreamDefinition faultStreamDefinition = faultStreamJunction.getStreamDefinition();
        StreamEventFactory faultStreamEventFactory = new StreamEventFactory(0, 0,
                faultStreamDefinition.getAttributeList().size());
        faultStreamEventConverter = new FaultStreamEventConverter(faultStreamEventFactory);
    }
    try {
        Annotation asyncAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ASYNC,
                streamDefinition.getAnnotations());
        if (asyncAnnotation != null) {
            async = true;
            String bufferSizeString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_BUFFER_SIZE);
            if (bufferSizeString != null) {
                this.bufferSize = Integer.parseInt(bufferSizeString);
            }
            String workersString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_WORKERS);
            if (workersString != null) {
                this.workers = Integer.parseInt(workersString);
                if (workers <= 0) {
                    throw new SiddhiAppCreationException("Annotation element '" +
                            SiddhiConstants.ANNOTATION_ELEMENT_WORKERS + "' cannot be negative or zero, " +
                            "but found, '" + workers + "'.", asyncAnnotation.getQueryContextStartIndex(),
                            asyncAnnotation.getQueryContextEndIndex(), siddhiAppContext.getName(),
                            siddhiAppContext.getSiddhiAppString());
                }
            }
            String batchSizeString = asyncAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_MAX_BATCH_SIZE);
            if (batchSizeString != null) {
                this.batchSize = Integer.parseInt(batchSizeString);
                if (batchSize <= 0) {
                    throw new SiddhiAppCreationException("Annotation element '" +
                            SiddhiConstants.ANNOTATION_ELEMENT_MAX_BATCH_SIZE + "' cannot be negative or zero, " +
                            "but found, '" + batchSize + "'.", asyncAnnotation.getQueryContextStartIndex(),
                            asyncAnnotation.getQueryContextEndIndex(), siddhiAppContext.getName(),
                            siddhiAppContext.getSiddhiAppString());
                }
            }
        }
        Annotation onErrorAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_ON_ERROR,
                streamDefinition.getAnnotations());
        if (onErrorAnnotation != null) {
            this.onErrorAction = OnErrorAction.valueOf(onErrorAnnotation
                    .getElement(SiddhiConstants.ANNOTATION_ELEMENT_ACTION).toUpperCase());
        }
    } catch (DuplicateAnnotationException e) {
        throw new DuplicateAnnotationException(e.getMessageWithOutContext() + " for the same Stream " +
                streamDefinition.getId(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(),
                siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
    }
    isTraceEnabled = log.isTraceEnabled();
}
 
Example 10
Source File: Sink.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public final void init(StreamDefinition streamDefinition, String type, OptionHolder transportOptionHolder,
                       ConfigReader sinkConfigReader, SinkMapper sinkMapper, String mapType,
                       OptionHolder mapOptionHolder, SinkHandler sinkHandler, List<Element> payloadElementList,
                       ConfigReader mapperConfigReader, Map<String, String> deploymentProperties,
                       StreamJunction streamJunction, SiddhiAppContext siddhiAppContext) {
    this.streamDefinition = streamDefinition;
    this.type = type;
    this.streamJunction = streamJunction;
    this.siddhiAppContext = siddhiAppContext;
    this.onErrorAction = OnErrorAction.valueOf(transportOptionHolder
            .getOrCreateOption(SiddhiConstants.ANNOTATION_ELEMENT_ON_ERROR, "LOG")
            .getValue().toUpperCase());
    if (siddhiAppContext.getStatisticsManager() != null) {
        this.throughputTracker = QueryParserHelper.createThroughputTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SINKS, type);
        this.mapperLatencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext,
                streamDefinition.getId(),
                SiddhiConstants.METRIC_INFIX_SINK_MAPPERS,
                type + SiddhiConstants.METRIC_DELIMITER + mapType);
    }
    StateFactory<S> stateFactory = init(streamDefinition, transportOptionHolder, sinkConfigReader,
            siddhiAppContext);
    stateHolder = siddhiAppContext.generateStateHolder(streamDefinition.getId() + "-" +
            this.getClass().getName(), stateFactory);
    if (sinkMapper != null) {
        sinkMapper.init(streamDefinition, mapType, mapOptionHolder, payloadElementList, this,
                mapperConfigReader, mapperLatencyTracker, transportOptionHolder, siddhiAppContext);
        this.mapper = sinkMapper;
    }
    if (sinkHandler != null) {
        sinkHandler.initSinkHandler(siddhiAppContext.getName(), streamDefinition,
                new SinkHandlerCallback(sinkMapper), siddhiAppContext);
        this.handler = sinkHandler;
    }
    scheduledExecutorService = siddhiAppContext.getScheduledExecutorService();
    serviceDeploymentInfo = exposeServiceDeploymentInfo();
    if (serviceDeploymentInfo != null) {
        serviceDeploymentInfo.addDeploymentProperties(deploymentProperties);
    } else if (!deploymentProperties.isEmpty()) {
        throw new SiddhiAppCreationException("Deployment properties '" + deploymentProperties +
                "' are defined for sink '" + type + "' which does not expose a service");
    }
}
 
Example 11
Source File: SiddhiAppRuntimeImpl.java    From siddhi with Apache License 2.0 4 votes vote down vote up
public SiddhiAppRuntimeImpl(Map<String, AbstractDefinition> streamDefinitionMap,
                            Map<String, AbstractDefinition> tableDefinitionMap,
                            Map<String, AbstractDefinition> windowDefinitionMap,
                            Map<String, AbstractDefinition> aggregationDefinitionMap,
                            InputManager inputManager,
                            Map<String, QueryRuntime> queryProcessorMap,
                            Map<String, StreamJunction> streamJunctionMap,
                            Map<String, Table> tableMap,
                            Map<String, Window> windowMap,
                            ConcurrentMap<String, AggregationRuntime> aggregationMap,
                            Map<String, List<Source>> sourceMap,
                            Map<String, List<Sink>> sinkMap,
                            Map<String, PartitionRuntime> partitionMap,
                            ConcurrentMap<String, Trigger> triggerMap,
                            SiddhiAppContext siddhiAppContext,
                            Map<String, SiddhiAppRuntime> siddhiAppRuntimeMap) {
    this.streamDefinitionMap = streamDefinitionMap;
    this.tableDefinitionMap = tableDefinitionMap;
    this.windowDefinitionMap = windowDefinitionMap;
    this.aggregationDefinitionMap = aggregationDefinitionMap;
    this.inputManager = inputManager;
    this.queryProcessorMap = queryProcessorMap;
    this.streamJunctionMap = streamJunctionMap;
    this.tableMap = tableMap;
    this.windowMap = windowMap;
    this.aggregationMap = aggregationMap;
    this.sourceMap = sourceMap;
    this.sinkMap = sinkMap;
    this.partitionMap = partitionMap;
    this.triggerMap = triggerMap;
    this.siddhiAppContext = siddhiAppContext;
    this.siddhiAppRuntimeMap = siddhiAppRuntimeMap;
    if (siddhiAppContext.getStatisticsManager() != null) {
        monitorQueryMemoryUsage();
        monitorBufferedEvents();
        onDemandQueryLatencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext, "query",
                SiddhiConstants.METRIC_INFIX_ON_DEMAND_QUERIES, null);
    }

    for (Map.Entry<String, List<Sink>> sinkEntries : sinkMap.entrySet()) {
        addCallback(sinkEntries.getKey(),
                new SinkCallback(sinkEntries.getValue(), streamDefinitionMap.get(sinkEntries.getKey())));
    }
    for (Map.Entry<String, List<Source>> sourceEntries : sourceMap.entrySet()) {
        InputHandler inputHandler = getInputHandler(sourceEntries.getKey());
        for (Source source : sourceEntries.getValue()) {
            source.getMapper().setInputHandler(inputHandler);
        }
    }
}