{"id":798,"date":"2022-12-19T17:34:58","date_gmt":"2022-12-19T09:34:58","guid":{"rendered":"http:\/\/wordpress.loc\/?p=798"},"modified":"2023-08-15T01:47:22","modified_gmt":"2023-08-14T17:47:22","slug":"esp32_ch1-42","status":"publish","type":"post","link":"https:\/\/www.nmking.io\/index.php\/2022\/12\/19\/798\/","title":{"rendered":"\u5168\u53f0\u6700\u5feb\u7684mqttgo.io\u4e0a\u7dda\u4e86"},"content":{"rendered":"\n<figure class=\"wp-block-pullquote\"><blockquote><p>\u5168\u53f0\u6700\u5feb\u7684MQTT\u4e0a\u7dda\u4e86(&lt;-\u5ee3\u544a\u7528\u8a5e)\uff0c\u5927\u5bb6\u4e0d\u7528\u518d\u8dd1\u6fb3\u9580emqx\uff0c\u4e5f\u4e0d\u7528\u6253\u540d\u5b50\u8d85\u9577\u7684eclipseprojects<br>\u4eab\u7528\u5c0f\u9738\u738b\u5be6\u9a57\u5ba4\u6240\u5efa\u7acb\u7684\u53f0\u7063\u6700\u5feb\u6700\u7a69(&lt;-\u5ee3\u544a\u7528\u8a5e)\u7531HiveMQ\u6240\u67b6\u8a2d\u7684MQTT Broker\uff0c\u5b8c\u5168\u514d\u8cbb\uff5e\u4ee5\u5f8c\u4e5f\u4e0d\u6703\u6536\u8cbb<\/p><\/blockquote><\/figure>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-ht-block-toc is-style-rounded htoc htoc--position-wide toc-list-style-plain\" data-htoc-state=\"expanded\"><span class=\"htoc__title\"><span class=\"ht_toc_title\">Table of Contents<\/span><span class=\"htoc__toggle\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"16\" height=\"16\"><g fill=\"#444\"><path d=\"M15 7H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><path d=\"M15 1H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1zM15 13H1c-.6 0-1 .4-1 1s.4 1 1 1h14c.6 0 1-.4 1-1s-.4-1-1-1z\"><\/path><\/g><\/svg><\/span><\/span><div class=\"htoc__itemswrap\"><ul class=\"ht_toc_list\"><li class=\"\"><a href=\"#htoc-mqttgo\">MQTTGO\u8aaa\u660e<\/a><\/li><li class=\"\"><a href=\"#htoc-hivemq-ce\">\u4e00\u3001\u5b89\u88ddHiveMQ CE<\/a><\/li><li class=\"\"><a href=\"#htoc-plug-in\">\u4e8c\u3001\u5b89\u88dd\u76f8\u95dcPlug-in<\/a><\/li><li class=\"\"><a href=\"#htoc-prometheus\">\u4e09\u3001\u5b89\u88ddPrometheus\u76e3\u6e2c\u8edf\u9ad4<\/a><\/li><li class=\"\"><a href=\"#htoc-grafana\">\u56db\u3001\u5b89\u88ddGrafana\u6578\u64da\u5316\u9762\u677f<\/a><\/li><li class=\"\"><a href=\"#htoc-\">\u4e94\u3001\u8a2d\u5b9a\u6240\u6709\u670d\u52d9\u70ba\u958b\u6a5f\u81ea\u52d5\u57f7\u884c<\/a><\/li><\/ul><\/div><\/div>\n\n\n\n<p>\u6211\u7684ESP32\u5be6\u505a\u66f8\u7c4d\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.nmking.io\/index.php\/2022\/11\/10\/esp32_ch1-2\/\" target=\"_blank\">\u6211\u51fa\u66f8\u4e86 ESP32 \u7269\u806f\u7db2\u5c08\u984c<\/a><br>\u535a\u5ba2\u4f86\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.books.com.tw\/products\/0010901195\" target=\"_blank\">https:\/\/www.books.com.tw\/products\/0010901195<\/a><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-mqttgo\">MQTTGO\u8aaa\u660e<\/h2>\n\n\n\n<p>\u5168\u53f0\u6700\u5feb\u7684MQTT\u4e0a\u7dda\u4e86(&lt;-\u5ee3\u544a\u7528\u8a5e)\uff0c\u5927\u5bb6\u4e0d\u7528\u518d\u8dd1\u6fb3\u9580emqx\uff0c\u4e5f\u4e0d\u7528\u6253\u540d\u5b50\u8d85\u9577\u7684eclipseprojects<br>\u4eab\u7528\u5c0f\u9738\u738b\u5be6\u9a57\u5ba4\u6240\u5efa\u7acb\u7684\u53f0\u7063\u6700\u5feb\u6700\u7a69(&lt;-\u5ee3\u544a\u7528\u8a5e)\u7531HiveMQ\u6240\u67b6\u8a2d\u7684MQTT Broker\uff0c\u5b8c\u5168\u514d\u8cbb\uff5e\u4ee5\u5f8c\u4e5f\u4e0d\u6703\u6536\u8cbb<br>\u76f4\u63a5\u5728MQTT Broker\u8f38\u5165<br>\u4f4d\u5740\uff1amqttgo.io<br>port\uff1a1883<br>\u4e0d\u9808\u5e33\u865f\u5bc6\u78bc\uff0cTopic\u81ea\u5df1\u53d6\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e2d\u6587Topic\u5594\u3002<br>Websocket\u4e5f\u5373\u5c07\u958b\u901a\u5594\uff5e<br>\u672c\u7b46\u8a18\u5c07\u8aaa\u660e\u5982\u4f55\u5728ubuntu\u5b89\u88ddHiveMQ CE\uff0c\u53ef\u4ee5\u5206\u6210\u4ee5\u4e0b\u4e94\u500b\u6b65\u9a5f<\/p>\n\n\n\n<p>\u4e00\u3001\u5b89\u88ddHiveMQ CE<\/p>\n\n\n\n<p>\u4e8c\u3001\u5b89\u88dd\u76f8\u95dcPlug-in<\/p>\n\n\n\n<p>\u4e09\u3001\u5b89\u88ddPrometheus\u76e3\u6e2c\u8edf\u9ad4<\/p>\n\n\n\n<p>\u56db\u3001\u5b89\u88ddGrafana\u6578\u64da\u5316\u9762\u677f<\/p>\n\n\n\n<p>\u4e94\u3001\u8a2d\u5b9a\u6240\u6709\u670d\u52d9\u70ba\u958b\u6a5f\u81ea\u52d5\u57f7\u884c<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-hivemq-ce\">\u4e00\u3001\u5b89\u88ddHiveMQ CE<\/h2>\n\n\n\n<p>1.Update\u7cfb\u7d71<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get update\nsudo apt-get upgrade -y<\/code><\/pre>\n\n\n\n<p>2.\u5efa\u8b70\u5b89\u88ddChromium\uff08\u6b64\u70ba\u500b\u4eba\u7fd2\u6163\uff0c\u8207\u672c\u5b89\u88dd\u7121\u95dc\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install chromium-browser<\/code><\/pre>\n\n\n\n<p>3.\u5b89\u88ddJava\u74b0\u5883<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install default-jre -y default-jdk -y<\/code><\/pre>\n\n\n\n<p>4.HiveMQ CE\u7248\u539f\u59cb\u6a94\u7db2\u5740\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/hivemq\/hivemq-community-edition\" target=\"_blank\">https:\/\/github.com\/hivemq\/hivemq-community-edition<\/a><br>\u76f4\u63a5\u4e0b\u8f09\u57f7\u884c\u6a94\uff0c\u89e3\u58d3\u7e2e\u5f8c\uff0c\u653e\u5230Home\u76ee\u9304\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654202198-3068255854-g_n.png?resize=840%2C375&#038;ssl=1\" alt=\"\" width=\"840\" height=\"375\"\/><\/figure>\n\n\n\n<p>\u89e3\u58d3\u7e2e\u5f8c\uff0c\u9032\u5165\u8cc7\u6599\u593e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd hivemq-ce-&lt;version&gt;<\/code><\/pre>\n\n\n\n<p>\u4e26\u57f7\u884c\u547d\u4ee4\u5373\u53ef\u555f\u52d5mqtt<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bin\/run.sh<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654202475-3408578518-g_n.png?resize=840%2C357&#038;ssl=1\" alt=\"\" width=\"840\" height=\"357\"\/><figcaption class=\"wp-element-caption\">\u555f\u52d5MQTT\u756b\u9762<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654202496-164553674-g_n.png?resize=839%2C338&#038;ssl=1\" alt=\"\" width=\"839\" height=\"338\"\/><\/figure>\n\n\n\n<p>\u6b64\u6642\u53ef\u4ee5\u5229\u7528MQTTLENS\uff08Chrome\u641c\u5c0bMQTTLENS\u5b89\u88dd\u6b64\u61c9\u7528\u7a0b\u5f0f\uff09\uff0c\u4f7f\u7528localhost\uff1a1883\u9032\u884c\u6e2c\u8a66<\/p>\n\n\n\n<p>\u8a02\u95b1\u4e26\u63a8\u64ad\u540c\u4e00\u500b\u4e3b\u984c\uff0c\u770b\u770b\u662f\u5426\u80fd\u6536\u5230\u8cc7\u6599\uff0c\u5982\u679c\u6709\u7684\u8a71\uff0c\u5c31\u7b97\u5b8c\u6210\u57fa\u790e\u7684MQTT Broker\u7684\u5b89\u88dd\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654202842-3001035372-g_n.png?resize=842%2C519&#038;ssl=1\" alt=\"\" width=\"842\" height=\"519\"\/><\/figure>\n\n\n\n<p>\u76ee\u524d\u9019\u500bBroker\u4ecd\u5c6c\u65bc\u6700\u57fa\u672c\u7684\u670d\u52d9\uff0c\u5efa\u8b70\u5b8c\u6210\u7b2c\u4e8c\u6b65\u9a5f\u7684\u63d2\u4ef6\u5b89\u88dd<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-plug-in\">\u4e8c\u3001\u5b89\u88dd\u76f8\u95dcPlug-in<\/h2>\n\n\n\n<p>\u672c\u90e8\u4efd\u9810\u671f\u5b89\u88dd\u5169\u500b\u63d2\u4ef6\uff1aPrometheus\u6548\u80fd\u6aa2\u8996\u3001denywildcard\u7981\u6b62\u700f\u89bd\u76ee\u9304\u5b89\u5168\u5957\u4ef6<br>Prometheus\uff1a<a href=\"https:\/\/www.hivemq.com\/extension\/prometheus-extension\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.hivemq.com\/extension\/prometheus-extension\/<\/a><br>denywildcard\uff1a<a href=\"https:\/\/www.hivemq.com\/extension\/deny-root-wildcard-subscriptions-extension\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.hivemq.com\/extension\/deny-root-wildcard-subscriptions-extension\/<\/a><br>\u4e0b\u8f09\u5f8c\uff0c\u89e3\u58d3\u7e2e\u653e\u7f6e\u5230hive\u8cc7\u6599\u593e\u7684extension\u5167\uff0c\u52a0\u4e0a\u539f\u672c\u7684allow-all-extension\uff0c\u9019\u6a23\u5c31\u4e00\u5171\u4e09\u500b<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654203140-3102952290-g.png?resize=841%2C428&#038;ssl=1\" alt=\"\" width=\"841\" height=\"428\"\/><\/figure>\n\n\n\n<p>\u8996\u9700\u8981\u9032\u884c\u4fee\u6539\u8a2d\u5b9a\u6a94\uff0c\u958b\u555fPrometheus-extension\u8cc7\u6599\u593e\u5167\u7684\u8a2d\u5b9a\u6a94prometheusconfiguration.properties\uff0c\u5176\u4e2dport=9399\u3001metric_path=\/metrics\uff0c\u4ee3\u8868\u9019\u500b\u670d\u52d9\u6703\u5efa\u7acb\u5728localhost:9399\/metric\u4e0b\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654203459-1972174783-g.png?resize=842%2C498&#038;ssl=1\" alt=\"\" width=\"842\" height=\"498\"\/><\/figure>\n\n\n\n<p>\u4f7f\u7528Ctrl+C\uff0c\u95dc\u9589HiveMQ\u670d\u52d9\uff0c\u4e26\u91cd\u65b0\u555f\u52d5\uff0c\u5373\u53ef\u555f\u52d5\u63d2\u4ef6\u670d\u52d9<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654203701-1266754980-g_n.png?resize=845%2C596&#038;ssl=1\" alt=\"\" width=\"845\" height=\"596\"\/><\/figure>\n\n\n\n<p>Prometheus\u555f\u52d5\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u5230localhost:9399\/metric\u67e5\u770b\u6578\u64da<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654203776-1756951444-g_n.png?resize=840%2C498&#038;ssl=1\" alt=\"\" width=\"840\" height=\"498\"\/><\/figure>\n\n\n\n<p>\u9019\u4e9b\u6578\u64da\u70ba\u6587\u5b57\u65b9\u5f0f\uff0c\u4e0d\u597d\u8fa8\u8b58\uff0c\u56e0\u6b64\u6211\u5011\u9700\u8981\u518d\u5b89\u88dd\u5716\u5f62\u754c\u9762\uff0c\u7b2c\u4e00\u500b\u662fPrometheus\u7684Web\u670d\u52d9\uff0c\u7136\u5f8c\u662fGrafana\u6578\u64da\u5316\u9762\u677f\uff0c\u8acb\u53c3\u8003\u7b2c\u4e09\u7b2c\u56db\u7bc0<\/p>\n\n\n\n<p>\u5230\u9019\u88e1\u70ba\u6b62\uff0c\u5176\u5be61883\u7684Broker\u5df2\u7d93\u53ef\u4ee5\u6b63\u5e38\u904b\u4f5c\u4e86\uff0c\u5982\u679c\u8981\u65b0\u589eWSS(WebSocket)\u7684\u8a71\uff0c\u53ef\u4ee5\u958b\u555fhivemq\u8cc7\u6599\u593e\u5167\u7684conf\u8cc7\u6599\u593e\u7684\u6a94\u6848config.xml<\/p>\n\n\n\n<p>\u4e26\u5c07\u4ee5\u4e0b\u5167\u5bb9\u52a0\u5165\u5230\u539f\u672c\u7684listeners\u5340\u6bb5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    &lt;websocket-listener&gt;\n          &lt;port&gt;8000&lt;\/port&gt;\n          &lt;bind-address&gt;0.0.0.0&lt;\/bind-address&gt;\n          &lt;path&gt;\/mqtt&lt;\/path&gt;\n          &lt;name&gt;my-websocket-listener&lt;\/name&gt;\n          &lt;subprotocols&gt;\n              &lt;subprotocol&gt;mqttv3.1&lt;\/subprotocol&gt;\n              &lt;subprotocol&gt;mqtt&lt;\/subprotocol&gt;\n          &lt;\/subprotocols&gt;\n          &lt;allow-extensions&gt;true&lt;\/allow-extensions&gt;\n    &lt;\/websocket-listener&gt;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654239878-1437944217-g.png?resize=840%2C623&#038;ssl=1\" alt=\"\" width=\"840\" height=\"623\"\/><\/figure>\n\n\n\n<p>\u5b58\u6a94\u5f8c\uff0c\u91cd\u65b0\u958b\u555fHiveMQ\uff0c\u5c31\u53ef\u4ee5\u4f7f\u75288000\u9032\u884cWSS\u901a\u8a0a\u4e86<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-prometheus\">\u4e09\u3001\u5b89\u88ddPrometheus\u76e3\u6e2c\u8edf\u9ad4<\/h2>\n\n\n\n<p>\u63a5\u4e0b\u4f86\u8981\u555f\u52d5Prometheus\u7684Web\u670d\u52d9\uff0c\u8acb\u81f3\u6b64\u8655\u4e0b\u8f09\uff1a<a href=\"https:\/\/prometheus.io\/download\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/prometheus.io\/download\/<\/a>\uff0c\u4e0b\u8f09\u9700\u8981\u7684\u7248\u672c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654204454-4269687159-g.png?resize=840%2C405&#038;ssl=1\" alt=\"\" width=\"840\" height=\"405\"\/><\/figure>\n\n\n\n<p>\u4e0b\u8f09\u5f8c\uff0c\u4e00\u6a23\u89e3\u58d3\u7e2e\u5230Home\u5e95\u4e0b<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654204542-912585896-g_n.png?resize=839%2C561&#038;ssl=1\" alt=\"\" width=\"839\" height=\"561\"\/><\/figure>\n\n\n\n<p>\u5982\u9808\u8a2d\u5b9a\u76f8\u95dc\u5167\u5bb9\uff0c\u8acb\u958b\u555f\u8cc7\u6599\u593e\u5167\u7684prometheus.yml\uff0c\u4fee\u6539\u8cc7\u6599\u4f86\u6e90\u70ba\u4e0a\u9762localhost:9399\uff0c\u6240\u4ee5\u6539\u70ba9393\uff0c\u5b8c\u6210\u4fee\u6539\u5f8c\u5b58\u6a94\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654204940-3118998289-g.png?resize=839%2C518&#038;ssl=1\" alt=\"\" width=\"839\" height=\"518\"\/><\/figure>\n\n\n\n<p>\u57f7\u884c\u65b9\u5f0f\uff1a\u76f4\u63a5\u9ede\u5169\u4e0b\u57f7\u884c\u6a94prometheus\u5373\u53ef\u57f7\u884c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654263553-1795148745-g.png?resize=838%2C631&#038;ssl=1\" alt=\"\" width=\"838\" height=\"631\"\/><\/figure>\n\n\n\n<p>\u6b64\u6642\u53ef\u4ee5\u5229\u7528\u700f\u89bd\u5668\u958b\u555f\uff1alocalhost:9090\uff0c\u5728\u4e2d\u9593\u7a7a\u767d\u8655\u8f38\u5165hive\u5c31\u53ef\u4ee5\u5217\u51fahiveMQ\u7684\u76f8\u95dc\u6578\u64da\u6b04\u4f4d\uff0c\u5982\u679c\u6c92\u6709\u5217\u51fahive\u7684\u4efb\u4f55\u6578\u64da\uff0c\u8acb\u6aa2\u67e5\u4e0a\u9762\u7684\u8a2d\u5b9aport\u662f\u5426\u76f8\u7b26\u3002<\/p>\n\n\n\n<p>\u6b64\u8655\u6211\u9078\u64c7incoming_publish_count\u4f5c\u70ba\u76e3\u6e2c\u5167\u5bb9\uff0c\u9078\u64c7\u5f8c\uff0c\u6309\u4e0b\u53f3\u5074\u7684Execute\u6309\u9215\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654205308-2120645253-g_n.png?resize=840%2C343&#038;ssl=1\" alt=\"\" width=\"840\" height=\"343\"\/><\/figure>\n\n\n\n<p>\u4e26\u9078\u64c7Graph\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u5373\u6642\u6578\u64da\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654205349-2711624529-g_n.png?resize=839%2C557&#038;ssl=1\" alt=\"\" width=\"839\" height=\"557\"\/><\/figure>\n\n\n\n<p>\u4e0d\u904e\u9019\u500b\u5716\u8868\u6578\u64da\u4e0d\u6703\u81ea\u5df1\u66f4\u65b0\uff0c\u4e5f\u4e0d\u80fd\u5b58\u6a94\uff0c\u6240\u4ee5\u6c92\u4ec0\u9ebc\u5c41\u7528\u3002\u5b89\u88dd\u9019\u500b\u7684\u771f\u6b63\u539f\u56e0\u662f\u8981\u628a\u6578\u64da\u518d\u50b3\u7d66\u4e0b\u9762\u9019\u500bGrafana\u4f86\u986f\u793a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-grafana\">\u56db\u3001\u5b89\u88ddGrafana\u6578\u64da\u5316\u9762\u677f<\/h2>\n\n\n\n<p>\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install -y apt-transport-https software-properties-common wget -y\nwget -q -O - https:\/\/packages.grafana.com\/gpg.key | sudo apt-key add -\necho \"deb https:\/\/packages.grafana.com\/oss\/deb stable main\" | sudo tee -a \/etc\/apt\/sources.list.d\/grafana.list\nsudo apt-get update\nsudo apt-get install grafana<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u547d\u4ee4\u5247\u70ba\u555f\u52d5\u672c\u670d\u52d9\u547d\u4ee4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl start grafana-server<\/code><\/pre>\n\n\n\n<p>\u63a5\u8457\u6211\u5011\u958b\u555flocalhost:3000\uff0c\u5373\u53ef\u958b\u555fGrafana\u7db2\u7ad9\u3002\u7b2c\u4e00\u6b21\u767b\u5165\u4f7f\u7528admin\/admin\u767b\u5165\uff0c\u7136\u5f8c\u6703\u99ac\u4e0a\u8981\u6c42\u8f38\u5165\u5f8c\u7e8c\u7684\u767b\u5165\u5bc6\u78bc<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207087-3486380588-g_n.png?resize=844%2C947&#038;ssl=1\" alt=\"\" width=\"844\" height=\"947\"\/><\/figure>\n\n\n\n<p>\u9032\u5165\u4e3b\u529f\u80fd\u5340<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207000-3737302644-g_n.png?resize=841%2C607&#038;ssl=1\" alt=\"\" width=\"841\" height=\"607\"\/><\/figure>\n\n\n\n<p>\u52a0\u5165prometheus\u8cc7\u6599\u4f86\u6e90<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207416-3661774200-g_n.png?resize=842%2C509&#038;ssl=1\" alt=\"\" width=\"842\" height=\"509\"\/><\/figure>\n\n\n\n<p>\u5728URL\u8655\u8f38\u5165prometheus\u7684\u7db2\u5740\uff1ahttp:\/\/localhost:9090\uff0c\u5176\u9918\u4e0d\u7528\u8b8a\u66f4\uff0c\u76f4\u63a5\u6309\u6700\u4e0b\u9762\u7684Save and Test<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207452-3038754030-g.png?resize=842%2C555&#038;ssl=1\" alt=\"\" width=\"842\" height=\"555\"\/><\/figure>\n\n\n\n<p>\u5b8c\u6210\u5f8c\uff0c\u5373\u6703\u51fa\u73fe\u8cc7\u6599\u4f86\u6e90\u6c92\u554f\u984c\u7684\u8a0a\u606f<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207565-6270990-g.png?resize=844%2C547&#038;ssl=1\" alt=\"\" width=\"844\" height=\"547\"\/><\/figure>\n\n\n\n<p>\u52a0\u5165\u4e00\u500bDashboard\u5716\u8868\uff0c\u4e26\u9078New Panel<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654207999-1772387178-g.png?resize=841%2C593&#038;ssl=1\" alt=\"\" width=\"841\" height=\"593\"\/><\/figure>\n\n\n\n<p>\u4e0b\u65b9\u52a0\u5165\u4e00\u500b\u8981\u76e3\u6e2c\u7684\u6b04\u4f4d\u5f8c\uff0c\u9ede\u9078+Query\uff0c\u78ba\u8a8d\u6578\u64da\u662f\u5426\u6b63\u78ba\uff0c\u6700\u5f8c\u6309\u53f3\u4e0a\u7684Apply\u5373\u53ef\u5b8c\u6210\u7b2c\u4e00\u500b\u76e3\u6e2c\u5716\u8868<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654208126-4150935676-g_n.png?resize=839%2C524&#038;ssl=1\" alt=\"\" width=\"839\" height=\"524\"\/><\/figure>\n\n\n\n<p>\u53ef\u4ee5\u4f9d\u64da\u9700\u6c42\u52a0\u5165\u591a\u500b\u5716\u8868\uff0c\u4f46\u8a18\u5f97\u5c0dDashboard\u5b58\u6a94<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/pic.pimg.tw\/youyouyou\/1654208438-3997782239-g_n.png?resize=840%2C364&#038;ssl=1\" alt=\"\" width=\"840\" height=\"364\"\/><\/figure>\n\n\n\n<p>\u4f5c\u5230\u9019\u88e1\u7cfb\u7d71\u4e0d\u50c5\u53ef\u4ee5\u6b63\u5e38\u904b\u4f5c\uff0c\u4e5f\u53ef\u4ee5\u6709\u7cfb\u7d71\u904b\u4f5c\u7684\u6578\u64da\u756b\u9762\u3002<\/p>\n\n\n\n<p>\u6700\u5f8c\u4e00\u6b65\u5c31\u662f\u5c07\u4e0a\u9762\u4e09\u500b\u670d\u52d9\u90fd\u8a2d\u5b9a\u70ba\u81ea\u52d5\u555f\u52d5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"htoc-\">\u4e94\u3001\u8a2d\u5b9a\u6240\u6709\u670d\u52d9\u70ba\u958b\u6a5f\u81ea\u52d5\u57f7\u884c<\/h2>\n\n\n\n<p>\u78ba\u8a8d\u4e0a\u9762\u7684\u8a2d\u5b9a\u90fd\u6c92\u554f\u984c\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u5c07\u6240\u6709\u670d\u52d9\u90fd\u8a2d\u5b9a\u70ba\u81ea\u884c\u555f\u52d5\u3002\u5305\u62ec<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>HiveMQ CE<\/li>\n\n\n\n<li>prometheus<\/li>\n\n\n\n<li>Grafana<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\">HiveMQ CE\u7684\u81ea\u52d5\u57f7\u884c<\/p>\n\n\n\n<p>1.\u5728\/etc\/systemd\/system\/\u5efa\u7acb\u4e00\u500b\u6a94\u6848\uff0c\u526f\u6a94\u540d\u5fc5\u9808\u662f.service\uff0c\u4f8b\u5982HiveMQTT.service<\/p>\n\n\n\n<p>2.\u5c07MQTT\u57f7\u884c\u7684SH\u6a94\u6539\u70ba\u53ef\u81ea\u52d5\u57f7\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod +x \/<strong>\u4fee\u6539\u6210\u4f60\u7684MQTT\u57f7\u884c\u8def\u5f91<\/strong><\/code><\/pre>\n\n\n\n<p>3.\u6a94\u6848\u5167\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\r\n#\u7c21\u55ae\u63cf\u8ff0\r\nDescription=Start HiveMQTT Service \r\nAfter=network.target\r\n\r\n&#91;Service]\r\n#\u7a0b\u5f0f\u8def\u5f91\r\nExecStart=<strong>\/\u4fee\u6539\u6210\u4f60\u7684MQTT\u57f7\u884c\u8def\u5f91<\/strong>\r\n#\u4e00\u76f4\u91cd\u65b0\u555f\u52d5\r\nRestart=always \r\n#\u91cd\u65b0\u555f\u52d5\u6642\u9593=10s\r\nRestartSec=10 \r\n#\u7cfb\u7d71\u4e2d\u7684\u540d\u7a31\r\nSyslogIdentifier=HiveMQTTSerive \r\n#\u4f7f\u7528\u57f7\u884c\u7684\u6b0a\u9650\r\nUser=root\r\n\r\n&#91;Install]\r\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p>4.\u8a2d\u5b9a\u958b\u6a5f\u555f\u52d5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable HiveMQTT.service<\/code><\/pre>\n\n\n\n<p>5. \u7acb\u5373\u555f\u52d5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start HiveMQTT.service <\/code><\/pre>\n\n\n\n<p>6.\u67e5\u770b\u57f7\u884c\u72c0\u614b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status HiveMQTT.service <\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">prometheus<\/p>\n\n\n\n<p>\u4f9d\u7167MQTT\u7684\u65b9\u5f0f\u9032\u884c\u8655\u7406\uff0cservice \u6a94\u6848\u7684\u5167\u5bb9\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;Unit]\r\nDescription=Prometheus\r\nWants=network-online.target\r\nAfter=network-online.target\r\n\r\n&#91;Service]\r\nUser=prometheus\r\nGroup=prometheus\r\nRestart=always\r\nType=simple\r\nExecStart=\/usr\/local\/bin\/prometheus \\\r\n    --config.file=\/etc\/prometheus\/prometheus.yml \\\r\n    --storage.tsdb.path=\/var\/lib\/prometheus\/ \\\r\n    --web.console.templates=\/etc\/prometheus\/consoles \\\r\n    --web.console.libraries=\/etc\/prometheus\/console_libraries \\\r\n    --web.listen-address=0.0.0.0:9090\r\n\r\n&#91;Install]\r\nWantedBy=multi-user.target<\/code><\/pre>\n\n\n\n<p class=\"has-medium-font-size\">grafana\u8a2d\u5b9a\u555f\u52d5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ln -s \/lib\/systemd\/system\/grafana-server.service \/etc\/systemd\/system\/grafana-server.service\r\nsudo systemctl enable grafana-server\r\nsudo systemctl start grafana-server<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5168\u53f0\u6700\u5feb\u7684MQTT\u4e0a\u7dda\u4e86(&lt;-\u5ee3\u544a\u7528\u8a5e)\uff0c\u5927\u5bb6\u4e0d\u7528\u518d\u8dd1\u6fb3\u9580emqx\uff0c\u4e5f\u4e0d\u7528\u6253\u540d\u5b50\u8d85\u9577\u7684eclipsepr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-798","post","type-post","status-publish","format-standard","hentry","category-esp32"],"blocksy_meta":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/798","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/comments?post=798"}],"version-history":[{"count":3,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/798\/revisions"}],"predecessor-version":[{"id":1311,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/posts\/798\/revisions\/1311"}],"wp:attachment":[{"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/media?parent=798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/categories?post=798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nmking.io\/index.php\/wp-json\/wp\/v2\/tags?post=798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}