/[sysadmin-cookbook]/recepies/netpipe-tcp/np2graphviz.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

Contents of /recepies/netpipe-tcp/np2graphviz.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 172 - (show annotations)
Sun Feb 21 14:33:05 2010 UTC (9 years, 6 months ago) by dpavlin
File MIME type: text/plain
File size: 1585 byte(s)
show symetrical transfer as single dashed edge

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 my $graph;
7
8 my ($max,$min);
9
10 foreach my $file ( glob '*/*.np' ) {
11
12 my $direction = $file;
13 $direction =~ s/\.np$//;
14 my ( $from, $to ) = split(m{/},$direction,2);
15
16 my $line = `tail -1 $file`;
17 $line =~ s{^\s+}{};
18 $line =~ s{\s+$}{};
19 my ( $size, $speed, $rtt ) = split(/\s+/, $line);
20
21 warn "$from -> $to | $size | $speed | $rtt\n";
22
23 my $len = int($speed / 100);
24
25 my $rev = qq|"$to" -> "$from"|;
26
27 # make edge bi-directional if speed difference is less then 10%
28 if ( $graph->{$rev} && abs($graph->{$rev}->{speed}->[0] - $speed) < ($speed/10) ) {
29 $graph->{$rev}->{speed}->[1] = int($speed);
30 $graph->{$rev}->{dir} = 'both';
31 } else {
32 $graph->{ qq|"$from" -> "$to"| } = {
33 size => $size,
34 speed => [ int($speed) ],
35 rtt => $rtt,
36 dir => 'forward',
37 };
38 }
39
40 $min ||= $speed;
41 $min = $speed if $speed < $min;
42
43 $max ||= $speed;
44 $max = $speed if $speed > $max;
45
46 }
47
48 warn "# speed $min ... $max\n";
49
50 print qq|
51 digraph "netpipe" {
52 |,
53 join("\n", map {
54 my $node = $_;
55 my @speed = @{ $graph->{$node}->{speed} };
56 my $speed = 0;
57 $speed += $_ foreach @speed;
58 $speed /= $#speed + 1;
59 my $c = 'ff0000';
60 $c = '00ff00' if ( $speed / 100 ) > 5;
61 $c = '0000ff' if ( $speed / 1000 ) > 1;
62 $c = '8888ff' if ( $speed / 1000 ) > 2;
63 my $label = qq|labelfontsize=10,weight=$speed,|;
64 $label .= qq|headlabel=$speed[0],| if $speed[0];
65 $label .= qq|taillabel=$speed[1],| if $speed[1];
66 $label .= qq|style=dashed,| if $graph->{$node}->{dir} eq 'both';
67 qq|$node [ $label color="#$c",dir=$graph->{$node}->{dir} ]|;
68 } keys %$graph),
69 qq|
70 }
71 |;
72

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26