Database: PostgreSQL
Jmix Add-ons: Data Tools, Business Calendars, Quartz.
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework:spring-jdbc'
management.endpoints.web.exposure.include=*
management.metrics.tags.application=business-metrics-app
businessMetrics.activeUsers.job.cronExpression=0/10 * * * * ?
ActuatorSecurityConfiguration - the spring security configuration for getting direct access to the prometheus actuator endpoint without the authorization
LoginEvent - the entity for representing the event of user entering into the system
MetricDTO - the data transfer object for getting data from the database
UserLoginListener - the listener for the login events registration
ActiveUsersMetricsDAO - the service for getting data from the database
Note. The DTO and JDBC are used instead of using JPA technology because of the specific complex SQL queries. For example:
select sum(count_per_day)/:businessDaysCount
from (select count(DISTINCT user_id) as count_per_day
from LOGIN_EVENT
where
DATE_TRUNC('day', LOGIN_TIME) IN (:businessDays)
group by DATE_TRUNC('day', LOGIN_TIME))
ActiveUsersMetricsService - the service for the micrometer metrics data modifying
Note. The MultiGaude type of micrometer metrics is used.
BusinessDaysService - the service for getting business days for the week or month
Note. If you don't have the ability to use Business calendars Jmix Add-on, you can implement your own implementation of this service.
ActiveUsersMetricsUpdateJob - the job for the metrics state updating
MetricsConfiguration - the configuration for the job
Note. businessMetrics.activeUsers.job.cronExpression application parameter is used to determine the schedule of metrics update.
active_users_dau{application="$application", instance="$instance"}
active_users_wau{application="$application", instance="$instance"}
active_users_mau{application="$application", instance="$instance"}
This is the result of following query executing
active_users_wau{application="$application", instance="$instance"}
The following list of transformations was applied for the WAU metric visualization. The DAU metrics visualization is very simple. It contains only three transformations: Labels to fields, Format time and Organize field by name. The MAU metrics visualization is very similar to the DAU metrics.
So the following description is for the DAU metric visualization.
Labels to fields - is used to transform the metric with labels to a table where the labels become fields

Format time - to transform time into the required format(DD-MM-YYYY for DAU, Wo [week] of YYYY for WAU, and MMMM YYYY for MAU)

Group By - for grouping data by time periods(days, or weeks, or month)

Join by field - behaves like SQL join. It combines some datasets into a single one with rows joining by some field

Organize fields by name - solves three problems. It helps to hide not necessary fields. It helps to give human-readable names for fields. And it helps reorder fields.

Add field from calculation - adds additional field with values that the result of mathematical calculantion

Organize field by name - in this case we use it for final reordering the fields

The final dataset can be visualized in a different ways.
The whole dashboard configuration could be found here Dashboard configuration
You can find a ready-to-use Docker-compose project with ready Prometheus and Grafana services configurations.
The project is in the /monitoring folder.
Predefined Grafana user account is "admin/password1".

