4. Prometheus spring boot actuator | exposing prometheus metrics using spring boot java 2020

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey hello welcome back in last two videos we discuss about why to use prometheus and what are the use cases where we can use prometheus in our infrastructure and how prometheus works or how is the architecture of a prometheus but in this video we are going to do some hands-on using spring boot activator to expose a matrix so let's get started first you need a springboard project so how to create a springboot project so visit star dot spring dot io it's a spring initializer using spring initializer you can create a project so create a maman project using a java version i will keep it as default 2.344 group id i will name it as a com.example.demo and promit ts actuator okay and in the description i will change it like a premium project from for a from this egg to editor okay and packaging i will keep it as a jar and java version 1.8 and once it's everything is filled click on generate it will generate a project tool and you can see it's generated and it is downloading a project yeah so here it's downloaded now what you need to do just import this project in your editor okay so go here in the pom.xml you can see springboot version 2.3.4 and dependencies are added for jersey and spring starter web okay and you can see here structure is already created for us with the default main class to start the application so everything is correct everything is ready now next endpoint we are here to expose the promises end point using actuator so let's check first activator so you can see from here spring boot activator this is the production ready feature which help you to monitor and manage the application when you push it to production so it has a mini http endpoint okay and where you can monitor your application so this is very good feature in springboot you can use activator to monitor your application so what is the need you you need to add this as a dependency in your maven project so i am going to copy this dependency and i will add into our project so let's go to pom.xml here i will add the springboot starter activator so you can see it's downloaded now the next thing okay this is done next thing is there are multiple endpoints once you add that dependency you can see it will expose actuator end point and where you can see many things so in activator these are the end points supported so how to enable it it will be like very difficult if actuator enable all the endpoints by default then you will have lot of endpoints in your application so it's not the case for the spring boot activator in spring boot actuator if you want to enable any of the endpoint then what you need to do you need to add this management dot endpoint dot id dot enabled to true okay and here you can see there is a one called prometheus which is also exposed like a actuator slash promise prometheus and what it is doing exposing a matrix in a format that can be scrapped by the prompt server and that is our requirement but it requires a dependency on micrometer registry promises need to add this dependency in our palm.xml so let's go to our project here in the dependency you need to add one extra dependency i know it is from micrometer and artifact id is this which i copied from their website it's resolving the dependency in the meantime we can check here okay this is added so it means it will enable promises endpoints now let's check in our project here i will just create one package resource because i am going to write one java class just a simple hello world which will be rest controller and which will have one gate mapping for hello and which will just simply return hello world okay so before starting application let's build or clean let's do a maven clean build of our application so in the terminal you go and type mvn sorry clean install so as you can see build is successful then i am going to run the project run promises application i will just maximize this and now you can see started from this application but at the same time you can see expose two endpoints beneath the base path activator so you can see actuator is exposed now let's go to the browser so my application is running on localhost 8080 port and you know what there is one of the endpoint called hello you can see hello world my application is running as application got started you can see it says there is a two end point exposed beneath the base path actuator so let's try to run this you can see here there is actuator and another one is the health and saying i am up and running and the third one is the you can see path or info so there's nothing we added so as of now just remember this is nothing called a promise you do you see something like slash from me ts no there's nothing so that means we are missing something so let's go again to the documentation you can see enabling a endpoint so if you need to enable any endpoint you need to do like this management dot endpoint dot shutdown meaning this is id so you can add it as a we can add a prometheus here so management endpoint dot from case.enable true there is a this is one way and another one is this is like exposing a matrix we can use endpoints are exposed using following technology called include or exclude so we can use this management.endpoint.web.exposure.include so let's try to change our project so here let's go to resource application.property add this as we need health to say my application up is up or running or not you don't need it so include as of now just promise yes and that's it it will expose a matrix let's add this one also matrix and health okay this three end point we need to expose now let's run the project again running a project and now you can see exposing three end point beneath the base pass actuator let's go back here and you can see here now actuator is their health is there and one is prometheus so oops s is missing this is the matrix exposed now you may ask hey push we didn't write somewhere in a code what data should be analyzed and expose as a matrix then from where this data came from so answer is this is the default matrix but we can expose custom matrix also where we can say which data need to be monitored we are going to see this in coming videos and second maybe you have a question you said matrix is a human readable rich text but we are unable to understand this so don't worry that i am also going to cover in next videos so keep watching and keep learning see you next video [Music] you
Info
Channel: Namaste Java
Views: 9,615
Rating: undefined out of 5
Keywords: spring boot prometheus, spring boot, expose prometheus endpoint spring boot, prometheus spring boot, spring boot actuator prometheus, spring boot prometheus custom metrics, spring boot grafana prometheus, spring boot grafana, prometheus monitoring, spring boot microservices, spring boot tutorial, namaste java, spring boot actuator, spring boot with micrometer, micrometer prometheus example, spring boot micrometer prometheus example, spring boot with prometheus, grafana
Id: JTf8wiGbMbM
Channel Id: undefined
Length: 10min 18sec (618 seconds)
Published: Wed Nov 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.