 Thank you, so I think I'm live. Yes, you are hopefully cool. So let's start Yeah, I will talk about the ASP.net core health checks Today but first I Will quickly introduce myself. So my name is Jürgen Gutsch. I'm from southern Germany. I'm a Microsoft MVP for several years five years I think I'm blogging writing a Lot leading it on a user group since years and Speaking at several community events and meetups and I also started a stream on Twitch not regularly But from time to time I'm a software engineer at the U in Basel. So so I'm working Switzerland living in in southern Germany Hopefully the sound is good last time last year. This is the first 10 minutes were awful, it's it's going well this time So I have a quick agenda I need to quickly Close not close minimize Skype window. So I see two versions of the agenda currently so yeah, I will quickly quickly introduce ASP.net core health checks and Then I will show a basic implementation of the health health checks And there are also a lot of Checks in the community. So we'll have a quick look there and how to visualize the health of subsystems of an application and If there's some time left, I will show you quickly and enhance scenario So I built something with Docker containers to show how this could look like So all the sources I will show today are will be available on GitHub. So the repo already exists But I will push it afterwards So what's next exactly about the health checks? What are the health checks? So that's health checks are kind of on framework inside the ASP.net framework to check the health of Application subsystems, maybe databases or services, which are not inside the application or you can also check Your system you can check memory you can check Your space of your hard drive, whatever you want to check You can also handle the the health of your subsystems to get a feedback The checks give you the state of your subsystems and you can Handle them. You can show the states in your application And you can provide an endpoint to show the information about the health of your current application and of the subsystems of the current application so the namespace is Microsoft.extensions.diagnostics.healthchecks. You'll find all the stuff here and yeah a little bit of history So I'm was pretty much involved into health checks. So the development started at 2016 I think I'm not sure when exactly But during the MVP summit in 2016, Glenn Kondren asked me on via Twitter If there's anyone who want to attend the ASP.net hackathon and help him to write checks for the ASP.net health checks the first version I think it was a draft at the time So Damien said yes, I said yes, and we met Glenn Kondren and another nurse at the ASP.net hackathon and started hacking some checks Then it moved through some repositories until it makes it into the product. So it is in the product still ASP.net code 2.2. I think What can you do with health checks? You know, well, maybe you mentioned it It is monitoring the health of parts of your application or Yours or subsystems of your application image on a databases some web APIs, GRPC services, any other services or The environment of your application you can check memory performance drive space and so on and You can provide the health side of your application including the health of the subsystems You want to check so you get an endpoint that Tells you about the health of the whole system of the entire system. I think yeah, that's Almost about the theory. Why should you use the health checks? Yeah, you can handle unhealthy states in your application You can maybe provide information to the users That some of the subsystems or databases are not available currently You can keep your partially running in case of an unhealthy state of a subsystem maybe there's Yeah, a specific database not running and you can keep your Application partially running without these database for example or to you can tell the users about the unhealthy states and so on You can switch to alternative subsystems in case of an unhealthy state of this specific subsystem Maybe you have a different one and What I didn't mention here in the slide is you can provide an Endpoint, I think it's exactly same endpoint to The what is called Azure load balancer thing So you can connect your Azure environment to this endpoint and the load balancer can is able to to switch the applications Or the this switch between the instances of your application Okay, let's Show some code on this section. I will demo you a simple implementation of health checks So this is a kind of an agenda of this section Just created a speed on care a speed of net core MVC application using the net CLI I already did this then we will configure some Basic simple health checks without any logic in it We will implement a custom health check and we will use the health check service to to call the checks and to To visualize the states of the subsystems This is the basic configuration on the startup of your SP.net core application you can add the health check services in the configure service method and You need to provide the the end point I mentioned this is the end point now, which provides the state of your application including the subsystems So we say up use health checks So I think next is the demo exactly. I will switch to the console Hopefully the font size is okay. We can increase it a little bit And I'll open VS code and go to this startup and This is Common ASP.net core MVC application. I already added the health checks here The health check services and I added the endpoint. This is a little different than in the slides because in ASP.net core 3.0 we have the new endpoint routing and The middlewares which provides routes are now registered here with map Something map controller route or map health checks This is the endpoint. I mentioned so this is the basic configuration just to add health checks or just to Have the possibility to add health checks so Now I want to add a few health checks so this is a way to add Delegate-based or lambda-based health check pretty simple. This doesn't add us nothing here. It just outputs on healthy state So we can say add check Some overrides here You can do it in the delegate way or we can add a health check instance. We will see this later We can do it the generic way to add a health check type here or as well with the with the funk We get a health check result No, we return a result. That's that's so That's one. We can also return an unhealthy state some options Some things to return we can return healthy unhealthy or something in between degraded so we leave this and Have another quick sample which is more useful. I think it is a check to ping a subsystem. Okay, this one Starts a ping oops wrong keys here And did you know that you can press windows dot add emojis here? Yeah, what works? Okay We create a new ping. I Said send the ping to local host because it's currently it's hard to find the Service on Azure somewhere which responds to a ping. I think all the Azure services don't respond so I can't Ping.net conf.net also kind of ping my own block and so on so I need to find find a host to ping So if it's not a success date, then I will return unhealthy If this needs more than 100 milliseconds, I think yes Then it's degraded. It's pretty slow then And if it's all fine, I will return an healthy state So in case of errors, I will also return an unhealthy state. I think that's with the delegate Checks, but we can also create More yeah more complex checks Using classes So it's this one You can create an eye health check So I need to find the interface. It's not implemented correctly. So I need to get this one the cancellation token and Now it's implemented so it's Almost similar to the to the lambda expressions here So high in this so we will return a health check result and get a context and we get a cancellation token So this is more complex way We can check the state of something. So this is just an example. I set it to true So it's healthy and if it's if the subsystem is healthy or return a healthy state and Otherwise an unhealthy state So here this line you can put your checks whatever you want to check I Will show you a more useful sample later Okay So we need to add this Check use the generic way So I don't need to add a name next oops That's good being null. I think and here we need to add some text I have a different keyboard layout here. So now it's working. So it's switching between German and US American Layout, okay So this should work, but I This should work If I call the the endpoint, let's try it I press a fifth a five Also the language is switching between German and English Please tell me if something bad with the with a screen font size audio and so on Okay, this should work browser so Yeah, here it is. So it's running if I press a five I see something's going on here And the endpoint was It's unhealthy It's unhealthy the complete application is unhealthy because of this Here you will switch this to the healthy state to okay and restart it So this is the end point. Okay, you can extend the endpoint a little bit So I need to find the snippet for this Yeah, there's some Options we need to set and the configure and we can have these lines here Say predicate to true say response writer is the you I response writer to find the Using so this isn't there. Let's check the namespace options response right to remove this I Will show it in the next demo then Okay, that's about the one end point, but what about visualizing so to visualize the the health of your application I Can use their health check service and you can call all the checks on demand and Display result the results in your View So to do this Go to the home controller and Inject the health check service like this. This is already in the DI container so we can use it wherever we want and I'm going to add a new View also need to add the views here. So just copy the privacy and call it health and Put some code in it. Okay So we use the diagnostics health checks here our model is the health report and then we write out the The status of the model so the model is the health report We return this from the control action We can display the duration of all the checks and we can iterate through the checks and Display the state of all the checks we have Okay, let's Change this back to unhealthy return a better message And restart it. So I should be there. Yeah So we haven't Create a link for the health. I will do it so I think Did something wrong at the end point endpoint and the view Do have the same URL so we name this endpoint. No, I'm wrong. I did it wrong. So I Shouldn't have changed the the endpoint here. It should be enter home health exactly. So that's it So the state is unhealthy We need it five milliseconds seconds a millisecond So the foo is healthy. The bar is not healthy healthy And we have the ping here. We should have set the name and we have the sample health check So the ping is healthy We have a name here should be ping. We don't see it. Anyway, so It's working. We have the the health state of our subsystems here and We can also add an indicator To the page to see If the entire application is healthy or not so to do this Open the layout CSH TML dependence injection here So you can do a dependence injection in your view. I inject the health check service and I use it and a code block put it here So we await the check health async and With this we get the health health state. So I think this is a health state response or health result So we can see it here This is a health report Okay, we have the same in the layout and we can check the states here so as set a background color in case The state is unhealthy degraded or I don't set it in case it's all healthy So and I'm able to set it here and let's see what happens. I need to rebuild it. I think Yeah, so let's close this one No, that is red and unhelp and if you change this Let's say this is Take rated To rebuild it again, it should be orange them Or whatever set here Orange yes So and the healthy state doesn't have a background color. So it's white. Okay. Do we have any questions until yet? If not, I will continue with the slides Hey, you're there Let's have a quick look into What the community did? So what I expected after I Had another look into the health checks health checks Aposts playing around with the health checks for a year or so and it didn't had a look until this time this period and After I had another look I expected some health checks created by Microsoft, but there are almost no health checks The reason is that it's pretty simple to implement some and the other reason is that The community already created a lot of health checks. So if you see this slide Yeah, if you're interested go to this repository, that's but I saw burial I'll pronounce it right. He created the ASP.net core diagnostic health checks package packages On the right side you see a list of of nougat packages available. So you can check the system You can check networks. You could serve a MongoDB and so on Redis event store CQlite a lot of Azure stuff also I'm Amazon web services can't be check tank fire signal are and so on Kubernetes And I think the list will increase a lot. So this project is port from beat pulse and it also provides UI features So I'll Show you in the more enhanced demo So, please have a look also use some of these packages to check SQL server or SQLite and so on Also try to check SQLite, I think this doesn't work currently I need to check it again. Maybe I did something wrong Or if not, I will raise an issue here So it wasn't possible to connect to and SQLite Database inside a Docker container. That didn't work Okay So about the health check UI also into this project. They created a pretty nice health check UI so we can add it with With this service registration and with these Middlewares here and this also provides another endpoint Which is Specific for this UI And it also provides a health checks UI endpoint with a nice HTML UI. So let's have a look what I did for this demonstration, I created something like dummy weather statistics application and downloaded a lot of weather data from Washington State. I have Implemented four different weather stations pre-maton, Cedar Lake, Kent Monroe and a health monitoring app What's missing currently is where the data visualization app, but this is not important here, and it's all running on Docker So let's have a look. We'll close This one here and go to the console This one, OpenVS Coach So these are Six applications. This one doesn't count. It's not implemented yet Added a common library to share classes also shared the The DB context This is this is the health monitoring app and we have the four different weather stations here I'll go through You have core to connect to the SQLite database. So this is all wired together with Docker compose This is the Visualization app, the health visualization Export some ports. It depends on the four stations and also need to link the the Docker containers together There's this Docker networking stuff here and I created four different Docker files per Container one to run so So let's quickly look here This is the configure services of the of the check visualization app So I created the dummy foo Health check just to check whether it's working or not And I added a database context check. I Think this is the only health check provided by Microsoft the only Finished health check Then I added a check for URI so this is called you're a group. It's in the URI package You can set your eye you want to check give a name Like with the other ones you need to tag this or it makes sense to tag this Maybe to filter it later on so I created for ping checks and for data checks this one for checks only Check whether the services are available or not and the other one are really loading data and Check whether there's a result or not so I also added the health checks UI and I'll also set it to the To the To the apps here, so this is the health checks. This is what I wanted to show in the previous demo You need to define a different response writer and With it this you can enhance your own endpoint to add some more information. I will show it quickly And I need to add the health checks UI middleware So I don't want to start it here with VS code. I use the console and run docker Compose up It's all compiled It only needs to start so all the services are available So we see the name docker container here tennis here. This one is the monitoring App and the other ones are the stations so Let's call it It's not hdps And it's running. This one is just a single web API Application and this is our endpoint we extended so now we get a JSON result. We got this date here It's not a longer a simple text And we get a lot of more information So the duration we get all the entries these are all the checks we have The health checks I also provides an endpoint. This is almost the same but Needed for the for the UI So This is The Health checks you I provided by these guys by the community So and here we see all the all the Services that are running So these are running in the docker container This is in the also in a docker container, but in the in the visualization app And this is our dummy Just to check so what happens if we Kill one of these This with a little bit so here are the containers running so Little bit bad. We'll resize it all the way around so like this I want to kill one of them The weather station in Kent was Some It's just docker kill it's It's not docker container kill really Try it with dr. Container. There you go. Yeah. No, it's killed. Thank you Yeah, almost almost done. It's just this last demo Okay, you can see now the the station in Kent was offline. It's offline and You see the checks are unhealthy. Okay So that's pretty much it I say thank you and hopefully you enjoyed it I really like seeing the the level of community interaction here with the health checks. You're right they're so simple to write and Already so many of these that really help with those other integrations and services that we want to know the health of Yeah, absolutely. There's a lot of implementations here a lot of documentation and from the community Yeah The user interface do it right. We saw the same thing with the folks who do swagger stuff to have health checks. You why? It's it's something every user administrator is going to need. Yeah, so absolutely. Yeah, I didn't know that was out there I'm I definitely need to make sure I add that to my applications going forward Yeah, great. All right. Thanks so much. You're good. Thanks a bunch here again. Thanks to you. Thanks for hosting Thanks for having me. All right, and we will see you next time Bye-bye