C
C#17mo 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
Cuda17mo 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
JakenVeina17mo 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
Cuda17mo ago
I mean like for this to work we have to edit the file.
JakenVeina
JakenVeina17mo ago
for what to work?
Cuda
Cuda17mo ago
aspnetcorehealthcheck the npm module.
JakenVeina
JakenVeina17mo ago
.....we're talking about Javascript? that doesn't appear to be a registered npm module
Cuda
Cuda17mo 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
JakenVeina17mo ago
still don't see that on npm in any case, I'd still like you to answer any of the previous questions
Cuda
Cuda17mo ago
aspnetcore.healthchecks.ui it's this one specifically.. no it's not javascript
JakenVeina
JakenVeina17mo ago
well, that's what npm is node package manager
Cuda
Cuda17mo ago
Ok well I'm not really trying to add anything with javascript ..
JakenVeina
JakenVeina17mo ago
yes, Nuget Package Manager has the same initials, but node has the damn trademark on "npm"
Cuda
Cuda17mo ago
lol.
JakenVeina
JakenVeina17mo 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
Cuda17mo ago
yes those are what I'm referring to. Ok appreciate the help.. 👋
JakenVeina
JakenVeina17mo 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
JakenVeina17mo 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
Mayor McCheese17mo ago
Sounds like they have devices that they want to add at runtime; so like modifying configuration gets new devices added
Cuda
Cuda17mo 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
MODiX17mo 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
Mayor McCheese17mo ago
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
JakenVeina17mo ago
if all we're talking about is monitoring some websites, that's hardly necessary
Mayor McCheese
Mayor McCheese17mo ago
He says devices; I'm assuming they need to set up some complex custom health Checks
Cuda
Cuda17mo ago
Lets forget the devices part I mean essentially monitoring a websites uptime as an example.
JakenVeina
JakenVeina17mo ago
write the code for that and stick it in an IHealthCheck class
Cuda
Cuda17mo 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
JakenVeina17mo 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
Cuda17mo ago
I agree wholeheartedly. But oh well...
JakenVeina
JakenVeina17mo ago
so AspNetCore.HealthChecks.UI
Cuda
Cuda17mo ago
yup that one All I do is asign it my say.. sqlite db and it starts pouplating it..
JakenVeina
JakenVeina17mo 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
Cuda17mo ago
lol. I was hoping I didn't have to do that....
JakenVeina
JakenVeina17mo 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
Cuda17mo ago
hmm....don't think so let me try
JakenVeina
JakenVeina17mo ago
I don't see anything in docs for configuring the health checks to perform, in code
Cuda
Cuda17mo ago
Cuda
Cuda17mo ago
Doesn't allow to add.. It's just to expand it. Yeah the docs are empty
JakenVeina
JakenVeina17mo 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
Cuda17mo ago
ok
Cuda
Cuda17mo ago
Cuda
Cuda17mo ago
thats under
JakenVeina
JakenVeina17mo ago
what is .AddHealthChecks() there?
Cuda
Cuda17mo ago
Not sure to be honest. That is what the documentation asks to add to be able to monitor these.
JakenVeina
JakenVeina17mo ago
yes, what IS it? where is it defined?
Cuda
Cuda17mo ago
Cuda
Cuda17mo ago
You mean This?
JakenVeina
JakenVeina17mo ago
yeah, but don't cut off the top
Cuda
Cuda17mo ago
JakenVeina
JakenVeina17mo 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
Cuda17mo 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
JakenVeina17mo 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
Cuda17mo ago
yeah it sure looks like that's the right approach to this.
JakenVeina
JakenVeina17mo 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
Cuda17mo ago
yeah gonna weigh my options here to take a choice...but yeah appreciate the help with this..
Accord
Accord17mo 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