{"id":34691,"date":"2025-03-11T14:33:57","date_gmt":"2025-03-11T06:33:57","guid":{"rendered":"https:\/\/www.yunshan.net\/blog\/?p=34691"},"modified":"2025-03-11T14:33:57","modified_gmt":"2025-03-11T06:33:57","slug":"prometheus%e5%a6%82%e4%bd%95%e7%9b%91%e6%8e%a7%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e6%80%a7%e8%83%bd%e4%b8%8e%e5%81%a5%e5%ba%b7%e7%8a%b6%e6%80%81%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yunshan.net\/blog\/archives\/34691.html","title":{"rendered":"Prometheus\u5982\u4f55\u76d1\u63a7\u6570\u636e\u5e93\u7684\u6027\u80fd\u4e0e\u5065\u5eb7\u72b6\u6001\uff1f"},"content":{"rendered":"<p style=\"text-align: center;\">\n<p><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2025\/03\/vobo54mP3E.jpg\" alt=\"Prometheus\u5982\u4f55\u76d1\u63a7\u6570\u636e\u5e93\u7684\u6027\u80fd\u4e0e\u5065\u5eb7\u72b6\u6001\uff1f\" ><\/p>\n<\/p>\n<hr>\n<p><strong>\u524d\u8a00<\/strong><br \/>\n\u5728\u6570\u5b57\u5316\u8f6c\u578b\u7684\u6d6a\u6f6e\u4e2d\uff0c\u6570\u636e\u5e93\u4f5c\u4e3a\u4f01\u4e1a\u6838\u5fc3\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5176\u6027\u80fd\u4e0e\u5065\u5eb7\u72b6\u6001\u76f4\u63a5\u5f71\u54cd\u4e1a\u52a1\u8fde\u7eed\u6027\u4e0e\u7528\u6237\u4f53\u9a8c\u3002\u4e00\u6b21\u7a81\u53d1\u7684\u6570\u636e\u5e93\u5b95\u673a\u6216\u67e5\u8be2\u5ef6\u8fdf\uff0c\u53ef\u80fd\u610f\u5473\u7740\u6570\u767e\u4e07\u7684\u635f\u5931\u751a\u81f3\u54c1\u724c\u4fe1\u4efb\u5371\u673a\u3002\u7136\u800c\uff0c\u9762\u5bf9\u590d\u6742\u7684\u6570\u636e\u5e93\u67b6\u6784\u548c\u52a8\u6001\u53d8\u5316\u7684\u8d1f\u8f7d\uff0c\u5982\u4f55\u5b9e\u73b0<strong>\u5b9e\u65f6\u76d1\u63a7<\/strong>\u3001<strong>\u7cbe\u51c6\u9884\u8b66<\/strong>\u4e0e<strong>\u9ad8\u6548\u5206\u6790<\/strong>\uff1f\u4f5c\u4e3a\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u76d1\u63a7\u5229\u5668\uff0c<strong><a href=\"https:\/\/www.yunshan.net\/\"   target=\"_blank\" style=\"color:blue\">Prometheus<\/a><\/strong>\u51ed\u501f\u5176\u7075\u6d3b\u7684\u6307\u6807\u91c7\u96c6\u80fd\u529b\u548c\u5f3a\u5927\u7684\u544a\u8b66\u673a\u5236\uff0c\u6210\u4e3a\u6570\u636e\u5e93\u76d1\u63a7\u9886\u57df\u7684\u70ed\u95e8\u9009\u62e9\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7<a href=\"https:\/\/www.yunshan.net\/\"   target=\"_blank\" style=\"color:blue\">Prometheus<\/a>\u6784\u5efa\u4e00\u5957<strong>\u5168\u94fe\u8def\u6570\u636e\u5e93\u76d1\u63a7\u4f53\u7cfb<\/strong>\uff0c\u8986\u76d6\u4ece\u6838\u5fc3\u6307\u6807\u5b9a\u4e49\u3001\u6570\u636e\u6293\u53d6\u914d\u7f6e\u5230\u53ef\u89c6\u5316\u4e0e\u544a\u8b66\u7684\u5b8c\u6574\u95ed\u73af\u3002<\/p>\n<hr>\n<h3 id=\"\u4e00-prometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u6838\u5fc3\u903b\u8f91\"><strong>\u4e00\u3001Prometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u6838\u5fc3\u903b\u8f91<\/strong><\/h3>\n<p>Prometheus\u7684\u67b6\u6784\u8bbe\u8ba1\u4ee5<strong>\u62c9\u53d6\uff08Pull\uff09\u6a21\u5f0f<\/strong>\u4e3a\u6838\u5fc3\uff0c\u901a\u8fc7\u5468\u671f\u6027\u5730\u4ece\u76ee\u6807\u670d\u52a1\u66b4\u9732\u7684HTTP\u63a5\u53e3\uff08\u901a\u5e38\u662f<code>\/metrics<\/code>\uff09\u91c7\u96c6\u6307\u6807\u6570\u636e\u3002\u5bf9\u4e8e\u6570\u636e\u5e93\u8fd9\u7c7b\u975e\u539f\u751f\u652f\u6301Prometheus\u534f\u8bae\u7684\u670d\u52a1\uff0c\u9700\u4f9d\u8d56<strong>Exporter<\/strong>\u4f5c\u4e3a\u4e2d\u95f4\u6865\u6881\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>MySQL<\/strong>\uff1a\u4f7f\u7528<code>mysqld_exporter<\/code>\n<\/li>\n<li><strong>PostgreSQL<\/strong>\uff1a\u4f7f\u7528<code>postgres_exporter<\/code>\n<\/li>\n<li><strong>Redis<\/strong>\uff1a\u4f7f\u7528<code>redis_exporter<\/code>\n<\/li>\n<\/ul>\n<p>\u8fd9\u4e9bExporter\u901a\u8fc7\u8fde\u63a5\u6570\u636e\u5e93\u5b9e\u4f8b\uff0c\u6267\u884c\u9884\u5b9a\u4e49\u7684\u67e5\u8be2\uff08\u5982<code>SHOW GLOBAL STATUS<\/code>\uff09\uff0c\u5c06\u7ed3\u679c\u8f6c\u5316\u4e3aPrometheus\u53ef\u8bc6\u522b\u7684\u6307\u6807\u683c\u5f0f\u3002\u4f8b\u5982\uff0cMySQL\u7684<code>mysql_global_status_connections<\/code>\u6307\u6807\u53ef\u53cd\u6620\u5f53\u524d\u8fde\u63a5\u6570\uff0c<code>mysql_global_status_uptime<\/code>\u5219\u8bb0\u5f55\u8fd0\u884c\u65f6\u957f\u3002<\/p>\n<hr>\n<h3 id=\"\u4e8c-\u6570\u636e\u5e93\u6027\u80fd\u4e0e\u5065\u5eb7\u7684\u5173\u952e\u76d1\u63a7\u6307\u6807\"><strong>\u4e8c\u3001\u6570\u636e\u5e93\u6027\u80fd\u4e0e\u5065\u5eb7\u7684\u5173\u952e\u76d1\u63a7\u6307\u6807<\/strong><\/h3>\n<p>\u6570\u636e\u5e93\u7684\u76d1\u63a7\u9700\u8986\u76d6<strong>\u8d44\u6e90\u5c42<\/strong>\u3001<strong>\u670d\u52a1\u5c42<\/strong>\u4e0e<strong>\u4e1a\u52a1\u5c42<\/strong>\uff0c\u4ee5\u4e0b\u4e3a\u516d\u5927\u6838\u5fc3\u7ef4\u5ea6\uff1a<\/p>\n<ol>\n<li><strong>\u8d44\u6e90\u5229\u7528\u7387<\/strong>\n<\/li>\n<\/ol>\n<ul>\n<li><strong>CPU\u4e0e\u5185\u5b58<\/strong>\uff1a\u9ad8\u8d1f\u8f7d\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u961f\u5217\u5806\u79ef\u3002\u901a\u8fc7<code>process_cpu_seconds_total<\/code>\u548c<code>process_resident_memory_bytes<\/code>\u76d1\u63a7\u6570\u636e\u5e93\u8fdb\u7a0b\u7684\u8d44\u6e90\u6d88\u8017\u3002\n<\/li>\n<li><strong>\u78c1\u76d8IO\u4e0e\u5bb9\u91cf<\/strong>\uff1a\u5173\u6ce8<code>disk_io_reads_total<\/code>\u548c<code>disk_io_writes_total<\/code>\uff0c\u907f\u514d\u56e0\u78c1\u76d8\u74f6\u9888\u5bfc\u81f4\u7684\u5199\u5165\u5ef6\u8fdf\u3002\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u8fde\u63a5\u6c60\u5065\u5eb7\u5ea6<\/strong>\n<\/li>\n<\/ol>\n<ul>\n<li><strong>\u6d3b\u8dc3\u8fde\u63a5\u6570<\/strong>\uff08\u5982<code>mysql_global_status_threads_connected<\/code>\uff09\u4e0e<strong>\u6700\u5927\u8fde\u63a5\u6570<\/strong>\uff08<code>mysql_global_variables_max_connections<\/code>\uff09\u7684\u6bd4\u503c\u8d85\u8fc780%\u65f6\uff0c\u9700\u8b66\u60d5\u8fde\u63a5\u6c60\u8017\u5c3d\u98ce\u9669\u3002\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u67e5\u8be2\u6027\u80fd<\/strong>\n<\/li>\n<\/ol>\n<ul>\n<li><strong>\u6162\u67e5\u8be2\u7387<\/strong>\uff1a\u901a\u8fc7<code>mysql_global_status_slow_queries<\/code>\u7edf\u8ba1\u6bcf\u5206\u949f\u6162\u67e5\u8be2\u6b21\u6570\u3002\n<\/li>\n<li><strong>\u9501\u7b49\u5f85\u65f6\u95f4<\/strong>\uff1a\u5982<code>mysql_info_schema_innodb_trx_wait_seconds<\/code>\u53cd\u6620\u4e8b\u52a1\u963b\u585e\u60c5\u51b5\u3002\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u590d\u5236\u4e0e\u9ad8\u53ef\u7528\u72b6\u6001<\/strong>\n<\/li>\n<\/ol>\n<ul>\n<li>\u4e3b\u4ece\u5ef6\u8fdf\uff08<code>mysql_slave_status_seconds_behind_master<\/code>\uff09\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u53ef\u80fd\u5f71\u54cd\u8bfb\u5199\u5206\u79bb\u67b6\u6784\u7684\u7a33\u5b9a\u6027\u3002\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u5b58\u50a8\u5f15\u64ce\u6307\u6807<\/strong>\n<\/li>\n<\/ol>\n<ul>\n<li>\u9488\u5bf9InnoDB\u5f15\u64ce\uff0c\u76d1\u63a7<code>innodb_buffer_pool_reads<\/code>\uff08\u76f4\u63a5\u78c1\u76d8\u8bfb\u53d6\u6b21\u6570\uff09\u4e0e<code>innodb_row_lock_time_avg<\/code>\uff08\u884c\u9501\u5e73\u5747\u8017\u65f6\uff09\uff0c\u4f18\u5316\u7f13\u5b58\u547d\u4e2d\u7387\u3002\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u4e1a\u52a1\u81ea\u5b9a\u4e49\u6307\u6807<\/strong><br \/>\n\u7ed3\u5408\u4e1a\u52a1SQL\u6a21\u677f\uff0c\u7edf\u8ba1\u5173\u952e\u4e8b\u52a1\u7684\u8017\u65f6\uff08\u5982<code>app_order_query_duration_seconds<\/code>\uff09\uff0c\u5b9e\u73b0\u4e1a\u52a1\u7ea7\u53ef\u89c2\u6d4b\u6027\u3002\n<\/li>\n<\/ol>\n<hr>\n<h3 id=\"\u4e09-\u5b9e\u6218-\u914d\u7f6eprometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u56db\u5927\u6b65\u9aa4\"><strong>\u4e09\u3001\u5b9e\u6218\uff1a\u914d\u7f6ePrometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u56db\u5927\u6b65\u9aa4<\/strong><\/h3>\n<h4 id=\"\u6b65\u9aa41-\u90e8\u7f72\u4e0e\u914d\u7f6eexporter\"><strong>\u6b65\u9aa41\uff1a\u90e8\u7f72\u4e0e\u914d\u7f6eExporter<\/strong><\/h4>\n<p>\u4ee5MySQL\u4e3a\u4f8b\uff0c\u901a\u8fc7Docker\u5feb\u901f\u542f\u52a8<code>mysqld_exporter<\/code>\uff1a<\/p>\n<pre><code class=\"language-bash\">docker run -d --name mysql-exporter \\  \r\n-e DATA_SOURCE_NAME=&quot;user:password@(mysql-host:3306)\/&quot; \\  \r\nprom\/mysqld-exporter  \r\n<\/code><\/pre>\n<p>\u786e\u4fddExporter\u80fd\u8bbf\u95ee\u6570\u636e\u5e93\u5e76\u62e5\u6709<code>PROCESS<\/code>\u548c<code>SHOW DATABASES<\/code>\u6743\u9650\u3002<\/p>\n<h4 id=\"\u6b65\u9aa42-prometheus\u6293\u53d6\u76ee\u6807\u914d\u7f6e\"><strong>\u6b65\u9aa42\uff1aPrometheus\u6293\u53d6\u76ee\u6807\u914d\u7f6e<\/strong><\/h4>\n<p>\u5728<code>prometheus.yml<\/code>\u4e2d\u6dfb\u52a0Job\uff0c\u5b9a\u4e49\u6293\u53d6\u9891\u7387\u4e0e\u8d85\u65f6\u65f6\u95f4\uff1a<\/p>\n<pre><code class=\"language-yaml\">scrape_configs:  \r\n- job_name: 'mysql'  \r\nstatic_configs:  \r\n- targets: ['mysql-exporter:9104']  \r\nscrape_interval: 15s  \r\nscrape_timeout: 10s  \r\n<\/code><\/pre>\n<h4 id=\"\u6b65\u9aa43-grafana\u53ef\u89c6\u5316\u4e0e\u544a\u8b66\u89c4\u5219\"><strong>\u6b65\u9aa43\uff1aGrafana\u53ef\u89c6\u5316\u4e0e\u544a\u8b66\u89c4\u5219<\/strong><\/h4>\n<p>\u5bfc\u5165\u793e\u533a\u6a21\u677f\uff08\u5982ID 7362\uff09\uff0c\u5feb\u901f\u751f\u6210\u5305\u542b<strong>QPS<\/strong>\u3001<strong>\u8fde\u63a5\u6570\u8d8b\u52bf<\/strong>\u3001<strong>\u590d\u5236\u72b6\u6001<\/strong>\u7684\u4eea\u8868\u76d8\u3002\u540c\u65f6\uff0c\u901a\u8fc7Prometheus\u7684<code>rules.yml<\/code>\u914d\u7f6e\u544a\u8b66\uff1a<\/p>\n<pre><code class=\"language-yaml\">groups:  \r\n- name: mysql-alerts  \r\nrules:  \r\n- alert: HighConnections  \r\nexpr: mysql_global_status_threads_connected \/ mysql_global_variables_max_connections &gt; 0.8  \r\nfor: 5m  \r\nlabels:  \r\nseverity: critical  \r\nannotations:  \r\nsummary: &quot;MySQL\u8fde\u63a5\u6c60\u4f7f\u7528\u7387\u8d85\u8fc780%&quot;  \r\n<\/code><\/pre>\n<h4 id=\"\u6b65\u9aa44-\u96c6\u6210alertmanager\u5b9e\u73b0\u591a\u901a\u9053\u901a\u77e5\"><strong>\u6b65\u9aa44\uff1a\u96c6\u6210Alertmanager\u5b9e\u73b0\u591a\u901a\u9053\u901a\u77e5<\/strong><\/h4>\n<p>\u914d\u7f6e\u90ae\u4ef6\u3001Slack\u6216\u4f01\u4e1a\u5fae\u4fe1\u901a\u77e5\uff0c\u786e\u4fdd\u544a\u8b66\u4fe1\u606f\u5b9e\u65f6\u89e6\u8fbe\u8fd0\u7ef4\u56e2\u961f\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-yaml\">route:  \r\nreceiver: 'wechat'  \r\nreceivers:  \r\n- name: 'wechat'  \r\nwechat_configs:  \r\n- send_resolved: true  \r\ncorp_id: 'xxxx'  \r\nto_user: '@all'  \r\nagent_id: '1000002'  \r\napi_secret: 'xxxx'  \r\n<\/code><\/pre>\n<hr>\n<h3 id=\"\u56db-\u907f\u514d\u8e29\u5751-\u6570\u636e\u5e93\u76d1\u63a7\u7684\u6700\u4f73\u5b9e\u8df5\"><strong>\u56db\u3001\u907f\u514d\u8e29\u5751\uff1a\u6570\u636e\u5e93\u76d1\u63a7\u7684\u6700\u4f73\u5b9e\u8df5<\/strong><\/h3>\n<ol>\n<li>\n<p><strong>\u6307\u6807\u9009\u62e9\u9075\u5faa\u201c\u5c11\u800c\u7cbe\u201d\u539f\u5219<\/strong><br \/>\n\u907f\u514d\u91c7\u96c6\u8fc7\u591a\u4f4e\u4ef7\u503c\u6307\u6807\uff0c\u4f18\u5148\u5173\u6ce8<strong>\u9ec4\u91d1\u4fe1\u53f7<\/strong>\uff08\u5ef6\u8fdf\u3001\u6d41\u91cf\u3001\u9519\u8bef\u3001\u9971\u548c\u5ea6\uff09\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u52a8\u6001\u8c03\u6574\u6293\u53d6\u9891\u7387<\/strong><br \/>\n\u9ad8\u8d1f\u8f7d\u671f\u95f4\u7f29\u77ed<code>scrape_interval<\/code>\uff08\u59825\u79d2\uff09\uff0c\u540c\u65f6\u8bbe\u7f6e\u5408\u7406\u7684<code>scrape_timeout<\/code>\u9632\u6b62\u8d85\u65f6\u5806\u79ef\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u957f\u671f\u5b58\u50a8\u4e0e\u964d\u91c7\u6837<\/strong><br \/>\n\u7ed3\u5408Thanos\u6216VictoriaMetrics\uff0c\u5b9e\u73b0\u5386\u53f2\u6570\u636e\u7684\u4f4e\u6210\u672c\u5b58\u50a8\u4e0e\u5feb\u901f\u67e5\u8be2\u3002<\/p>\n<\/li>\n<li>\n<p><strong>Exporter\u7248\u672c\u517c\u5bb9\u6027<\/strong><br \/>\n\u5b9a\u671f\u5347\u7ea7Exporter\u4ee5\u652f\u6301\u65b0\u7248\u672c\u7684\u6570\u636e\u5e93\u7279\u6027\uff08\u5982MySQL 8.0\u7684\u7a97\u53e3\u51fd\u6570\u76d1\u63a7\uff09\u3002<\/p>\n<\/li>\n<\/ol>\n<hr>\n<h3 id=\"\u4e94-\u4ece\u76d1\u63a7\u5230\u4f18\u5316-\u6570\u636e\u9a71\u52a8\u7684\u6027\u80fd\u8c03\u4f18\"><strong>\u4e94\u3001\u4ece\u76d1\u63a7\u5230\u4f18\u5316\uff1a\u6570\u636e\u9a71\u52a8\u7684\u6027\u80fd\u8c03\u4f18<\/strong><\/h3>\n<p>\u901a\u8fc7Prometheus\u7684\u65f6\u5e8f\u6570\u636e\uff0c\u53ef\u5b9a\u4f4d\u5468\u671f\u6027\u6027\u80fd\u74f6\u9888\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u65f6\u95f4\u76f8\u5173\u6027\u5206\u6790<\/strong>\uff1a\u53d1\u73b0\u6bcf\u65e510\u70b9\u7684CPU\u5cf0\u503c\u4e0e\u5b9a\u65f6\u6279\u5904\u7406\u4efb\u52a1\u5173\u8054\uff1b\n<\/li>\n<li><strong>\u591a\u7ef4\u4e0b\u94bb<\/strong>\uff1a\u6309\u7528\u6237\u3001\u5e94\u7528\u6807\u7b7e\u8fc7\u6ee4\u6162\u67e5\u8be2\uff0c\u8bc6\u522b\u4f4e\u6548SQL\u6a21\u677f\uff1b\n<\/li>\n<li><strong>\u5bb9\u91cf\u9884\u6d4b<\/strong>\uff1a\u57fa\u4e8e\u7ebf\u6027\u56de\u5f52\u6a21\u578b\uff08Prometheus <code>predict_linear()<\/code>\u51fd\u6570\uff09\uff0c\u9884\u6d4b\u78c1\u76d8\u8017\u5c3d\u65f6\u95f4\u3002\n<\/li>\n<\/ul>\n<p>*\u67d0\u7535\u5546\u5e73\u53f0\u901a\u8fc7\u5206\u6790<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u5728\u6570\u5b57\u5316\u8f6c\u578b\u7684\u6d6a\u6f6e\u4e2d\uff0c\u6570\u636e\u5e93\u4f5c\u4e3a\u4f01\u4e1a\u6838\u5fc3\u6570\u636e\u7684\u8f7d\u4f53\uff0c\u5176\u6027\u80fd\u4e0e\u5065\u5eb7\u72b6\u6001\u76f4\u63a5\u5f71\u54cd\u4e1a\u52a1\u8fde\u7eed\u6027\u4e0e\u7528\u6237\u4f53\u9a8c\u3002\u4e00\u6b21\u7a81\u53d1\u7684\u6570\u636e\u5e93\u5b95\u673a\u6216\u67e5\u8be2\u5ef6\u8fdf\uff0c\u53ef\u80fd\u610f\u5473\u7740\u6570\u767e\u4e07\u7684\u635f\u5931\u751a\u81f3\u54c1\u724c\u4fe1\u4efb\u5371\u673a\u3002\u7136\u800c\uff0c\u9762\u5bf9\u590d\u6742\u7684\u6570\u636e\u5e93\u67b6\u6784\u548c\u52a8\u6001\u53d8\u5316\u7684\u8d1f\u8f7d\uff0c\u5982\u4f55\u5b9e\u73b0\u5b9e\u65f6\u76d1\u63a7\u3001\u7cbe\u51c6\u9884\u8b66\u4e0e\u9ad8\u6548\u5206\u6790\uff1f\u4f5c\u4e3a\u4e91\u539f\u751f\u65f6\u4ee3\u7684\u76d1\u63a7\u5229\u5668\uff0cPrometheus\u51ed\u501f\u5176\u7075\u6d3b\u7684\u6307\u6807\u91c7\u96c6\u80fd\u529b\u548c\u5f3a\u5927\u7684\u544a\u8b66\u673a\u5236\uff0c\u6210\u4e3a\u6570\u636e\u5e93\u76d1\u63a7\u9886\u57df\u7684\u70ed\u95e8\u9009\u62e9\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7Prometheus\u6784\u5efa\u4e00\u5957\u5168\u94fe\u8def\u6570\u636e\u5e93\u76d1\u63a7\u4f53\u7cfb\uff0c\u8986\u76d6\u4ece\u6838\u5fc3\u6307\u6807\u5b9a\u4e49\u3001\u6570\u636e\u6293\u53d6\u914d\u7f6e\u5230\u53ef\u89c6\u5316\u4e0e\u544a\u8b66\u7684\u5b8c\u6574\u95ed\u73af\u3002 \u4e00\u3001Prometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u6838\u5fc3\u903b\u8f91 Prometheus\u7684\u67b6\u6784\u8bbe\u8ba1\u4ee5\u62c9\u53d6\uff08Pull\uff09\u6a21\u5f0f\u4e3a\u6838\u5fc3\uff0c\u901a\u8fc7\u5468\u671f\u6027\u5730\u4ece\u76ee\u6807\u670d\u52a1\u66b4\u9732\u7684HTTP\u63a5\u53e3\uff08\u901a\u5e38\u662f\/metrics\uff09\u91c7\u96c6\u6307\u6807\u6570\u636e\u3002\u5bf9\u4e8e\u6570\u636e\u5e93\u8fd9\u7c7b\u975e\u539f\u751f\u652f\u6301Prometheus\u534f\u8bae\u7684\u670d\u52a1\uff0c\u9700\u4f9d\u8d56Exporter\u4f5c\u4e3a\u4e2d\u95f4\u6865\u6881\u3002\u4f8b\u5982\uff1a MySQL\uff1a\u4f7f\u7528mysqld_exporter PostgreSQL\uff1a\u4f7f\u7528postgres_exporter Redis\uff1a\u4f7f\u7528redis_exporter \u8fd9\u4e9bExporter\u901a\u8fc7\u8fde\u63a5\u6570\u636e\u5e93\u5b9e\u4f8b\uff0c\u6267\u884c\u9884\u5b9a\u4e49\u7684\u67e5\u8be2\uff08\u5982SHOW GLOBAL STATUS\uff09\uff0c\u5c06\u7ed3\u679c\u8f6c\u5316\u4e3aPrometheus\u53ef\u8bc6\u522b\u7684\u6307\u6807\u683c\u5f0f\u3002\u4f8b\u5982\uff0cMySQL\u7684mysql_global_status_connections\u6307\u6807\u53ef\u53cd\u6620\u5f53\u524d\u8fde\u63a5\u6570\uff0cmysql_global_status_uptime\u5219\u8bb0\u5f55\u8fd0\u884c\u65f6\u957f\u3002 \u4e8c\u3001\u6570\u636e\u5e93\u6027\u80fd\u4e0e\u5065\u5eb7\u7684\u5173\u952e\u76d1\u63a7\u6307\u6807 \u6570\u636e\u5e93\u7684\u76d1\u63a7\u9700\u8986\u76d6\u8d44\u6e90\u5c42\u3001\u670d\u52a1\u5c42\u4e0e\u4e1a\u52a1\u5c42\uff0c\u4ee5\u4e0b\u4e3a\u516d\u5927\u6838\u5fc3\u7ef4\u5ea6\uff1a \u8d44\u6e90\u5229\u7528\u7387 CPU\u4e0e\u5185\u5b58\uff1a\u9ad8\u8d1f\u8f7d\u53ef\u80fd\u5bfc\u81f4\u67e5\u8be2\u961f\u5217\u5806\u79ef\u3002\u901a\u8fc7process_cpu_seconds_total\u548cprocess_resident_memory_bytes\u76d1\u63a7\u6570\u636e\u5e93\u8fdb\u7a0b\u7684\u8d44\u6e90\u6d88\u8017\u3002 \u78c1\u76d8IO\u4e0e\u5bb9\u91cf\uff1a\u5173\u6ce8disk_io_reads_total\u548cdisk_io_writes_total\uff0c\u907f\u514d\u56e0\u78c1\u76d8\u74f6\u9888\u5bfc\u81f4\u7684\u5199\u5165\u5ef6\u8fdf\u3002 \u8fde\u63a5\u6c60\u5065\u5eb7\u5ea6 \u6d3b\u8dc3\u8fde\u63a5\u6570\uff08\u5982mysql_global_status_threads_connected\uff09\u4e0e\u6700\u5927\u8fde\u63a5\u6570\uff08mysql_global_variables_max_connections\uff09\u7684\u6bd4\u503c\u8d85\u8fc780%\u65f6\uff0c\u9700\u8b66\u60d5\u8fde\u63a5\u6c60\u8017\u5c3d\u98ce\u9669\u3002 \u67e5\u8be2\u6027\u80fd \u6162\u67e5\u8be2\u7387\uff1a\u901a\u8fc7mysql_global_status_slow_queries\u7edf\u8ba1\u6bcf\u5206\u949f\u6162\u67e5\u8be2\u6b21\u6570\u3002 \u9501\u7b49\u5f85\u65f6\u95f4\uff1a\u5982mysql_info_schema_innodb_trx_wait_seconds\u53cd\u6620\u4e8b\u52a1\u963b\u585e\u60c5\u51b5\u3002 \u590d\u5236\u4e0e\u9ad8\u53ef\u7528\u72b6\u6001 \u4e3b\u4ece\u5ef6\u8fdf\uff08mysql_slave_status_seconds_behind_master\uff09\u8d85\u8fc7\u9608\u503c\u65f6\uff0c\u53ef\u80fd\u5f71\u54cd\u8bfb\u5199\u5206\u79bb\u67b6\u6784\u7684\u7a33\u5b9a\u6027\u3002 \u5b58\u50a8\u5f15\u64ce\u6307\u6807 \u9488\u5bf9InnoDB\u5f15\u64ce\uff0c\u76d1\u63a7innodb_buffer_pool_reads\uff08\u76f4\u63a5\u78c1\u76d8\u8bfb\u53d6\u6b21\u6570\uff09\u4e0einnodb_row_lock_time_avg\uff08\u884c\u9501\u5e73\u5747\u8017\u65f6\uff09\uff0c\u4f18\u5316\u7f13\u5b58\u547d\u4e2d\u7387\u3002 \u4e1a\u52a1\u81ea\u5b9a\u4e49\u6307\u6807 \u7ed3\u5408\u4e1a\u52a1SQL\u6a21\u677f\uff0c\u7edf\u8ba1\u5173\u952e\u4e8b\u52a1\u7684\u8017\u65f6\uff08\u5982app_order_query_duration_seconds\uff09\uff0c\u5b9e\u73b0\u4e1a\u52a1\u7ea7\u53ef\u89c2\u6d4b\u6027\u3002 \u4e09\u3001\u5b9e\u6218\uff1a\u914d\u7f6ePrometheus\u76d1\u63a7\u6570\u636e\u5e93\u7684\u56db\u5927\u6b65\u9aa4 \u6b65\u9aa41\uff1a\u90e8\u7f72\u4e0e\u914d\u7f6eExporter \u4ee5MySQL\u4e3a\u4f8b\uff0c\u901a\u8fc7Docker\u5feb\u901f\u542f\u52a8mysqld_exporter\uff1a docker run -d &#8211;name mysql-exporter \\ -e DATA_SOURCE_NAME=&quot;user:password@(mysql-host:3306)\/&quot; \\ prom\/mysqld-exporter \u786e\u4fddExporter\u80fd\u8bbf\u95ee\u6570\u636e\u5e93\u5e76\u62e5\u6709PROCESS\u548cSHOW DATABASES\u6743\u9650\u3002 \u6b65\u9aa42\uff1aPrometheus\u6293\u53d6\u76ee\u6807\u914d\u7f6e \u5728prometheus.yml\u4e2d\u6dfb\u52a0Job\uff0c\u5b9a\u4e49\u6293\u53d6\u9891\u7387\u4e0e\u8d85\u65f6\u65f6\u95f4\uff1a scrape_configs: &#8211; job_name: &#8216;mysql&#8217; static_configs: &#8211; targets: [&#8216;mysql-exporter:9104&#8217;] scrape_interval: 15s scrape_timeout: 10s [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":34692,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-34691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-product-news"],"_links":{"self":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/34691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/comments?post=34691"}],"version-history":[{"count":1,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/34691\/revisions"}],"predecessor-version":[{"id":34693,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/34691\/revisions\/34693"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media\/34692"}],"wp:attachment":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media?parent=34691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/categories?post=34691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/tags?post=34691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}