How To Install Prometheus And Grafana On Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
monitoring it devices is incredibly important because it's in our interests to be proactive rather than reactive for instance it's better to know a hard drive has reached 70 capacity than it is to find a computer has stopped working because it ran out of disk space now there are lots of monitoring tools out there that you can use an interesting open source combination that's available for free is Prometheus and grafana but how do you install Prometheus and grafana in docker well that's something that you're interested in finding out then stick around and watch this video because that's what we'll be going over now as this video is specifically about installing Prometheus and grafana I'm going to assume that you already have Docker setup if not I do have another video available which shows you how to actually install Docker in a virtual machine on Xbox ve so you can take advantage of both virtualization Technologies now in order for Prometheus to gather metrics from an actual device it needs access to an explorer so this is going to make information on the computer available in a presentable format and then on a regular basis Prometheus is going to check up on that exporter and gather the metrics at that moment in time now what we're going to do for this video is to actually monitor the actual computer itself the docker and ultimately Prometheus and grafana are running on and because it's a Linux computer we're going to use the Nord exporter for that so what I'm going to be doing is to use Docker compose for this so I need to edit the docker Dash compose.yml file as you can see I haven't set anything up yet so it's completely blank which case I'm just gonna copy and paste in configuration which got directly from the main website so what we're doing here is to Define our version at the top we've then got our services section and then under there you start to Define your actual containers so in this case we're only defining the actual Nordic sport a container that we're going to be setting up first now for the image we need to point it to the nordx Sporter image and we want the latest version of that then got our container name in this case we're just calling it Nordic Sporter to make it easier to identify we've then got a command which sets path.root FS to slash host the network mortar set to hosts because we want access to the actual network of the host process ID of host and then we've got restarts set to unless Dash stopped now the idea is that we want to be monitoring something like this 24x7 if there's ever a reboot of the computer for instance we want this container back up and running so if you want something running 24x7 you could set the restart as always in which case it'll always actually start this actual container up the only problem is you might actually want to carry out some maintenance in which case I've got this set to unless stopped so the idea is if the actual container is manually shut down then don't actually started back up on the other hand if computer actually reboots for example then yeah restart it back up again and then finally what we've got to find underneath volumes is a map with its slash host option here so we're pointing this to the actual slash fold in other words the root folder of the actual computer itself and then we've got slash host which is that slash host reference within the actual container and because we're actually just using this for monitoring we've got this all set to read only access we've got Ro and our slave as the options for the actual volume so on save that file then what we're going to do is we're going to start it up and I'm just going to use Docker compose up which this is just going to start up any containers that are defined within that yaml file if they're not already running that is we want this running in the background the one of the words I don't want to leave the actual terminal open because well if the computer ever gets restarted someone will then need to log back in again for instance so I want this all running in the background so that's what the Dash D options for so off it goes now because that image doesn't already exist on the computer it's actually pulling it down from the internet and then it's actually running the container so if we do Docker PS you can see we've now got an image which has just been up for a few seconds but what I can do is actually check on how that actual export is doing by pointing to the IP address of the computer and then port line 100 we didn't Define that within the actual uh container settings but that is the actual default Port there so I hit turn and it comes back and says well this is the Nordic sport what we've got here is our metrics URL so I click on that it actually gives me all of the metrics and then it can actually tap into so this is basically what Prometheus itself is going to connect to and then start gathering this information over a period of time now in order for Prometheus to work it needs a configuration file and my goal here is to actually run Prometheus as a container on this computer and I like to keep things separated so that reason best thing I need to do is to actually create a folder for it and I'm going to call that Prometheus and then we're going to create the actual configuration of file itself which will be called prometheus.yml and then I'll copy and paste configuration into that so right at the top we've got our default or global settings and all we're defining here is what's known as the scrape interval so that's the frequency that Prometheus goes out and actually gathers metrics from things like exporters now this is a default or Global setting you can change it for individual actual targets as we've defined lower down so it's quite flexible in that respect but by default it's going to be every one minute which seems quite reasonable I mean the idea is you don't want to overload a computer too much by checking on it on a very very frequent basis on the other hand you don't want to leave it too long but what you set this to is entirely up to you and then below We've Got What It defined as the script config so these are basically the tasks or targets that we want Prometheus to check upon and actually scrape so we've got one which is defined as Prometheus in other words we're actually getting it to connect to itself so for that reason we're using local horses the actual Target destination and the port is 9090. now these are actually running as two separate containers so we've got one container I'll explain a little shortly that runs Prometheus and then we've got another container which is running our nodex folder so for that reason Prometheus needs something other than the local horse to connect to when it wants to talk to the nordx folder I want to keep things as simple as possible so for that reason I'm actually going to point it to the IP address of the actual main computer and then 0.9100 so this is just exactly what we used when we were connecting and testing nordxporter within that web browser but you can use an fqdn and you can go so far as actually setting it up with IP addressing within Docker itself if you want to but as I say I want to just keep things as simple as possible so what we're finding here is just a global default setting for how often we want to pull and then at this stage we just want to get it to check up on Prometheus itself plus the Nordic Sporter so we'll save that config and then we can start thinking about setting up Prometheus itself now because I'm using Docker compose to set up my actual Docker containers you know the setup Prometheus I'm going to have to edit the docker compose file so I'm going to use Nano to edit Docker Dash compose.yml and then in here we're going to set up a details for prunikius so I'm just going to copy and paste in some details most of this comes from the actual main website I've just converted it over for use with Docker controls so it's paste in the actual container details there but right up here at the top we're defining a volume called Prometheus Dash data the reason being is that well if we don't have an actual volume to store data physically on the computer the actual data would get lost we need that information to survive a reboot for instance so we get Docker to actually create this volume which we're calling Prometheus Dash data the actual file name ends up as something completely different but it's a reference that we can use lowered down and then we actually Define the container and we're calling this one for Prometheus here the image that we're going to be using is this and then we've got our setting of layers because we always want the latest version we're defining the actual container name to be Prometheus to make it easy to recognize what this actual container is and then we've got the default ports of 1990. as before I want this to actually restart all of the time unless it's actually been manually shut down because like maintenance issues for example and I don't want it to automatically restart under those circumstances I've actually got to map the configuration file it uses so it sees a config file has been slash Etsy Prometheus prometheus.yml I've got to reference that file back to the config file we created earlier in this case we're pointing it to the Prometheus folder that we've got um and then the prometheus.yml file within there then what we're doing is we're actually mapping this slash Prometheus folder that the container sees to the actual volume that we've created up here now this is where things get a bit interesting because I wanted to use this dash web.enable dash lifecycle command so I've got a command section to find the reason for that is that if you make a change to the configuration file then you'd have to actually restart the actual container but there is an option to actually get it to essentially reload the actual config file on the fly but you have to put this command in to be able to do that the only catch was when I added this command in the actual container broke without putting that in things were working fine but as soon as I put that command in I kept complaining that it couldn't find the actual config file so I had to add in an extra command here to actually tell it that the config file is its slash Etsy slash Prometheus slash Prometheus dot yml so just something I I ran into um specifically because I put that extra command in but either way I'm going to save these changes now and then what we're going to do is to actually spin that actual container up so we're going to use Docker compose up Dash D so we'll get this to run in the background it hasn't done this before so it's obviously going off to the internet pulling things down and then once it's actually pulled all of these uh actual Parts down and then created that it's then going to actually run the actual image as a container and then it should return us back to the actual shell because I was using the Dash D option to run it in the background now if we use dockerps it's actually seeing it's been up and running for several seconds so that looks good so what we're then going to do is we're going to go over to our web browser we're then going to point it over to the actual uh Prometheus container that we've got there so we want to point it to same IP addresses that we're using for Nordic sport because it's the IP address of the host but we want to use port 1990 which is what it's listening on then if we go to stairs for example and ask for targets you can see we've got two Targets one's the it's referencing the end points this is our Prometheus Target the other one is the Nord exporter at the moment we're waiting for the actual information to be gathered it doesn't have any information at the moment so we've got to give it a bit of time to actually get that information but you can also go to service Discovery for instance to get a bit of a breakdown of the information of those targets if you want but there we go it just took a while because it's set to a default interval of one minute which means you've literally got to wait one minute it doesn't automatically start that connection it waits one minute before it then goes and checks then what export it but as you can see it's connected and as far as it's concerned it's actually up which is good you already know the metrics are there but all we're doing here as far as Prometheus is concerned is just Gathering that information here now if you ever do make changes to the configuration let's go back to terminal session rather than restarting the container what you can actually do is use Curl tell it to actually restart or at least reload the configuration for Prometheus so I'm using the dash X option because I want to use the close command I want to send it this reload command tell it to reload so if I send it that because if I was to just browse to that URL it wouldn't work and be using the get option so that's the reason I'm using curl I wanted to actually send it a post option I want to send information to the actual web servers specifically I want to tell it to do a Reload and then what I can do is if I want to actually check on that I'll go back to the web browser what I can actually do is 0.2 Prometheus except the slash status URL there and it actually tells you if your configuration reload was successful it also tells you when the last the last reload was so that's a good way to actually check if the configuration has reloaded but it's it is very very useful because I say it just saves you having to actually do a complete reload of a container but either way as far as we can see Prometheus is now up and running and it is starting to pull information from the actual Nord exporter that we wanted to collect now it's all well and good having Prometheus gather all these metrics but we want to see these in a more presentable formats we want them on a dashboard we want to see gauges we want to see charts and so on and that's where grafana comes in so because we're going to be setting this up as another container in Docker we're going to edit the actual yaml file or Docker can pause and then we're going to put in the details for grafana so similar to Prometheus I need to create a volume all grafana to use to actually store all of its information in because we'll be actually making configuration changes and so on and then what we want to do is to actually create a container here so let's say right at the top we've got a volume of calling that grafana Dash data and that'll get created the first time this spins up but then we're defining what our grafana container is so we're pointing it to the image and we're seeing what the latest version we're giving it a name of grafana so it's a bit easier to identify going with the default ports here of 3000 and as before it's a case of I want this thing running 24x7 but I don't want it to automatically spin up if I'm doing maintenance so rather than having restart set always Etc unless stopped and then what you've got to do is to actually map in the volume so in the container's perspective it's slash VAR slash lib slash grafana but we're actually linking that over to the grafana dash data volume that we created before so we'll see that configuration file then what we're going to do is to actually spin this container because I want to use compose or Dash D so that this will get done in the background and then off it goes and it starts to actually download things and then eventually it'll actually start up the container well the download has now completed the container is up and running but I left it a while because it seemed that the actual web interface wasn't responding or at least not for a while so it obviously took a bit of a while to catch up but now if I open up a new tab paste in url for Griffon and then just hit return it's now getting that point where it's asking for me to log in now the default credentials are admin for the user account and admin for the password click on login first time you log in it actually asks you to change that default password so I'll put in a new one as ever I would suggest using something a lot more complicated and longer than I'm using there is the option to skip if you want but it always makes sense you really want to be using default credentials so I'll click on submit and now it's loading up and there you go we've now got grafana Robin running well now that we've got grafana installed we actually have to configure it and point it over to Prometheus so over here we've got an option called Data sources and it's saying here add your first data source so we're going to click on that and interestingly enough first option right in the top list is Prometheus so we'll click on that now you can change the name if you like well it's what we definitely need to do is to actually point it to uh our instance of Prometheus so I need a copy and paste in the URL for that so in my case I'm just using IP addresses but I've got to use HTTP it's not using any certificates at all but it's still Port 1990 by default then scroll down and click on Save and test and as you can see it's actually successfully connected to our actual Prometheus server in which case if we go back to home we've got an option here to actually create dashboards because that's what we really need I mean we've actually pointed it over the actual data but we need a dashboard to actually display all this now if you're just getting started with grafana well that can be a bit complicated if you don't know what you're doing to begin with but fortunately there are people out there actually making dashboards that you can use so if we go over to the website for grafana and on this dashboards URL here it's quite a lot of actual dashboards people make available one of which is this nor exporter full which is specifically for showing the actual metrics that are used with nordx border so if we click on that you can see you'll get examples of what the actual output looks like but what we really want is that ID down there because if I click on copy ID the clipboard then go back to rafana go to the menu then select dashboards then on this new drop down menu if I select import I can actually paste in that actual ID and then click load I can change the name if I wanted to and what I do have to do though is actually point it to the actual Prometheus data source then I'll click on import it actually sets up the actual dashboard for me so this is a dashboard that's already been put together that we can take advantage of to make our lives easier you can learn all the things and have a look at this information and find out how it's put together and then start making your own dashboards uh you might be prefer to see things out but there's there's a lot of useful information in in here I mean obviously Prometheus itself has to gather quite a lot of information over a longer period of time I mean by default looking at about like 15 days it will collect and then I'll start a discard information but straight away you can see we're getting some useful information about system loads Ram utilization and so on we can start drilling down into all sorts of information in here that it's Gathering as a um as a Linux computer I mean Network traffic all sorts of stuff on here about the network packets errors and so on we've got storage disk space information read writes all this is perhaps a ton of information that's been gathered here but as you can see hopefully it is pretty easy to set up especially when you've got people actually creating these dashboards for you hopefully as you can see it's not too difficult to set up Prometheus and grafana once you know how Grant and we've only got Prometheus monitoring itself at this stage so you'll want to add other devices for other Linux computers for instance you can still not export run them but we'd probably do that as a binary rather than a Docker container and there are a lot of other exporters available and usually someone has created a useful dashboard to go with it now although I haven't touched on alerts Prometheus does support these so it can alert you when thresholds have been reached for instance so I'll say this monitoring solution offers a lot of scope now if you find this video to be useful then do consider subscribing to the channel and does that really mean a lot to me but it's also a good indicator to let me know how videos like this are helpful to people such as yourselves that are watching in which case thank you on the other hand if you're not ready for that level of commitment then I'd really appreciate it if you could press the like button is that where that will help you get the video out to other people that might find it useful as well
Info
Channel: Tech Tutorials - David McKone
Views: 7,034
Rating: undefined out of 5
Keywords: how to install prometheus and grafana on docker, install prometheus and grafana on docker, install prometheus docker, install grafana on docker. install grafana and prometheus, install grafana and prometheus docker, install grafana and prometheus on docker, install prometheus and grafana docker, how to install prometheus and grafana, how to install grafana and prometheus, how to install grafana and prometheus on docker
Id: jj38y6f6UpE
Channel Id: undefined
Length: 22min 23sec (1343 seconds)
Published: Tue Aug 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.