C
C#2y ago
Cuda

❔ How to modify aspnetcorehealthcheck to add devices programmatically.

I have aspnetcorehealthcheck on a .net core app. Everything works fine. How would we go about and adding new devices to check? I can't seem to find how to do this.
57 Replies
snowy | switching accounts
New devices? What do you mean by that?
Cuda
CudaOP2y ago
I mean like to take a healthcheck you need to add it to the program.cs file. How would we do it to add it programmatically instead of adding it in that file
JakenVeina
JakenVeina2y ago
uhhh I feel like we're still missing something for one, what the hell does "programmatically" mean if writing code in a .cs file ISN'T that? what are you talking about with "add it to the program.cs file"? like, specifically? IServiceCollection.AddHealthCheck() and IApplicationBuilder.MapHealthChecks()?
Cuda
CudaOP2y ago
I mean like for this to work we have to edit the file.
JakenVeina
JakenVeina2y ago
for what to work?
Cuda
CudaOP2y ago
aspnetcorehealthcheck the npm module.
JakenVeina
JakenVeina2y ago
.....we're talking about Javascript? that doesn't appear to be a registered npm module
Cuda
CudaOP2y ago
sorry no it's aspnetcore it's a healthcheck module from npm. it's under aspnetcore.healthcheck. We can try again tomorrow need to catch some 💤 .
JakenVeina
JakenVeina2y ago
still don't see that on npm in any case, I'd still like you to answer any of the previous questions
Cuda
CudaOP2y ago
aspnetcore.healthchecks.ui it's this one specifically.. no it's not javascript
JakenVeina
JakenVeina2y ago
well, that's what npm is node package manager
Cuda
CudaOP2y ago
Ok well I'm not really trying to add anything with javascript ..
JakenVeina
JakenVeina2y ago
yes, Nuget Package Manager has the same initials, but node has the damn trademark on "npm"
Cuda
CudaOP2y ago
lol.
JakenVeina
JakenVeina2y ago
so back to the questions at hand
what are you talking about with "add it to the program.cs file"? like, specifically? IServiceCollection.AddHealthCheck() and IApplicationBuilder.MapHealthChecks()?
and yes, feel free to return tomorrow
Cuda
CudaOP2y ago
yes those are what I'm referring to. Ok appreciate the help.. 👋
JakenVeina
JakenVeina2y ago
so, now I'm going to ask "what is a device, then" cause that package does not have any concept of "devices" it adds middleware to your pipeline that responds to a single endpoint the response that the endpoint gives is based on how many IHealthCheck implementations you have registered and those can be... basically anything you want if there's some set of "devices" on your server that you want to check for some sort of status, write the code for that, and stick it in an IHealthCheck class if that list of devices can change over time, then write the code for that
JakenVeina
JakenVeina2y ago
Health checks in ASP.NET Core
Learn how to set up health checks for ASP.NET Core infrastructure, such as apps and databases.
snowy | switching accounts
Nick Chapsas
YouTube
The Best Way to Add Health Checks in Any .NET App
Check out my courses: https://dometrain.com Become a Patreon and get source code access: https://www.patreon.com/nickchapsas Hello, everybody, I'm Nick, and in this video, I will show you the right way to add clean and elegant Health Checks to your .NET application. I've never worked in a company, big or small, where we did not have health chec...
Mayor McCheese
Sounds like they have devices that they want to add at runtime; so like modifying configuration gets new devices added
Cuda
CudaOP2y ago
Ok just got back been a busy morning. yes correct. Ive seen those videos. like i said its up and running. everything works ok. But say i wanted to just add a website or service i want to monitor. I have to keep editing the config files like program.cs. I dont want to keep editing those files manually. I want to create its own front end to make this process easier. Hope I make sense.
MODiX
MODiX2y ago
JakenVeina
if there's some set of "devices" on your server that you want to check for some sort of status, write the code for that, and stick it in an IHealthCheck class
React with ❌ to remove this embed.
Mayor McCheese
You can always load some assemblies from something like blob storage, or s3 and write some code to add them at runtime; otherwise you can use some custom configuration to achieve a similar effect; there's pros and cons to both.
JakenVeina
JakenVeina2y ago
if all we're talking about is monitoring some websites, that's hardly necessary
Mayor McCheese
He says devices; I'm assuming they need to set up some complex custom health Checks
Cuda
CudaOP2y ago
Lets forget the devices part I mean essentially monitoring a websites uptime as an example.
JakenVeina
JakenVeina2y ago
write the code for that and stick it in an IHealthCheck class
Cuda
CudaOP2y ago
Right but what I'm confused is if this npm module (if this is what is called) autocreates it's own db (say sqlite for example) and it uses whatever is in the program.cs class to stick into the db. How do we use our own db to manipulate without using the builder class...etc..
JakenVeina
JakenVeina2y ago
this npm module (if this is what is called)
Nuget Package
autocreates it's own db
it doesn't oh, son of a bitch okay this is a goddamn third-party package why do people insist on naming their shit after shit they don't own? you're not Microsoft, you have no business using an established microsoft product name as a prefix on your own package okay
Cuda
CudaOP2y ago
I agree wholeheartedly. But oh well...
JakenVeina
JakenVeina2y ago
so AspNetCore.HealthChecks.UI
Cuda
CudaOP2y ago
yup that one All I do is asign it my say.. sqlite db and it starts pouplating it..
JakenVeina
JakenVeina2y ago
bottom line, you either read the docs for THAT product that tell you how to dynamically change what health checks are enabled/configured or you reverse-engineer it and figure out how or you accept that it doesn't support such a thing
Cuda
CudaOP2y ago
lol. I was hoping I didn't have to do that....
JakenVeina
JakenVeina2y ago
so, like does this package not ALREADY do that? kinda what it looks like, from screenshots on the list of health checks, there's a plus button is that not for adding new health checks?
Cuda
CudaOP2y ago
hmm....don't think so let me try
JakenVeina
JakenVeina2y ago
I don't see anything in docs for configuring the health checks to perform, in code
Cuda
CudaOP2y ago
Cuda
CudaOP2y ago
Doesn't allow to add.. It's just to expand it. Yeah the docs are empty
JakenVeina
JakenVeina2y ago
I see configuration for what do DO with health check info you can create API endpoints that clients will call to retrieve health-check info you can create webhooks for publishing health-check info you can create an endpoint for the UI show me the code you want to make "programmatic"
Cuda
CudaOP2y ago
ok
Cuda
CudaOP2y ago
Cuda
CudaOP2y ago
thats under
JakenVeina
JakenVeina2y ago
what is .AddHealthChecks() there?
Cuda
CudaOP2y ago
Not sure to be honest. That is what the documentation asks to add to be able to monitor these.
JakenVeina
JakenVeina2y ago
yes, what IS it? where is it defined?
Cuda
CudaOP2y ago
Cuda
CudaOP2y ago
You mean This?
JakenVeina
JakenVeina2y ago
yeah, but don't cut off the top
Cuda
CudaOP2y ago
JakenVeina
JakenVeina2y ago
:/ there SHOULD be a line there that says what assembly it's being pulled from, but whatever so, that's actually NOT the UI package we're back to where we started all the UI package is doing is polling the Microsoft HealthChecks system and saving that data for later use also, providing a whole bunch of ready-made health check implementations for existing services you're limited by the configuration that the health checks system allows you have two options A) build a system for building the health checks service from config I.E. read from config to decide each .AddXXXHealthCheck() call you make write to that config from your new custom UI and force a restart of the app each time it changes so that it re-reads the config and re-builds the IoC container cause that's just the limitation of how the IoC container works B) build your own implementation of IHealthCheck that is dynamic
Cuda
CudaOP2y ago
Ahhh.....ok... Makes sense. Hadn't thought of it that way. I was hoping there was a more straitforward way of doing it with this.... But yeah what you are sayin makes sense.
JakenVeina
JakenVeina2y ago
in theory, you might be able to reuse all those existing IHealthCheck implementations WITHIN your custom one as long as you can collate the results that those checks produce in a way that preserves what they would look like when separate so that the UI layer still interprets them properly but there's a chance you'd just end up just re-doing a full IoC container inside your custom IHealthCheck to preserve all the dependencies at that point, how much value is there really in the custom solution?
Cuda
CudaOP2y ago
yeah it sure looks like that's the right approach to this.
JakenVeina
JakenVeina2y ago
there's really nothing terribly WRONG with restarting the whole app to reload changes I would think A) that's not gonna happen terribly often and B) you can still embed that within your code, to make it relatively seamless
Cuda
CudaOP2y ago
yeah gonna weigh my options here to take a choice...but yeah appreciate the help with this..
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server