Apereo CAS - Monitoring Metrics with Prometheus and Grafana

Posted by Misagh Moayyed on March 20, 2023 · 9 mins read ·
Content Unavailable
Your browser is blocking content on this website. Please check your browser settings and try again.

When Apereo CAS is deployed in production, it needs to be monitored and observed to watch out for possible performance issues. Many commercial tools can tap into the APM (Application Performance Metrics) exported by CAS to provide monitoring capabilities. In this post, we will examine two open-source tools called Prometheus and Grafana which gather and store metrics data in a time-series format and visualize it on dashboards.

This tutorial specifically requires and focuses on:

CAS Metrics

As a Spring Boot application, CAS provides two dedicated actuator endpoints that export metrics and curate that data for Prometheus. Assuming your CAS server is running on post 8080, these endpoints typically are available at:

  • http://localhost:8080/cas/actuator/metrics
  • http://localhost:8080/cas/actuator/prometheus

To allow these endpoints to properly collect and export CAS metrics, you would need to include the following modules in your CAS build:

implementation "org.apereo.cas:cas-server-support-reports"
implementation "org.apereo.cas:cas-server-support-metrics"

You may also need to enable the prometheus endpoint and have it export metrics data:

management.endpoint.prometheus.enabled=true
management.prometheus.metrics.export.enabled=true

Note that in addition to all the usual metric data collected by Spring Boot, CAS itself provides specific metrics that monitor and observe ticketing and service management operations by employing Micrometer Observations. For example, you may notice the following metrics when you access the prometheus endpoint:

# HELP org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds  
# TYPE org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds summary
org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds_active_count 0.0
org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds_duration_sum 0.0

# HELP org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds_max  
# TYPE org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds_max gauge
org_apereo_cas_ticket_registry_TicketRegistrySupport_getAuthenticationFrom_active_seconds_max 0.0

# HELP org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds_max  
# TYPE org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds_max gauge
org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds_max{error="none",} 0.003608625

# HELP org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds  
# TYPE org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds summary
org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds_count{error="none",} 3.0
org_apereo_cas_ticket_registry_TicketRegistryCleaner_clean_seconds_sum{error="none",} 0.006713916

Collecting Metrics via Prometheus

Prometheus is an open-source systems monitoring and alerting toolkit. It collects and stores its metrics as time series data, i.e. metrics information is stored with the timestamp at which it was recorded, alongside optional key-value pairs called labels. Metrics are numeric measurements. Time series means that changes are recorded over time.

You can run Prometheus as a Docker container. For example,

docker run --rm -d -p 9090:9090 --name "prom-server" \
  -v "/path/to/prometheus.yml":/etc/prometheus/prometheus.yml \
  prom/prometheus

The prometheus.yml should instruct Prometheus to pull metrics data from CAS:

scrape_configs:
  - job_name: 'Apereo CAS Metrics'
    metrics_path: '/cas/actuator/prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['CAS_SERVER_URL_GOES HERE']
        labels:
          application: 'Apereo CAS'

Once you have it up and running, you can access the Prometheus dashboard and query for metrics:

…or build graphs from CAS metrics data on ticketing operations:

…or you can examine Prometheus targets to see how often data is ingested and scraped from CAS:

Visualizing Metrics via Grafana

Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.

Just as before, you can run Grafana using Docker:

docker run --rm -d -p 3000:3000 --name "grafana-server" \
  -e GF_SECURITY_ADMIN_PASSWORD=admin \
  -e GF_SERVER_DOMAIN=localhost
  grafana/grafana-oss

Next, Prometheus needs to be configured in Grafana as a data source:

At this point, you should be able to explore the Prometheus data source and check out the collection of available metrics:

…and then, get your graphs added to the dashboard:

Need Help?

If you have questions about the contents and the topic of this blog post, or if you need additional guidance and support, feel free to send us a note and ask about consulting and support services.

So…

I hope this review was of some help to you and I am sure that both this post as well as the functionality it attempts to explain can be improved in any number of ways. Please feel free to engage and contribute as best as you can.

Happy Coding,

Misagh Moayyed