Showing posts with label Liferay JMX Metrics. Show all posts
Showing posts with label Liferay JMX Metrics. Show all posts

Monday, July 26, 2021

Liferay Portal Monitoring with Prometheus and Grafana

Grafana is popular open-source solution for monitoring applications. It will provide graphical dashboards to build monitoring visualization.

 


Any graphical view required data or metrics, so metrics data will be provided by Prometheus.

 


Prometheus is another monitoring tools to pull data from different application with help of JMX Exporter Agent.

 


Grafana is ability to connect Prometheus to pull metrics data and it will be represented as graphical view. We can build nice dashboards to show metrics data in different graphical view in the Grafana web UI.







Prerequisite



Setup a Liferay Cluster



http://www.liferaysavvy.com/2021/07/liferay-portal-apache-webserver.html

 




Following are steps to Demonstrate Liferay Cluster Monitoring.

 


  • Setup Prometheus for Liferay Cluster
  • Install Grafana
  • Configure Prometheus Data source in Grafana
  • Create Liferay Cluster Dashboard

 



Setup Prometheus for Liferay Cluster



Follow the below article to setup Prometheus for Liferay cluster.



http://www.liferaysavvy.com/2021/07/liferay-portal-monitoring-with.html

 


After configured JMX Exporter for Liferay Portal, Start all servers in the cluster.

 




Install Grafana

 


Follow the below article to install Grafana on windows.

 

http://www.liferaysavvy.com/2021/07/grafana-installation-on-windows.html

 




Configure Prometheus Data source in Grafana



Now it’s time to configure Prometheus Data source in Grafana. Prometheus already have metrics data which is pulled from Liferay portal server with help of JMX exporter Java agent. That is already covered in the previous step.

 


Access Grafana Web UI with following URL

 


 

 

http://localhost:3000/

 

 

 


Home page click on Setting and Under Configuration click on “Data sources

 




 

Click on Add Data source.

 





 

Select Prometheus Data source in the List.

 





 

Provide Prometheus URL where its running. Default port is 9090. Once provided required information click on Test &Save.  Grafana successfully connected to Prometheus data source.

 


 

http://localhost:9090/

 

 




 





Create Liferay Cluster Dashboard



Grafana home page click on Dashboard icon and Click on Manage

 




 

There are free available Grafana dashboards for Tomcat. Creating Grafana dashboard is very easy and it’s just need to import Dashboard JSON file.

 


Go to following URL and get Grafana Tomcat dashboard file to local.

 

https://github.com/LiferaySavvy/liferay-monitoring-prometheus/blob/master/tomcat-dashboard_rev10.json

 

 

OR

 

https://grafana.com/api/dashboards/8704/revisions/10/download

 


Import “tomcat-dashboard_rev10.json” file into Grafana dashboard.

 


Click on import button.

 




 


Click on Upload JSON file button and Select “tomcat-dashboard_rev10.json” file from local drive.





 

Once selected file, click on import then Dashboard will be imported into Grafana.

 




 

 



 

 


Go to Dashboards in the Grafana home page and select Tomcat Dashboard.

 




 

We Can see Dashboard with many panels and all metrics will be represented as Graphs.

 


Dashboard Screen: 1

 




 

 


We can edit Dashboard based on metrics provided by Prometheus or JMX Exporter.

 


We can see all Metrics with following JMX URL’s and these metrics attribute keys are matching in Grafana Dashboard JSON file. This is how Grafana build dashboards based on JMX Metrics.

 


 

 

http://localhost:7171/metrics

 

http://localhost:7272/metrics

 

 

 




Author

 

Sunday, July 25, 2021

Liferay Portal Monitoring with Prometheus

Prometheus is popular opensource monitoring tool. It can monitor applications with help of JMX Exporter Java agent.


This Article demonstrate the Liferay Portal Server Monitoring with Prometheus.



Prerequisite


Install Liferay Cluster

 


http://www.liferaysavvy.com/2021/07/liferay-portal-apache-webserver.html

 



  • Download JMX Exporter
  • Configure JMX Exporter for Liferay Portal Servers
  • Start Liferay Portal with JMX Exporter Agent
  • Install Prometheus
  • Configure Prometheus scrape for Liferay Portal Servers
  • Verify Liferay Cluster in Prometheus

 


 

Download JMX Exporter



Download JMX Exporter jar file from following location.


https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.16.1/



Direct link for latest JMX Exporter JAR


https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.16.1/jmx_prometheus_javaagent-0.16.1.jar

 

OR


https://github.com/LiferaySavvy/liferay-monitoring-prometheus/raw/master/jmx_prometheus_javaagent-0.16.1.jar


 

Download and get the jar to local directory.

 




 



Configure JMX Exporter for Liferay Portal Server



We need to configure the exporter configuration for Liferay Portal Server such a way JMX agent exports the required metrics from Liferay Portal Server.


Get the following JMX Exporter configuration file from below location and place it in local drive.



https://github.com/prometheus/jmx_exporter/blob/master/example_configs/tomcat.yml

 

OR


https://github.com/LiferaySavvy/liferay-monitoring-prometheus/blob/master/tomcat.yml

 


We can use below one too.



 

 

lowercaseOutputLabelNames: true

lowercaseOutputName: true

rules:

- pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+):'

  name: tomcat_$3_total

  labels:

    port: "$2"

    protocol: "$1"

  help: Tomcat global $3

  type: COUNTER

- pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount):'

  name: tomcat_servlet_$3_total

  labels:

    module: "$1"

    servlet: "$2"

  help: Tomcat servlet $3 total

  type: COUNTER

- pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount):'

  name: tomcat_threadpool_$3

  labels:

    port: "$2"

    protocol: "$1"

  help: Tomcat threadpool $3

  type: GAUGE

- pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions):'

  name: tomcat_session_$3_total

  labels:

    context: "$2"

    host: "$1"

  help: Tomcat session $3 total

  type: COUNTER

 

 




 



Start Liferay Portal with JMX Exporter Agent



It’s required to start JMX Exporter agent with Liferay Portal. Set JMX Exporter java agent in JAVA_OPTS in setenv.bat file of Liferay Portal.


JAVA agent syntax


 

-javaagent:C:/kafka-workspace/kafka-monitoring/jmx_prometheus_javaagent-0.15.0.jar=<port>:<exporter-config-file-path>

 



Set JAVA_OPTS in Liferay setenv.bat file. Locate to tomcat bin directory and update setenv.bat file with following JAVA_OPTS. This need to be update in All Liferay Portal Servers in the cluster.


 

Liferay Portal Node1


https://github.com/LiferaySavvy/liferay-monitoring-prometheus/blob/master/setenv-node1.bat

 


 

set "JAVA_OPTS=%JAVA_OPTS% -javaagent:C:/kafka-workspace/kafka-monitoring/jmx_prometheus_javaagent-0.16.1.jar=7171:C:/kafka-workspace/kafka-monitoring/tomcat.yml"

 

 

 



 

Liferay Portal Node2



https://github.com/LiferaySavvy/liferay-monitoring-prometheus/blob/master/setenv-node2.bat

 

 

 

set "JAVA_OPTS=%JAVA_OPTS% -javaagent:C:/kafka-workspace/kafka-monitoring/jmx_prometheus_javaagent-0.16.1.jar=7272:C:/kafka-workspace/kafka-monitoring/tomcat.yml"

 

 






Start Liferay Node1



Open command prompt and locate Liferay Portal Tomcat bin directory and use following commands.



 

cd C:\Liferay\Liferay74\liferay-ce-portal-7.4.1-ga2-node1\tomcat-9.0.43\bin

startup.bat

 

 






Start Liferay Node2


Open command prompt and locate Liferay Portal Tomcat bin directory and use following commands.

 


 

cd C:\Liferay\Liferay74\liferay-ce-portal-7.4.1-ga2-node2\tomcat-9.0.43\bin

startup.bat

 

 

 





Now Liferay Portal servers started with JMX Exporter agent.


 

Make sure all JMX Exporter are started successfully and we can access metrics with following URL’s. We are running all java agents in same machine, its required to change ports accordingly.

 


 

 http://localhost:7171/metrics

 

http://localhost:7272/metrics

 

 




 


Install Prometheus

 


Follow the below URL and Install Prometheus.


http://www.liferaysavvy.com/2021/07/prometheus-installation-on-windows.html

 



Configure Prometheus scrape for Liferay Portal Servers

 


Locate to Prometheus directory and update “prometheus.yml” file with following Liferay Portal Server scrape.

 

Find the file from following location


https://github.com/LiferaySavvy/liferay-monitoring-prometheus/blob/master/prometheus.yml

 

 


  

- job_name: 'liferay'

    static_configs:

    - targets: ['localhost:7171','localhost:7272']

      labels:

          env: "liferay-dev"

 

Targets should be JMX Exporter java agent host:port.

 



Complete “prometheus.yml” file

 



# my global config

global:

  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

  # scrape_timeout is set to the global default (10s).

 

# Alertmanager configuration

alerting:

  alertmanagers:

  - static_configs:

    - targets:

      # - alertmanager:9093

 

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.

rule_files:

  # - "first_rules.yml"

  # - "second_rules.yml"

 

# A scrape configuration containing exactly one endpoint to scrape:

# Here it's Prometheus itself.

scrape_configs:

  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.

  - job_name: 'prometheus'

 

    # metrics_path defaults to '/metrics'

    # scheme defaults to 'http'.

 

    static_configs:

    - targets: ['localhost:9090']

   

  - job_name: 'liferay'

    static_configs:

    - targets: ['localhost:7171','localhost:7272']

      labels:

          env: "liferay-dev"

         

                    

         

 

Start “Prometheus”



Open command prompt and locate to “Prometheus” root directory. Use the following start command and pass web listen address and config file as options.



 

prometheus.exe --config.file prometheus.yml --web.listen-address ":9090" --storage.tsdb.path "data"

 

 

 



Verify Liferay Cluster in Prometheus



Access “Prometheus” web interface with following URL and its running on 9090 port.

 


 

http://localhost:9090/

 

 

 



Targets Status



Go to Status menu and click on targets so we can see Liferay cluster health for each Node.





 

We can see Liferay Portal Cluster health in the Prometheus.

 


 

http://localhost:9090/targets

 

 

 

 

 





Author

 

 

 

 

Recent Posts

Recent Posts Widget

Popular Posts