<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Uzosike Lynda</title>
    <description>The latest articles on DEV Community by Uzosike Lynda (@lynn).</description>
    <link>https://dev.to/lynn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F224910%2Fe4bf8938-19ce-4d0c-a840-1b4549dc7e0e.jpeg</url>
      <title>DEV Community: Uzosike Lynda</title>
      <link>https://dev.to/lynn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/lynn"/>
    <language>en</language>
    <item>
      <title>MONITORING AN API WITH PROMETHEUS AND GRAFANA USING SPRING BOOT ACTUATOR</title>
      <dc:creator>Uzosike Lynda</dc:creator>
      <pubDate>Wed, 11 Sep 2019 16:07:22 +0000</pubDate>
      <link>https://dev.to/lynn/monitoring-an-api-with-prometheus-and-grafana-using-spring-boot-actuator-46hi</link>
      <guid>https://dev.to/lynn/monitoring-an-api-with-prometheus-and-grafana-using-spring-boot-actuator-46hi</guid>
      <description>&lt;p&gt;&lt;strong&gt;This&lt;/strong&gt; tutorial provides a complete guide on how to monitor an API on your local system using a visualizing tool Grafana.&lt;/p&gt;

&lt;p&gt;We will be integrating Spring Boot Actuator into Prometheus then, visualizing and monitoring on Grafana&lt;/p&gt;

&lt;p&gt;Spring Boot Actuator generates metrics for our API which prometheus queries and binds to grafana where it is visualized and monitored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SPRING BOOT ACTUATOR&lt;/strong&gt; provides production-ready features such as metrics gathering, HTTP tracing etc.these features can be accessed over JMX or HTTP endpoints and can be integrated with external application monitoring systems like Prometheus, Graphite etc. &lt;a href="https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html" rel="noopener noreferrer"&gt;read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Integrating Spring Boot actuator into our application.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The prometheus endpoint is exposed by Spring Boot when micrometer-registry-prometheus dependency is available on the classpath.&lt;/p&gt;

&lt;p&gt;Check out how to integrate Spring boot Actuator into your Application &lt;a href="https://www.tutorialspoint.com/spring_boot/spring_boot_actuator.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have integrated spring boot actuator to a simple Api i created on my local system.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can get the the application we used for the Prometheus setup from this &lt;a href="https://github.com/Lyndaar/Grafana-Monitoring" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Run your application on your Local IDE.&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Then configure Prometheus to query the application and get results.&lt;/p&gt;

&lt;p&gt;The prometheus endpoint exposes metrics data in a format that can be scraped by a Prometheus server. You can see the exposed metrics data by navigating to the prometheus endpoint (&lt;a href="http://localhost:8080/actuator/prometheus" rel="noopener noreferrer"&gt;http://localhost:8080/actuator/prometheus&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PROMETHEUS&lt;/strong&gt; is a time-series database and an open source monitoring system.&lt;a href="https://prometheus.io/" rel="noopener noreferrer"&gt;read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download and configure Prometheus&lt;/strong&gt;  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt;First download &lt;a href="https://prometheus.io/download/" rel="noopener noreferrer"&gt;Prometheus&lt;/a&gt;&lt;br&gt;
  &lt;strong&gt;-&lt;/strong&gt;Extract to your selected directory&lt;br&gt;
  &lt;strong&gt;-&lt;/strong&gt;To configure your application to be monitored, In the prometheus folder, &lt;br&gt;
       you can either use the sample prometheus.yml file or create new .yml &lt;br&gt;
       files. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   *Below is the configuration of a new file i have created*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz9343huujdrlv8971xhi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fz9343huujdrlv8971xhi.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-Run prometheus server using the command prometheus.exe --config.file=YAML_FILE_PATH.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;example&lt;/strong&gt;: C:\Users\user\Desktop\prometheus-2.12.0.windowsamd64&amp;gt;prometheus.exe --config.file=tutor.yml&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F61gp8mhdi5d7a3xdiuev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F61gp8mhdi5d7a3xdiuev.png" alt="Alt Text"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Browse the URL &lt;a href="http://localhost:9090/" rel="noopener noreferrer"&gt;http://localhost:9090/&lt;/a&gt; to test the prometheus sever. If you see the page below, Prometheus server running fine and scraping the metrics which is based on the configuration you made using tutor.yml on starting the server.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl83i35ksfd0np9ttiovr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl83i35ksfd0np9ttiovr.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GRAFANA&lt;/strong&gt; is an open source software used for visualizing, monitoring and analysing data performances.It has very beautiful visual representations and supports different datasourses.&lt;a href="https://grafana.com/" rel="noopener noreferrer"&gt;read more&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download and configure Grafana&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Download &lt;a href="https://grafana.com/grafana/download" rel="noopener noreferrer"&gt;Grafana&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Extract files to desired directory&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; In the extracted grafana folder,open the "conf" directory,configurations can be done in the ".ini" files, To avoid complications, we will continue with the default settings.which will configure "admin/admin" as the username and password.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; In the"bin" directory of the Grafana folder. Run the server by executing grafana-server.exe&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Now you can log in to Grafana inputing &lt;a href="http://localhost:3000" rel="noopener noreferrer"&gt;http://localhost:3000&lt;/a&gt; in your&lt;br&gt;
browser.&lt;br&gt;
Remember username and password are "admin/admin". You can change this anytime using the .ini file we discussed earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlw99ekjtolidtgneaq8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fzlw99ekjtolidtgneaq8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; On the Home page Click on "create your first data source". This will open a page to add a data source.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7b91p6tup2z6jti9e9jz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7b91p6tup2z6jti9e9jz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Select Prometheus as the datasource &lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Give a suitable name to the data source.&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Select Prometheus as the "type".&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; The URL should be "&lt;a href="http://localhost:9090" rel="noopener noreferrer"&gt;http://localhost:9090&lt;/a&gt;" since we have Prometheus running&lt;br&gt;
on port 9090.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Click "Save &amp;amp; Test."&lt;br&gt;
If Grafana is able to connect with Prometheus with the details provided, then you will get a message saying "Data source is working." If you get any errors, check your values.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fotyzra6if1u54p7qgsvb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fotyzra6if1u54p7qgsvb.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build your Grafana Dashboard&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; You can create your own dashboard or import dashboard&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; Click on the "+" option on the left menu of the home screen to create or import a dashboard.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I'm creating a new dashboard&lt;/em&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F19vz1fuwkkpwzc2knlwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F19vz1fuwkkpwzc2knlwn.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; click on choose visualization and select "Graph"&lt;br&gt;
&lt;strong&gt;-&lt;/strong&gt; On the left menu tab select "queries" to add a query&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F9etfgot2j96g103tj7yj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F9etfgot2j96g103tj7yj.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt; Make a query&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxsc8471zdam5dq0eyl32.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fxsc8471zdam5dq0eyl32.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;-&lt;/strong&gt;Our metrics will be populated in the graph&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7gobsvhgdfjukrwcs0ln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F7gobsvhgdfjukrwcs0ln.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Awesome! we can now visualize and monitor metrics of the&lt;/em&gt; "jvm_gc_pause_seconds_count" &lt;em&gt;realtime.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;You can now add more queries to your dashboard.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CONCLUSION&lt;/strong&gt;&lt;br&gt;
API Monitoring is important to gain visibility into performance, availability and functional correctness.Creating dashboards on Grafana helps us quickly address errors, check the health of our application, if an application is responding correctly and if the service is accessible at all time etc.&lt;br&gt;
Using spring boot actuator to generate and customize your metrics and Prometheus to query these metrics and visualize them on Grafana, Has made monitoring an application quite easy.&lt;/p&gt;

&lt;p&gt;If you have any questions  or contibutions regarding this post you can send an &lt;a href="//uzosikelynda20@gmail.com"&gt;Email&lt;/a&gt; or &lt;strong&gt;DM&lt;/strong&gt; on Twitter &lt;a href="https://twitter.com/arh_darh" rel="noopener noreferrer"&gt;@arh_darh&lt;/a&gt;   feel free to comment below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;THANKS!!!&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>grafana</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
