Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Sunday, 25 December 2022

How to Monitor Java application using prometheus?

 




Most Used Docker Commands:Interview Question

Pre-Requisite: 


What is Prometheus?


Prometheus is a free software application used for
 event monitoring and alerting. It records real-time metrics in a time series database (allowing for high dimensionality) built using a HTTP pull model, with flexible queries and real-time alerting.

Monitor Java Applications with Prometheus

This section will explain how an existing Java application can be updated to publish metrics and monitored by Prometheus.

Prometheus collects metrics from monitored targets by scraping metrics HTTP endpoints on these targets.

As discussed earlier, Prometheus collects metrics from monitored targets by scraping from an HTTP endpoint on these targets. By default, these metrics are expected to be published at /metrics. Any existing Java application can be updated to publish Prometheus-style metrics at this endpoint.

An earlier chapter explained a simple Java EE application that talks to a MySQL database. This application also publishes Prometheus-style metrics for the underlying JVM at /metrics. It also publishes application-specific metrics such as total number of times GET / and GET /{id} is called.

The complete set of JVM metrics are explained at https://github.com/prometheus/client_java. Refer to https://github.com/arun-gupta/docker-javaee/tree/master/employees/src/main/java/org/javaee/samples/employees/metrics for more details on how these metrics are enabled.

Start Java application

  1. Use the Compose file to deploy a simple the Java EE application. This will start WildFly Swarm application and MySQL database.

    docker stack deploy --compose-file=docker-compose.yml webapp

    This will create webapp_default overlay network, and start the webapp_web and webapp_db services.

  2. Verify the network:

    $ docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    u6ybdaqx5h5y        webapp_default      overlay             swarm

    Other networks may be shown here as well.

  3. Verify the services:

    $ docker service ls
    ID                  NAME                MODE                REPLICAS            IMAGE                            PORTS
    ucztcpf1vw0a        webapp_db           replicated          1/1                 mysql:8                          *:3306->3306/tcp
    jttfgvr09kre        webapp_web          replicated          1/1                 arungupta/docker-javaee:latest   *:8080->8080/tcp,*:9990->9990/tcp
  4. Verify that the endpoint is accessible:

    $ curl http://localhost:8080/resources/employees
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><collection><employee><id>1</id><name>Penny</name></employee><employee><id>2</id><name>Sheldon</name></employee><employee><id>3</id><name>Amy</name></employee><employee><id>4</id><name>Leonard</name></employee><employee><id>5</id><name>Bernadette</name></employee><employee><id>6</id><name>Raj</name></employee><employee><id>7</id><name>Howard</name></employee><employee><id>8</id><name>Priya</name></employee></collection>
  5. Access the metrics published by the endpoint using curl http://localhost:8080/metrics to see the output:

    # HELP jvm_info JVM version info
    # TYPE jvm_info gauge
    jvm_info{version="1.8.0_141-8u141-b15-1~deb9u1-b15",vendor="Oracle Corporation",} 1.0
    # HELP jvm_gc_collection_seconds Time spent in a given JVM garbage collector in seconds.
    # TYPE jvm_gc_collection_seconds summary
    jvm_gc_collection_seconds_count{gc="PS Scavenge",} 25.0
    jvm_gc_collection_seconds_sum{gc="PS Scavenge",} 0.386
    jvm_gc_collection_seconds_count{gc="PS MarkSweep",} 6.0
    jvm_gc_collection_seconds_sum{gc="PS MarkSweep",} 0.546
    # HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
    # TYPE process_cpu_seconds_total counter
    process_cpu_seconds_total 25.5
    # HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
    # TYPE process_start_time_seconds gauge
    process_start_time_seconds 1.508056592419E9
    # HELP process_open_fds Number of open file descriptors.
    # TYPE process_open_fds gauge
    process_open_fds 499.0
    # HELP process_max_fds Maximum number of open file descriptors.
    # TYPE process_max_fds gauge
    process_max_fds 1048576.0
    # HELP process_virtual_memory_bytes Virtual memory size in bytes.
    # TYPE process_virtual_memory_bytes gauge
    process_virtual_memory_bytes 4.244393984E9
    # HELP process_resident_memory_bytes Resident memory size in bytes.
    # TYPE process_resident_memory_bytes gauge
    process_resident_memory_bytes 5.06601472E8
    # HELP jvm_classes_loaded The number of classes that are currently loaded in the JVM
    # TYPE jvm_classes_loaded gauge
    jvm_classes_loaded 13096.0
    # HELP jvm_classes_loaded_total The total number of classes that have been loaded since the JVM has started execution
    # TYPE jvm_classes_loaded_total counter
    jvm_classes_loaded_total 13096.0
    # HELP jvm_classes_unloaded_total The total number of classes that have been unloaded since the JVM has started execution
    # TYPE jvm_classes_unloaded_total counter
    jvm_classes_unloaded_total 0.0
    # HELP jvm_threads_current Current thread count of a JVM
    # TYPE jvm_threads_current gauge
    jvm_threads_current 60.0
    # HELP jvm_threads_daemon Daemon thread count of a JVM
    # TYPE jvm_threads_daemon gauge
    jvm_threads_daemon 12.0
    # HELP jvm_threads_peak Peak thread count of a JVM
    # TYPE jvm_threads_peak gauge
    jvm_threads_peak 67.0
    # HELP jvm_threads_started_total Started thread count of a JVM
    # TYPE jvm_threads_started_total counter
    jvm_threads_started_total 93.0
    # HELP jvm_threads_deadlocked Cycles of JVM-threads that are in deadlock waiting to acquire object monitors or ownable synchronizers
    # TYPE jvm_threads_deadlocked gauge
    jvm_threads_deadlocked 0.0
    # HELP jvm_threads_deadlocked_monitor Cycles of JVM-threads that are in deadlock waiting to acquire object monitors
    # TYPE jvm_threads_deadlocked_monitor gauge
    jvm_threads_deadlocked_monitor 0.0
    # HELP jvm_memory_bytes_used Used bytes of a given JVM memory area.
    # TYPE jvm_memory_bytes_used gauge
    jvm_memory_bytes_used{area="heap",} 1.2072508E8
    jvm_memory_bytes_used{area="nonheap",} 9.3550048E7
    # HELP jvm_memory_bytes_committed Committed (bytes) of a given JVM memory area.
    # TYPE jvm_memory_bytes_committed gauge
    jvm_memory_bytes_committed{area="heap",} 2.69484032E8
    jvm_memory_bytes_committed{area="nonheap",} 1.0133504E8
    # HELP jvm_memory_bytes_max Max (bytes) of a given JVM memory area.
    # TYPE jvm_memory_bytes_max gauge
    jvm_memory_bytes_max{area="heap",} 4.66092032E8
    jvm_memory_bytes_max{area="nonheap",} -1.0
    # HELP jvm_memory_pool_bytes_used Used bytes of a given JVM memory pool.
    # TYPE jvm_memory_pool_bytes_used gauge
    jvm_memory_pool_bytes_used{pool="Code Cache",} 1.4589888E7
    jvm_memory_pool_bytes_used{pool="Metaspace",} 6.9998048E7
    jvm_memory_pool_bytes_used{pool="Compressed Class Space",} 8962112.0
    jvm_memory_pool_bytes_used{pool="PS Eden Space",} 2.3732032E7
    jvm_memory_pool_bytes_used{pool="PS Survivor Space",} 6073592.0
    jvm_memory_pool_bytes_used{pool="PS Old Gen",} 9.0919456E7
    # HELP jvm_memory_pool_bytes_committed Committed bytes of a given JVM memory pool.
    # TYPE jvm_memory_pool_bytes_committed gauge
    jvm_memory_pool_bytes_committed{pool="Code Cache",} 1.47456E7
    jvm_memory_pool_bytes_committed{pool="Metaspace",} 7.5800576E7
    jvm_memory_pool_bytes_committed{pool="Compressed Class Space",} 1.0788864E7
    jvm_memory_pool_bytes_committed{pool="PS Eden Space",} 9.2274688E7
    jvm_memory_pool_bytes_committed{pool="PS Survivor Space",} 3.8797312E7
    jvm_memory_pool_bytes_committed{pool="PS Old Gen",} 1.38412032E8
    # HELP jvm_memory_pool_bytes_max Max bytes of a given JVM memory pool.
    # TYPE jvm_memory_pool_bytes_max gauge
    jvm_memory_pool_bytes_max{pool="Code Cache",} 2.5165824E8
    jvm_memory_pool_bytes_max{pool="Metaspace",} -1.0
    jvm_memory_pool_bytes_max{pool="Compressed Class Space",} 1.073741824E9
    jvm_memory_pool_bytes_max{pool="PS Eden Space",} 9.699328E7
    jvm_memory_pool_bytes_max{pool="PS Survivor Space",} 3.8797312E7
    jvm_memory_pool_bytes_max{pool="PS Old Gen",} 3.49700096E8

    It shows all the JVM metrics that are published by the Prometheus JVM Client. The metrics generated by the application are not shown yet. It requires for the application to be accessed first.

Let’s access the JVM metrics in Prometheus dashboard first, and then we’ll access the app to show app-specific metrics.

Start Prometheus service

  1. Make sure to terminate any previously running Prometheus endpoints:

    docker service rm metrics
  2. Create a directory prometheus and change into that directory.

  3. Create a text file prometheus.yml and add the following content:

    global:
      scrape_interval: 10s
    scrape_configs:
      - job_name: 'webapp'
        dns_sd_configs:
          - names: ['tasks.webapp_web']
            type: 'A'
            port: 8080

    This defines the configuration for the HTTP endpoint that publishes Prometheus-style metrics from the Java application.

  4. Start Prometheus service:

    docker service create \
      --replicas 1 \
      --network webapp_default \
      --name metrics \
      --mount type=bind,source=`pwd`/prometheus.yml,destination=/etc/prometheus/prometheus.yml \
      --publish 9090:9090 \
      prom/prometheus

    Note, this service is using the webapp_default overlay network that is created when the application stack was deployed.

  5. Access Prometheus dashboard at http://localhost:9090

  6. Check the configured targets at http://localhost:9090/targets:

    prometheus metrics target4

    It shows that the application metrics HTTP endpoint is configured as a Prometheus target.

View application metrics

  1. On Prometheus dashboard, click on -insert metric at cursor- to see the list of metrics available:

    prometheus metrics12

    JVM metrics shown earlier are displayed here as well.

  2. Select jvm_memory_pool_bytes_used metric and click on Execute to view the metric.

    prometheus metrics13
  3. Select Graph to view the graphical representation

    prometheus metrics14
  4. Now access the application using curl http://localhost:8080/resources/employees a few times.

  5. Refresh Prometheus dashboard and see the updated list of metrics:

    prometheus metrics15

    Note, app* and requests* that are generated by the application.

  6. Select requests_get_all metric and view the graph:

    prometheus metrics16
  7. Access the application a few times using curl http://localhost:8080/resources/employees/5 and then watch the requests_get_one metric.

****************************************

TOP 15 BDD - CUCUMBER Interview Q&A


************************************************

✍️AUTHOR: LinkedIn Profile

************************************************

Learn (API-Microservice)Testing+ Selenium UI Automation-SDET with Self Paced Videos prepared by FAANG employees and LIVE Doubt Session 

SDET TRANING VIDEOS AVAILABLE with Live Doubt Session(course-1 below,API TRaining Videos With Class Notes and Coding Set) and (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122. 
This includes classnotes, 300+ interview questions, 3 projects, Java Coding question set for product companies along with career guidance from FAANG employees for Automation and SDET.

For more details whatsapp : https://lnkd.in/dnBWDM33

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

https://automationreinvented.blogspot.com/search/label/SeleniumWebdriver

API Testing Interview Question Set:

https://automationreinvented.blogspot.com/2022/03/top-80-api-testing-interview-questions.html

DevOps Interview Q&A:

https://automationreinvented.blogspot.com/2021/11/top-11-devops-interview-questions-and.html 

Kubernetes Interview Question Set

https://automationreinvented.blogspot.com/search/label/Kubernetes

Docker Interview Question Set

https://automationreinvented.blogspot.com/Docker

Linux Interview question Set

https://automationreinvented.blogspot.com/search/label/Linux

Automation Testing/SDET Framework Design

https://automationreinvented.blogspot.com/search/label/FrameworkDesign

Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java

GIT Interview Question Set:

https://automationreinvented.blogspot.com/2021/09/top-40-git-interview-questions-and.html

Coding Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Coding%20Questions

Mobile Testing Interview Question Set:

https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

Python Interview Question Set for QAE - SDET - SDE:

https://automationreinvented.blogspot.com/search/label/Python


Friday, 19 August 2022

How to do Docker Tooling in Intellij Idea

 



Most Used Docker Commands:Interview Question


Pre-Requisite: 




Docker and IntelliJ IDEA

This chapter will show you basic Docker tooling with IntelliJ IDEA:

  • Pull Docker images

  • Run, stop, or delete a Container

  • Build an Image

Install Docker Plugin in IDEA

Go to “Preferences”, “Plugins”, “Install JetBrains plugin…​”, search on “docker” and click on “Install”

docker intellij plugin install


Restart IntelliJ IDEA to active plugin.

Click on “Create New Project”, select “Java”, “Web Application”

docker intellij create java project


Click on “Next”, give the project a name “dockercon”, click on “Finish”. This will open up the project in IntelliJ window.

Go to “Preferences”, “Clouds”, add a new deployment by clicking on “+”. Click on “Import credentials from Docker Machine”, “Detect”, and see a successful connection. You may need to check the IP address of your Docker Machine. Find the IP address of your Docker Machine as docker-machine ip <machine-name> and specify the correct IP address here.

docker intellij cloud connection


Go to “View”, “Tool Windows”, “Docker Tooling Window”. Click on “Connect”" to connect with Docker Machine. Make sure Docker Machine is running.

Warning
IDEA does not work with “Docker for Mac” at this time. (ADD BUG #)

docker intellij tool window

************************


******************************


Pull an Image

Select top-level node with the name “Docker”, click on “Pull image”

docker intellij pull image

Type an image name, such as arungupta/couchbase, and “OK”

docker intellij repository name

Expand “Containers” and “Images” to see existing running containers and images.

The specified image is now downloaded and shown as well.

Run a Container

Select the downloaded image, click on “Create container”

Select “After launch” and enter the URL as http://192.168.99.100:8091. Make sure to match the IP address of your Docker Machine.

docker intellij deployment after launch

In “Container” tab, add “Port bindings” for 8091:8091

docker intellij container ports

Click on “Run” to run the container.

This will bring up the browser window and display the page http://192.168.99.100:8091 and looks like:

docker intellij run container browser

This image uses Couchbase REST API to configure the Couchbase server.

Right-click on the running container, select “Inspect” to see more details about the container.

docker intellij container inspect

Click on “Stop container” to stop the container and “Delete container” to delete the container.

Build an Image

  1. Refer to the instructions https://www.jetbrains.com/help/idea/2016.1/docker.html

  2. Right-click on the project, create a new directory docker-dir

  3. Artifact

    1. Click on top-right for “Project Structure”

    2. select “Artifacts”

    3. change “Type:” to “Web Application: Archive”

    4. change the name to dockercon

    5. change Output directory to docker-dir

  4. Create “Dockerfile” in this directory. Use the contents

    FROM jboss/wildfly
    
    ADD dockercon.war /opt/jboss/wildfly/standalone/deployments/
  5. “Run”, “Edit Configurations”, add new “Docker Deployment”

    1. “Deployment” tab

      1. Change the name to dockercon

      2. Select “After launch”, change the URL to “http://192.168.99.100:18080/dockercon/index.jsp”;

      3. In “Before launch”, add “Build Artifacts” and select the artifact

    2. “Container” tab

      1. Add “Port bindings” for “8080:18080”

  6. View, Tool Windows, Docker, connect to it

  7. Run the project


Special credit to arun gupta*

Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122
Entire course content can be found below:  COURSE CONTENT


  • Interview questions for SDET/Automation Testing:
  • Top 21 GIT interview questions
  • Top 30 Selenium Webdriver Interview Q&A 
  • Top 20 API Testing Interview Q&ASelenium Interview Question SET-4 
  • Selenium Interview Question SET-1
  • Selenium Interview Question SET-2
  • Selenium Interview Questions SET-3
  • Selenium Interview Question SET-4

      
  •        Check GIT commands for Interview preparation SET-1:

    GIT Interview Question 1 to 11

    Check GIT commands for Interview preparation SET-2:

    GIT Interview Question 12 to 21

    Check GIT commands for Interview preparation SET-3:

    GIT Interview Question 21 to 30

    Check below link for question and answers with code:

    Top API Interview Question 1-10

    *************************************************

    SeleniumWebdriver Automation Testing Interview Questions:

    API Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Rest-API

     
    Kubernetes Interview Question Set
    https://automationreinvented.blogspot.com/search/label/Kubernetes

     
    Docker Interview Question Set
    https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

     
    Linux Interview question Set
    https://automationreinvented.blogspot.com/search/label/Linux

     
    Automation Testing/SDET Framework Design
    https://automationreinvented.blogspot.com/search/label/FrameworkDesign


    Java Related Interview Question Set

    https://automationreinvented.blogspot.com/search/label/Java


    GIT Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/GIT


    Coding Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Coding%20Questions
    Mobile Testing Interview Question Set:
    https://automationreinvented.blogspot.com/search/label/Mobile%20Testing

    Python Interview Question Set for QAE - SDET - SDE:
    https://automationreinvented.blogspot.com/search/label/Python

    All Time Popular Posts

    Most Featured Post

    𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀?

    ❓ 𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀? The issue isn’t your logic—it’s the lack of pattern recogniti...