From 87c84e71cab2e0aa94856a0dec535fa64bb45938 Mon Sep 17 00:00:00 2001 From: Ralph Soika Date: Wed, 4 Dec 2024 17:13:08 +0100 Subject: [PATCH] update docu --- src/site/markdown/engine/metrics.md | 214 +++++++++++++++++++++++++--- 1 file changed, 191 insertions(+), 23 deletions(-) diff --git a/src/site/markdown/engine/metrics.md b/src/site/markdown/engine/metrics.md index b3c87eb98..cf5cc1a77 100644 --- a/src/site/markdown/engine/metrics.md +++ b/src/site/markdown/engine/metrics.md @@ -84,40 +84,208 @@ The default metric api endpoint for Payara Server is: A Prometheus configuration to scrape the metrics from Imixs-Workflow can look like in the following example: - - global: - scrape_interval: 15s # By default, scrape targets every 15 seconds. - # Attach these labels to any time series or alerts when communicating with - # external systems (federation, remote storage, Alertmanager). - external_labels: - monitor: 'imixs-monitor' - - scrape_configs: - # Prometheus itself - - job_name: 'prometheus' - scrape_interval: 5s - static_configs: - - targets: ['localhost:9090'] - - # Imixs-Office Job - - job_name: 'imixs' - scrape_interval: 5s - metrics_path: /metrics - static_configs: - - targets: ['app:8080'] - +``` +global: + scrape_interval: 15s # By default, scrape targets every 15 seconds. + # Attach these labels to any time series or alerts when communicating with + # external systems (federation, remote storage, Alertmanager). + external_labels: + monitor: 'imixs-monitor' + +scrape_configs: + # Prometheus itself + - job_name: 'prometheus' + scrape_interval: 5s + static_configs: + - targets: ['localhost:9090'] + + # Imixs-Office Job + - job_name: 'imixs' + scrape_interval: 5s + metrics_path: /metrics + static_configs: + - targets: ['app:8080'] + ``` ### Prometheus Dashboard +To setup Prometheus with docker-compose you can add the container like shown in the following example: + +```yaml + prometheus: + image: prom/prometheus:latest + ports: + - "9090:9090" + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + - prometheusdata:/prometheus/ + +volumes: + prometheusdata: +``` + + From the Prometheus Dashboard you can test the data within your web browser: ### Monitoring Metrics with Grafana + + grafana: + image: grafana/grafana:7.1.0 + ports: + - "3000:3000" + To monitor you workflow you can easily connect your Prometheus server with a Grafana Instance. This allows you to visualize your metrics in an individual and more detailed dashboard. -There are a huge amount of functions available in Grafana to analyze and monitor data. You can also activate individual alerts to notify your process owner about the load of your business processes. \ No newline at end of file +There are a huge amount of functions available in Grafana to analyze and monitor data. You can also activate individual alerts to notify your process owner about the load of your business processes. + + +## Custom Metric Service + +You can also implement your own custom metric service by just observing the # + + +```java + +@ApplicationScoped +public class MyCustomMetricService { + + @Inject + @ConfigProperty(name = "metrics.enabled", defaultValue = "false") + private boolean metricsEnabled; + + @Inject + @RegistryScope(scope = MetricRegistry.APPLICATION_SCOPE) + MetricRegistry metricRegistry; + + /** + * ProcessingEvent listener to generate a metric. + */ + public void onProcessingEvent(@Observes ProcessingEvent processingEvent) throws AccessDeniedException { + + if (!metricsEnabled) { + return; + } + try { + Counter counter = buildMetric(processingEvent); + counter.inc(); + } catch (IncompatibleClassChangeError | ObserverException oe) { + mpMetricNoSupport = true; + logger.warning("...Microprofile Metrics not supported!"); + } + } + + + /** + * This method builds a custom Microprofile Metric + */ + private Counter buildMetric(DocumentEvent event) { + + + // create a metadata object.... + Metadata metadata = Metadata.builder().withName(METRIC_DOCUMENTS) + .withDescription("My custom metric").build(); + .... + ........ + // export custom metrics.... + Tag[] tags = { new Tag("my_metric", method) }; + Counter counter = metricRegistry.counter(metadata, tags); + + return counter; + } +} +``` + +### Metric Types + +The Eclipse MicroProfile Metrics Framework supports the different metric types: + + +**Counter:** + + +A simple incrementing counter that can only be increased +Useful for counting events like API calls or errors + +Example: + +```java +@Counted(name = "requestCount", absolute = true) +public void doRequest() { + // Method implementation +} +``` + +**Gauge** + +A gauge represents a single numerical value that can increase and decrease. +Perfect for instantaneous values like CPU usage or active threads + +Example: + +```java +@Gauge(unit = MetricUnits.NONE) +public int getQueueSize() { + return queue.size(); +} +``` + +**Meter** + +The Meter metric measures the rate at which events occur over time +Calculates mean rate, one-minute, five-minute, and fifteen-minute rates + +Example: + +```java +@Metered(name = "requestMeter") +public void handleRequest() { + // Request processing +} +``` + +**Timer** + +A Timer combines Meter and Histogram for time measurements +Measures both frequency and duration of events + +Example: + +```java +@Timed(name = "processingTime") +public void processData() { + // Time-intensive operation +} +``` + + +**Histogram** + +A histogram tracks the distribution of values over time +Calculates statistical values like min, max, mean, and percentiles + +Example: + +```java +@Metric(name = "histogram") +private Histogram histogram; +``` + +**ConcurrentGauge** + +Specialized gauge for concurrent access +Tracks current, maximum, and minimum concurrent invocations + +Example: + +```java +@ConcurrentGauge(name = "activeRequests") +public void handleRequest() { + // Concurrent request handling +} +``` \ No newline at end of file