diff --git a/.vscode/settings.json b/.vscode/settings.json index c7a7554..aa96d3a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,12 +4,12 @@ // - Linux: $HOME/.config/Code/User/settings.json // - Mac: $HOME/Library/Application Support/Code/User/settings.json { - "editor.formatOnSave": true, + // Organize Java Imports "editor.codeActionsOnSave": { "source.organizeImports": "explicit" }, - "java.checkstyle.version": "8.44", - "java.checkstyle.autocheck": true, + // Checkstile "java.checkstyle.configuration": "https://raw.githubusercontent.com/imixs/imixs-workflow/master/imixs-checkstyle-8.44.xml", - "java.configuration.updateBuildConfiguration": "automatic" -} \ No newline at end of file + "editor.formatOnSave": true +} + \ No newline at end of file diff --git a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupController.java b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupController.java index 31017b6..cb02282 100644 --- a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupController.java +++ b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupController.java @@ -11,7 +11,7 @@ import org.eclipse.microprofile.metrics.Counter; import org.eclipse.microprofile.metrics.MetricID; import org.eclipse.microprofile.metrics.MetricRegistry; -import org.eclipse.microprofile.metrics.annotation.RegistryType; +import org.eclipse.microprofile.metrics.annotation.RegistryScope; import org.imixs.archive.backup.util.LogController; import jakarta.enterprise.context.RequestScoped; @@ -45,7 +45,7 @@ public class BackupController implements Serializable { String metricsEndpoint; @Inject - @RegistryType(type = MetricRegistry.Type.APPLICATION) + @RegistryScope(scope = MetricRegistry.APPLICATION_SCOPE) MetricRegistry metricRegistry; @Inject @@ -147,10 +147,8 @@ public void stop() { * @return */ public long getCounterByName(String name) { - // find counter by name SortedMap allCounters = metricRegistry.getCounters(); - for (Map.Entry entry : allCounters.entrySet()) { MetricID metricID = entry.getKey(); @@ -158,7 +156,7 @@ public long getCounterByName(String name) { return entry.getValue().getCount(); } } - logger.warning("Metric Counter : " + name + " not found!"); + logger.fine("Metric Counter : " + name + " not found!"); return 0; } } \ No newline at end of file diff --git a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java index 6610b24..f321011 100644 --- a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java +++ b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java @@ -27,6 +27,10 @@ import java.util.logging.Logger; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.eclipse.microprofile.metrics.Counter; +import org.eclipse.microprofile.metrics.Metadata; +import org.eclipse.microprofile.metrics.MetricRegistry; +import org.eclipse.microprofile.metrics.annotation.RegistryScope; import org.imixs.archive.backup.util.FTPConnector; import org.imixs.archive.backup.util.LogController; import org.imixs.archive.backup.util.RestClientHelper; @@ -75,6 +79,9 @@ public class BackupService { @Inject LogController logController; + public static final String METRIC_EVENTS_PROCESSED = "backup_events_processed"; + public static final String METRIC_EVENTS_ERRORS = "backup_events_errors"; + // timeout interval in ms @Inject @ConfigProperty(name = BackupApi.WORKFLOW_SYNC_INTERVAL, defaultValue = "10000") @@ -121,6 +128,10 @@ public class BackupService { @Inject BackupStatusHandler backupStatusHandler; + @Inject + @RegistryScope(scope = MetricRegistry.APPLICATION_SCOPE) + MetricRegistry metricRegistry; + @PostConstruct public void init() { // init timer.... @@ -201,12 +212,17 @@ public void onTimeout(jakarta.ejb.Timer _timer) { // finally remove the event log entry... eventLogClient.deleteEventLogEntry(id); success++; + + countMetric(METRIC_EVENTS_PROCESSED); + } catch (InvalidAccessException | EJBException | BackupException | RestAPIException e) { // we also catch EJBExceptions here because we do not want to cancel the // ManagedScheduledExecutorService logController.warning(BackupApi.TOPIC_BACKUP, "SnapshotEvent " + id + " backup failed: " + e.getMessage()); errors++; + countMetric(METRIC_EVENTS_ERRORS); + } } @@ -230,6 +246,23 @@ public void onTimeout(jakarta.ejb.Timer _timer) { } } + /** + * Helper method to create a counter and inc the coutner + * + * @param name + */ + private void countMetric(String name) { + + try { + Metadata metadata = Metadata.builder().withName(name) + .withDescription("Imixs-Backup Service - processed backup events").build(); + Counter counter = metricRegistry.counter(metadata); + counter.inc(); + } catch (Exception e) { + logger.severe("Unable to create metrics for ' " + name + "'"); + } + } + /** * Asynchronous method to release dead locks * diff --git a/imixs-archive-backup/src/main/webapp/index.xhtml b/imixs-archive-backup/src/main/webapp/index.xhtml index 84b2e25..92aab41 100644 --- a/imixs-archive-backup/src/main/webapp/index.xhtml +++ b/imixs-archive-backup/src/main/webapp/index.xhtml @@ -1,5 +1,4 @@ - @@ -7,110 +6,112 @@ -
-
-

- Imixs Backup Service -

-
-
- -
-
- - -

- Imixs-Workflow API - Endpoint Configuration. -

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Imixs-Workflow Instance:#{backupController.getInstanceEndpoint()}
Backup Status:#{backupController.getStatus()} - - - - - -
Interval:#{backupController.getInterval()} ms
Next Timeout:#{backupController.getNextTimeout()}
FTP Host:#{backupController.ftpServer}:#{backupController.ftpPort}
Backup Space:#{backupController.ftpPath}
+
+
+

+ Imixs Backup Service +

+
-
- - - +
+
+ + +

+ Imixs-Workflow API + Endpoint Configuration. +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Imixs-Workflow Instance:#{backupController.getInstanceEndpoint()}
Backup Status:#{backupController.getStatus()} + + + + + + +
Interval:#{backupController.getInterval()} ms
Next Timeout:#{backupController.getNextTimeout()}
FTP Host:#{backupController.ftpServer}:#{backupController.ftpPort}
Backup Space:#{backupController.ftpPath}
+
+ +
+ + + + + + +
-
- + - +
- +

- #{exportController.getCounterByName('eventProcessed')} Events + #{backupController.getCounterByName('backup_events_processed')} Events

- Number of processed export events since last start.

- - - + Total Number of processed backup events since last start.

+ + +

- #{exportController.getCounterByName('errors')} Errors + #{backupController.getCounterByName('backup_events_errors')} + Errors

- Number of processed export errors since last start.

- + Total backup errros since last start.

+
@@ -130,4 +131,4 @@
-
+ \ No newline at end of file