{"id":162175,"date":"2024-11-04T12:45:23","date_gmt":"2024-11-04T04:45:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/162175\/"},"modified":"2024-11-04T12:45:24","modified_gmt":"2024-11-04T04:45:24","slug":"%e7%9b%a3%e6%8e%a7%e5%88%a9%e5%99%a8%e5%87%ba%e9%9e%98%ef%bc%9aprometheus-grafana-%e7%9b%a3%e6%8e%a7-mysql%e3%80%81redis-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/162175\/","title":{"rendered":"\u76e3\u63a7\u5229\u5668\u51fa\u9798\uff1aPrometheus + Grafana \u76e3\u63a7 MySQL\u3001Redis \u6578\u64da\u5eab"},"content":{"rendered":"<h1 id=\"%e7%9b%a3%e6%8e%a7%e5%88%a9%e5%99%a8%e5%87%ba%e9%9e%98%ef%bc%9aprometheus-grafana-%e7%9b%a3%e6%8e%a7-mysql%e3%80%81redis-%e6%95%b8%e6%93%9a%e5%ba%ab-wEOTqynNOg\">\u76e3\u63a7\u5229\u5668\u51fa\u9798\uff1aPrometheus + Grafana \u76e3\u63a7 MySQL\u3001Redis \u6578\u64da\u5eab<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u76e3\u63a7\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u7121\u8ad6\u662f MySQL \u9084\u662f Redis\uff0c\u9019\u4e9b\u6578\u64da\u5eab\u7cfb\u7d71\u90fd\u627f\u64d4\u8457\u95dc\u9375\u7684\u696d\u52d9\u529f\u80fd\uff0c\u56e0\u6b64\uff0c\u78ba\u4fdd\u5b83\u5011\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Prometheus \u548c Grafana \u4f86\u76e3\u63a7 MySQL \u548c Redis \u6578\u64da\u5eab\uff0c\u5e6b\u52a9\u60a8\u53ca\u6642\u767c\u73fe\u554f\u984c\u4e26\u9032\u884c\u8abf\u6574\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-prometheus-%e5%92%8c-grafana%ef%bc%9f-wEOTqynNOg\">\u4ec0\u9ebc\u662f Prometheus \u548c Grafana\uff1f<\/h2>\n<p>Prometheus \u662f\u4e00\u500b\u958b\u6e90\u7684\u76e3\u63a7\u7cfb\u7d71\u548c\u6642\u9593\u5e8f\u5217\u6578\u64da\u5eab\uff0c\u5c08\u70ba\u53ef\u9760\u6027\u548c\u53ef\u64f4\u5c55\u6027\u800c\u8a2d\u8a08\u3002\u5b83\u80fd\u5920\u81ea\u52d5\u6293\u53d6\u548c\u5b58\u5132\u6642\u9593\u5e8f\u5217\u6578\u64da\uff0c\u4e26\u63d0\u4f9b\u5f37\u5927\u7684\u67e5\u8a62\u8a9e\u8a00\u4f86\u5206\u6790\u9019\u4e9b\u6578\u64da\u3002<\/p>\n<p>Grafana \u5247\u662f\u4e00\u500b\u958b\u6e90\u7684\u6578\u64da\u53ef\u8996\u5316\u5e73\u53f0\uff0c\u80fd\u5920\u8207\u591a\u7a2e\u6578\u64da\u6e90\uff08\u5305\u62ec Prometheus\uff09\u96c6\u6210\uff0c\u5e6b\u52a9\u7528\u6236\u5275\u5efa\u52d5\u614b\u7684\u5100\u8868\u677f\uff0c\u5be6\u6642\u986f\u793a\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87-prometheus-%e5%92%8c-grafana%ef%bc%9f-wEOTqynNOg\">\u70ba\u4ec0\u9ebc\u9078\u64c7 Prometheus \u548c Grafana\uff1f<\/h2>\n<ul>\n<li><strong>\u9ad8\u6548\u7684\u6578\u64da\u6293\u53d6\uff1a<\/strong>Prometheus \u4f7f\u7528\u62c9\u53d6\u6a21\u578b\uff0c\u80fd\u5920\u5b9a\u671f\u5f9e\u76ee\u6a19\u670d\u52d9\u5668\u6293\u53d6\u6578\u64da\uff0c\u9019\u4f7f\u5f97\u76e3\u63a7\u66f4\u52a0\u9748\u6d3b\u3002<\/li>\n<li><strong>\u5f37\u5927\u7684\u67e5\u8a62\u8a9e\u8a00\uff1a<\/strong>PromQL \u662f Prometheus \u7684\u67e5\u8a62\u8a9e\u8a00\uff0c\u80fd\u5920\u9032\u884c\u8907\u96dc\u7684\u6578\u64da\u5206\u6790\u3002<\/li>\n<li><strong>\u9748\u6d3b\u7684\u53ef\u8996\u5316\uff1a<\/strong>Grafana \u63d0\u4f9b\u591a\u7a2e\u5716\u8868\u548c\u5100\u8868\u677f\u9078\u64c7\uff0c\u80fd\u5920\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u986f\u793a\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%9b%a3%e6%8e%a7-mysql-%e6%95%b8%e6%93%9a%e5%ba%ab-wEOTqynNOg\">\u76e3\u63a7 MySQL \u6578\u64da\u5eab<\/h2>\n<p>\u8981\u76e3\u63a7 MySQL \u6578\u64da\u5eab\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd Prometheus \u7684 MySQL Exporter\u3002\u9019\u662f\u4e00\u500b\u5c08\u9580\u7528\u65bc\u6293\u53d6 MySQL \u6027\u80fd\u6307\u6a19\u7684\u5de5\u5177\u3002<\/p>\n<h3 id=\"%e5%ae%89%e8%a3%9d-mysql-exporter-wEOTqynNOg\">\u5b89\u88dd MySQL Exporter<\/h3>\n<pre><code>docker run -d --name mysql-exporter \n  -e DATA_SOURCE_NAME=\"user:password@(hostname:port)\/\" \n  -p 9104:9104 \n  prom\/mysqld-exporter<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u547d\u4ee4\u4e2d\uff0c\u60a8\u9700\u8981\u66ff\u63db `user:password@(hostname:port)\/` \u70ba\u60a8\u7684 MySQL \u8cec\u6236\u4fe1\u606f\u548c\u4e3b\u6a5f\u5730\u5740\u3002\u9019\u6a23\uff0cMySQL Exporter \u5c31\u6703\u958b\u59cb\u6293\u53d6\u6578\u64da\u3002<\/p>\n<h3 id=\"%e9%85%8d%e7%bd%ae-prometheus-wEOTqynNOg\">\u914d\u7f6e Prometheus<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5728 Prometheus \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0 MySQL Exporter \u7684\u76ee\u6a19\uff1a<\/p>\n<pre><code>scrape_configs:\n  - job_name: 'mysql'\n    static_configs:\n      - targets: ['hostname:9104']<\/code><\/pre>\n<p>\u9019\u6a23\uff0cPrometheus \u5c31\u6703\u5b9a\u671f\u6293\u53d6 MySQL \u7684\u6027\u80fd\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%9b%a3%e6%8e%a7-redis-%e6%95%b8%e6%93%9a%e5%ba%ab-wEOTqynNOg\">\u76e3\u63a7 Redis \u6578\u64da\u5eab<\/h2>\n<p>\u5c0d\u65bc Redis\uff0c\u60a8\u540c\u6a23\u9700\u8981\u4f7f\u7528 Redis Exporter\u3002\u9019\u500b\u5de5\u5177\u80fd\u5920\u6293\u53d6 Redis \u7684\u5404\u7a2e\u6027\u80fd\u6307\u6a19\u3002<\/p>\n<h3 id=\"%e5%ae%89%e8%a3%9d-redis-exporter-wEOTqynNOg\">\u5b89\u88dd Redis Exporter<\/h3>\n<pre><code>docker run -d --name redis-exporter \n  -p 9121:9121 \n  oliver006\/redis_exporter<\/code><\/pre>\n<p>\u9019\u6a23\uff0cRedis Exporter \u5c31\u6703\u958b\u59cb\u904b\u884c\u4e26\u6293\u53d6\u6578\u64da\u3002<\/p>\n<h3 id=\"%e9%85%8d%e7%bd%ae-prometheus-wEOTqynNOg\">\u914d\u7f6e Prometheus<\/h3>\n<p>\u5728 Prometheus \u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0 Redis Exporter \u7684\u76ee\u6a19\uff1a<\/p>\n<pre><code>scrape_configs:\n  - job_name: 'redis'\n    static_configs:\n      - targets: ['hostname:9121']<\/code><\/pre>\n<h2 id=\"%e4%bd%bf%e7%94%a8-grafana-%e5%8f%af%e8%a6%96%e5%8c%96%e6%95%b8%e6%93%9a-wEOTqynNOg\">\u4f7f\u7528 Grafana \u53ef\u8996\u5316\u6578\u64da<\/h2>\n<p>\u4e00\u65e6 Prometheus \u958b\u59cb\u6293\u53d6 MySQL \u548c Redis \u7684\u6578\u64da\uff0c\u60a8\u5c31\u53ef\u4ee5\u4f7f\u7528 Grafana \u4f86\u5275\u5efa\u5100\u8868\u677f\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728 Grafana \u4e2d\u6dfb\u52a0 Prometheus \u4f5c\u70ba\u6578\u64da\u6e90\u3002<\/p>\n<h3 id=\"%e6%b7%bb%e5%8a%a0%e6%95%b8%e6%93%9a%e6%ba%90-wEOTqynNOg\">\u6dfb\u52a0\u6578\u64da\u6e90<\/h3>\n<ul>\n<li>\u767b\u9304\u5230 Grafana\u3002<\/li>\n<li>\u5c0e\u822a\u5230\u300cConfiguration\u300d&gt;\u300cData Sources\u300d\u3002<\/li>\n<li>\u9078\u64c7 Prometheus\uff0c\u4e26\u586b\u5beb URL\uff08\u901a\u5e38\u662f http:\/\/localhost:9090\uff09\u3002<\/li>\n<li>\u6e2c\u8a66\u4e26\u4fdd\u5b58\u6578\u64da\u6e90\u3002<\/li>\n<\/ul>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e5%84%80%e8%a1%a8%e6%9d%bf-wEOTqynNOg\">\u5275\u5efa\u5100\u8868\u677f<\/h3>\n<p>\u5728 Grafana \u4e2d\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u65b0\u7684\u5100\u8868\u677f\uff0c\u4e26\u6dfb\u52a0\u5404\u7a2e\u5716\u8868\u4f86\u986f\u793a MySQL \u548c Redis \u7684\u6027\u80fd\u6307\u6a19\u3002\u4f7f\u7528 PromQL \u67e5\u8a62\u8a9e\u8a00\uff0c\u60a8\u53ef\u4ee5\u81ea\u5b9a\u7fa9\u986f\u793a\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wEOTqynNOg\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528 Prometheus \u548c Grafana \u76e3\u63a7 MySQL \u548c Redis \u6578\u64da\u5eab\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u53ca\u6642\u767c\u73fe\u6027\u80fd\u74f6\u9838\u548c\u6f5b\u5728\u554f\u984c\u3002\u9019\u7a2e\u76e3\u63a7\u89e3\u6c7a\u65b9\u6848\u4e0d\u50c5\u9748\u6d3b\u4e14\u529f\u80fd\u5f37\u5927\uff0c\u9084\u80fd\u5920\u63d0\u4f9b\u5be6\u6642\u7684\u6578\u64da\u53ef\u8996\u5316\uff0c\u8b93\u60a8\u66f4\u597d\u5730\u7ba1\u7406\u548c\u512a\u5316\u6578\u64da\u5eab\u6027\u80fd\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u9019\u4e9b\u5de5\u5177\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u5982\u4f55\u4f7f\u7528 Prometheus \u548c Grafana \u76e3\u63a7 MySQL \u548c Redis \u6578\u64da\u5eab\uff0c\u63d0\u5347\u7cfb\u7d71\u6027\u80fd\u8207\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-162175","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162175","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=162175"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162175\/revisions"}],"predecessor-version":[{"id":162176,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/162175\/revisions\/162176"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=162175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=162175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=162175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}