This is a possible way. Just put this script on each box and run it with starman or plackup and you have an instant, on demand JSON report of the box. I added pid filtering as a *minimal* API proof of concept. I also did pretty printing on the JSON for the benefit of playing around which I wouldn't do in production.

cow@moo[1316]~/bin>plackup proc.psgi HTTP::Server::PSGI: Accepting connections at http://0:5000/ ...

Then you can ask for the full process data at http://localhost:5000/ and filter by pid with http://localhost:5000/123,9876,4433 and such like. As given, the code is *too* free and easy with the arg parsing.

You might not want to publish the stuff so openly. You could *easily* add a "security" layer with Plack::Middleware::Auth::Basic. And I'd recommend a whitelist/filter of the processes you'd like to show.

use warnings; use strict; use JSON; use Plack::Request; use Proc::ProcessTable; sub { my $req = Plack::Request->new(+shift); my %pids = map { $_ => 1 } $req->path =~ /(\d+)/g; my $procs = Proc::ProcessTable->new; my $json = JSON->new; my %status; for my $proc ( @{ $procs->table } ) { next if scalar(%pids) and not $pids{$proc->pid}; for my $field ( $procs->fields ) { $status{$proc->pid}{$field} = $proc->$field; } } return [ 200, [ "Content-Type" => "application/json" ], [ $json->pretty->encode(\%status) ] ]; };

In reply to Re: Networking Perl by Your Mother
in thread Networking Perl by sun9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.