{"id":208350,"date":"2025-07-13T20:00:07","date_gmt":"2025-07-13T12:00:07","guid":{"rendered":"https:\/\/server.hk\/cnblog\/?p=208350"},"modified":"2025-07-13T22:08:07","modified_gmt":"2025-07-13T14:08:07","slug":"linux-windows-%e4%bc%ba%e6%9c%8d%e5%99%a8%e6%aa%a2%e8%a6%96cpu%e8%b3%87%e6%ba%90%e4%bd%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/208350\/","title":{"rendered":"Linux\/Windows \u4f3a\u670d\u5668\u6aa2\u8996CPU\u8cc7\u6e90\u4f54\u7528"},"content":{"rendered":"<h5 dir=\"auto\">\u5f15\u8a00<\/h5>\n<p dir=\"auto\">\u4f5c\u70ba\u4e00\u540d\u6280\u8853\u54e1\uff0c\u76e3\u63a7\u4f3a\u670d\u5668\u7684CPU\u4f7f\u7528\u60c5\u6cc1\u662f\u78ba\u4fdd\u7cfb\u7d71\u6027\u80fd\u548c\u907f\u514d\u5b95\u6a5f\u7684\u91cd\u8981\u4efb\u52d9\u3002\u7121\u8ad6\u662f\u7ba1\u7406Linux\u3001Windows\u9084\u662fmacOS\u4f3a\u670d\u5668\uff0c\u9084\u662f\u4f7f\u7528\u50cfIDC.NET\u63d0\u4f9b\u7684<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u3001<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u96f2\u4f3a\u670d\u5668<\/a>\u9019\u6a23\u7684\u96f2\u89e3\u6c7a\u65b9\u6848\uff0c\u638c\u63e1\u9069\u5408\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u4f7f\u7528\u5167\u7f6e\u5de5\u5177\u3001\u5c08\u696d\u76e3\u63a7\u8edf\u9ad4\u4ee5\u53ca\u96f2\u5e73\u53f0\u529f\u80fd\u4f86\u6aa2\u67e5CPU\u4f7f\u7528\u60c5\u6cc1\uff0c\u4e26\u63d0\u4f9b\u6700\u4f73\u5be6\u8e10\u5efa\u8b70\u3002<\/p>\n<h5 dir=\"auto\">\u5167\u7f6e\u5de5\u5177\u7684\u4f7f\u7528<\/h5>\n<h6 dir=\"auto\">Linux\u4f3a\u670d\u5668<\/h6>\n<p dir=\"auto\">Linux\u63d0\u4f9b\u4e86\u591a\u7a2e\u547d\u4ee4\u884c\u5de5\u5177\u4f86\u76e3\u63a7CPU\u4f7f\u7528\u60c5\u6cc1\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>top<\/strong>\uff1a\u5be6\u6642\u986f\u793a\u7cfb\u7d71\u9032\u7a0b\uff0c\u5305\u62ecCPU\u4f7f\u7528\u7387\uff0c\u6309\u300c1\u300d\u53ef\u67e5\u770b\u6bcf\u500b\u6838\u5fc3\u7684\u8a73\u60c5\u3002<\/li>\n<li><strong>htop<\/strong>\uff1atop\u7684\u589e\u5f37\u7248\uff0c\u754c\u9762\u66f4\u53cb\u597d\u3002<\/li>\n<li><strong>mpstat<\/strong>\uff1asysstat\u5305\u7684\u4e00\u90e8\u5206\uff0c\u63d0\u4f9bCPU\u7d71\u8a08\uff0c\u4f8b\u5982mpstat 5 1\u6bcf5\u79d2\u63a1\u6a23\u4e00\u6b21CPU\u4f7f\u7528\u7387\u3002<\/li>\n<li><strong>ps<\/strong>\uff1a\u67e5\u770b\u9032\u7a0b\u7d1aCPU\u4f54\u7528\uff0c\u4f8b\u5982ps -aux &#8211;sort=-%cpu | head -10\u986f\u793aCPU\u4f54\u7528\u6700\u9ad8\u768410\u500b\u9032\u7a0b\u3002<\/li>\n<\/ul>\n<h6 dir=\"auto\">Windows\u4f3a\u670d\u5668<\/h6>\n<ul dir=\"auto\">\n<li><strong>\u4efb\u52d9\u7ba1\u7406\u5668<\/strong>\uff1a\u6309Ctrl+Shift+Esc\u6253\u958b\uff0c\u5207\u63db\u5230\u300c\u6027\u80fd\u300d\u9078\u9805\u5361\uff0c\u9078\u64c7\u300cCPU\u300d\u67e5\u770b\u4f7f\u7528\u7387\u5716\u8868\u548c\u6838\u5fc3\u4f7f\u7528\u6578\u64da\u3002<\/li>\n<li><strong>PowerShell<\/strong>\uff1a\u4f7f\u7528Get-Counter &#8216;\\Processor(*)\\% Processor Time&#8217;\u7372\u53d6\u5be6\u6642CPU\u4f7f\u7528\u7387\u3002<\/li>\n<\/ul>\n<h6 dir=\"auto\">macOS\u4f3a\u670d\u5668<\/h6>\n<ul dir=\"auto\">\n<li><strong>top<\/strong>\uff1a\u4f7f\u7528top -o cpu\u6309CPU\u4f7f\u7528\u7387\u6392\u5e8f\u9032\u7a0b\u3002<\/li>\n<li><strong>\u6d3b\u52d5\u76e3\u8996\u5668<\/strong>\uff1a\u5f9e\u300c\u61c9\u7528\u7a0b\u5f0f\u300d&gt;\u300c\u5be6\u7528\u5de5\u5177\u300d\u6253\u958b\uff0c\u5207\u63db\u5230\u300cCPU\u300d\u9078\u9805\u5361\u67e5\u770b\u4f7f\u7528\u60c5\u6cc1\u3002<\/li>\n<\/ul>\n<h5 dir=\"auto\">\u5c08\u696d\u76e3\u63a7\u5de5\u5177<\/h5>\n<p dir=\"auto\">\u91dd\u5c0d\u751f\u7522\u74b0\u5883\uff0c\u63a8\u85a6\u4f7f\u7528\u5c08\u696d\u76e3\u63a7\u5de5\u5177\uff1a<\/p>\n<div dir=\"auto\"><button type=\"button\" aria-label=\"\u590d\u5236\" data-state=\"closed\"><\/button><\/p>\n<table dir=\"auto\" data-wide=\"false\">\n<thead>\n<tr>\n<th data-col-size=\"sm\">\u5de5\u5177\u540d\u7a31<\/th>\n<th data-col-size=\"md\">\u529f\u80fd\u7279\u9ede<\/th>\n<th data-col-size=\"lg\">\u5b89\u88dd\u547d\u4ee4\u793a\u4f8b<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td data-col-size=\"sm\">Nagios<\/td>\n<td data-col-size=\"md\">\u4f01\u696d\u7d1a\u76e3\u63a7\uff0c\u652f\u6301\u8b66\u5831<\/td>\n<td data-col-size=\"lg\">apt install nagios<\/td>\n<\/tr>\n<tr>\n<td data-col-size=\"sm\">Zabbix<\/td>\n<td data-col-size=\"md\">\u5206\u6563\u5f0f\u76e3\u63a7\uff0c\u6b77\u53f2\u8cc7\u6599\u5206\u6790<\/td>\n<td data-col-size=\"lg\">yum install zabbix-server<\/td>\n<\/tr>\n<tr>\n<td data-col-size=\"sm\">Prometheus + Grafana<\/td>\n<td data-col-size=\"md\">\u53ef\u8996\u5316\u5100\u8868\u677f\uff0c\u9069\u5408\u5bb9\u5668\u76e3\u63a7<\/td>\n<td data-col-size=\"lg\">docker-compose up<\/td>\n<\/tr>\n<tr>\n<td data-col-size=\"sm\">Netdata<\/td>\n<td data-col-size=\"md\">\u63d0\u4f9b\u5be6\u6642\u5100\u8868\u677f\uff0c\u5f00\u7bb1\u5373\u7528<\/td>\n<td data-col-size=\"lg\">bash &lt;(curl -Ss https:\/\/my-netdata.io\/kickstart.sh)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p dir=\"auto\">\u9019\u4e9b\u5de5\u5177\u7279\u5225\u9069\u5408<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u548c<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2fVPS<\/a>\uff0c\u63d0\u4f9b\u5168\u9762\u7684\u6027\u80fd\u6d1e\u5bdf\u3002<\/p>\n<h5 dir=\"auto\">\u96f2\u5e73\u53f0\u76e3\u63a7<\/h5>\n<p dir=\"auto\">\u5982\u679c\u4f7f\u7528\u96f2\u4f3a\u670d\u5668\uff0c\u5927\u591a\u6578\u63d0\u4f9b\u5546\uff08\u5982IDC.NET\u7684<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u96f2\u4f3a\u670d\u5668<\/a>\uff09\u90fd\u63d0\u4f9b\u5167\u7f6e\u76e3\u63a7\u5de5\u5177\u3002\u4f8b\u5982\uff1a<\/p>\n<ul dir=\"auto\">\n<li>\u767b\u5165IDC.NET\u5e33\u6236\uff0c\u9032\u5165\u4f3a\u670d\u5668\u7ba1\u7406\u90e8\u5206\u3002<\/li>\n<li>\u67e5\u627e\u76e3\u63a7\u6216\u6027\u80fd\u9078\u55ae\u5361\uff0c\u67e5\u770bCPU\u4f7f\u7528\u7387\u5716\u8868\u548c\u6307\u6a19\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u9019\u8b93\u60a8\u7121\u9700\u984d\u5916\u8edf\u9ad4\u5373\u53ef\u76e3\u63a7\u4f3a\u670d\u5668\u5065\u5eb7\u72c0\u6cc1\u3002<\/p>\n<h5 dir=\"auto\">\u95dc\u9375CPU\u6307\u6a19\u89e3\u8b80<\/h5>\n<p dir=\"auto\">\u76e3\u63a7CPU\u6642\uff0c\u9700\u95dc\u6ce8\u4ee5\u4e0b\u6307\u6a19\uff1a<\/p>\n<ul dir=\"auto\">\n<li><strong>%user<\/strong>\uff1a\u4f7f\u7528\u8005\u9032\u7a0b\u4f54\u7528\u7387\uff0c\u6b63\u5e38\u503c\u61c9&lt;70%\u3002<\/li>\n<li><strong>%system<\/strong>\uff1a\u7cfb\u7d71\u5167\u6838\u4f54\u7528\u7387\uff0c\u6b63\u5e38\u503c\u61c9&lt;30%\u3002<\/li>\n<li><strong>%iowait<\/strong>\uff1aI\/O\u7b49\u5f85\u4f54\u6bd4\uff0c\u9ad8\u65bc15%\u53ef\u80fd\u9700\u8b66\u5831\u3002<\/li>\n<li><strong>Load Average<\/strong>\uff1a\u7cfb\u7d71\u8ca0\u8f09\uff0c\u986f\u793a1\/5\/15\u5206\u9418\u5e73\u5747\u503c\uff0c\u8207CPU\u6838\u5fc3\u6578\u6bd4\u8f03\u5224\u65b7\u8ca0\u8f09\u3002<\/li>\n<\/ul>\n<h5 dir=\"auto\">\u9ad8CPU\u4f54\u7528\u6545\u969c\u6392\u67e5<\/h5>\n<p dir=\"auto\">\u767c\u73fe\u9ad8CPU\u4f7f\u7528\u7387\u6642\uff0c\u53ef\u6309\u4ee5\u4e0b\u6b65\u9a5f\u6392\u67e5\uff1a<\/p>\n<ol dir=\"auto\">\n<li>\u4f7f\u7528top\u6216htop\u5b9a\u4f4d\u9ad8\u8ca0\u8f09\u9032\u7a0b\u7684PID\u3002<\/li>\n<li>\u7528ps -p [PID] -o pid,ppid,cmd,%mem,%cpu\u5206\u6790\u9032\u7a0b\u8a73\u60c5\u3002<\/li>\n<li>\u7528top -H -p [PID]\u6aa2\u67e5\u7dda\u7a0b\u7d1a\u6d88\u8017\u3002<\/li>\n<li>\u7528strace -p [PID]\u5206\u6790\u9032\u7a0b\u5806\u758a\u3002<\/li>\n<li>\u7528perf record -p [PID]\u751f\u6210\u6027\u80fd\u5831\u544a\u3002<\/li>\n<\/ol>\n<h5 dir=\"auto\">\u81ea\u52d5\u5316\u76e3\u63a7\u8173\u672c<\/h5>\n<p dir=\"auto\">\u53ef\u4f7f\u7528\u8173\u672c\u6301\u7e8c\u76e3\u63a7CPU\u4f7f\u7528\u7387\uff0c\u4f8b\u5982\u4ee5\u4e0bBash\u8173\u672c\uff0c\u6bcf5\u79d2\u8a18\u9304\u4e00\u6b21\uff1a<\/p>\n<div dir=\"auto\">\n<div>\n<div>bash<\/div>\n<div>\n<div>\n<div><button type=\"button\">\u6536\u8d77<\/button><button type=\"button\">\u81ea\u52a8\u6362\u884c<\/button><button type=\"button\">\u8fd0\u884c<\/button><\/div>\n<p><button type=\"button\">\u590d\u5236<\/button><\/div>\n<\/div>\n<div><code><\/code><\/p>\n<div>\n<div>\n<div>#!\/bin\/bash<\/div>\n<div># \u6bcf5\u79d2\u6536\u96c6CPU\u6578\u64da<\/div>\n<div>while true; do<\/div>\n<div>timestamp=$(date &#8220;+%Y-%m-%d %H:%M:%S&#8221;)<\/div>\n<div>cpu_usage=$(top -bn1 | grep &#8220;Cpu(s)&#8221; | sed &#8220;s\/.*, *\\([0-9.]*\\)%* id.*\/\\1\/&#8221; | awk &#8216;{print 100 &#8211; $1}&#8217;)<\/div>\n<div>echo &#8220;[$timestamp] CPU\u4f7f\u7528\u7387: ${cpu_usage}%&#8221;<\/div>\n<div>sleep 5<\/div>\n<div>done<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div><\/div>\n<div><\/div>\n<\/div>\n<\/div>\n<p dir=\"auto\">\u751f\u7522\u74b0\u5883\u5efa\u8b70\u4f7f\u7528\u66f4\u9ad8\u7d1a\u7684\u76e3\u63a7\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h5 dir=\"auto\">\u6700\u4f73\u5be6\u8e10<\/h5>\n<ul dir=\"auto\">\n<li><strong>\u6301\u7e8c\u76e3\u63a7<\/strong>\uff1a\u4f7f\u7528Prometheus\u7b49\u5de5\u5177\u9032\u884c\u9577\u671f\u76e3\u63a7\u3002<\/li>\n<li><strong>\u8a2d\u7f6e\u8b66\u5831<\/strong>\uff1aCPU\u4f7f\u7528\u7387\u905480%\u8b66\u544a\uff0c95%\u56b4\u91cd\u6642\u89f8\u767c\u8b66\u5831\u3002<\/li>\n<li><strong>\u5b9a\u671f\u5831\u544a<\/strong>\uff1a\u6bcf\u65e5\u6216\u6bcf\u5468\u751f\u6210CPU\u4f7f\u7528\u7387\u5831\u544a\uff0c\u5206\u6790\u8da8\u52e2\u3002<\/li>\n<li><strong>\u5bb9\u5668\u74b0\u5883<\/strong>\uff1aDocker\u7528docker stats\uff0cKubernetes\u7528kubectl top pods\u3002<\/li>\n<\/ul>\n<p dir=\"auto\">\u9078\u64c7\u96f2\u670d\u52d9\u5546\u6642\uff0c\u63a8\u85a6IDC.NET\u7684<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u3001<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2fVPS<\/a>\u548c<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u96f2\u4f3a\u670d\u5668<\/a>\uff0c\u63d0\u4f9b\u53ef\u9760\u670d\u52d9\u548c\u6613\u7528\u7684\u76e3\u63a7\u5de5\u5177\u3002<\/p>\n<h5 dir=\"auto\">\u7d50\u8ad6<\/h5>\n<p dir=\"auto\">\u76e3\u63a7CPU\u4f7f\u7528\u7387\u5c0d\u6280\u8853\u54e1\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u7d50\u5408\u5167\u7f6e\u5de5\u5177\u3001\u5c08\u696d\u8edf\u9ad4\u548c\u96f2\u5e73\u53f0\u529f\u80fd\uff0c\u60a8\u80fd\u78ba\u4fdd\u4f3a\u670d\u5668\u7a69\u5b9a\u904b\u884c\u3002\u91dd\u5c0d\u7ba1\u7406<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u3001<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">\u9999\u6e2f\u96f2\u4f3a\u670d\u5668<\/a>\uff0c\u5982IDC.NET\u9019\u6a23\u7684\u63d0\u4f9b\u5546\u63d0\u4f9b\u4fbf\u6377\u7684\u63a7\u5236\u9762\u677f\u76e3\u63a7\u3002\u5efa\u8b70\u5be6\u65bd\u6301\u7e8c\u76e3\u63a7\u548c\u8b66\u5831\u6a5f\u5236\uff0c\u63d0\u524d\u767c\u73fe\u6027\u80fd\u74f6\u9838\uff0c\u907f\u514d\u670d\u52d9\u4e2d\u65b7\u3002<\/p>\n<hr \/>\n<p dir=\"auto\">\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00 \u4f5c\u70ba\u4e00\u540d\u6280\u8853\u54e1\uff0c\u76e3\u63a7\u4f3a\u670d\u5668&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-208350","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208350","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=208350"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/208350\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=208350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=208350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=208350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}