Prometheus and Grafana installation using Docker Compose

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello people welcome back to my channel and let's learn how we can install Prometheus and grafana using Docker compost so Prometheus is a metric server like where multiple servers can push their metric and grafana is basically used to view those metrics plot graphs plot visualization and basically do alerting kind of thing so there are some prerequisites to it and the first thing is what Docker must be installed and then the other another thing is Docker compose must be installed I have already written a block post here like install Docker on your machine and this basically list down different ways in which you can install Docker on your either Windows machine or UB 2 or like Centos so I'm I'll be gradually adding more links here and you can refer to this blog post and whatever operating system you have you can follow the link and basically install Docker on your operating system so these are the two prerequisites now what we are going to do is basically there's a whole post operating system on your machine and there is this Docker environment so whenever you install a Docker create containers out of it so a Docker environment is created so there's the main machine you can say it is a Windows machine that is the main machine or host operating system and there's a Docker environment so inside the docker environment what we are going to do we will be installing the docker container or creating the docker container for for Prometheus Prometheus container will expose the port 9090 on on inside the docker environment and same will be mapped to 9090 port on the host operating system so if you want to access the Prometheus you can use 9090 port on the host operating system and all the request will get forwarded to 9090 port on the docker environment and there will be a prometheus. yaml file which will be present on your host operating system and we will basically mount it to the docker container so that you do configurational changes add new configuration related to Prometheus exporters and other thing on the host operating system file and same will be reflected inside the docker container the another thing is what we'll be installing grafana which is like the graphical user interface to view the metrics that has been collected from Prometheus so this will be exposed on Port 3000 inside the docker environment and same will be mapped to Port 3,000 on the host operating system then we'll make a connection in between these two like the metrics which is being uh ingested into the Prometheus server or Prometheus Docker container this graph will point to this server and basically it will read the metric and plot the visualization so I have already written a block post here that is Prometheus and grafana installation using Docker compose you can follow this also to get quick Snippets from here so that it can help you so let's start the process so let's start writing the docker compos file and basically start the application so I'll go to my terminal here here basically I'm using WSL of windows so if I do a LS and I do WordPress so I'll come here and then I'll go to YouTube playground and inside here there are some files which are already present so I'll create a new file that will be what as the block suggest it is Prometheus graph. EML so I'll say prom. EML so this is the file name I'll open my intell ID here and then what we going to do we are going to open that folder so this is present inside my WSL and and that would be on home and then self TS and then there will be a folder name workspace inside workspace there is a folder name YouTube playground let's open it so this is the folder that is present here and we just created this new file that is Prometheus graph. yl so this is the file that was created so let's add the configuration for our Prometheus Docker container and here is the configuration so what we are doing we are doing version three because we are using the version three of Docker compose syntax writing and this is the service so you need to define the list of services here so the first service that we are defining is Prometheus and the image that we are taking is prom / Prometheus so this image is coming from dockerhub so what I'm going to do I'll just show you once that I'll just copy it go to the browser uh open a new terminal and click and search for Docker Hub so this is the online space or you can say online repository where you find all the docker images so if I search it it is giving prom promia so you can see that details here so what we are doing here is like we are we'll be fetching this image from the docker Hub and then we'll do some configurations so the configuration is what the first thing is Port that is 9090 and at inside the docker container and on the host machine also it is 9090 same way for volumes we will be having this prometheus. EML file which will be present here only so if you want you can create a new file and that file will be equal to prometheus. EML why this file is important because you need to provide some configuration like from where scraping will be done what will be the time interval for all those scrapings so this file is for this configuration so we have already seen in our slide that we are creating a Prometheus EML file on the host operating system and when we run it so the volume will be mounted inside the docker container so this is that configuration so we are saying volume Prometheus EML and then SLC Prometheus prometheus. EML this is the path inside the docker container so this is the configuration for Prometheus Docker container now let's add the configuration for grafana so I'll just do what I'll just do paste here so this is the grafana service that we will be creating and then again the image name is what grafana / grafana this is present on Docker Hub the container name here is grafana if you want to give a container name here so you can give that is container name equal to Prometheus so let's say the container name is also Prometheus here so same way here the container name is grafana again the ports are what 3,000 which is present inside the docker container and 3,000 which is on the host operating system so restart is like unlet stopped so that is fine that is a configuration and the involvement variables are what GF security admin and GF security admin user and password so we are uh providing the username and password as admin admin you can change it whatever you want and again we are creating a volume that is do/ grafana so in the folder where we have this prometheus. EML files at the same place a graph folder will be created and that will basically host your data sources so why this volume is important because if you kill this container if you restart this container still your data should persist so this is the configuration for our Docker compost file now let's go to our terminal and let's try to start it so if I do LS here it is fine if I do cat and then this Prometheus uh grafana so this will list down the data so that is fine now and say Docker compose hyphen f and then Prometheus and then grafana yaml and up so I'm just providing it as up because I want to see the locks on the forr ground if I do hyph D so what will happen it will start in Demon mode and the locks will not be printed I have to go to the docker containers logs and check it so I'm doing just up here I'll hit enter so what it is saying it is creating the two uh containers it didn't downloaded the image why because already the image was present on my local system so if I show you Docker images so here you can see graan is already present and same way the this Prometheus will also be present so if you can see here prom Prometheus is also present so that's why it didn't downloaded the image but in your case it will download the image so now what it is saying that okay everything is working fine I'm not seeing any error locks now let's go to our browser and we'll see that the Prometheus container is hosted on Port 9090 and the grafana is hosted on the port 3,000 so let's go to the terminal here and just type Local Host and then 9,000 let's see what happens so this is giving me reload Local Host what is this okay 9090 is there so let me hit 9090 so you can see the Prometheus uh some UI is there we will not go into the details of it so here you can write your expression to fetch the data and other thing but it is visible now like the Prometheus is working fine and if you will ingest data inside it uh we'll seen later videos like how to ingest the data uh and so after that you can just write some queries here and you will be able to view the results now let's see what is the thing with graph so Local Host and then again 3,000 so hit enter and you can see okay the G is fine it is also working we have set the default uh username as admin and the password is also admin so let's login it is asking me to change the password so I will change it so I'll just give any password okay I need to do the confirm password hit submit and you can see that I'm inside the grafana terminal or you can say grafana interface now inside the administration what you need to do is you need to uh Define some data sources so inside connection you need to define the data source we'll say add data source and here it is saying okay the data source you can add as a Prometheus also so here what we are going to do is we will say Prometheus is the name and here we'll say Prometheus 9090 so now this Prometheus is important because why we have given the service name or the container name as Prometheus so if you have seen in the configuration that the name of the service is Promethea so you are able to call the service with that name with that host name that becomes a automatic host name why because both Prometheus and grafana are deployed inside the same doer environment so they can access each other so this can this grafana can access Prometheus with this name Prometheus because we have given the service name as Prometheus and if the Prometheus wants to access grafana it can also access grafana with with this name if some other service are also deployed they can also access using these service names so this is fine and if I add it here 9090 and if I go to bottom save and test so it is saying what successfully queried the Prometheus API save and test okay so it is saved so the connection is also established and everything is working fine so if I go to home now you can basically create a dashboard and then add a new visualization you can select this as the source and then basically you can also write some code filter or whatever you want I don't know like uh there are a number of queries that you can write based on the data which is present on the Prometheus so this is the way how you install uh Prometheus and grafana using compose so hope you like this video hope you like my channel if you want to support me give me a thanks on the video and you can also go to the description I've given some links you can support me there thank you
Info
Channel: CodeWithRajRanjan
Views: 1,027
Rating: undefined out of 5
Keywords: prometheus, grafana, prometheus docker compose, grafana docker compose, prometheus grafana docker compose
Id: -Ec5wzzV9lM
Channel Id: undefined
Length: 11min 44sec (704 seconds)
Published: Sun May 12 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.