{"id":1463,"date":"2010-05-23T14:19:49","date_gmt":"2010-05-23T13:19:49","guid":{"rendered":"http:\/\/www.devco.net\/?p=1463"},"modified":"2010-06-27T19:03:46","modified_gmt":"2010-06-27T18:03:46","slug":"mcollective_pgrep","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2010\/05\/23\/mcollective_pgrep.php","title":{"rendered":"MCollective pgrep"},"content":{"rendered":"

The unix pgrep utility is great, it lets you grep through your process list and find interesting things. I wanted to do something similar but for my entire server group so built something quick ontop of MCollective.<\/p>\n

I am using the Ruby sys-proctable<\/a> gem to do the hard work, it returns a massive amount of information about each process and have written a simple agent on top of this.<\/p>\n

The agent supports grepping the process tree but also supports kill and pgre+kill though I have not yet implemented more than the basic grep on the command line. Frankly the grep+kill combination scares me and I might remove it. A simple grep slipup and you will kill all processes on all your machine \ud83d\ude42 Sometimes too much power is too much and should just be avoided.<\/p>\n

At the moment mc-pgrep outputs a set format but I intend to make that configurable on the command line, here’s a sample:<\/p>\n

<\/p>\n

\r\n% mc-pgrep -C \/dev_server\/ ruby\r\n\r\n * [ ============================================================> ] 4 \/ 4\r\n\r\ndev1.my.com\r\n       root   9833  ruby \/usr\/sbin\/mcollectived --pid=\/var\/run\/mcollectived.pid \r\n       root  21608  \/usr\/lib\/ruby\/gems\/1.8\/gems\/passenger-2.2.2\/lib\/phusion_pass\r\n\r\ndev2.my.com\r\n       root  14568  \/usr\/lib\/ruby\/gems\/1.8\/gems\/passenger-2.2.2\/lib\/phusion_pass\r\n       root  31595  ruby \/usr\/sbin\/mcollectived --pid=\/var\/run\/mcollectived.pid \r\n\r\ndev3.my.com\r\n       root   1620  \/usr\/lib\/ruby\/gems\/1.8\/gems\/passenger-2.2.2\/lib\/phusion_pass\r\n       root  14093  ruby \/usr\/sbin\/mcollectived --pid=\/var\/run\/mcollectived.pid \r\n\r\ndev4.my.com\r\n       root   3231  \/usr\/lib\/ruby\/gems\/1.8\/gems\/passenger-2.2.2\/lib\/phusion_pass\r\n       root  20557  ruby \/usr\/sbin\/mcollectived --pid=\/var\/run\/mcollectived.pid \r\n\r\n   ---- process list stats ----\r\n        Matched hosts: 4\r\n    Matched processes: 8\r\n        Resident Size: 37.264KB\r\n         Virtual Size: 629.578MB\r\n<\/pre>\n

<\/code><\/p>\n

You can also limit it to only find zombies with the -z<\/i> option.<\/p>\n

This has been quite interesting for me, if I limit the pgrep to “.” (the pattern is regex) every machine will send back a Sys::ProcTable hash for all its processes. This is a 50 to 70 KByte payload per server. I’ve so far seen no problem getting his much traffic through ActiveMQ + MCollective and processing it all in a very short time:<\/p>\n

<\/p>\n

\r\n% time mc-pgrep -F \"country=\/uk|us\/\" .\r\n\r\n   ---- process list stats ----\r\n        Matched hosts: 20\r\n    Matched processes: 1958\r\n        Resident Size: 1.777MB\r\n         Virtual Size: 60.072GB\r\n\r\nmc-pgrep -F \"country=\/uk|us\/\" .  0.19s user 0.06s system 7% cpu 3.420 total\r\n<\/pre>\n

<\/code><\/p>\n

That 3.4 seconds is with a 2 second discovery overhead client machine in Germany and the filter matching UK and US machines – all the way to the West Coast – my biggest delay here is network and not MC or ActiveMQ.<\/p>\n

The code can be found at my GitHub account<\/a> and still a bit of a work in progress, wiki pages will follow once I am happy with it.<\/p>\n

And as an aside, I am slowly migrating at least my code to GitHub if not wiki and ticketing. So far my Plugins have moved, MC will move soon too.<\/p>\n","protected":false},"excerpt":{"rendered":"

The unix pgrep utility is great, it lets you grep through your process list and find interesting things. I wanted to do something similar but for my entire server group so built something quick ontop of MCollective. I am using the Ruby sys-proctable gem to do the hard work, it returns a massive amount of […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[121,78,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1463"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1463"}],"version-history":[{"count":8,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1463\/revisions"}],"predecessor-version":[{"id":1505,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1463\/revisions\/1505"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}