"Vibe-coding" a status dashboard
I work in the engineering division of a supply chain company and our development process, as most companies do, involves the setting up of our SaaS platform locally.
This means that there are a lot of dependent services that need to be run first that support the overall execution of the platform.
For e.g. -
Our platform's stack requires SQL Server, Solr, Redis, Postgres, RabbitMQ, MongoDB as core services to be running first.
Once these are all running and available, a service called WebAPI can be run that makes use of some of the above to run as well.
Following this, there are a few more microservices that need to run, but that need not be part of this article since the underlying concept will already come through with the above being demonstrated.
It all started when in practice on a day-to-day basis, whenever I spun up these services, every now and then, at least ONE of them would go down and at best, the error trace was clear enough from the dependent services as to what the issue was.
But at worst, it's a rabbit hole of errors to wade through before I would land on the root cause and if one of the service's unavailability was the cause, I would feel really sad about having lost all that time.
So having gone through this time and time again, I thought I could do something about this.
ITERATION 1 - The first result of this thought was simply - a checklist.
While it got the bare minimum accomplished, in that, I now had a ready reckoner of all the services that needed to be up each time, I had no way of tracking when something went Down during operations. Additionally, if any of the services were not started , either at startup or by me, the service would simply be neglected till such time as an error would alert me.
Rejected coz : Tick-boxes fixed my initial forgetfulness but still left me blind to mid-session crashes.
This was not working out.
Over time, I tried/considered a few more things -
a) writing a script to start them all at once at startup - this failed miserably more often than not since there were some interfering services running because of other ongoing experiments.
b) Creating batch scripts since aliases were missing in Windows and this is predominantly a Windows based platform
c) Docker-izing All the services. But the amount of RAM that was consumed when I ran all the services (except SQL Server and company-specific-services) was a bit more than I liked - speaks to my lack of knowledge in optimizing Docker, I'm sure.
d) I was also suggested a Prometheus dashboard that I summarily rejected because of the unnecessary level of complexity I was inviting for myself for a personal setup. (Although, I Will set something up with Prometheus eventually - just for masochism's sake.)
So after months of this sort of juggling, a few weeks ago, I thought -
FACT : I've enjoyed using Textual for other projects.
FACT : Many of these services can be polled for their status from their ports / Win processes.
INFERENCE : Why not write a Textual app combining these two facts?
What is it? Textual is a Rapid Application Development framework for Python, built by Will McGugan and the team at textualize.io. One can build sleek GUI applications Inside the terminal using Python.
Actually let's back up - Iteration 2.
I did not think of Textual right from the start. Because initially all I knew was, I wanted a dashboard that would monitor all the services I have running and I could look at for when something went down.
So the second iteration’s end result was something like this -
Rejected coz : Curling ports gave me machine-readable streaming truth, but looking at raw JSONs is still annoying.
Iteration 3 -
The improvement on the above was a CLI based table with ASCII ✔ and ✖ .
Like so -
Rejected coz : A CLI table with ✔/✖ cut my scan-time, yet wasn’t appealing enough. It’s all about the looks now.
Iteration 4 -
Here is where I thought of Textual. And I asked for a service monitoring dashboard which did not look as plain as the JSON response above nor the Ascii checks . The result was a little error-ridden but this is where Knowing programming while 'vibe-coding' helps.
The changes I had to make were around providing the right command to obtain the statuses of different services, modifying the ports, fixing the styles etc.
After the manual fixes, which admittedly took lesser time than if I'd had to hand-code the whole script, the result was something like this -
NOT Rejected : PROGRESS. Now for the final lap!
Final set of iterations and the end result -
From here on, it was mostly smooth sailing.
I got ChatGPT to fix the universal status symbols to be indicators of Success and Failure - green and red dots, tweak the borders etc.
There were again, obvious AI-slop-ish errors in the code, which again, was fixable trivially.
All in all, the exercise took me less than an hour and I was very happy with it!
Next steps
- I'd like to make this an installer so that it can be easily installed without the dependency installation hassle.
- Want to implement an exponential retry and backoff when a service goes down
- ON/OFF controls for the services
References :
ChatGippity (to hear Primeagen say it)
https://textual.textualize.io/
The Internet
Codebase -
All the code for this project, if you’d like to set it up, can be found here.
Thanks for reading Everything Python! Subscribe for free to receive new posts and support my work.
PS - At the time of this article, we’d just hit 600 readers! Thank you for being one of them!!