You want to see something really cool? And see how to easily it is to use Laravel Horizon + Prometheus and Grafana? Then have a look! I have something for you! An easy package for getting the whole data from Laravel Horizon into your Prometheus + Grafana Stack! So you will never search for any bottleneck without a great interface. But let`s start with a small story about helping a friend with his product:
If you are interested in some internals of @pingpingapp, here we go. These are our @laravelphp horizon queues for the last 30 days. We also see the deployments there to notice any change.— Stefan Bauer (@stefanbauerme) October 22, 2019
Thanks for help setting this up some weeks ago @Lukas_Kae. pic.twitter.com/PzQ0ssK1LC
You maybe saw this Twitter Post from Stefan Bauer. He is the owner of PingPing, a really cool and nice monitoring service which allows you to easily monitor your uptime or your SSL certificates! Check it out 🥰.
I've got some question about how we achieved this nice dashboard. So first of all we use Prometheus, a open source monitoring solution built by SoundCloud, for scraping (aka get the data) and Grafana for the visualization of the data.
We wanted to have a long time overview about what the systems from PingPing handle every day. So i helped Stefan with this small task. I had builded a small exporter based on Superbalists Laravel Prometheus Exporter and this worked quite well! Unfortunately the package is not much maintained anymore, so i decided to create a new package and open source this. And here we are.
Laravel Horizon Prometheus Exporter
You can find the source code of this package on Github, but i will go through each step for setting up this package and the corresponding Grafana dashboard. I assume that you have knowledge about Prometheus and Grafana.
First of all you will have your project. You need to just run:
composer require lkdevelopment/laravel-horizon-prometheus-exporter
And basically thats it! After this you should see a new route under /metrics.
Okay.... there are some more steps if you don't want to expose your metrics on the internet. So you need to publish the configuration files:
php artisan vendor:publish --provider=LKDevelopment\\HorizonPrometheusExporter\\HorizonPrometheusExporterServiceProvider
Now you will find a horizon-exporter.php in your config folder. Open this file and add the IP from your Prometheus server in the ip_whitelist array - by default the route is available from the whole internet.
After this just tell your Prometheus server to scrape from http://<your_url>/metrics every five seconds and thats all! Now you need to go to your Grafana and import a dashboard. After this, your Grafana Dashboard can look like this:
Thats basically all! You can extend the whole dashboard of course or contribute other exporter to the package!