Grafana: различия между версиями

Строка 30: Строка 30:
</gallery>
</gallery>


=== Установка и настройка Telegraf на контроллер Wiren Board ===
=== Установка и настройка Telegraf ===
Telegraf — это сервис, который устанавливается на контроллер Wiren Board и отправляет данные в базу данных Grafana Cloud.


# Установите и запустите Telegraf в соответствии с [https://docs.influxdata.com/telegraf/v1.19/introduction/installation/ https://docs.influxdata.com/telegraf/v1.19/introduction/installation/]:
Установка Telegraf:
#: <syntaxhighlight lang="bash">
# Установите дополнительные пакеты:
#:<syntaxhighlight lang="bash">
apt update && apt install apt-transport-https
apt update && apt install apt-transport-https
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
</syntaxhighlight>
source /etc/os-release
# Добавьте ключ репозитория telegraf:
test $VERSION_ID = "7" && echo "deb https://repos.influxdata.com/debian wheezy stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
#:<syntaxhighlight lang="bash">
test $VERSION_ID = "8" && echo "deb https://repos.influxdata.com/debian jessie stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
wget -qO- https://repos.influxdata.com/influxdb.key | apt-key add -
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
</syntaxhighlight>
test $VERSION_ID = "10" && echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
# Добавьте в список apt-репозиториев ссылку на репозиторий telegraf:
#*<syntaxhighlight lang="bash">
source /etc/os-release  
</syntaxhighlight>
#* Здесь <code>$VERSION_ID = "9"</code> и <code>stretch</code> — версия ОС:
#*:<syntaxhighlight lang="bash">
test $VERSION_ID = "9" && echo "deb https://repos.influxdata.com/debian stretch stable" | tee /etc/apt/sources.list.d/influxdb.list
</syntaxhighlight>
# Обновите список пакетов и установите telegraf:
#:<syntaxhighlight lang="bash">
apt update && apt install telegraf
apt update && apt install telegraf
systemctl start telegraf
</syntaxhighlight>
</syntaxhighlight>
# Добавьте в <code>/etc/telegraf/telegraf.conf</code> секции для получения данных из MQTT и отправки данных в Grafana Cloud. В секции отправки данных замените логин и пароль на указанные на странице [https://grafana.com/orgs/wiren https://grafana.com/orgs/wiren] в разделе Prometheus - Send metrics.
# Запустите установленный сервис:
#: <syntaxhighlight lang="bash">
#:<syntaxhighlight lang="bash">
service telegraf start
</syntaxhighlight>
 
Отредактируйте файл <code>/etc/telegraf/telegraf.conf</code>:
* Секция '''inputs.mqtt_consumer''', поля ''servers'', ''topics'', ''data_format'' и ''data_type'':
*: <syntaxhighlight lang="bash">
[[inputs.mqtt_consumer]]
[[inputs.mqtt_consumer]]
   ## Broker URLs for the MQTT server or cluster.  To connect to multiple
   ## Broker URLs for the MQTT server or cluster.  To connect to multiple
Строка 113: Строка 129:
     data_type = "float"
     data_type = "float"
</syntaxhighlight>
</syntaxhighlight>
#: <syntaxhighlight lang="bash">
* Секция '''outputs.http''', поля ''url'', ''username'', ''password'', ''data_format'' и ''[outputs.http.headers]''. Ссылку и логин с паролем мы сохраняли в разделе про регистрацию.
*:<syntaxhighlight lang="bash">
[[outputs.http]]
[[outputs.http]]
   ## URL is the address to send metrics to
   ## URL is the address to send metrics to
Строка 131: Строка 148:
     X-Prometheus-Remote-Write-Version = "0.1.0"
     X-Prometheus-Remote-Write-Version = "0.1.0"
</syntaxhighlight>
</syntaxhighlight>
# Проверьте, что Telegraf работает без ошибок.
 
## Остановите его и запустите вручную:<syntaxhighlight lang="bash">
Проверьте, что Telegraf работает без ошибок:
systemctl stop telegraf
# Остановите сервис:
telegraf -debug
#:<syntaxhighlight lang="bash">
service telegraf stop
</syntaxhighlight>
# Запустите сервис в режиме отладки и убедитесь, что данные отправляются:
#:<syntaxhighlight lang="console" highlight="15-19">
# telegraf -debug
2021-11-29T16:47:13Z I! Starting Telegraf 1.20.4
2021-11-29T16:47:13Z I! Using config file: /etc/telegraf/telegraf.conf
2021-11-29T16:47:13Z I! Loaded inputs: cpu disk diskio kernel mem mqtt_consumer processes swap system
2021-11-29T16:47:13Z I! Loaded aggregators:
2021-11-29T16:47:13Z I! Loaded processors:
2021-11-29T16:47:13Z I! Loaded outputs: http
2021-11-29T16:47:13Z I! Tags enabled: host=wirenboard-AWQBNTYP
2021-11-29T16:47:13Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"wirenboard-AWQBNTYP", Flush Interval:10s
2021-11-29T16:47:13Z D! [agent] Initializing plugins
2021-11-29T16:47:13Z D! [agent] Connecting outputs
2021-11-29T16:47:13Z D! [agent] Attempting connection to [outputs.http]
2021-11-29T16:47:13Z D! [agent] Successfully connected to outputs.http
2021-11-29T16:47:13Z D! [agent] Starting service inputs
2021-11-29T16:47:13Z I! [inputs.mqtt_consumer] Connected [tcp://127.0.0.1:1883]
2021-11-29T16:47:24Z D! [outputs.http] Wrote batch of 31 metrics in 696.002545ms
2021-11-29T16:47:24Z D! [outputs.http] Buffer fullness: 1 / 10000 metrics
2021-11-29T16:47:33Z D! [outputs.http] Wrote batch of 34 metrics in 129.098071ms
2021-11-29T16:47:33Z D! [outputs.http] Buffer fullness: 0 / 10000 metrics
</syntaxhighlight>
</syntaxhighlight>
##Если ошибок нет, запустите Telegraf:<syntaxhighlight lang="bash">
# Если ошибок нет, то остановите команду клавишами <kbd>Ctrl</kbd>+<kbd>C</kbd>.
systemctl start telegraf
# Запустите сервис в автоматическом режиме:
#:<syntaxhighlight lang="bash">
service telegraf start
</syntaxhighlight>
</syntaxhighlight>