cmic has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks. Right in the middle of a SNMP application, I want to display/monitor several constantly changing variables (say like ethernet ifInOctets ?) Alas, nph-application are not OK with some browsers. Is there a elegant solution with Perl only, or should I try to use a JavaScript window in which I will display my values, like a dashboard ?
Any code excerpt is welcome !
Thanks.
--
cmic.
Life helps. Perl Too.

Replies are listed 'Best First'.
Re: refreshing CGI display
by gsiems (Deacon) on Jun 05, 2005 at 20:28 UTC

    I have a couple of perl powered web pages that are used for monitoring servers/services at $work. I'm not at $work at the moment, but IIRC, for the pages that I want to have automatically refresh themselves I put the following in the header (where refresh is usually 90 or 300 depending):

    # config stuff: my $cfg = { refresh => 300, interval => 5, }; # at some point later in the script: my $expires = strftime("Expires: %a, %d %b %Y %H:%M:%S GMT\n", gmtime(time+60*$cfg->{interval})); print <<"EOF"; Content-Type: $content_type Refresh: $cfg->{refresh} Pragma: no-cache Expires: $expires EOF

    No javascript needed.

      Hello. Thanks gsiems. I get it. I will open a window to display the results of the SNMP poll or whatever, and use the Refresh thing to display. Needless to say, the CGI is Perl only, and I want it to work with most of today browsers.

      --
      cmic. Life helps. Perl Too.
Re: refreshing CGI display
by jasonk (Parson) on Jun 05, 2005 at 20:22 UTC

    If you are not willing to use NPH because some browsers don't support it, then really your only option is to use Refresh: headers (or meta refresh tags) and redraw the whole page every time... NPH is more widely supported than javascript is.


    We're not surrounded, we're in a target-rich environment!
      NPH is a feature of the web server, not the browser.
Re: refreshing CGI display
by TedPride (Priest) on Jun 05, 2005 at 21:18 UTC
    Depends what you need, really. If your application doesn't have to be pretty, you can output the variables to the browser whenever they change, and view the page with a browser that doesn't require the entire page to load before displaying (I use an early version of NS). If your application does need to be pretty, and you don't want to save where you are in the process, reload the page, and and start where you left off, you could use frames and have one frame refresh every x seconds with a variable readout, while the other frame runs your app and updates the variables every so often.

    More clarification on why you're trying to do what you're doing will help us explain the best way to do it.

Re: refreshing CGI display
by merlyn (Sage) on Jun 06, 2005 at 10:46 UTC