Adding radio metrics in Prometheus format to the web server at the "/metrics" path#264
Open
omgiafs wants to merge 1 commit into
Open
Adding radio metrics in Prometheus format to the web server at the "/metrics" path#264omgiafs wants to merge 1 commit into
omgiafs wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
English
Good day!
Why is this necessary?
Due to network and other errors, the radio may stop playing, switch to another network, etc. To automatically resume playback, you need to send the "play" command. However, before this patch, there was no way to easily (for example, using
curl) check the stream's playback status remotely.I honestly tried to write a script to automate this—connect to telnet, send the cli.info command, and then exit. But I can't send the command via nc (BusyBox), netcat, or ncat.
Using MQTT for this task is overhead. Of course, not if you already have smart home infrastructure, but like many others, I don't.
There is no information about the player's status on the web page.
Based on the above, code was generated using a neural network that adds Prometheus-like metrics. The code doesn't seem to load the CPU; essentially, it writes the values of other variables from memory to a string variable using a timer, without any computation.
Now it is possible to quickly find out the radio status using
curland send the necessary commands using the samecurl.What's added
This patch adds radio metrics in
Prometheusformat to the/metricsweb page.Metric values are periodically collected into a string variable, and the string containing the metrics is displayed on the web page. The process is asynchronous, meaning metric values are not requested during the page request; the web server returns cached data.
The default metrics update interval is 5 seconds. I don't see the point in doing it more often than that.
Nevertheless, the code has been tested to the extent that someone with a superficial knowledge of C++ can. The code has been compiled, deployed, and works. And, importantly, it doesn't appear to break anything that was previously working.
Metrics and their values (example)
Русский
Добрый день!
Зачем это нужно
Из-за сетевых и прочих ошибок радио может останавливать воспроизведение, переключаться на другую сеть и т.д. Для автоматического восстановления воспроизведения нужно послать команду "play". Но до этого патча не было возможности легко (например, при помощи
curl) удалённо узнать состояние воспроизведения потока.Я честно пытался скриптом написать автоматизацию - подключиться к
telnet, послать командуcli.infoи уйти. Но команду послать не получается ни черезnc(BusyBox), ни черезnetcat, ни черезncat.MQTT использовать для такой задачи - оверхед. Естественно не в том случае, если у вас уже используется инфраструктура умного дома, но у меня, как и у многих, её нет.
В веб-странице нет информации о статусе проигрывателя.
Исходя из вышеперечисленного‼️ с помощью нейросети‼️ был сгенерирован код, который добавляет Prometheus-like метрики. Код вроде бы ЦПУ не нагружает, по сути - по таймеру пишет в переменную типа string значения других переменных из памяти, вычислений никаких.
Теперь возможно с помощью
curlбыстро узнать статус радио и тем жеcurlотправить нужные команды.Что добавлено
Данный патч добавляет метрики радио в формате
Prometheusна веб-странице/metrics.Значения метрик периодически собираются в строковую переменную, строка с метриками отображается на веб-странице. Процесс асинхронный. т.е. значения метрик не запрашиваются во время запроса страницы, веб-сервер отдаёт кешированные данные.
По умолчанию интервал обновления метрик - 5 секунд. Чаще не вижу смысла.
Тем не менее код проверен настолько, насколько его может их проверить человек с поверхностным знанием C++. Код скомпилирован, залит в железку и работает. И, что важно, судя по всему ничего ранее работающего не ломает.
Метрики и их значения (пример)