{"id":5413,"date":"2020-07-30T13:10:06","date_gmt":"2020-07-30T05:10:06","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5413"},"modified":"2020-07-30T13:10:06","modified_gmt":"2020-07-30T05:10:06","slug":"%e7%9b%91%e6%8e%a7%e5%91%bd%e4%bb%a4%e4%b9%8btsar","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5413","title":{"rendered":"\u76d1\u63a7\u547d\u4ee4\u4e4btsar"},"content":{"rendered":"<h1>1.1 tsar\u662f\u4ec0\u4e48\uff1f<\/h1>\n<div>\n<div id=\\\"cnblogs_post_body\\\">\n\u3000\u3000tsar\u662f\u6dd8\u5b9d\u81ea\u5df1\u5f00\u53d1\u7684\u4e00\u4e2a\u91c7\u96c6\u5de5\u5177\uff08\u7c7b\u4f3c\u4e8esar\u5de5\u5177\uff09\uff0c\u4e3b\u8981\u7528\u6765\u6536\u96c6\u670d\u52a1\u5668\u7684\u7cfb\u7edf\u4fe1\u606f\uff08\u5982cpu\uff0cio\uff0cmem\uff0ctcp\u7b49\uff09\uff0c\u4ee5\u53ca\u5e94\u7528\u6570\u636e\uff08\u5982squid haproxy nginx\u7b49\uff09\u3002<br \/>\n\u6536\u96c6\u5230\u7684\u6570\u636e\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\uff0c\u53ef\u4ee5\u968f\u65f6\u67e5\u8be2\u5386\u53f2\u4fe1\u606f\uff0c\u8f93\u51fa\u65b9\u5f0f\u7075\u6d3b\u591a\u6837\uff0c\u53e6\u5916\u652f\u6301\u5c06\u6570\u636e\u5b58\u50a8\u5230mysql\u4e2d\uff0c\u4e5f\u53ef\u4ee5\u5c06\u6570\u636e\u53d1\u9001\u5230nagios\u62a5\u8b66\u670d\u52a1\u5668\u3002<br \/>\ntsar\u5728\u5c55\u793a\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u6a21\u5757\uff0c\u5e76\u4e14\u53ef\u4ee5\u5bf9\u591a\u6761\u4fe1\u606f\u7684\u6570\u636e\u8fdb\u884cmerge\u8f93\u51fa\uff0c\u5e26&#8211;live\u53c2\u6570\u53ef\u4ee5\u8f93\u51fa\u79d2\u7ea7\u7684\u5b9e\u65f6\u4fe1\u606f\u3002<br \/>\ntsar\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u6a21\u5757\u8f7b\u677e\u6269\u5c55\uff0c\u8fd9\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u4e14\u591a\u529f\u80fd\u7684\u62a5\u544a\u5de5\u5177\u3002<br \/>\n\u5b98\u65b9\u7f51\u5740\uff1a<a href=\\\"http:\/\/tsar.taobao.org\/\\\">http:\/\/tsar.taobao.org<\/a><br \/>\ngithub\u5730\u5740\uff1a<a href=\\\"https:\/\/github.com\/alibaba\/tsar\\\">https:\/\/github.com\/alibaba\/tsar<\/a><\/p>\n<h3 id=\\\"auto-id-1\\\">1.1.1 \u603b\u4f53\u67b6\u6784<\/h3>\n<p>tsar\u662f\u57fa\u4e8e\u6a21\u5757\u5316\u8bbe\u8ba1\u7684\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u6709\u4e24\u90e8\u5206\u7ec4\u6210\uff1a\u6846\u67b6\u548c\u6a21\u5757\u3002<br \/>\n\u6846\u67b6\u7a0b\u5e8f\u6e90\u4ee3\u7801\u4e3b\u8981\u5728src\u76ee\u5f55\uff0c\u800c\u6a21\u5757\u6e90\u4ee3\u7801\u4e3b\u8981\u5728modules\u76ee\u5f55\u4e2d\u3002<br \/>\n\u6846\u67b6\u63d0\u4f9b\u5bf9\u914d\u7f6e\u6587\u4ef6\u7684\u89e3\u6790\uff0c\u6a21\u5757\u7684\u52a0\u8f7d\uff0c\u547d\u4ee4\u884c\u53c2\u6570\u7684\u89e3\u6790\uff0c\u5e94\u7528\u6a21\u5757\u7684\u63a5\u53e3\u5bf9\u6a21\u5757\u539f\u59cb\u6570\u636e\u7684\u89e3\u6790\u4e0e\u8f93\u51fa\u3002 \u6a21\u5757\u63d0\u4f9b\u63a5\u53e3\u7ed9\u6846\u67b6\u8c03\u7528\u3002<br \/>\ntsar\u4f9d\u8d56\u4e0ecron\u6bcf\u5206\u949f\u6267\u884c\u91c7\u96c6\u6570\u636e\uff0c\u56e0\u6b64\u5b83\u9700\u8981\u7cfb\u7edf\u5b89\u88c5\u5e76\u542f\u7528crond\uff0c\u5b89\u88c5\u540e\uff0ctsar\u6bcf\u5206\u949f\u4f1a\u6267\u884ctsar &#8211;cron\u6765\u5b9a\u65f6\u91c7\u96c6\u4fe1\u606f\uff0c\u5e76\u4e14\u8bb0\u5f55\u5230\u539f\u59cb\u65e5\u5fd7\u6587\u4ef6\u3002<\/p>\n<h3 id=\\\"auto-id-2\\\">1.1.2 tsar\u7684\u8fd0\u884c\u6d41\u7a0b\u56fe<\/h3>\n<p align=\\\"center\\\">\u00a0<img src=\\\"https:\/\/images2018.cnblogs.com\/blog\/1190037\/201806\/1190037-20180604214121023-576776588.png\\\" alt=\\\"\\\" \/><\/p>\n<p>\u4e3b\u8981\u6267\u884c\u6d41\u7a0b\u6709\uff1a<br \/>\n(1)\u89e3\u6790\u8f93\u5165<br \/>\n\u6839\u636e\u7528\u6237\u7684\u8f93\u5165\uff0c\u521d\u59cb\u5316\u4e00\u4e9b\u5168\u5c40\u4fe1\u606f\uff0c\u5982\u95f4\u9694\u65f6\u95f4\uff0c\u662f\u5426merge\uff0c\u662f\u5426\u6307\u5b9a\u6a21\u5757\uff0c\u8fd0\u884c\u6a21\u5f0f<br \/>\n(2)\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u4fe1\u606f<br \/>\n\u4e3b\u8981\u89e3\u6790tsar\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5982\u679cinclude\u751f\u6548\uff0c\u5219\u4f1a\u89e3\u6790include\u7684\u914d\u7f6e\u6587\u4ef6<br \/>\n\u914d\u7f6e\u6587\u4ef6\u7528\u6765\u83b7\u5f97tsar\u9700\u8981\u52a0\u8f7d\u7684\u6a21\u5757\uff0c\u8f93\u51fa\u65b9\u5f0f\uff0c\u6bcf\u4e00\u7c7b\u8f93\u51fa\u65b9\u5f0f\u5305\u542b\u7684\u6a21\u5757\uff0c\u548c\u6b64\u8f93\u51fa\u65b9\u5f0f\u7684\u63a5\u6536\u4fe1\u606f\uff0c\u5982mod_cpu on\u4ee3\u8868\u91c7\u96c6cpu\u7684\u4fe1\u606f<br \/>\noutput_interface file,nagios\u8868\u793a\u5411\u6587\u4ef6\u548cnagios\u670d\u52a1\u5668\u53d1\u9001\u91c7\u96c6\u4fe1\u606f\u548c\u62a5\u8b66\u4fe1\u606f<br \/>\n(3)\u52a0\u8f7d\u76f8\u5e94\u6a21\u5757<br \/>\n\u6839\u636e\u914d\u7f6e\u6587\u4ef6\u7684\u6a21\u5757\u5f00\u542f\u5173\u95ed\u60c5\u51b5\uff0c\u5c06\u6a21\u5757\u7684\u52a8\u6001\u5e93load\u5230\u7cfb\u7edf<br \/>\n(4)tsar\u7684\u4e09\u79cd\u8fd0\u884c\u6a21\u5f0f<br \/>\ntsar\u5728\u8fd0\u884c\u7684\u65f6\u5019\u6709\u4e09\u79cd\u6a21\u5f0f\uff1a<br \/>\nprint\u6a21\u5f0f,\u4ec5\u4ec5\u8f93\u51fa\u6307\u5b9a\u7684\u6a21\u5757\u4fe1\u606f\uff0c\u9ed8\u8ba4\u663e\u793a\u6700\u8fd1\u4e00\u5929\u7684\uff1b<br \/>\nlive\u6a21\u5f0f,\u662f\u8f93\u51fa\u5f53\u524d\u4fe1\u606f\uff0c\u53ef\u4ee5\u7cbe\u786e\u5230\u79d2\u7ea7<br \/>\ncron\u6a21\u5f0f\uff0c\u6b64\u4e00\u822c\u662fcrontab\u5b9a\u65f6\u6267\u884c\uff0c\u6bcf\u4e00\u5206\u949f\u91c7\u96c6\u4e00\u6b21\u6240\u6709\u914d\u7f6e\u7684\u6a21\u5757\u4fe1\u606f\uff0c\u5e76\u5c06\u6570\u636e\u5199\u5165\u539f\u59cb\u6587\u4ef6\uff0c\u5728cron\u8fd0\u884c\u7684\u65f6\u5019 \u4f1a\u5224\u65ad\u662f\u5426\u914d\u7f6e\u8f93\u51fa\u5230db\u6216\u8005nagios\uff0c\u5982\u679c\u914d\u7f6e\u5219\u5c06\u76f8\u5e94\u683c\u5f0f\u7684\u6570\u636e\u8f93\u51fa\u5230\u5bf9\u5e94\u63a5\u53e3\u3002<br \/>\n(5)\u91ca\u653e\u8d44\u6e90<br \/>\n\u7a0b\u5e8f\u6700\u540e\uff0c\u91ca\u653e\u52a8\u6001\u5e93\uff0c\u7a0b\u5e8f\u7ed3\u675f<\/p>\n<h2 id=\\\"auto-id-3\\\">1.2 tsar\u7684\u5b89\u88c5<\/h2>\n<h3 id=\\\"auto-id-4\\\">1.2.1 \u4f7f\u7528git\u4e0b\u8f7d\u6e90\u7801\u5305<\/h3>\n<p>\u53ef\u4ee5\u8bbf\u95eealibaba\u7684github\u627e\u5230tsar\u8fdb\u884c\u4e0b\u8f7d<\/p>\n<div>\n<div>\n<pre>$ git clone git:\/\/github.com\/kongjian\/tsar.git\n$ cd tsar\n$ make\n# make install<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-5\\\">1.2.2 \u4e0b\u8f7dzip\u6587\u4ef6\u5e76\u5b89\u88c5<\/h3>\n<p>\u8bbf\u95ee\u8fde\u63a5\u5730\u5740\uff0c\u83b7\u53d6\u6e90\u7801\u5305\uff0c\u8fdb\u884c\u7f16\u8bd1\u5b89\u88c5<\/p>\n<div>\n<div>\n<pre>$ wget -O tsar.zip https:\/\/github.com\/alibaba\/tsar\/archive\/master.zip --no-check-certificate\n$ unzip tsar.zip\n$ cd tsar\n$ make\n# make install<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-6\\\">1.2.3 \u76ee\u5f55\u6587\u4ef6\u8bf4\u660e<\/h3>\n<p>\u5b89\u88c5\u540e\uff0c\u60a8\u53ef\u80fd\u4f1a\u770b\u5230\u8fd9\u4e9b\u6587\u4ef6\uff1a<\/p>\n<div>\n<div>\n<pre>\/etc\/tsar\/tsar.conf\uff0c\u8fd9\u662ftsar\u7684\u4e3b\u8981\u914d\u7f6e\u6587\u4ef6;\n\/etc\/cron.d\/tsar\uff0c\u7528\u4e8e\u6bcf\u5206\u949f\u8fd0\u884ctsar\u6536\u96c6\u4fe1\u606f;\n\/etc\/logrotate.d\/tsar \u5c06\u6bcf\u4e2a\u6708\u8f6e\u8be2tsar\u7684\u65e5\u5fd7\u6587\u4ef6;\n\/usr\/local\/tsar\/modules \u662f\u6240\u6709\u6a21\u5757\u5e93\uff08* .so\uff09\u6240\u5728\u7684\u76ee\u5f55;\n\/usr\/local\/man\/man8\/ \u5e2e\u52a9\u6587\u4ef6<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-7\\\">1.2.4 tsar\u914d\u7f6e\u6587\u4ef6\u8bf4\u660e<\/h3>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# cat \/etc\/tsar\/tsar.conf\n####debug_level(INFO DEBUG WARN ERROR FATAL)\ndebug_level ERROR  #\u6307\u5b9atsar\u7684\u8fd0\u884c\u7ea7\u522b\uff0c\u4e3b\u8981\u7528\u6765\u8c03\u8bd5\u4f7f\u7528\n####[module]  ##on\/off to enable mod\nmod_cpu on\nmod_mem on\nmod_swap on\nmod_tcp on\nmod_udp on\nmod_traffic on\nmod_io on\nmod_pcsw on\nmod_partition on\nmod_tcpx on\nmod_load on\nmod_apache off\nmod_lvs off\nmod_haproxy off\nmod_squid off\nmod_nginx off\nmod_nginx_multiport off\nmod_nginx_live off\n#mod_nginx_sys_mport on 80 8080\nmod_swift off\nmod_swift_code off\nmod_swift_domain off\nmod_swift_esi off\nmod_swift_fwd off\nmod_swift_store off\nmod_swift_swapdir off\nmod_swift_purge off\nmod_swift_sys off\nmod_swift_tcmalloc off\nmod_tmd off\nmod_percpu off\nmod_tcprt off\nmod_proc off pidname\nmod_pharos off\nmod_tmd4 off\nmod_keyserver off\n#mod_erpc on \/etc\/tsar\/erpc.conf\n#mod_search on\n####output_interface file,db,nagios\noutput_interface file   #\u8bbe\u7f6e\u8f93\u51fa\u7c7b\u578b\uff0c\u652f\u6301file\uff0cnagios\uff0cdb\n####[output_file] original data to store\noutput_file_path \/var\/log\/tsar.data\n####[output_stdio] these mod will be show as using tsar command  #\u8bbe\u7f6e\u7528\u6237\u7ec8\u7aef\u9ed8\u8ba4\u663e\u793a\u7684\u6a21\u5757\noutput_stdio_mod mod_swap,mod_partition,mod_cpu,mod_mem,mod_lvs,mod_haproxy,mod_traffic,mod_squid,mod_load,mod_tcp,mod_udp,mod_tcpx,mod_apache,mod_pcsw,mod_io,mod_percpu\n####[output_db]  #\u8bbe\u7f6e\u54ea\u4e9b\u6a21\u5757\u8f93\u51fa\u5230\u6570\u636e\u5e93\n#output_db_mod mod_swap,mod_partition,mod_cpu,mod_mem,mod_traffic,mod_load,mod_tcp,mod_udp,mod_pcsw,mod_io\n#output_db_addr console2:56677  #\u6570\u636e\u5e93\u7684ip\u548c\u7aef\u53e3\n####[output_tcp]\n#output_tcp_mod mod_swap,mod_cpu\n#output_tcp_addr localhost:9666\n#output_tcp_merge on\n####support include other mod conf\ninclude \/etc\/tsar\/conf.d\/*.conf\n####The IP address or the host running the NSCA daemon\n#server_addr nagios.server.com\n####The port on which the daemon is running - default is 5667\n#server_port 8086\n####The cycle of send alert to nagios\n#cycle_time 300  #\u6307\u5b9a\u4e0a\u62a5\u7684\u95f4\u9694\u65f6\u95f4\uff0c\u7531\u4e8etsar\u6bcf\u4e00\u5206\u949f\u91c7\u96c6\u4e00\u6b21\uff0c\u4e0a\u62a5\u65f6\u4f1a\u5224\u65ad\u662f\u5426\u7b26\u5408\u65f6\u95f4\u95f4\u9694\uff0c\u5982\u8bbe\u7f6e300\u7684\u8bdd\uff0c\u5219\u57280\uff0c5\u7b49\u6574\u70b9\u5206\u949f\u4f1a\u4e0a\u62a5\n####nsca client program\n#send_nsca_cmd \/usr\/bin\/send_nsca\n#send_nsca_conf \/home\/a\/conf\/amon\/send_nsca.conf\n####tsar mod alert config file\n####threshold servicename.key;w-min;w-max;c-min;cmax;\n#threshold cpu.util;N;N;N;N;\n#\u8bbe\u7f6e\u67d0\u4e2a\u8981\u62a5\u8b66\u9879\u7684\u9600\u503c,\u524d\u9762\u662f\u6a21\u5757\u548c\u8981\u76d1\u63a7\u7684\u5177\u4f53\u540d\u79f0\uff0c\u540e\u9762\u7684\u56db\u4e2a\u6570\u636e\u4ee3\u8868\u62a5\u8b66\u7684\u8303\u56f4\uff0cwarn\u548ccritical\u7684\u8303\u56f4\u3002<\/pre>\n<\/div>\n<\/div>\n<h2 id=\\\"auto-id-8\\\">1.3 tsar\u7684\u4f7f\u7528<\/h2>\n<p>\u67e5\u770b\u4f7f\u7528\u5e2e\u52a9<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --help\nUsage: tsar [options]\nOptions:\n    -check         display last record for alert #\u68c0\u67e5\u663e\u793a\u8b66\u62a5\u7684\u6700\u540e\u8bb0\u5f55\n    --check\/-C     display last record for alert.example:tsar --check \/ tsar --check --cpu --io\n    --watch\/-w     display last records in N mimutes. example:tsar --watch 30 \/ tsar --watch 30 --cpu --io\n    --cron\/-c      run in cron mode, output data to file\n    --interval\/-i  specify intervals numbers, in minutes if with --live, it is in seconds  #\u6307\u5b9a\u95f4\u9694\u6570\u5b57\uff0c\u5982\u679c\u4f7f\u7528--live\uff0c\u5219\u4ee5\u5206\u949f\u4e3a\u5355\u4f4d\uff0c\u4ee5\u79d2\u4e3a\u5355\u4f4d\n    --list\/-L      list enabled modules\n    --live\/-l      running print live mode, which module will print\n    --file\/-f      specify a filepath as input\n    --ndays\/-n     show the value for the past days (default: 1)\n    --date\/-d      show the value for the specify day(n or YYYYMMDD)\n    --merge\/-m     merge multiply item to one\n    --detail\/-D    do not conver data to K\/M\/G  #\u4e0d\u4f1a\u5c06\u6570\u636e\u8f6c\u6362\u4e3aK \/ M \/ G\n    --spec\/-s      show spec field data, tsar --cpu -s sys,util\n    --item\/-I      show spec item data, tsar --io -I sda\n    --help\/-h      help\nModules Enabled:\n    --cpu               CPU share (user, system, interrupt, nice, &amp; idle)\n    --mem               Physical memory share (active, inactive, cached, free, wired)\n    --swap              swap usage\n    --tcp               TCP traffic     (v4)\n    --udp               UDP traffic     (v4)\n    --traffic           Net traffic statistics\n    --io                Linux I\/O performance\n    --pcsw              Process (task) creation and context switch\n    --partition         Disk and partition usage\n    --tcpx              TCP connection data\n    --load              System Run Queue and load average<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-9\\\">1.3.1 \u5e38\u7528\u547d\u4ee4<\/h3>\n<p>#\u4ee51\u79d2\u949f\u4e3a\u95f4\u9694\uff0c\u5b9e\u65f6\u6253\u5370tsar\u7684\u6982\u8ff0\u6570\u636e<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]#  tsar -i 1 -l\nTime              ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda---  ---load-\nTime                util     util   retran    bytin  bytout     util     load1\n04\/06\/18-21:09:22   0.00    18.48     0.00    60.00  278.00     0.00     0.00\n04\/06\/18-21:09:23   1.96    18.48     0.00    60.00  198.00     0.00     0.00\n04\/06\/18-21:09:24   0.00    18.48     0.00    60.00  198.00     0.00     0.00\n04\/06\/18-21:09:25   0.00    18.48     0.00    60.00  198.00     0.00     0.00<\/pre>\n<\/div>\n<\/div>\n<p># \u68c0\u67e5\u78c1\u76d8io\u60c5\u51b5<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --io  --check\nclsn6    tsar    io:sda:rrqms=0.0 io:sda:wrqms=0.0 io:sda:rs=0.0 io:sda:ws=0.1 io:sda:rsecs=0.0 io:sda:wsecs=0.7 io:sda:rqsize=4.9 io:sda:qusize=0.0 io:sda:await=0.7 io:sda:svctm=0.6 io:sda:util=0.0<\/pre>\n<\/div>\n<\/div>\n<p># tsar \u663e\u793a1\u5929\u5185\u7684\u5386\u53f2\u6c47\u603b\uff08summury\uff09\u4fe1\u606f\uff0c\u4ee5\u9ed8\u8ba45\u5206\u949f\u4e3a\u95f4\u9694<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --swap   --check\nclsn6    tsar    swap:swpin=0.0 swap:swpout=0.0 swap:total=805302272.0 swap:util=0.0\n[root@clsn6 tsar]# tsar\nTime           ---cpu-- ---mem-- ---tcp-- -----traffic---- --sda---  ---load-\nTime             util     util   retran    bytin  bytout     util     load1\n04\/06\/18-20:45   0.16    18.39     0.00    72.00   89.00     0.15     0.00\n04\/06\/18-20:50   0.16    18.41     0.00     5.00    3.00     0.03     0.00\n04\/06\/18-20:55   0.15    18.39     0.00     4.00    3.00     0.01     0.00\n04\/06\/18-21:00   0.15    18.54     0.00     4.00    3.00     0.02     0.00\n04\/06\/18-21:05   0.16    18.24     0.00    21.00   32.00     0.10     0.00\n04\/06\/18-21:10   0.18    18.27     0.00    19.00   24.00     0.01     0.00\nMAX              0.16    18.54     0.00    72.00   89.00     0.15     0.00\nMEAN             0.16    18.37     0.00    10.60   13.00     0.03     0.00\nMIN              0.16    18.24     0.00     4.00    3.00     0.03     0.00<\/pre>\n<\/div>\n<\/div>\n<p># tsar &#8211;cpu -i 1 \u663e\u793a\u4e00\u5929\u5185cpu\u7684\u5386\u53f2\u4fe1\u606f\uff0c\u4ee51\u5206\u949f\u4e3a\u95f4\u9694<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --cpu -i 1\nTime           -----------------------cpu----------------------\nTime             user     sys    wait    hirq    sirq    util\n04\/06\/18-20:37   0.01    0.10    0.02    0.00    0.03    0.14\n04\/06\/18-20:38   0.00    0.13    0.30    0.00    0.02    0.15\n04\/06\/18-20:39   0.02    0.12    0.00    0.00    0.05    0.18\n04\/06\/18-20:40   0.02    0.13    0.00    0.00    0.03    0.18\n04\/06\/18-20:41   0.00    0.08    0.00    0.00    0.03    0.12\n04\/06\/18-20:42   0.02    0.10    0.00    0.00    0.03    0.15\n\u00b7\u00b7\u00b7<\/pre>\n<\/div>\n<\/div>\n<p># tsar &#8211;live &#8211;mem -i 2 \u4ee52\u79d2\u949f\u4e3a\u95f4\u9694\uff0c\u5b9e\u65f6\u6253\u5370mem\u7684\u6570\u636e\u3002<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --live --mem -i 2\nTime              -----------------------mem----------------------\nTime                free    used    buff    cach   total    util\n04\/06\/18-21:14:47 142.1M   87.5M   51.2M  193.8M  474.6M   18.44\n04\/06\/18-21:14:49 142.1M   87.5M   51.2M  193.8M  474.6M   18.44\n04\/06\/18-21:14:51 142.1M   87.5M   51.2M  193.8M  474.6M   18.44\n\u00b7\u00b7\u00b7<\/pre>\n<\/div>\n<\/div>\n<p># tsar &#8211;cpu &#8211;mem -i 1 \u663e\u793a\u4e00\u5929\u5185\u7684cpu\u548c\u5185\u5b58\u5386\u53f2\u6570\u636e\uff0c\u4ee51\u5206\u949f\u4e3a\u95f4\u9694\u3002<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]# tsar --cpu --mem -i 1\nTime           -----------------------cpu---------------------- -----------------------\nmem----------------------\nTime             user     sys    wait    hirq    sirq    util     free    used    buff\n   cach   total    util\n04\/06\/18-20:37   0.01    0.10    0.02    0.00    0.03    0.14   148.0M   84.7M   50.3M\n 191.6M  474.6M   17.85\n04\/06\/18-20:38   0.00    0.13    0.30    0.00    0.02    0.15   147.6M   84.8M   50.4M\n 191.8M  474.6M   17.87\n04\/06\/18-20:39   0.02    0.12    0.00    0.00    0.05    0.18   147.6M   84.8M   50.4M\n 191.8M  474.6M   17.88\n04\/06\/18-20:40   0.02    0.13    0.00    0.00    0.03    0.18   146.3M   86.1M   50.4M\n 191.8M  474.6M   18.15\n04\/06\/18-20:41   0.00    0.08    0.00    0.00    0.03    0.12   147.5M   84.9M   50.4M\n 191.8M  474.6M   17.89\n\u00b7\u00b7\u00b7<\/pre>\n<\/div>\n<\/div>\n<h2 id=\\\"auto-id-10\\\">1.4 tsar\u6dfb\u52a0\u6a21\u5757<\/h2>\n<h3 id=\\\"auto-id-11\\\">1.4.1 \u6a21\u5757\u5f00\u53d1<\/h3>\n<p>tsar\u7f16\u8bd1\u5b89\u88c5\u540e\u5373\u53ef\u4ee5\u8fdb\u884c\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u5f00\u53d1<br \/>\n\u6b65\u9aa4\u5982\u4e0b<br \/>\n1.\u6267\u884ctsardevel mymod\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u751f\u6210\u4e00\u4e2amymod\u6587\u4ef6\u5939<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]#  tsardevel mymod\nbuild:make\ninstall:make install\nuninstall:make uninstall\ntest:tsar --list or tsar --mymod --live -i 1\n[root@clsn6 tsar]#  tsardevel mymod\nbuild:make\ninstall:make install\nuninstall:make uninstall\ntest:tsar --list or tsar --mymod --live -i 1<\/pre>\n<\/div>\n<\/div>\n<p>2.\u4fee\u6539\u91cc\u9762\u7684mod_mymod.c\u6210\u81ea\u5df1\u60f3\u8981\u7684\u91c7\u96c6\u7a0b\u5e8f\u5f00\u53d1\u624b\u518c\uff0cmake make install\u5373\u53ef\u4ee5\u5b89\u88c5\u5230\u7cfb\u7edf<\/p>\n<div>\n<div>\n<pre>[root@clsn6 mymod]# make\ngcc -I\/usr\/local\/tsar\/devel -Wall -fPIC --shared -g  mod_mymod.c -o mod_mymod.so\n[root@clsn6 mymod]# make install\ncp .\/mod_mymod.so \/usr\/local\/tsar\/modules\/\ncp .\/mod_mymod.conf \/etc\/tsar\/conf.d\/mymod.conf<\/pre>\n<\/div>\n<\/div>\n<p>3.\u8fd9\u65f6\u7cfb\u7edf\u5373\u53ef\u4ee5\u4f7f\u7528mymod\u7684\u91c7\u96c6\uff1a<\/p>\n<div>\n<div>\n<pre>[root@clsn6 mymod]# tsar -i 1 -l --mymod\nTime        ----------mymod---------\nTime                  value1  value2  value3\n04\/06\/18-21:32:19    1.0     1.0     1.0\n04\/06\/18-21:32:20    1.0     1.0     1.0\n04\/06\/18-21:32:21    1.0     1.0     1.0<\/pre>\n<\/div>\n<\/div>\n<p>4.\u81ea\u5b9a\u4e49\u7684\u6a21\u5757\u914d\u7f6e\uff1a\/etc\/tsar\/conf.d\/mymod.conf \u53ef\u4ee5\u5728\u8fd9\u4e2a\u6587\u4ef6\u914d\u7f6e\u6a21\u5757\u5f00\u542f\u5173\u95ed\uff0c\u662f\u5426\u8f93\u51fa\u5230db\/nagios\uff0c\u4ee5\u53canagios\u7684\u62a5\u8b66\u9600\u503c mod_mymod on<\/p>\n<div>\n<div>\n<pre>#add it to tsar default output\noutput_stdio_mod mod_mymod\n#add it to center db\n#output_db_mod mod_mymod\n#add it to nagios send\n#set nagios threshold for alert\noutput_nagios_mod mod_mymod\nthreshold mymod.value1;N;N;N;N;<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-12\\\">1.4.2 \u5b89\u88c5nginx\u6a21\u5757<\/h3>\n<p>tsar\u4e2d\u53ef\u4ee5\u6dfb\u52a0\u5f88\u591a\u7684\u76d1\u63a7\u6a21\u5757\uff0c\u8fd9\u6b21\u6dfb\u52a0nginx\u76d1\u63a7\u6a21\u5757\u3002<br \/>\ntsar\u7684nginx\u6269\u5c55\u6a21\u5757\u9879\u76ee\u4e3b\u9875\u4e3a\uff1ahttps:\/\/github.com\/taobao\/tsar-mod_nginx \uff0c\u70b9\u51fb\u4e0b\u8f7dzip\u5305\u3002<\/p>\n<div>\n<div>\n<pre>[root@clsn6 tsar]#   unzip tsar-mod_nginx-master.zip\n[root@clsn6 tsar]#   tsardevel nginx\nbuild:make\ninstall:make install\nuninstall:make uninstall\ntest:tsar --list or tsar --nginx --live -i 1\n[root@clsn6 tsar]#   cp tsar-mod_nginx-master\/mod_nginx.c nginx\/\ncp\uff1a\u662f\u5426\u8986\u76d6\\\"nginx\/mod_nginx.c\\\"\uff1f y\n[root@clsn6 tsar]#   cd nginx\/\n[root@clsn6 nginx]# ls\nMakefile  mod_nginx.c  mod_nginx.conf\n[root@clsn6 nginx]# make &amp;&amp; make install<\/pre>\n<\/div>\n<\/div>\n<p>\u6d4b\u8bd5<\/p>\n<div>\n<div>\n<pre>[root@clsn6 nginx]# service nginx start\n\u6b63\u5728\u542f\u52a8 nginx\uff1a                                           [\u786e\u5b9a]\n[root@clsn6 nginx]# tsar --nginx --live -i 1<\/pre>\n<\/div>\n<\/div>\n<h3 id=\\\"auto-id-13\\\">1.4.3 nginx\u6a21\u5757\u4e0d\u80fd\u7528\u95ee\u9898\u7684\u5904\u7406<\/h3>\n<p>\u6b64\u65f6\u901a\u8fc7\u4f7f\u7528tsar &#8211;nginx &#8211;live -i 1 \u547d\u4ee4\u67e5\u770b\uff0c\u82e5\u51fa\u73b0\u90fd\u662f\u6a2a\u7ebf\u3002\u662f\u56e0\u4e3anginx\u6ca1\u6709\u5f00\u542fstatus\u7edf\u8ba1\u9875\u9762 \u3002<br \/>\n\u56e0\u4e3a\u8be5\u5de5\u5177\u7edf\u8ba1\u7684\u539f\u7406\u662f\u901a\u8fc7\u83b7\u53d6status\u9875\u9762\u7684\u8f93\u51fa\u7ed3\u679c\uff0c\u5e76\u5bf9\u8f93\u51fa\u5185\u5bb9\u8fdb\u884c\u7edf\u8ba1\u548c\u8ba1\u7b97\u5f97\u51fa\u7684\u7ed3\u679c\u3002\u800c\u4e14\u5176\u83b7\u53d6\u72b6\u6001\u9875\u7684url\u9ed8\u8ba4\u662fhttp:\/\/127.0.0.1\/nginx_status \uff0c\u6240\u4ee5\u5728nginx\u4e0a\u4f60\u5fc5\u987b\u6709\u5982\u4e0b\u7684\u914d\u7f6e\uff1a<\/p>\n<div>\n<div>\n<pre>location \/nginx_status {\n          stub_status on;\n          access_log   off;\n          allow 127.0.0.1;\n          deny all;\n        }<\/pre>\n<\/div>\n<\/div>\n<p>\u6ce8\uff1a\u4ee5\u4e0a\u7684url\u5e76\u975e\u4e0d\u80fd\u66f4\u6539\uff0c\u53ef\u4ee5\u4fee\u6539\u73af\u5883\u53d8\u91cf\u5b9e\u73b0\u3002\u5176\u81ea\u5e26\u7684\u51e0\u4e2a\u73af\u5883\u53d8\u91cf\u5982\u4e0b\u3002<\/p>\n<div>\n<div>\n<pre>export NGX_TSAR_HOST=192.168.0.1\nexport NGX_TSAR_PORT=8080\nexport NGX_TSAR_SERVER_NAME=status.taobao.com\nexport NGX_TSAR_URI=\/nginx_status<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1.1 tsar\u662f\u4ec0\u4e48\uff1f \u3000\u3000tsar\u662f\u6dd8\u5b9d\u81ea\u5df1\u5f00\u53d1\u7684\u4e00\u4e2a\u91c7\u96c6\u5de5\u5177\uff08\u7c7b\u4f3c\u4e8esar\u5de5\u5177\uff09\uff0c\u4e3b\u8981\u7528\u6765\u6536\u96c6\u670d\u52a1\u5668\u7684\u7cfb &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5413\"> <span class=\"screen-reader-text\">\u76d1\u63a7\u547d\u4ee4\u4e4btsar<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[102,124],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"1.1 tsar\u662f\u4ec0\u4e48\uff1f \u3000\u3000tsar\u662f\u6dd8\u5b9d\u81ea\u5df1\u5f00\u53d1\u7684\u4e00\u4e2a\u91c7\u96c6\u5de5\u5177\uff08\u7c7b\u4f3c\u4e8esar\u5de5\u5177\uff09\uff0c\u4e3b\u8981\u7528\u6765\u6536\u96c6\u670d\u52a1\u5668\u7684\u7cfb&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5413"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5413"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5413\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5413"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}