{"id":10020774,"date":"2025-04-27T00:45:48","date_gmt":"2025-04-26T16:45:48","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020774"},"modified":"2025-04-27T00:45:48","modified_gmt":"2025-04-26T16:45:48","slug":"%e3%80%90%e6%97%a5%e5%bf%97%e7%ae%a1%e7%90%86%e3%80%91%e4%bb%8e%e6%80%a7%e8%83%bd%e6%8c%87%e6%a0%87%e7%9b%91%e6%b5%8b%e5%88%b0%e9%94%99%e8%af%af%e7%8e%87%e5%88%86%e6%9e%90%ef%bc%9a%e6%89%93%e9%80%a0","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020774","title":{"rendered":"\u3010\u65e5\u5fd7\u7ba1\u7406\u3011\u4ece\u6027\u80fd\u6307\u6807\u76d1\u6d4b\u5230\u9519\u8bef\u7387\u5206\u6790\uff1a\u6253\u9020\u9ad8\u6548\u65e5\u5fd7\u7cfb\u7edf\u7684\u5b9e\u8df5\u6307\u5357"},"content":{"rendered":"<h2>\u6458\u8981<\/h2>\n<p>\u7cfb\u7edf\u65e5\u5fd7\u662f\u8fd0\u7ef4\u548c\u5f00\u53d1\u8005\u7528\u6765\u53d1\u73b0\u7cfb\u7edf\u6027\u80fd\u74f6\u9888\u3001\u5b9a\u4f4d\u95ee\u9898\u7684\u5173\u952e\u5de5\u5177\u3002\u901a\u8fc7\u4ece\u65e5\u5fd7\u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u7cfb\u7edf\u7a33\u5b9a\u6027\u6307\u6807\uff08\u5982\u54cd\u5e94\u65f6\u95f4\u3001\u9519\u8bef\u7387\u3001\u8d44\u6e90\u4f7f\u7528\u7387\u7b49\uff09\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u7cfb\u7edf\u95ee\u9898\u7684\u65e9\u671f\u9884\u8b66\uff0c\u4ece\u800c\u63d0\u5347\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4ece\u65e5\u5fd7\u4e2d\u63d0\u53d6\u548c\u5206\u6790\u6027\u80fd\u6307\u6807\uff0c\u5e76\u7ed3\u5408\u4ee3\u7801\u793a\u4f8b\u548c\u53ef\u89c6\u5316\u5c55\u793a\uff0c\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u5177\u4f53\u7684\u5b9e\u8df5\u65b9\u6848\u3002<\/p>\n<h2>\u5f15\u8a00<\/h2>\n<p>\u65e5\u5fd7\u662f\u5f00\u53d1\u8005\u8bca\u65ad\u7cfb\u7edf\u95ee\u9898\u7684\u91cd\u8981\u5de5\u5177\u3002\u7136\u800c\uff0c\u5927\u591a\u6570\u65e5\u5fd7\u53ea\u662f\u7b80\u5355\u5730\u8bb0\u5f55\u4fe1\u606f\uff0c\u5e76\u672a\u88ab\u5145\u5206\u5229\u7528\u3002\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u548c\u5fae\u670d\u52a1\u67b6\u6784\u65e5\u76ca\u666e\u53ca\u7684\u4eca\u5929\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u4ece\u6d77\u91cf\u65e5\u5fd7\u4e2d\u63d0\u53d6\u51fa\u5173\u952e\u6027\u80fd\u6307\u6807\uff0c\u6210\u4e3a\u4fdd\u969c\u7cfb\u7edf\u7a33\u5b9a\u6027\u7684\u91cd\u8981\u6311\u6218\u3002\u672c\u6587\u65e8\u5728\u5c55\u793a\u5982\u4f55\u5229\u7528\u65e5\u5fd7\u63d0\u53d6\u7cfb\u7edf\u7684\u6027\u80fd\u6307\u6807\uff0c\u5e76\u8fdb\u884c\u53ef\u89c6\u5316\u5206\u6790\uff0c\u4ee5\u5b9e\u73b0\u5bf9\u6f5c\u5728\u95ee\u9898\u7684\u65e9\u671f\u9884\u8b66\u3002<\/p>\n<h2>\u65e5\u5fd7\u4e2d\u7684\u5173\u952e\u6027\u80fd\u6307\u6807<\/h2>\n<p>\u5728\u5b9e\u9645\u7684\u7cfb\u7edf\u4e2d\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u4e14\u6709\u4ef7\u503c\u7684\u6027\u80fd\u6307\u6807\uff1a<\/p>\n<ul>\n<li><strong>\u54cd\u5e94\u65f6\u95f4\uff08Latency\uff09<\/strong>\uff1a\u6bcf\u4e2a\u8bf7\u6c42\u4ece\u53d1\u8d77\u5230\u5b8c\u6210\u6240\u9700\u7684\u65f6\u95f4\u3002<\/li>\n<li><strong>\u9519\u8bef\u7387\uff08Error Rate\uff09<\/strong>\uff1a\u5355\u4f4d\u65f6\u95f4\u5185\u53d1\u751f\u9519\u8bef\u7684\u8bf7\u6c42\u6bd4\u4f8b\u3002<\/li>\n<li><strong>\u8d44\u6e90\u4f7f\u7528\u7387\uff08Resource Usage\uff09<\/strong>\uff1aCPU\u3001\u5185\u5b58\u3001\u78c1\u76d8\u548c\u7f51\u7edc\u7684\u4f7f\u7528\u60c5\u51b5\u3002<\/li>\n<li><strong>\u8bf7\u6c42\u541e\u5410\u91cf\uff08Throughput\uff09<\/strong>\uff1a\u5355\u4f4d\u65f6\u95f4\u5185\u7cfb\u7edf\u5904\u7406\u7684\u8bf7\u6c42\u6570\u91cf\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u6307\u6807\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u8bc6\u522b\u6027\u80fd\u74f6\u9888\uff0c\u5e76\u5b9a\u4f4d\u95ee\u9898\u7684\u6839\u672c\u539f\u56e0\u3002<\/p>\n<h2>\u65e5\u5fd7\u683c\u5f0f\u8bbe\u8ba1<\/h2>\n<p>\u4e3a\u4e86\u80fd\u591f\u65b9\u4fbf\u5730\u63d0\u53d6\u6027\u80fd\u6307\u6807\uff0c\u65e5\u5fd7\u683c\u5f0f\u5e94\u5305\u542b\u4ee5\u4e0b\u5b57\u6bb5\uff1a<\/p>\n<ul>\n<li>\u65f6\u95f4\u6233\uff1a\u8bb0\u5f55\u65e5\u5fd7\u7684\u65f6\u95f4\u3002<\/li>\n<li>\u65e5\u5fd7\u7ea7\u522b\uff1a\u5982 INFO\u3001ERROR \u7b49\u3002<\/li>\n<li>\u8bf7\u6c42\u6807\u8bc6\uff1a\u552f\u4e00\u6807\u8bc6\u8bf7\u6c42\u7684 ID\u3002<\/li>\n<li>\u54cd\u5e94\u65f6\u95f4\uff1a\u5f53\u524d\u8bf7\u6c42\u7684\u5904\u7406\u65f6\u95f4\u3002<\/li>\n<li>\u9519\u8bef\u4fe1\u606f\uff1a\u8bb0\u5f55\u9519\u8bef\u4ee3\u7801\u6216\u9519\u8bef\u63cf\u8ff0\u3002<\/li>\n<\/ul>\n<p>\u793a\u4f8b\u65e5\u5fd7\u683c\u5f0f\uff1a<\/p>\n<pre><code class=\"txt\">2025-01-01T12:00:00Z INFO RequestID=12345 Latency=120ms Status=200\n2025-01-01T12:00:01Z ERROR RequestID=12346 Latency=0ms Status=500 Error=&quot;NullPointerException&quot;<\/code><\/pre>\n<h2>\u5b9e\u73b0\u6027\u80fd\u6307\u6807\u63d0\u53d6\u548c\u5206\u6790<\/h2>\n<h3>\u6570\u636e\u63d0\u53d6<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528 Python \u811a\u672c\u4ece\u65e5\u5fd7\u4e2d\u63d0\u53d6\u6307\u6807\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"python\">import re\nimport pandas as pd\n\n# \u65e5\u5fd7\u89e3\u6790\u51fd\u6570\ndef parse_logs(log_file):\n    pattern = r&quot;(?P&lt;timestamp&gt;\/S+) (?P&lt;level&gt;\/S+) RequestID=(?P&lt;request_id&gt;\/S+) Latency=(?P&lt;latency&gt;\/d+)ms Status=(?P&lt;status&gt;\/d+)(?: Error=\/&quot;(?P&lt;error&gt;.+?)\/&quot;)?&quot;\n    logs = []\n    with open(log_file, 'r') as file:\n        for line in file:\n            match = re.match(pattern, line)\n            if match:\n                logs.append(match.groupdict())\n    return pd.DataFrame(logs)\n\n# \u793a\u4f8b\u7528\u6cd5\nlog_file = &quot;system_logs.txt&quot;\ndata = parse_logs(log_file)\ndata['latency'] = data['latency'].astype(int)\ndata['status'] = data['status'].astype(int)\ndata.to_csv(&quot;parsed_logs.csv&quot;, index=False)\n<\/code><\/pre>\n<h3>\u6570\u636e\u5206\u6790<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528 Pandas \u5bf9\u63d0\u53d6\u7684\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u5206\u6790\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"python\"># \u9519\u8bef\u7387\u5206\u6790\ntotal_requests = len(data)\nerror_requests = len(data[data['status'] &gt;= 400])\nerror_rate = error_requests \/ total_requests\n\nprint(f&quot;Total Requests: {total_requests}&quot;)\nprint(f&quot;Error Requests: {error_requests}&quot;)\nprint(f&quot;Error Rate: {error_rate:.2%}&quot;)\n\n# \u54cd\u5e94\u65f6\u95f4\u5206\u5e03\nprint(&quot;Latency Statistics:&quot;)\nprint(data['latency'].describe())\n<\/code><\/pre>\n<h3>\u6570\u636e\u53ef\u89c6\u5316<\/h3>\n<p>\u901a\u8fc7 Matplotlib \u6216 Seaborn \u53ef\u89c6\u5316\u6027\u80fd\u6307\u6807\uff1a<\/p>\n<pre><code class=\"python\">import matplotlib.pyplot as plt\n\n# \u54cd\u5e94\u65f6\u95f4\u5206\u5e03\nplt.hist(data['latency'], bins=20, color='blue', alpha=0.7)\nplt.title(&quot;Response Time Distribution&quot;)\nplt.xlabel(&quot;Latency (ms)&quot;)\nplt.ylabel(&quot;Frequency&quot;)\nplt.show()\n\n# \u9519\u8bef\u7387\u8d8b\u52bf\ndata['timestamp'] = pd.to_datetime(data['timestamp'])\ndata.set_index('timestamp', inplace=True)\nerror_trend = data[data['status'] &gt;= 400].resample('1T').size()\n\nplt.plot(error_trend, color='red', label='Error Rate')\nplt.title(&quot;Error Rate Trend&quot;)\nplt.xlabel(&quot;Time&quot;)\nplt.ylabel(&quot;Error Count&quot;)\nplt.legend()\nplt.show()\n<\/code><\/pre>\n<h2>QA \u73af\u8282<\/h2>\n<h3>\u95ee\u9898 1\uff1a\u65e5\u5fd7\u6570\u636e\u91cf\u8fc7\u5927\u5982\u4f55\u5904\u7406\uff1f<\/h3>\n<p><strong>\u89e3\u7b54<\/strong>\uff1a\u53ef\u4ee5\u91c7\u7528\u5206\u7247\u5b58\u50a8\u3001\u65e5\u5fd7\u538b\u7f29\u548c\u91c7\u6837\u7b49\u6280\u672f\u3002\u4f8b\u5982\uff0c\u5c06\u65e5\u5fd7\u5206\u65f6\u6bb5\u5b58\u50a8\u5230\u4e0d\u540c\u7684\u6587\u4ef6\uff0c\u5e76\u5bf9\u5386\u53f2\u65e5\u5fd7\u8fdb\u884c\u538b\u7f29\u4ee5\u8282\u7701\u7a7a\u95f4\u3002<\/p>\n<h3>\u95ee\u9898 2\uff1a\u5982\u4f55\u4fdd\u969c\u65e5\u5fd7\u7684\u5b9e\u65f6\u6027\uff1f<\/h3>\n<p><strong>\u89e3\u7b54<\/strong>\uff1a\u4f7f\u7528 Kafka \u7b49\u6d88\u606f\u961f\u5217\u5b9e\u73b0\u65e5\u5fd7\u6d41\u5904\u7406\uff0c\u7ed3\u5408\u5b9e\u65f6\u5206\u6790\u5de5\u5177\uff08\u5982 Apache Flink\uff09\u6765\u5904\u7406\u5b9e\u65f6\u65e5\u5fd7\u6570\u636e\u3002<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u4ece\u65e5\u5fd7\u4e2d\u63d0\u53d6\u6027\u80fd\u6307\u6807\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u5feb\u901f\u53d1\u73b0\u7cfb\u7edf\u6f5c\u5728\u95ee\u9898\uff0c\u5e76\u91c7\u53d6\u63aa\u65bd\u63d0\u5347\u7cfb\u7edf\u7684\u7a33\u5b9a\u6027\u3002\u672c\u6587\u63d0\u4f9b\u4e86\u5177\u4f53\u7684\u65e5\u5fd7\u683c\u5f0f\u8bbe\u8ba1\u3001\u6570\u636e\u63d0\u53d6\u4e0e\u5206\u6790\u65b9\u6cd5\uff0c\u4ee5\u53ca\u53ef\u8fd0\u884c\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u9ad8\u6548\u5730\u5229\u7528\u65e5\u5fd7\u3002<\/p>\n<p>\u672a\u6765\uff0c\u968f\u7740\u673a\u5668\u5b66\u4e60\u548c\u4eba\u5de5\u667a\u80fd\u7684\u8fdb\u4e00\u6b65\u53d1\u5c55\uff0c\u53ef\u4ee5\u63a2\u7d22\u66f4\u591a\u81ea\u52a8\u5316\u7684\u65e5\u5fd7\u5206\u6790\u65b9\u6cd5\uff0c\u4f8b\u5982\u5f02\u5e38\u68c0\u6d4b\u548c\u9884\u6d4b\u6a21\u578b\uff0c\u4ece\u800c\u8fdb\u4e00\u6b65\u63d0\u5347\u7cfb\u7edf\u7684\u53ef\u89c2\u5bdf\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<ol>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=pz7cuQ49bgAkW%2B81ZNt0Dg%3D%3D.rFxfGhQX3UmXkz40scvHQ1xUwX%2BedACLz49x9roPo1U%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Pandas \u5b98\u65b9\u6587\u6863<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=ei3tUXFNe3FVIzsgy%2B8yIQ%3D%3D.HrRIq%2FAaQi2ZOjPq63zTckvNW3bBtACoJjzzl14BKWmVilyx2292J0R1gpFHgwnh\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Matplotlib \u5b98\u65b9\u6587\u6863<\/a><\/li>\n<li><a href=\"https:\/\/link.segmentfault.com\/?enc=kiUzI2fmGmxN7ApMTdTxBg%3D%3D.CrIdJgXqshMvCUzDrw1WOp%2BGiEYSGQNaYPk5RgQ0gHf2dzMZ8OZnaWITHfLuOThy\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Kafka \u5b98\u65b9\u6587\u6863<\/a><\/li>\n<\/ol>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046474685\">https:\/\/segmentfault.com\/a\/1190000046474685<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981 \u7cfb\u7edf\u65e5\u5fd7\u662f\u8fd0\u7ef4\u548c\u5f00\u53d1\u8005\u7528\u6765\u53d1\u73b0\u7cfb\u7edf\u6027\u80fd\u74f6\u9888\u3001\u5b9a\u4f4d\u95ee\u9898\u7684\u5173\u952e\u5de5\u5177\u3002\u901a\u8fc7\u4ece\u65e5\u5fd7\u4e2d\u63d0\u53d6\u6709\u4ef7\u503c\u7684\u7cfb\u7edf\u7a33\u5b9a\u6027\u6307\u6807\uff08 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020774","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020774","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020774"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020774\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}