How To Monitor Your Go App With Prometheus

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
by the way guys before we start this video I want to let you know that I'm making the full-time goldf course which is an exclusive program that contains all the building blocks for people that want to be professionally active as a goaling engineer this program contains 10 years of my goaling experience divided in chapters ranging from beginner to expert we will cover the goal and Basics concurrency and move on to building real world projects nothing in this program is scripted it's all organically recorded so you can see me make mistakes which you can learn from there is also a chapter specifically dedicated on how to land a job where we will cover on how to make your resume appealing organizing your GitHub profile and how to build confidence as a developer and my treat to you guys you will get a complete chapter on how to build a blockchain from scratch for free not the one from YouTube but a complete new one the course is currently on pre-sale you get 30 off by the end of the month it's completely finished and the prices will range so hurry up and I'm looking forward to see you in the program Okay cool so what we're going to do is each time right each time we receive this message through this one receive through we're gonna do some metrics right we want to know how long it took for this message we want to know uh we want to know everything you know what I mean just like a girl they want to know everything or a woman um how are we gonna do this so what I'm thinking to do is um I'm gonna make it I'm gonna call this Pro metrics it's going to be a stricture so we can actually uh do some stuff later on and then we need to do a trick and we need to check how I did this because I forgot so we need to have wet hooks each uh let me copy this thing let's put some things things over here comment that out what do we need still this thingy with hooks let's copy that just for the actually to be honest and then kill the screen all right I'm going to comment this out yes we have a problem here this G get them out of here okay so we're gonna spawn uh this actor but we're gonna spawn it with middleware and it's going to be with Matrix so we're going to do something like this funk B pointers to Prometrics and we're gonna say he um with metrics or something I have no clue that's going to be this function here which is very weird an actors receive funk it's going to return an actor to see funk that's fine and to be honest do we need that can we not just to we will do it later on it doesn't matter let's copy the C boom missing return that's all fine now we need to return this wrench getting funky just like that can I choose next actors um return Funk next yeah return Funk C actor context yes oh wait I see I see what's going on with Matrix is going to be this guy which would turn this guy looking good to me all right um what is up look then what is up I will answer I will answer the questions all uh all all together all together later on later on guys no worries nobody's numbers I got your back uh but I don't want to be out of out of focus right so now we have this Pro metrics uh with metrics thing here so what we're gonna do is um I'm gonna check heat if I can access the message itself because we need that so we're going to say um fmt let's do this start is going to be a time now I'm gonna do that later on um message from intercepted intercepted if that's intercept that see message looks good to me and that we're gonna call next you know that with the context you know what I mean classic middleware shenanigans okay so the next thing we're going to do here is we're going to boot up this thing with an actor uh with middleware like this and then we're gonna say uh prom yeah we're gonna make a Constructor so we're gonna make a Constructor nobody's guys but now we're gonna not do it we're gonna do it later on because there is nothing to construct right you're gonna say maybe this pointer then uh prom Matrix just like this and I'm gonna say with metrics kind of coil pointer methods okay okay it's fine it's fine no problem hey it's fine it's fine it's fine learn everything in here paste that in heat uh delete everything in heat and then we're gonna say that the B handlers or P Matrix P method let's make it good B actually to be honest B Matrix is this guy and we're gonna do B Matrix cannot call pointed with metrics from oh boom boom what's going on oh yeah I see it's a yeah okay okay so you cannot do that and go because we can't so we're gonna make this first this one delete this one and then do this one and say uh with Matrix this one and now I made a mistake uh maybe another one yeah okay cool we're done right and if we right now if we do this again we're gonna uh run this thing you see now we have intercepted uh one this is going to be the actor started the actor initialized actor um started and it's going to be intercepted the full message all working fine cool right um what is my ID it's Neo Vim okay the next thing we're gonna do is actually install um Prometheus so how is this going to work first of all what I'm gonna do go to a GitHub uh uh you see this guy here well let me zoom in 150 for the blind homies this is an example from Prometheus Klein golang and what we're going to do is the only thing we're going to do in this example is copy this yes that's correct uh so we're going to say clear the screen go get we paste that in boom just like that of course we made a mistake uh that's a problem but it's no problem because we are problem solvers and then we press enter let me do a go mod tidy Maybe you know what I mean tidy things up once that is done we have basically installed uh Prometheus Google and client right so what Primitives will do basically is you need to expose a Handler an HTTP Handler and it will um automatically Auto magically already gathers a lot of metrics for you right and I will show you so what you're going to do here this guy can be gone um we're gonna see let me let me show you we're going to say http listen and surf actually I'm not quite sure are we gonna do this uh we're gonna say we we pick a port it doesn't really matter we're gonna pick two two two and there is a reason for it but you can pick any post you know what I mean listen and serve I think do we need this prom Handler from HTTP Handler is that is that the play he's not quite sure I think it is uh okay this is gonna block our whole application hey I'm aware no worries but I'm gonna show you go run that's not true I'm gonna do this no this one yes um God damn it do we need to do we need to install this all right you need to install it apparently right just uh do buddy do do what he tells you okay so basically now the program I'm gonna try this let me try to localhost without leaking nudes uh two two two Matrix all right look at this beautiful I'm gonna make this a little bit bigger for the blind homies you see so this is basically an exposed uh 222 Port metrics and that's coming from Prometheus itself right that's all these metrics is what you have out of the blue right and today we're gonna cover Prometheus itself but in the full-time godf program I'm covering also grafana right because rafana will basically pull these things uh from Prometheus and make a very very nice dashboard although you could have already some kind of a dashboard I'm going to show you later on because um later on but yeah this is basically you could see you have for example the guru teens and all that Shenanigans and and the duration of the garbage collector and you have a lot of stuff guys it's insane right so we're gonna put that aside okay cool the problem is that of course this thingy is blocking out application right so we're gonna put this in a good routine go Funk hop hop and call it a day you know what I mean that's what you're gonna do so this guy will basically be scheduled in another go routine and all good okay that's fine uh the next thing what we could do here is for example we could say uh let's first install Prometheus right let's first get this get that thing done so I'm going to quit this thing go back to CD CD into prom promedius look at this this is basically the Prometheus or depository you just go to github.com I don't know Primitives or something and you basically clone the project and I think you need to do make build or make install it doesn't really matter you guys are smart enough to figure out how to install that thing right [Music] this Windows song is insane but what I have here is a CD prompt and this is basically a folder can you guys actually see this you can't uh seems like terminal has been more space phones yeah maybe I have this this the shenanigans he's the most important thing you need to remember is basically this Prometheus yaml file right let's Vim into this thing Prometheus boom so you need to have this configuration it's all on the internet but I'm gonna cover it a little bit you're basically going to say scrape interval script timeout evaluation interval all that stuff right the amount of seconds it takes before it's going to scrape for new metrics because what Prometheus if you're gonna boot up the Prometheus client itself the Daemon basically what it will do is it will scrape your 222 metrics endpoint right for this Matrix okay um uh The Matrix Path metrics that's uh default I guess and then we're gonna have uh Targets this is important right you see this guy here these targets localhost that's basically uh or Handler we just created in our project I'm here for the Windows sound yeah can I do this can I can I force this sound I'll do a 4G sound I can't count for the sound I'm so sorry I basically was also uh setting up my my Linux Ubuntu system on my new pc but the problem is recording is slow for some reason I don't know what it is I need to figure it out it's it's Linux and it's drivers it's all right uh that's what you need right and then I have this uh run script look at this this not transcript this is motor landscape this is a run script it's basically a Docker and I'm gonna run this in a Docker container uh is that what I'm gonna do is that a play now I'm actually uh well we are using a Docker container you know what I mean so you don't need to install Prometheus you can just do this copy this line and you're good and it will be in the Hollywood repository so you can find that so basically we're gonna do this thing and I I don't think this is correct to be honest I don't think it's gonna work if I remember because I was trying this a couple days ago for something else and the problem was that let me open up it again because I'm using this booked WSL Prometheus cannot uh connect to this 2 to 2 port um I think I did something like um dot dot slash Prometheus there is your Windows sound uh promises there is Renaissance once again I'm so sorry and then men dash dash by the way um I think it's config.file can somebody know how can I turn this Bell off I think it's this one and I presented it's that easy it's that easy but now we have a problem let me open up another terminal because I'm not the teamix guy I missed that boat I missed that boat I'm gonna lie um let me quickly do something on the other screen heat guys I'm so sorry uh you can see what I'm doing right oh yes let me uh quickly figure this out uh dot file is going to be the same thing we did before right what's going on each let me open up um did I made a mistake here Prometheus no no no this is wrong this is wrong this is wrong this is the play yeah it's fine okay cool so now it's running my bad for this uh little um inconvenience here and if people are a Linux specialist let me know because I I have the biggest the biggest uh stack um but it's just slow I don't know what it is um all right so once you've started Prometheus what you could do is uh you can go what's going on Eid let me move this it's so annoying and streaming you always need to be careful with all your windows right so we need to go to a local host that will show you directly guys nowadays um that's going to be 1990 you see we go to 90 90 hit and now you have the Prometheus dashboard right it's so annoying what's going on with my screen is this it seems like it's transparent or something what's going on okay it's so annoying it's it's transparent for some reason on my screen anyway um what's slow about it it just I'm gonna I will explain later on uh okay cool so basically right now we can actually search some stuff you could basically he's gonna give you a lot of these um metrics for example Google Maps at uh amp cache says bytes click and it's basically execute and it's going to give you a result it's a zero well for some reason I don't know wait let me quickly check his status targets of course it cannot find metrics that's what I'm thinking so what we need to do here is [Music] um CD back to YouTube here Hollywood by the way Wood and um go run examples Matrix main.go boom of course right and now we're gonna wait for 15 seconds and then it's gonna pick up this um I'm a complete idiot um I'm a complete idiot because the problem is our application will exited right so what I'm gonna do is I'm gonna do this boom delete the sleep the gold rank is for later on right that's that it's fine let's run this bad boy boom boom okay cool now we are good right yeah yeah yeah yeah yeah yeah all right so let's refresh a little bit and this guy is basically gonna pick up our amp service and guys let me know do you guys see transparent on my uh camera can you see some transparent stuff I'm not quite sure what's going on uh yeah okay you see now localhost is up right so basically Prometheus has found or applications handled and it's polling metrics from it so right now we could go um alerts graph and then we're going to check for some example go maps at mallocs for example I don't know boom it's going to be here 591 something like that right and can you imagine you have a beautiful um you can have a graph like this problem is one hour is bad so you make it one minute and you have a nice beautiful graph right but what if we could post or push our own metrics right that's eight that's the play um yes transparent why is this thing what's going on each let me quickly check it properties Uh custom oh wait I know what it is it's the grandma probably from my filters uh display captured wait let me quickly do on the Fly Guys this is technical technical debating on the Fly wait filters OBS man color correction you see hey we fixed it but I think it's better it's fine all right now we fix it right okay cool custom metrics let's do that back in film let's kill this guy here okay so what we're gonna do we have this Prometheus structured heat so we could do something like uh for example message count is going to be I think it's a Prometheus counters it's going to be an interface so it's no pointers we're also going to have something like um latency latency and that's going to be a Prometheus is just like that of course now we need to have this beautiful constricted new from Matrix returning a promatics pointer dog is barking a new Prometric Siege um let's return from Matrix the pointers by the way Prometrics like that and we're going to say for example the message counter is going to be and I'm going to be very lazy I'm going to say prompt Auto dot um new counter I think this needs um Prometheus counter options I think counter Ops and I think it's going to have a message or a help yeah counter of the messages the actors received I don't know um we also need something else each I think it's going to be the name yeah baby it's the name and the name needs to be something like that for example actor underscore message underscore counter something like that there's a problem here because uh let's say we have multiple actors with different names then they're going to have the same name here right so it's going to be problematic we're going to fix that very soon um return from metrics so let's start with the counter so you're going to say the message counter is going to be the message counter it's easy as that right uh that's that so now we're gonna have a problem here because this boy here is going to be what's going on man messages all over the place uh there's going to be a new Prometrics and you could construct with other values I don't know you could construct your Matrix somewhere else it doesn't really matter right it's just for sake of an idea here um I think it's good by the way no we're not good because I think we're good no we don't desperate hooks you can delete this thing oh fine and then each time you're gonna have a message right each this thing is basically each time it intercepts a message so what we're gonna do here is p Dot message counter dot uh Inc just like that you see and that's why we basically attach the function receiver to put on metrics which seems a method but it's actually a function because it's syntactic sugar but it's an endless discussion we're not going to do right and if you want to see in depth of these metrics how you this is for actors but we also I'm also covering this for your normal microservices it's in the full-time goodf 30 off check it out today's main sponsor by the way um this is gonna delete that to defeat actually to be honest we can't right um it's for later message content Okay cool so what's going to happen is what we gonna do heat uh we're gonna make a yeah what I'm gonna do is I'm gonna make a girlfriend kit for this boy just like that and then we're gonna see a new actor that's fine Prometrics perfectly fine and I'm going to Loop Heat how long before average you're gonna time sleep time seconds and we're gonna say uh engine sent me to this bit message data let's make a y we're going to be zero you're going to send data it's going to be fmts s by the way s print evaluate and that's going to be message to who percentage d why actually to be honest okay unreachable code thank you very much uh yeah so basically what's going to happen is it's going to send messages every second and we're gonna pick that up into our Prometheus Shenanigans right so let's start this thing and see if it's gonna work um all right so basically it's it's printing out that it's receiving messages but we are going to check that here in our beautiful thing so let's get let's go to targets real quick okay Matrix is up let's refresh for the for certainty right all good up green green things perfectly fine uh we go back to graph and then we are gonna say how did we call that actor message counter heat boom execute pump and you see we have 19 19 messages graph one hour is too much let's delete that a little bit you see it's basically going up and up and up that's how you actually add custom metrics in Prometheus and this is basically for the actor model but you can already see it works in golang for every single thing right you just need to know how to weave with it you know what I mean weave things in uh we're gonna do a lost metric before I'm going to answer some questions and that is the latency right latency very important we want to measure if I'm receiving messages how long does it took to process these boys so we're going to call this this histogram we already did this so we're going to say uh MSG latency oh fine MSG latency is going to be a prom Auto if you don't use promoter you need to register it manually but hey if it's an auto it's an auto Prometheus uh um histogram options yeah it's the same thing right a name and the name is going to be um actors message latency copy this once again because we're going to do the help I mean just going to leave it like that but without these things right boom boom okay we also need Booker T and that's another topic just need buckets which is a slide a slice it's basically 40 hours I have no clue don't tell anyone you just need buckets guys and we make zero zero point one foreign you can make as much buckets as you want uh it's needed for your histogram right guys come on if you didn't know that let's put your histogram right and I'm gonna say uh MSG latency heat and it's going to be the MSG latency right and you could see you can mix as much metrics as you want right the sky's the limit the sky's the limit how do we do that well the first thing we're going to do is time start we're going to say started at the beginning you're going to say time now and then here we're going to say um latency is going to be time since starts seconds if you wanted a milliseconds you want any milliseconds you wanted a nanoseconds you can do it in nanoseconds it doesn't really matter to be honest in seconds that's and then we're gonna say B latency observe MS cannot use variable type in 64 Expo 64. cannot use a mass variable of type in 64. is that true you we take seconds that's what we're gonna do for some reason seconds it's returning us a float but that's fine right and then uh you're basically just gonna boot this thing up like this and then we're going back to our beautiful thingy here we're gonna see if we can find for example actors uh we maybe need to wait a little bit it's up that's fine we need to understand that sometimes if you boot it up directly it it did well it did not scrape it already if it makes sense okay and then you have these things right you have actor MSG latency bucket latency account and latency sum there is not really much you can do with it it's more for grafana that can basically uh use these things to make a new a beautifully um chart histogram whatever you want to call it but you could say latency sum or Contour something is going to be the same against 36 is going to be the same as messages you could also do something like um let's just um nobody knows you know what I mean take it in a graph make it a little bit smaller show that to your colleagues and you're a God you know what I mean and you have no clue what's going on but it doesn't need to be because it's Graphics you know what I mean Graphics oh nice look at this it's an uptrend you know all right that's basically it for uh
Info
Channel: Anthony GG
Views: 10,345
Rating: undefined out of 5
Keywords: prometheus, monitoring, grafana, go, golang, vim, vscode, microservices, golang microservice, prometheus monitoring, devops, metrics, prometheus monitoring tutorial, what is prometheus monitoring, prometheus monitoring with grafana, prometheus monitoring tutorial for beginners, programming, software, web developing, web developer, engineer, vscode vim, programmer humor, software engineering, prometheus setup, prometheus tutorial, devops tools
Id: LKBl6lN6ENk
Channel Id: undefined
Length: 31min 5sec (1865 seconds)
Published: Wed Apr 19 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.