/[scripts]/trunk/dwm-status.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/dwm-status.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 34 by dpavlin, Sun May 27 08:54:17 2007 UTC revision 37 by dpavlin, Sun May 27 19:31:52 2007 UTC
# Line 13  use Data::Dump qw/dump/; Line 13  use Data::Dump qw/dump/;
13  my $dt = 3;  my $dt = 3;
14  my $acpi_every = 10;  my $acpi_every = 10;
15    
16    my $disk_blk_size = 512;
17    
18  my $debug = shift @ARGV;  my $debug = shift @ARGV;
19    
20  $|=1;  $|=1;
# Line 36  sub unit { Line 38  sub unit {
38    
39          warn "unit( $v )\n" if ($debug);          warn "unit( $v )\n" if ($debug);
40    
41          my @units = qw/b k m g/;          my @units = qw/b k M G/;
42          my $o = 0;          my $o = 0;
43    
44          while ( ( $v / 1024 ) >= 1 ) {          while ( ( $v / 1024 ) >= 1 ) {
# Line 54  sub unit { Line 56  sub unit {
56  }  }
57    
58  my ( $lrx, $ltx ) = ( 0, 0 );  my ( $lrx, $ltx ) = ( 0, 0 );
59    my ( $ld_r, $ld_w ) = ( 0, 0 );
60  my $bat;  my $bat;
61    
62  my $i = 0;  my $i = 0;
# Line 105  while ( 1 ) { Line 108  while ( 1 ) {
108    
109          foreach ( split(/\n/, $net) ) {          foreach ( split(/\n/, $net) ) {
110                  s/^\s+//;                  s/^\s+//;
111                    s/:\s+/:/;
112                  my @n = split(/\s+/, $_, 17);                  my @n = split(/\s+/, $_, 17);
113                  next unless ( $n[0] =~ m!(eth\d|ath\d):! );                  next unless ( $n[0] =~ s!(eth\d|ath\d):!! );
114    
115                  warn dump( @n ) if ($debug);                  warn dump( @n ) if ($debug);
116                  $rx += $n[1];                  $rx += $n[0];
117                  $tx += $n[9];                  $tx += $n[8];
118          }          }
119          warn "rx: $rx tx: $tx\n" if ($debug);          warn "rx: $rx tx: $tx\n" if ($debug);
120    
121          my $r = ( $rx - $lrx ) / $dt;          my $net_rx = ( $rx - $lrx ) / $dt;
122          my $t = ( $tx - $ltx ) / $dt;          my $net_tx = ( $tx - $ltx ) / $dt;
123          ( $lrx, $ltx ) = ( $rx, $tx );          ( $lrx, $ltx ) = ( $rx, $tx );
124    
125          printf "%s | %s |%5s > %-5s| %s%s\n", $s, $load, unit( $r ), unit( $t ), $bat, $temp;          my $disk = read_file('/proc/diskstats');
126            my ( $d_r, $d_w ) = ( 0,0 );
127    
128            foreach ( split(/\n/, $disk) ) {
129                    s/^\s+//;
130                    my @d = split(/\s+/, $_, 17);
131                    next unless ( $d[2] =~ m/^[sh]d\w$/ );
132    
133                    warn dump( @d ) if ($debug);
134                    $d_r += $d[5] * $disk_blk_size;
135                    $d_w += $d[7] * $disk_blk_size;
136            }
137            warn "d_r: $d_r d_w: $d_w\n" if ($debug);
138    
139            my $d_read = ( $d_r - $ld_r ) / $dt;
140            my $d_write = ( $d_w - $ld_w ) / $dt;
141            ( $ld_r, $ld_w ) = ( $d_r, $d_w );
142    
143            printf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n",
144                    $s,
145                    $load,
146                    unit( $d_read ), unit( $d_write ),
147                    unit( $net_rx ), unit( $net_tx ),
148                    $bat, $temp,
149            );
150    
151          sleep $dt;          sleep $dt;
152  }  }

Legend:
Removed from v.34  
changed lines
  Added in v.37

  ViewVC Help
Powered by ViewVC 1.1.26