Thank you Francois and everyone for the great input and discussion. It sounds very promising indeed!
So let's say that I want to write a shell script that would continuously monitor nginx to know when an upstream server went down, and if so, which upstream server it is (IP or name).
With the approach you are proposing, can you explain how I would go about this? What would my shell script look like? It sounds like I would still need to modify nginx or write a module to monitor for this and tell nginx to report such a condition? What would be involved for that?