Showing posts with label Azure VM. Show all posts
Showing posts with label Azure VM. Show all posts

Tuesday, July 20, 2021

Azure Application Insights - APM integration with Java Applications

Azure Application Insights - APM integration with Java Applications

The focus of this article is to detail about integration of Java based application monitoring into Application Insights.

The following is the Agenda :

1) Brief Introduction about Azure Application Insights

2) Setup a sample Java Application on WildFly server running on Azure Virtual machine

3) Publish the Application and allow it to be accessible from LAN (VNET) and Internet

4) Provisioning of Azure Application Insights

5) Integration of sample java application with Application Insights

6) Application Insights monitoring dashboards

If you are specifically looking for the integration of Java application with Application sights, skip the sections and have a look into Step : 5) Integration of sample java application with Application Insights


Application Insights

Application insight is a Microsoft Azure native APM monitoring tool which helps the developers and DevOps professionals to understand about the application performance and how it is being used.

Image Reference : Microsoft Official documentation


Application Insights is billed based on the volume of telemetry data that your application sends and the number of web tests that you choose to run, The telemetry data is billed per Azure Log Analytics data ingestion rates.



https://docs.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview


2 & 3) Setup a sample Java Application on WildFly server running on Azure Virtual machine

Here i’m going to host a sample java application on wildfly 20.4 installed on windows server 2019 azure virtual machine.


Step 1: Installing Azure windows virtual machine


Reference : https://docs.microsoft.com/en-us/learn/modules/create-windows-virtual-machine-in-azure/3-exercise-create-a-vm 


Step 2: Install and configure Java & wildfly server


Reference: https://darrenoneill.eu/?p=594 


For the testing purpose you could run the wildfly server from binary instead of installing it as a service.


I’ve copied the wildfly server directory into C:\ 


By default wildfly server listen on port 8080 for web service and 9990 for management console

http://localhost:8080

http://localhost:9990 


Create a user account to login to Wildfly management console.


Navigate to C:\wildfly-24.0.0.Final\bin\ and run add-user.bat or add-user.ps1 (for windows OS)




Hit enter and input the password while prompt in the interactive cmd window


Open a browser tab and access wildfly management console http://localhost:9990 


Step 3: Host a Sample Java application


Download the Sample Web App war file from the link below Link.


Reference: https://github.com/AKSarav/SampleWebApp/raw/master/dist/SampleWebApp.war 


Open a browser tab and access wildfly management console http://localhost:9990 


Navigate to “Deployments” and drag & drop the Sample Web App war file into the right side pane which deploys the application in wildfly.


Open a new tab in the browser and try to access the webapp http://localhost:8080/SampleWebApp 



Step 4: Allow the WebApp to be accessible from LAN and internet.

Navigate to WildFly server root directory C:\wildfly-24.0.0.Final\standalone\configuration and open standalone.xml


Amend the following in standalone.xml


    <interfaces>

        <interface name="management">

            <inet-address value="${jboss.bind.address.management:0.0.0.0}"/>

        </interface>

        <interface name="public">

            <inet-address value="${jboss.bind.address:0.0.0.0}"/>

        </interface>

    </interfaces>



Restart the WildFly server by closing and re-ran standalone.bat file under C:\wildfly-24.0.0.Final\bin



Now you will be able to access the webapp using the network  interface IP address of your virtual machine.




Step 5: To Allow your webapp to be accessible from Internet

SInce it is a lab I'm exposing the virtual machine directly to the internet which is not at all recommended on any cloud hosted environments.

Application gateway, Proxy, Firewall, load balancer or any other flavor of load balancers can be added  in front of your virtual machine based on your wish to secure the traffic

Whitelist port 8080 on windows firewall (check IP tables if you’ve choose Linux)


Open a  powershell window and input the below command


New-NetFirewallRule -DisplayName "ALLOW TCP PORT 8080" -Direction inbound -Profile Any -Action Allow -LocalPort 8080 -Protocol TCP


Open port 8080 on Azure network security group attached to virtual machine on subnet.


Get the public IP address associated with the virtual machine and access it from your local computer to make sure it is accessible.



Now your infrastructure and application is ready to explore Application insights.


4) Provisioning of Azure Application Insights


Login to your Azure subscription and on the search bar type “Application Insights” then click on the create button.


Here I’m going to create a classic Application Insights which is going to be deprecated in the near future, you could try out the one which is work-space based (ie use Log Analytics work space).




Fill up the basic details and click on review and create.




5) Integration of sample java application with Application Insights

Configure Application Insights JavaAgent on WebServer


The Agent configuration can be done in 2 ways: inserting a piece of code into your application code but it is now old school.


So we will be using JavaAgent (Agent based monitoring which captures heath, state and performance of the application from inside of it).


Login to the virtual machine, create a directory for AppInsight under any volume, download and copy the agent into it.


Download JavaAgent provided by Microsoft from the below link


https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.1.1/applicationinsights-agent-3.1.1.jar 



Create  a new file with name and extension applicationinsights.json 


  • Strictly follow the naming convention (applicationinsights) and file extension (json)

  • The file must be placed in the directory/folder on which the applicationinsights-agent-3.1.1.jar file is copied.



Login to Azure portal → Application Insights → Your application insights → Overview → copy the connection string.



Login back to the virtual machine -> Navigate to the file applicationinsights.json and open it in a notepad or notepad ++ → copy eth connection string as shown below and save the file


Navigate to “”C:\wildfly-24.0.0.Final\bin” and open “”standalone.conf.bat” file.


Input the following parameters into the file.


set "JAVA_OPTS=-javaagent:C:\wildfly-24.0.0.Final\AppInsight\applicationinsights-agent-3.1.1.jar -Xms768m -Xmx6144m -XX:MetaspaceSize=1152M -XX:MaxMetaspaceSize=3072m"


what if you choose Springboot, Tomcat, jetty or websphere for hosting your application ?

Refer the below article for the java-standalone-arguments


https://docs.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-arguments



Restart the WildFly server by closing and re-ran standalone.bat file under C:\wildfly-24.0.0.Final\bin


When the wildfly server boots up you will be able to find the below in the cmd.



It means your configuration is loaded as expected and soon it will start sending application telemetries to the Application Insights.


Navigate back to the AppInsight directory and you could see a log file “applicationinsights.log”

 


Repeat above steps on all other virtual machines hosted with same application parse the logs and telemetry to Application Insights


6) Application Insights monitoring dashboards


The focus of this write up is to help developers or DevOps/Cloud engineers to integrate java based applications into Azure application Insights APM.


Few screenshots from Application Insights to understand about the basic capabilities of the Azure services offering.


Overview of your Application performance



Application map (display various components and integration in the App)




Live Metrics from your App




Availability of the Application from different geographic regions.


You could create a classic or standard rule to measure the availability of the application.




Failures within the Application



Drill down reports for each case.



Performance of the Application



Number of Active session to the Application



A report on usage cost



Thanks for reading and Hope it helps.


Reference :


https://docs.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview


https://docs.microsoft.com/en-us/learn/modules/create-windows-virtual-machine-in-azure/3-exercise-create-a-vm


https://darrenoneill.eu/?p=594


https://github.com/AKSarav/SampleWebApp/raw/master/dist/SampleWebApp.war


https://docs.microsoft.com/en-us/azure/azure-monitor/app/java-standalone-arguments

Sunday, February 21, 2021

Azure Managed Shared Disk

 Managed Share Disk in Azure

Azure shared disks is a new feature for Azure managed disks that allows you to attach a managed disk to multiple virtual machines (VMs) simultaneously. Attaching a managed disk to multiple VMs allows you to either deploy new or migrate existing clustered applications to Azure

Absence of shared disks was one of the limitation in Azure for those who wish to migrate their clustered compute resources into Azure. Ex: SQL Always on availability group with failover cluster.

The alternative option was create Azure Files and mount it into multiple virtual machines which provides a "shared file system" for the applications however it is suitable for the clustered environment.

Thanks to Azure team for bringing this new feature which will be helpful for those who wish to lift and shift the clustered environments into Azure compute.

The concept of Azure shared disk is similar to accessing storage blocks/volume via ISCSI as a LUN created in the SAN storage. SCSI PR(Persistent reservation) is an industry standard leveraged by applications running on Storage Area Network (SAN) on-premises.

Azure shared disk is now generally available in all regions however with some limitations; hopefully these limitations will be overcome in near future.

I will take you through step by step install and configure of Azure disk in brief, here we go.

Azure Shared Disk


Create a shared disk

Login to the Azure portal --> Type search in the Disks --> Click on Add Disk























Input the disk name and relevant information --> Change disk size

































Only Premium SSD and Ultra SSD disks from 256 GB size supports disk sharing, choose the appropraite disk based on the requirement. Here i'm going to select 256 GB disk which is having share capacity of 2 ie, can be added into virtual machine, suitable for 2 node clusters.















I'm leaving all other settings to default.





































On Advanced tab click on "Enable Shared disk" yes check box and select the number of shares, here the maximum is 2 so keeping the default value. If you have choose a shared disk with 5 shares; max shares can be opt from this window.
































Validate and create the shared disk




























































Create 2 Virtual Machines

Create 2 virtual machines based on your flavour to test the shared disk attachment, here I've created 2 windows server 2016 VM's to build 2 node windows failover cluster.

Virtual Machine 1 - fsclusternode01
Virtual Machine 2 - fsclusternode02

Attach Shared Disk

Shared disk cannot be attached to the 2 virtual machines when it is turned on, so stop the virtual machines before attaching the shared disk.





 






























Navigate to virtual machines --> Disks --> click on "attach existing disks" from under Data disks menu


























Select the shared disk which we have created from the drop down menu and change the host cache to read/write, then  save .



















Perform the same on the 2nd virtual machine "fsclusternode02"






















Start the virtual machines one by one; note that better avoid starting both virtual machines at same time instead start it one by one.




















LLogin to each virtual machine and verify that the shared disk is attached successfully, open disk management (run --> diskmgmt.msc) to verify the disk status.
































Install and configure windows failover cluster on VM's

Install windows server failover cluster feature into the virtual machines.

Once the feature is ready open failover cluster manager and create a cluster without adding disks

Refer the article below if you are not familiar with WSFC.























Go back to the disk management and initialise the shared disk and bring it online, then create a new simple volume.





















Volume creation is need to be performed only on one of the virtual machine/node in the cluster.

Add the disk into failover cluster 

Open failover cluster manager on the node where the volume is created --> failover cluster name --> storage --> disks --. add disk --> select the shared disk from the list.






Now login to the 2nd virtual machine/node --> open failover cluster manager --> cluster name --> storage --> disks

You could see the shared volume is added into the cluster disks




























In-order to use the disk as a shared one, convert it into cluster shared volume (CSVFS)

On failover cluster manager window --> storage --> disks --> Add to cluster shared volume from the right side menu pane




























Now the attached disk is added into failover cluster and converted into cluster volume. it is ready to use.

To test the shared volume, login to the 1st virtual machine "fsclusternode01"  --> open file explorer --> navigate to C:\Windows\ClusterStorage\volume1 and create a folder and file






















Now login to the another node/VM and check the same folder & file exists under  C:\Windows\ClusterStorage\volume1.






















If You check the properties of shared disk from Disks --> your shared disk name --> overview






















I've also tried to create snapshot of shared disk and created a new disk from it, so the shared disk in  can be administer in the same way as normal managed disk in azure with a additional feature of sharing.




Size and performance of the shared disk can be expanded but you need to stop the virtual machine before making the change.




















Supported use cases of Azure shared disk

Some popular applications running on WSFC include:

Linux

Azure shared disks are supported on:

If you would like to explore more feel free to have a look into the below Microsoft documentation.

https://docs.microsoft.com/en-us/azure/virtual-machines/disks-shared

Thanks for reading and hope this helps.

Happy to help 😊 if you have any queries, feel free to put your queries into the comment box