## Grafana 安裝 MQTT ## Installing ### Ubuntu 20 supports Grafana v7.0, but we need Grafana 8.0 as it supports streaming data sources (e.g. MQTT). ```bash sudo apt-get install -y gnupg2 curl curl https://packages.grafana.com/gpg.key | sudo apt-key add - sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main" sudo apt-get update sudo apt-get -y install grafana ``` ### Dashboard will be served on port 3000. Default username and password are "admin", you'll be prompted to change password. ## Add MQTT Data Source #### Install prerequisites ### Yarn ```bash $ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - $ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list $ sudo apt update $ sudo apt -y install yarn ``` ### Node v14 ```bash $ curl -sL https://deb.nodesource.com/setup_14.x | sudo bash - $ sudo apt update $ sudo apt -y install nodejs $ node --version v14.17.4 ``` ### Go ```bash $ sudo apt -y install golang $ mkdir -p ~/go $ go version go version go1.13.8 linux/amd64 ``` ### Add the following to your environment (e.g. .bashrc) ``` bash $ export GOPATH=~/go $ export PATH=$PATH:$GOPATH/bin ``` ### Mage ```bash $ go get -u -d github.com/magefile/mage $ cd $GOPATH/src/github.com/magefile/mage $ go run bootstrap.go $ mage -version Mage Build Tool v1.11.0-2-g4cf3cfc Build Date: 2021-08-03T11:57:28-07:00 Commit: 4cf3cfc built with: go1.13.8 ``` ### Build data source ```bash $ mkdir grafana-plugins $ cd grafana-plugins $ https://github.com/grafana/mqtt-datasource.git $ cd mqtt-datasource $ yarn build $ yarn install ``` ### Add data source to grafana - Edit /etc/grafana/grafana.ini. ```bash vi /etc/grafana/grafana.ini ``` #### Add data source folder #### Look for # Directory where grafana will automatically scan and look for plugins and update as follows # Directory where grafana will automatically scan and look for plugins ;plugins = /var/lib/grafana/plugins plugins = /path/to/grafana-plugins - Allow unsigned sources - Look for [plugins] section and update as follows ``` [plugins] ;enable_alpha = false ;app_tls_skip_verify_insecure = false Enter a comma-separated list of plugin identifiers to identify plugins that are allowed to be loaded even if they lack a valid signature. allow_loading_unsigned_plugins = mqtt-datasource ``` ### Restart service ```bash sudo systemctl restart grafana-server ```