Friday, 10 November 2017

Java Application monitoring with Prometheus

This is third blog post in series of Monitoring with Prometheus. When it comes to monitoring we all want to monitor how much CPU ,Memory etc used by each process.Basically node exporter will export metrics for hardware and OS exposed by *NIX kernels.But with Text file exporter we can achieve application monitoring with some shell scripts.

Here’s just a sample shell script which collect CPU,Memory and STATUS of particular process and export these logs to prometheus server.The fancy name we can have for script is java_process_exporter.sh. Create Metrics directory and store all our metrics file in directory.


#!/bin/bash
echo "Custom exporter for process $1"
while true
do
echo "Get Process ID"
Prometheus_ID=`ps -ef|grep $1|grep -v 'grep'|grep -v 'process_exporter'|awk '{print $2}'`
Prometheus_MEMORY_Value=`top -b -n 1|grep $Prometheus_ID |awk '{print $10}'`
echo "Process Status"
Prometheus_STATUS=`ps -p $Prometheus_ID|echo $?`
Prometheus_CPU_Value=`top -b -n 5|grep $Prometheus_ID |awk '{print $9}'|sort|head -1`
Prometheus_CPU_Value=${Prometheus_CPU_Value%.*}
echo ""$Process_Name"_MEMORY_Usage "$Prometheus_MEMORY_Value"
"$Process_Name"_CPU_Usage "$Prometheus_CPU_Value"
"$Process_Name"_STATUS "$Prometheus_STATUS"" > Metrics/"$Process_Name"_Metrics.prom
sleep 10s
done


Suppose, you want to monitor java process then you can pass process name as parameter to this script.


Running script:
#my_custom_exporter.sh java


It will create file named java_Metrics.prom in Metrics directory .It will look something like:
java_MEMORY_Usage 12
java_CPU_Usage 35
java_STATUS 0


We need to restart our node_exporter and pass path of Metrics directory to it as textfile collector.


Restart node Exporter:
./node_exporter --collector.textfile.directory=Metrics

After this the node exporter will export all these files data to prometheus server.
Check metrics in your prometheus dashboard.


You can write your own exporter and have metrics in prometheus dashboard.Prometheus makes it easy for us to monitor application metrics .You can also setup alerts CPU usage of particular service running on server goes above threshold value.

11 comments:

  1. It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted "Oracle Training in Bangalore".

    ReplyDelete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete
  3. And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
    java-training in chennai

    ReplyDelete
  4. Yup, I got this right, I guess. To get this clear, I can barely call myself as an experienced backender, if speaking of java itslef, because I'm on my top of the learning beginning yet, so I'm clear for sure with the fundamentals only. At this moment it works out quite nice to me to get all the theory on Java by these web courses, where I'm able to get the clear answers on a little unclear quetsions, like what to choose with no programming background to begin with, java or javascript https://explainjava.com/java-vs-javascript/ Now it seems to me that I'm progressing pretty fast, so I think it's the time to start on more difficult stuff, like app monitoring here)

    ReplyDelete
  5. very interesting article. i can learn more about java. very purposeful datas. best java training in chennai

    ReplyDelete
  6. For any management professionals, some of the skills that are required include being able to manage personnel, organizational design and communication, and financial analysis and decision making. Gigabyte B360M DS3H review

    ReplyDelete
  7. Thank you for sharing your article. Great efforts put it to find the list of articles which is very useful to know, Definitely will share the same to other forums.

    appvn

    ReplyDelete
  8. I am not aware of the common mistakes that drive online shoppers away from the E-commerce website. The checklist you have shared in the site is very much informative and helps to avoid the mistakes in E-commerce development.
    Hire Web Developer
    Hire Magento Developer
    Hire Wordpress Developer
    Mobile App Development India
    Hire Opencart Developer

    ReplyDelete

Amazon EKS - Kubernetes on AWS

By Komal Devgaonkar Amazon Elastic Container Service for Kubernetes (Amazon EKS), which is highly available and scalable AWS service....