{"id":130597,"date":"2018-12-18T09:35:10","date_gmt":"2018-12-18T01:35:10","guid":{"rendered":"https:\/\/gulass.cn\/?p=130597"},"modified":"2018-12-17T09:36:50","modified_gmt":"2018-12-17T01:36:50","slug":"golang-toolkits-userd","status":"publish","type":"post","link":"https:\/\/gulass.cn\/golang-toolkits-userd.html","title":{"rendered":"golang toolkits\u5305\u7684\u4f7f\u7528\u65b9\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"
\u5728\u67e5\u770b open-falcon<\/a> \u9879\u76ee\u6e90\u7801\u65f6\uff0c\u7ecf\u5e38\u4f1a\u770b\u5230\u5176\u5f15\u7528\u4e86\u4e00\u4e2a\u7c7b\u5e93\u00a0https:\/\/github.com\/toolkits<\/a> \uff0c\u800c\u4ed4\u7ec6\u67e5\u770b\u8be5\u7c7b\u5e93\u7684\u4f5c\u8005\u4e3a\u79e6\u6653\u8f89\uff08UlricQin\uff09--- \u539fOpen-Falcon\u4e3b\u7a0b\uff0c\u73b0\u6ef4\u6ef4\u4e91\u8fd0\u7ef4\u8d1f\u8d23\u4eba \u3002\u6240\u4ee5\u6709\u4e86\u8fd9\u5c42\u5173\u7cfb\u5c31\u4e0d\u96be\u7406\u89e3open-Falcon\u5f15\u7528toolkits\u91cc\u5f88\u591a\u4ee3\u7801\u7684\u539f\u56e0\u4e86\u5427\u3002toolkits\u91cc\u6839\u636e\u6a21\u5757\u7c7b\u578b\u5206\u4e86\u591a\u4e2a\u5b50\u9879\u76ee\uff0c\u5176\u6839\u636e\u7c7b\u578b\u53c8\u5206\u4e3aLINUX\u5e95\u5c42\u6027\u80fd\u76d1\u63a7\u7684\u3001\u90ae\u4ef6\u53d1\u9001\u7684\u3001\u7f51\u7edc\u7684\u7b49\uff0c\u8fd9\u91cc\u4ee5nux\u9879<\/a>\u4e3a\u4f8b\uff0c\u8bf4\u4e0b\u5982\u4e0b\u5f15\u7528\u3002<\/p>\n \u5982\u4e0b\u5f15\u7528\u5176\u4e2d\u7684\u90e8\u5206\u5b9e\u73b0\u7684\u51fd\u6570\u8fdb\u884c\u5904\u7406\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n <\/a><\/p>\n \u5176\u4ee3\u7801\u5199\u7684\u6bd4\u8f83\u6e05\u6670\u7b80\u6d01\uff0c\u53ef\u4ee5\u4f5c\u4e3a\u53c2\u8003\u4f7f\u7528\u4e0b\u3002\u4e0d\u8fc7\u5176\u5bf9\u90e8\u5206\u6307\u6807\u5904\u7406\u7684\u7ed3\u679c\u53ef\u80fd\u548c\u6211\u4eec\u6240\u9700\u7684\u7ed3\u679c\u8fd8\u662f\u6709\u4e00\u4e9b\u51fa\u5165\uff0c\u6bd4\u5982\uff0c\u6211\u4eec\u5e73\u65f6\u9700\u8981\u67e5\u770b\u7684CPU\u4f7f\u7528\u7387\uff0c\u5e76\u4e0d\u4f1a\u53d6\u5404\u5404\u6307\u6807\u5360\u7528\u7684CPU\u65f6\u95f4\uff0c\u800c\u662f\u76f4\u63a5\u50cftop\u67e5\u770b\u5230\u7684\u7ed3\u679c\u4e00\u6837\uff0c\u53ea\u770bidel\u3001us\u7b49\u5360\u7528\u7684CPU\u767e\u5206\u6bd4\u662f\u591a\u5c11\u3002\u6b63\u56e0\u4e3a\u5982\u4e9b\uff0c\u6240\u4ee5open-falcon\u9879\u76ee\u5728\u6b64\u57fa\u7840\u4e0a\u53c8\u8fdb\u884c\u4e86\u4e8c\u6b21\u5c01\u88c5\uff0c\u5176\u5730\u5740\u4e3a\uff1ahttps:\/\/github.com\/open-falcon\/falcon-plus\/blob\/master\/modules\/agent\/funcs\/cpustat.go<\/a>\u00a0\u8fd9\u91cc\u53ea\u53d6\u5176\u4e2d\u4e00\u4e2a\u6307\u6807\u7684\u83b7\u53d6\u65b9\u5f0f\u7684\u4ee3\u7801\uff0c\u5982\u4e0b\uff1a<\/p>\n \u5728\u67e5\u770b open-falcon \u9879\u76ee\u6e90\u7801\u65f6\uff0c\u7ecf\u5e38\u4f1a\u770b\u5230\u5176\u5f15\u7528\u4e86\u4e00\u4e2a\u7c7b\u5e93\u00a0https:\/\/github.com\/ […]<\/p>\n","protected":false},"author":643,"featured_media":130871,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-130597","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/130597","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=130597"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/130597\/revisions"}],"predecessor-version":[{"id":130900,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/130597\/revisions\/130900"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/130871"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=130597"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=130597"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=130597"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\/\/ code from www.361way.com\r\npackage main\r\nimport (\r\n\"fmt\"\r\n\"github.com\/toolkits\/nux\"\r\n)\r\nfunc main() {\r\nl,_ := nux.LoadAvg()\r\nfmt.Println(nux.LoadAvg())\r\nm,_ := nux.MemInfo()\r\nfmt.Println(l)\r\nfmt.Println(l.Avg1min)\r\nfmt.Println(m)\r\nfmt.Println(nux.NumCpu())\r\n\/\/fmt.Println(nux.CurrentProcStat())\r\nfmt.Println(nux.ListMountPoint())\r\nfmt.Println(nux.BuildDeviceUsage(\"\/dev\/mapper\/centos-root\",\"\/\",\"xfs\"))\r\n}\r\n\u6267\u884c\u7ed3\u679c\u5982\u4e0b\uff1a<\/pre>\n
func CpuIdle() float64 {\r\npsLock.RLock()\r\ndefer psLock.RUnlock()\r\ndt := deltaTotal()\r\nif dt == 0 {\r\nreturn 0.0\r\n}\r\ninvQuotient := 100.00 \/ float64(dt)\r\nreturn float64(procStatHistory[0].Cpu.Idle-procStatHistory[1].Cpu.Idle) * invQuotient\r\n}\r\n<\/pre>\n