Skip to content

jmix-projects/jmix-app-usage-metrics-sample

Repository files navigation

DAU, MAU, WAU metrics demo application

Base settings and environment

Database: PostgreSQL
Jmix Add-ons: Data Tools, Business Calendars, Quartz.

Necessary dependencies

implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.springframework:spring-jdbc'

Application properties

management.endpoints.web.exposure.include=*
management.metrics.tags.application=business-metrics-app
businessMetrics.activeUsers.job.cronExpression=0/10 * * * * ?

Key application classes and services

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.

Grafana dashboard. Key concepts

The dashboard variables for data filtering

image

The PromQL queries for getting metrics data

active_users_dau{application="$application", instance="$instance"}
active_users_wau{application="$application", instance="$instance"}
active_users_mau{application="$application", instance="$instance"}

Source data

This is the result of following query executing

active_users_wau{application="$application", instance="$instance"}
image

The used transformations

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 image

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) image

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

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

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. image

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

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

Vizualizations

The final dataset can be visualized in a different ways.

Table vizualization
image

Bar chart vizualization image

Full dashboard configuration

Dashboard for importing to ready infrastructure

The whole dashboard configuration could be found here Dashboard configuration

image

Docker-compose project

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".

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors