How to Monitor a Golang Application with Supervisor - Golang Web Development

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay guys welcome back to the channel this is tutura series number 20 here in maharakan's code okay so we would like to continue our supervisor tutorial guys regarding this supervisor d which uh right now we need to deploy our golang web server and then monitored by this supervisor um utility application for us to uh to keep close so keep an eye on our application and of course it's an automated one guys if our again if our uh production server suddenly uh restarted or booting up or something like unexpected uh uh restart or our application itself will uh suddenly is restarted or something isn't any unwanted eventualities that our application might be interrupted then we need to uh it is someone or some somebody or some like other tools should should automatically boot up our golang web server so in this case we will uh put this uh golang web server right now and where we're doing the go run main.go in our ubuntu there but it's not ideal because although it's we are still developing guys but i will give you some idea already in the future that you need to deploy after you have done all your codings and everything uh and then you need to deploy and go build and then go release so that it will be uh it will be your binary application or indicates your golang project so it will be compiled into a binary so nobody can see your source code okay so let's dive into this tutorial guys okay guys welcome back to the channel okay this is the supervisor right now uh when we access our ip address and then the port number column the port number is nine thousand zero and which is the default one we can you can always change the port number guys uh in this case uh again i will highlight again uh to you that this one should be highly confidential kind of thing in your configuration guys i no need for you to expose of course the port number for your supervisor but in this case uh is an exception because we are discussing uh together and then sharing it with you on how we can use this supervisor to monitor our applications that it will be keep running and even though the server is shut down or even even the surveys uh booting up or is has been restarted then our um then this supervisor will uh launch our application um when the moment the os has been uh boot up guys so um no need for us to scratch our head like uh our application is not running then the user uh start making noise okay so um right now we don't we don't have anything to monitor we would like to add one item which is our uh maharlikan's code which is this uh kind of thing guys so i need to clear first um the moment that we need to run right now this one guys go run main.go when we run this uh this idea guys because this one is currently on the development mode so when we refresh this of course it will uh open up our page again our uh this project right now we need to change this uh concept because this one is uh running locally here in our web server although it's still in the development mode but uh i just wanted to give you some idea in the future that after we finish uh our development works then we are ready to deploy to our production server or something we need to compile our go program guys so that uh all our source code will be compiled into one binary in this case in the linux here we will compile everything here so just say we just want to stop here because we don't want to run this one guys so what we can do is we need to go build guys okay i just want to prepare this one first so right now we are building uh our application here right we don't have we need to refresh first okay there is a binary here uh called the go web app because this is the name of our project um we need to go install this one guys so we need to install this and then it will become it will it will be automatically moved that the binary file there uh this binary will automatically move to the go in this case i i install go in uh under the root user here or i mean in my go here but in your case uh probably it should be there as well um it depends on your server path or something in this case guys i need to execute one command which is uh go install okay so and go back to the console there this file will be removed later in the go web app and then move to the go bin there so go install um basically it will just move to whatever the the location uh right now we don't have the location of your go when you search when you execute this go a and b which is the environment then you then you will know where is your golang gobind or something guys right now we don't have the beam here the bin folder because this is our first time to uh go install execute that command we need to refresh this one guys okay so the bin is here is present and then the go web application so in the future all your go programs uh when you the moment when you go install or build and then go install it will be throw everything here in this folder the go bin okay when you look back to your gold web uh this one you need to refresh okay so the file also just basically just move to whatever the go bin there then it will be this would be the what they call this uh the location of when you go install okay so right now we have some go binary and then we will call this this go web app by using this supervisor so we need to register this uh go web app go web app okay so this is the thing and then basically we need to write some of the script here for the configuration for the supervisor guys okay so we need the directory here and then uh i need the root uh gold and bin so basically my bin is here okay guys so this is the part here so you need to register alongside and the command need to find this go root uh root go then bin and then go web app okay basically this is the command that we need to call this one guys this binary here need to execute this binary inside this road go bin folder okay so we need to auto start these are all the standard command for the what they call the supervisor guys auto restart restart as well should be true okay auto start now you need to enable all these things guys start uh retries so we need to retries guess if something like you can this one is an integer value here like for example 10 times you keep retries when the starting up or when the first because we enable the auto start it's still not enabling if it is not uh enabled yet or started yet it will keep retrying this up to 10 times so it's up to you guys you can put more values here but um this one is a good enough for any guy so uh stop uh us group uh stop us group okay we just want to make it through as well guys this one is in the entire group but basically we have only one file so uh to run at the moment in this group you can consolidate i mean you can group together all these applications but that one is a more a bit complicated configuration guys so right now we have some straightforward so we need to put some note here guys unlock any events from this uh web service okay you just want to note like this um okay so uh cd out std out and then uh log file so basically i uh to capture our time guys i supply everything this one these are all the standard uh command or syntax for supervisor you can specify the stadia log file these are all the log related files guys so any uh the std out the std error or something like you can specify also the maximum log file size to a maximum of 50 mb or it's up to you guys and then log file all this standard one so these are your log file name but uh currently we don't have this one yet so now you can specify whatever uh your directory here guys so i think right now we don't have this at the moment okay so i'll just scroll over to my supervisor here uh hold on guys where is this okay i think we don't have yet so i can just create a new log file here guys called the logs folder okay because i in my configuration there i need to throw the any errors uh related to the supervisor throw to this log folder here so i just created one guys because uh we basically uh throw everything whatever the logs there okay but of course there is a safe limit which is the 50 mb so it will be just um i don't know how the the manage this supervisor one okay so we have some new configuration here we need to upload to our to this supervisor and that is a conf and then uh we'll basically upload this uh new configuration here uh under this con f.d folder so we have already this configuration guys that we have just created here okay so what we can do now is we need to restart our vertical supervisor here the service so sudo service supervisor and then restart this is the command guys okay so now totally restarted one so we need to go back here uh right now uh i just want to illustrate to you that we don't run the go run main let go now when we refresh this of course uh it will be through the five zero to band gateway because we never run our web server so we need to refresh this okay so this is the thing guys we have some program registered successfully here the state is just started okay so this is the name we have registered just now which is the go web app so you can just restart you can stop here as well okay you can start it again you can restart all right so if you have multiple things to monitor here guys so basically we will try to run this okay uh still okay we'll just uh uh monitor this file i guess all done guys so okay guys i downloaded the file here which is the logs so this is a good thing if you have a log here guys so um okay basically when you go to the supervisor there and then we can just check all these logs here because we already throw all the logs here guys so basically i downloaded here all the logs and then i check all the errors here so basically the error here is say saying that the html all the html file guys that one is not compiled of course this one is a it's not the go related scripts these are all the html external files so uh we need this html file to be uploaded remember that in our um what do you call this in our go web application guys uh we we have all these uh what they call these html files here okay so basically these are all our index html all these things guys so this means this one should not be this one is my demo only guys just okay so uh okay so we download all the html folder to the bin there okay i already uh uploaded everything guys so basically then it will create a autolog here again so our logs also working in in our deployment so um basically we need to enhance further um our directory here guys once we launch because if you have a multiple of projects here all inside a bin and then we need to specify or rename this folder itself like uh in our html there so uh in our project structure so we need to rename this one guys so like html something like uh something like when you rename so later when we we rename guys okay no worries uh i just want to give you some overview because we need to lamp everything here in the thing so like uh like a go web app or something like go web app guys so something like this okay but right now our program is uh specified uh under this folder like uh called the html so basically all the deploy deployable golang projects here will be thrown into the go bin into this uh directory guys so all your html and then your logs should be yeah there there's some kind of indicator guys okay okay so because we what already uploaded and then all the html only the html guys okay you need to deploy only the html and then the logs okay so the rest of course these are all go program our web server this one is no need because it's already compiled on this go web app as long it is a go file go program go scripts it will be all compiled into one binary file called in this case in our project name is your gold web app so everything is intact here guys so after your uh [Music] the development of your uh web page or i mean the uh in our project this is our source code right uh when we finalize everything or if you have another web server for a web development assume that this is our assume that this is our production totally no source code there guys okay what you can do is uh you need to build only there you need to deploy the source code there and then you build it from there or you have some exact replica of your uh what they call this um ubuntu web server or your linux web server then uh no need for you to to do that so you need to just copy the binary and then place it over to the bin there okay so you just upload the binary and then all your html files like this and then our logs is automatically created guys so basically you can just rename this as well uh this itr log there is a configuration also this is our own um package here so you can just rename the initialization there or you can throw everything to logs here or you can group together is it's up to you guys so okay if the log is a different file file name like itr log or something like a go web app or your application name then you can just throw everything into one logs folder but with different file name or you can just group together into a different folder this one is there is a configuration so this one is all customized one guys so for the sake of simplicity at the moment assume that we have one go application that runs on the web server in our production server so this is what we call the go web app for example this is our project so the structure is like this okay and then you then you upload all your html under this go bin so when we try uh refresh then it's working guys so basically when we launch i just want to illustrate to you that uh okay so i'm not running the go run here guys okay i just want to clear first i'm not running the go run main.go okay basically when i stop this service here okay the status in the supervisor this application is already stopped when we refresh this okay okay then it's a good indicator that our uh application is totally running and take care of over the under this uh supervisor okay guys so uh when we restart all or you want when you want to start let's see what will happen then we refresh again then it's okay guys okay retry for live version okay that one is for the cloudflare club that will also take care of our site so now it's totally running guys when we want to stop again just to ensure refresh okay it's not running again okay because we are already stopped when we restart oh let's see so now the status is running with the pid here okay the half time you can also use all these things okay so the supervisor is really important guys okay this is very very important for us because any any eventualities our web server this one although we are hosted in the cloud there but sometimes our server suddenly or the maintenance there or something like that guys in our hosting or whatsoever then or you want to restart your application you want to reboot or power on again then of course your supervisor will take care all these registered programs here that they want to monitor so right now it's running and then it will be auto start when the when our web server here is uh booting up again okay guys so right now we need to refresh okay now our application is totally take care of the supervisor so our web server is running smoothly and then take care of all this uh configuration here it's just a simple configuration here guys this one is just along with this one these are all the standard configuration for any kind of a go web application if you're running with the jungle is a jungle or python kind of thing you can also add some commands here okay so you need to add some like the command here is different guys because uh for golang is quite straightforward you just call this uh execute this go bin this binary this binary here under this go road bin under the go bin directory uh without any argument or something the the parameters something like that or the commands but for any kind of like a django application uh running with the if you want to run those hillary or celery or the flour those are workers or your jungle something like uh something like your bean celery and then all these basic code there is some a lot of arguments here they can just put like a port number you can add like that guys this one for go is so simple and straight forward guys okay but for other uh applications like all those uh um what they call this uh go i mean python or jungle you can add multiple um what they call this uh parameter like a dump needed so you can just uh bind together all those port number and then uh there are some commands guys um basically but for our go web program here is a very straightforward just call this binary and then uh okay so okay guys because we already installed into the go bin there we go i actually stopped here and then we refresh okay it's not running guys uh the moment that we go install and then all our binary is already here guys okay even if you even if it's not a web server or any kind of a simple one uh you can just call now that binary guys go web okay without the go run or something because now this is executable and callable inside the linux service server guys so you can just press this and then automatically it will run also our web server so when we run this is the manual way guys okay so i just want to illustrate to you refresh so i think uh because right now we need to uh upload all again our html file uh to the main or something guys when you run under this uh you see there is a matter already because we i already i'm not in the go root there although okay because it's in the main here uh what i'm going to do is cd i need to navigate to the where is the html location guys but if you don't have a html kind of thing it's just like a web server or something or any kind of a go program without any external html file needed to run that uh web application or go go program then you can straight away call that okay anywhere but the thing is we have this dependency which which because this one is a web uh web project guys so of course we need html there basically i need to navigate to this thing because the html files files are here so what we can do i just want to illustrate to you uh cd go web app okay ls so this is the home okay so we don't have the binary here but uh we can just call straight away the go web go web app okay so now the web server is running let me try to refresh okay then okay guys uh we don't use the go run main because we already have the compile one so every time do you have some changes or you have changes to your uh go program of go application you need to repeat again to go build and then compiled again guys your application go install okay now this one is totally executable okay so we don't execute with the go run main then go these are all executable binary file okay but if you are using the windows os then this one is a different case because you need to again that one is a go webapp dot xc already guys so it's it's a it is already executable if you're running with the windows os but in our linux here then it's okay same thing with the windows guys uh you need to deploy also the corresponding html files the entire html folder okay this is a good thing of our [Music] project structure in the uh in my previous discussion guys we have this go web application i mean the html the project structure because we can just uh easily you can just migrate this html folder okay we have some just some minor changes you can just rename this with the html underscore uh some like some kind of a unique indicator like the go web app okay you can just rename this in our source code so in our next discussion we will probably do that because we have noticed here in our bin uh that this one is a too generic here the folder name so we would like to isolate uh those uh belongs to the what they call this go web app binary here the executable one this one will also it will put some indicator if you have a multiple project of course we have some multiple projects in one server guys so here basically we need to group together or uh indicate with some unique uh identification based on this uh binary like a go web app and then you can we can just also renamed this easily in our project here guys so okay um that's all for today guys and then uh right now i need to stop this pro uh we need to monitor it with using this now i already stopped and then refresh again then our web server is not accessible okay so when i monitor this with the supervisor here okay so we need to now it's running then refresh then okay this one just use the live one okay so that's all for today guys and i hope you enjoy our tutorial here guys okay guys that's all for today's discussion and i hope you enjoy our tutorial series here in markets code and i hope i impart with you some uh valuable experience guys that we that we have discussed uh in this uh in this tutorial today and then uh probably in our next uh the video in our next material series and here in malik's code we can well probably we can now start our uh what they call this uh login package we call it the yabi package it's like a key uh the name is a localized name for from my place so um this uh the name is the yaobi so that means it's a key so this one is for the generic kind of user in um what they call these users login system guys but we are using the mysql databases we already set up our database server their mysql database server into our production site then we can slowly create our user interface of course we will be using the wasam there we also know how to use the wasa and then we call the api inside the wasab uh the web assembly what i mean guys so so right now all our infrastructure uh maybe you if you are new or a student uh probably you may be it's too overwhelming for you to to learn a lot of configurations because our site normally is as a developer programmer um it will be like a full stack kind of thing guys so we will uh we will know how to install but uh if you have some robust of course the organization is a lot of people there like separating like a server team they can install whatever you need for the developer but as a developer kind of thing a point of view it's a good thing that we know how to install everything guys for our site although we set up the ubuntu setup the mysql database we set up the https configurations everything because you know more knowledge is uh is more better guys than um than other people sometimes in sometimes in other cases um it's not the sometimes is uh too many people list too many con too many what they call this a lot of discussions or all of these things if you have uh that one is fine because that one is an organizational structure but if you are doing it alone for your own projects of course you don't you don't you don't rely to other people okay so and this is what i want uh i want you to uh to be here in marlinkans because we would like to to be uh reliable in our own self we are self-reliant this is what i want to portray here in americans code because uh normally we don't we don't realize if we have our own personal project guys so this is very important because everything you need to set up by your own self this is a good knowledge and good um um uh what they call that we call it the self-reliant guy so again you can be a full stack uh full stack developer so you don't um uh incu inquire additional cost for your whoever installed the server you have some limitation guys so um i hope i impart with you some knowledge now this one is decent enough we can manage our server by our own self we can develop the program application everything then we deploy by our own self as well um okay so i i hope i impart with you some good knowledge and i share it with you guys for my contribution to you in our society there okay especially in my country the philippines okay so thank you so much for watching my video guys and i hope you enjoy and uh share i share it with you some good knowledge here and then with of course in the actual uh guidance and then the step-by-step guides um this is what uh we can learn here in marlinkan's code if you if you're not subscribed yet can see please consider subscribing so that you can uh have more videos like these guys so on this um this is a very huge topic here in uh golang web application here so we will deal with many kind of uh techniques and then we will learn together and grow together here okay so thank you so much for watching my video may god bless us all thank you and [Music] bye-bye
Info
Channel: Maharlikans Code
Views: 175
Rating: undefined out of 5
Keywords: Life As Software Developer, Maharlikans, programming guides, step by step guides, go, golang web development series 20, golang web development course, web development with go, golang tutorial, learn to create web applications using golang, building scalable web apps in golang, golang good for web development, Monitoring a Golang application with Supervisor, supervisord, supervisorctl, server supervisor, supervisor inet_http_server
Id: Bd9KSopLNtM
Channel Id: undefined
Length: 34min 20sec (2060 seconds)
Published: Fri Dec 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.