Here is what i did and your comment is welcome. I have two questions:

1. When I calculate $CurSec, i tried following first and it didn't work. It seems I can't pass list variable to timelocal directly. Is that true?

====

my @CurTime=`date +%S,%M,%H,%d,%m,%Y`; my $CurSec=timelocal(@CurTime);

====

2. how can I aggregate the same client IP together so that report can show how much data were transferred and where data are.

Ideally, I am trying to format the report like:

TIME(second) CLIENT OP OFFSET(KB) BYTES PATHNAME 20,172.22.32.28, W,200,4056099,/export/nfs/file1

TIME - how long we run the trace programe, above line indicates 20 seconds

CLIENT - client server's IP

OP - operation, write or read

OFFSET(KB) - total data transferred during period of TIME

BYTES - size of the file

PATHNAME - location of created file

Thanks in advance,

carl

#!/usr/bin/perl use warnings; use strict; use Time::Local; my $Uptime=`ps -p 1 -o etime | tail -1`; my ($sec,$min,$hour,$mday,$mon,$year)=(localtime)[0,1,2,3,4,5]; my $CurSec=timelocal($sec,$min,$hour,$mday,$mon,$year+1900); sub LastReboot { my ($Days, $Hours, $Minutes, $Seconds, $UpSeconds); if ($Uptime =~ /[0-9]+\-/) { ($Days, $Hours, $Minutes, $Seconds) = $Uptime =~ /([0-9]*)\-?([0-9 +]+):([0-9]+):([0-9]+)/; } elsif ($Uptime =~ /[0-9]+:[0-9]+:[0-9]+/) { ($Hours, $Minutes, $Seconds) = $Uptime =~ /([0-9]+):([0-9]+): +([0-9]+)/; $Days = 0; } else { ($Minutes, $Seconds) = $Uptime =~ /([0-9]+):([0-9]+)/; $Days = 0; $Hours = 0;} $UpSeconds=$Days*24*60*60 + $Hours*60*60 + $Minutes*60 + $Seconds; return $CurSec-$UpSeconds; } my $BaseLine = &LastReboot; print "$BaseLine\n"; print "TIME(seconds),CLIENT,OP,OFFSET(KB),BYTES PATHNAME\n"; while (<DATA>) { next if ($. == 1); chomp; my @output = split; my $MyTime = localtime($BaseLine + $output[0]/1000000000); print "$MyTime,$output[1], $output[2], $output[3],$output[4],$output[5 +]\n"; } __DATA__ TIME(us) CLIENT OP OFFSET(KB) BYTES PATHNAME 13463659875129 172.22.32.28 W 4952 2934 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659884704 172.22.32.28 W 4952 3004 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659927187 172.22.32.28 W 4952 3144 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659899744 172.22.32.28 W 4952 3074 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659937424 172.22.32.28 W 4952 3214 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659999853 172.22.32.28 W 4952 3500 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660033528 172.22.32.28 W 4952 3570 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660043638 172.22.32.28 W 4952 3640 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659951798 172.22.32.28 W 4952 3291 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659977355 172.22.32.28 W 4952 3361 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463659990535 172.22.32.28 W 4952 3430 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660245464 172.22.112.136 W 5104 12471 /export/energ +y/energy_dev/stg/rw/sessions/backup/.nfs7C9F/../ds-259 7025835046513461/10.in 13463660202519 172.22.32.28 W 4952 4126 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660234779 172.22.32.28 W 4956 100 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660160523 172.22.32.28 W 4952 3918 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660249629 172.22.32.28 W 4956 170 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log 13463660267596 172.22.32.28 W 4956 249 /export/energ +y/energy_dev/stg/rw/log/GRIDLOGS/FrontOfficeSessionExt ractCash.log

original posting below

============================================================================

Dtrace is an utility in solaris 10. It can generate report with timestamp like following:

TIME(us) CLIENT OP OFFSET(KB) BYTES PATHNAME 13463659875129 172.22.32.28 W 4952 2934 /export/nfs/f +ile1 tractCash.log 13463659884704 172.22.32.28 W 4952 3004 /export/nfs/f +ile2 13463659927187 172.22.32.28 W 4952 3144 /export/nfs/f +ile1

NOTE: timestamp here is from last system reboot not EPOCH time.

In order to replace the first column with readable localtime, I am planning to do followings:

1. ps -p 1 -o etime | tail -1, it will give me the system uptime time in format "day-hour:minute:second"

2. use timelocal in module Time::Local to convert current time to seconds since EPOCH

3. Value from 2 minus Value from 1 should give me the EPOCH time of last system reboot

4. Value from 3 plus first column in dtrace script output("13463659884704/1000000") should give the EPOCH time of the record

5. localtime(Value 4) should display it in readable local time format.

Do you think this is the right approach? Is there better way to achieve the goal?

Your comment is appreciated!

carl


In reply to solved: timestamp to localtime by roadtest

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.