❔ 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
New devices?
What do you mean by that?
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
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()
?I mean like for this to work we have to edit the file.
for what to work?
aspnetcorehealthcheck the npm module.
.....we're talking about Javascript?
that doesn't appear to be a registered npm module
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 💤 .
still don't see that on npm
in any case, I'd still like you to answer any of the previous questions
aspnetcore.healthchecks.ui
it's this one specifically..
no it's not javascript
well, that's what npm is
node package manager
Ok well I'm not really trying to add anything with javascript ..
yes, Nuget Package Manager has the same initials, but node has the damn trademark on "npm"
lol.
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
yes those are what I'm referring to. Ok appreciate the help.. 👋
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 thatHealth checks in ASP.NET Core
Learn how to set up health checks for ASP.NET Core infrastructure, such as apps and databases.
watch this @Sp3c https://www.youtube.com/watch?v=p2faw9DCSsY
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...
Sounds like they have devices that they want to add at runtime; so like modifying configuration gets new devices added
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.
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
classQuoted by
<@137791696325836800> from #How to modify aspnetcorehealthcheck to add devices programmatically. (click here)
React with ❌ to remove this embed.
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.
if all we're talking about is monitoring some websites, that's hardly necessary
He says devices; I'm assuming they need to set up some complex custom health Checks
Lets forget the devices part
I mean essentially monitoring a websites uptime as an example.
write the code for that and stick it in an IHealthCheck
class
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..
this npm module (if this is what is called)Nuget Package
autocreates it's own dbit 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
I agree wholeheartedly. But oh well...
so
AspNetCore.HealthChecks.UI
yup that one
All I do is asign it my say.. sqlite db and it starts pouplating it..
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
lol. I was hoping I didn't have to do that....
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?
hmm....don't think so let me try
I don't see anything in docs for configuring the health checks to perform, in code
Doesn't allow to add..
It's just to expand it.
Yeah the docs are empty
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"
ok
thats under
what is
.AddHealthChecks()
there?Not sure to be honest. That is what the documentation asks to add to be able to monitor these.
yes, what IS it?
where is it defined?
You mean This?
yeah, but don't cut off the top
:/
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 dynamicAhhh.....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.
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?yeah it sure looks like that's the right approach to this.
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
yeah gonna weigh my options here to take a choice...but yeah appreciate the help with this..
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.