C
C#13mo 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
Cuda13mo 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
JakenVeina13mo 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
Cuda13mo ago
I mean like for this to work we have to edit the file.
JakenVeina
JakenVeina13mo ago
for what to work?
Cuda
Cuda13mo ago
aspnetcorehealthcheck the npm module.
JakenVeina
JakenVeina13mo ago
.....we're talking about Javascript? that doesn't appear to be a registered npm module
Cuda
Cuda13mo 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
JakenVeina13mo ago
still don't see that on npm in any case, I'd still like you to answer any of the previous questions
Cuda
Cuda13mo ago
aspnetcore.healthchecks.ui it's this one specifically.. no it's not javascript
JakenVeina
JakenVeina13mo ago
well, that's what npm is node package manager
Cuda
Cuda13mo ago
Ok well I'm not really trying to add anything with javascript ..
JakenVeina
JakenVeina13mo ago
yes, Nuget Package Manager has the same initials, but node has the damn trademark on "npm"
Cuda
Cuda13mo ago
lol.
JakenVeina
JakenVeina13mo 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
Cuda13mo ago
yes those are what I'm referring to. Ok appreciate the help.. 👋
JakenVeina
JakenVeina13mo 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
JakenVeina13mo 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 McCheese13mo ago
Sounds like they have devices that they want to add at runtime; so like modifying configuration gets new devices added
Cuda
Cuda13mo 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
MODiX13mo 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 McCheese13mo 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
JakenVeina13mo ago
if all we're talking about is monitoring some websites, that's hardly necessary
Mayor McCheese
Mayor McCheese13mo ago
He says devices; I'm assuming they need to set up some complex custom health Checks
Cuda
Cuda13mo ago
Lets forget the devices part I mean essentially monitoring a websites uptime as an example.
JakenVeina
JakenVeina13mo ago
write the code for that and stick it in an IHealthCheck class
Cuda
Cuda13mo 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
JakenVeina13mo 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
Cuda13mo ago
I agree wholeheartedly. But oh well...
JakenVeina
JakenVeina13mo ago
so AspNetCore.HealthChecks.UI
Cuda
Cuda13mo ago
yup that one All I do is asign it my say.. sqlite db and it starts pouplating it..
JakenVeina
JakenVeina13mo 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
Cuda13mo ago
lol. I was hoping I didn't have to do that....
JakenVeina
JakenVeina13mo 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
Cuda13mo ago
hmm....don't think so let me try
JakenVeina
JakenVeina13mo ago
I don't see anything in docs for configuring the health checks to perform, in code
Cuda
Cuda13mo ago
Cuda
Cuda13mo ago
Doesn't allow to add.. It's just to expand it. Yeah the docs are empty
JakenVeina
JakenVeina13mo 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
Cuda13mo ago
ok
Cuda
Cuda13mo ago
Cuda
Cuda13mo ago
thats under
JakenVeina
JakenVeina13mo ago
what is .AddHealthChecks() there?
Cuda
Cuda13mo ago
Not sure to be honest. That is what the documentation asks to add to be able to monitor these.
JakenVeina
JakenVeina13mo ago
yes, what IS it? where is it defined?
Cuda
Cuda13mo ago
Cuda
Cuda13mo ago
You mean This?
JakenVeina
JakenVeina13mo ago
yeah, but don't cut off the top
Cuda
Cuda13mo ago
JakenVeina
JakenVeina13mo 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
Cuda13mo 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
JakenVeina13mo 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
Cuda13mo ago
yeah it sure looks like that's the right approach to this.
JakenVeina
JakenVeina13mo 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
Cuda13mo ago
yeah gonna weigh my options here to take a choice...but yeah appreciate the help with this..
Accord
Accord13mo 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
More Posts
❔ Should procedural 2d maps be with structs or instantiated with 'new'?I am creating a game that can sometimes have a 1000x1000 interior grids in width and height. Exterio✅ public readonly bool Equals(...)? - SOLVEDI created struct for my needs of representing a phone number prefix and intellisense offered me a "p❔ How to display All the integers in a list concatenated with a stringHello! I was wondering if there was a possible way of cancatenating elements inside a list (that are❔ pick up and drop objects in top down perspective (unity 2d)I'm trying to make a top down game on unity and i want the player to be able to pick up one item at ❔ Need help trying to make 2D car move from above```cs // { if (Input.GetKeyDown(KeyCode.W) == true) { myRigidbody.velociEF Core: Keep Copy of Entity with old state when updatingHello, I am trying to update an entity and keep its previous state as a copy disconnected from the d❔ Part of me feels like I need to learn System.Linq; one day```cs float[] overlaps = new float[] { second.Left - first.Right, // left second.Right - fir✅ Handling changing Keys after an insertHello folks, I have a function that inserts new data into a sql database. the data is workflows and Picturebox not displaying my picturesI'm not sure what I'm doing wrong, my pictures don't show for some reason. This is my code: ```c pu✅ Complier Error CS0120, Can't understand why I can't call this private fieldI just had a quesiton about my code here: In my logic method, the moveOptions has a Compiler Error C