G'Day Dan,

On Tue, Dec 04, 2007 at 03:46:50PM -0800, Dan Price wrote:
> 
> I have been using Eric Kustarz's "nfstop" dtrace script to keep an eye on
> a server; the output looks like this:

Eric's script is going to become much easier with the stable NFS providers. :)

> host: 129.146.226.97  num nfs calls: 6
> host: 129.145.154.106  num nfs calls: 7
> host: 129.146.11.146  num nfs calls: 8
> host: 129.146.108.85  num nfs calls: 8
> host: 10.4.180.27  num nfs calls: 11
> host: 129.146.228.172  num nfs calls: 16
> host: 129.146.11.145  num nfs calls: 17
> host: 129.146.228.151  num nfs calls: 19
> host: 129.146.228.144  num nfs calls: 22
> ...
> 
> 
> While this is helpful, I'd much rather format the output as follows:
> 
> HOST                    OPS
> 129.146.226.97            6
> 129.145.154.106           7
> 129.146.11.146            8
> 129.146.108.85            8
> 10.4.180.27              11
> 129.146.228.172          16
> 129.146.11.145           17
> 129.146.228.151          19
> 129.146.228.144          22
> 
> Which to my eyes is a lot easier to process rapidly.
> 
> The problem here is that the IP address is stored byte by byte in the
> aggregation, as follows:
> 
>   @hosts[self->sin_addr[0], self->sin_addr[1], self->sin_addr[2],
>   self->sin_addr[3]] = count();
> 
> (There is a similar clause for ipv6 addresses which I have omitted here).
> 
> And so the printa() looks like this:
> 
>   printa("\nhost: %d.%d.%d.%d  num nfs calls: [EMAIL PROTECTED]", @hosts)
> 
> This would seem to make it fairly difficult to align the columns of output,
> unless I zero-fill each IP address (ugly).  My initial thought was to trying
> something like this:
> 
>   s = sprintf("%d.%d.%d.%d", self->sin_addr[0], self->sin_addr[1],
>       self->sin_addr[2], self->sin_addr[3]])
>   @hosts[s] = count();
> 
>   ...
> 
>   printa("%20s\t\t%d")
> 
> Unfortunately, there is no sprintf, I presume because printf processing 
> happens
> up in userland.  So I was wondering if there's a best practice here, or some
> other obvious way to cope with this problem?

I solved this once using a series of strjoin()s (see tcpsnoop.d in the
DTraceToolkit); but you really want to use inet_ntoa(), inet_ntoa6() or
inet_ntop(), which I added to DTrace several months ago (and to the DTrace
wiki about a week ago), for usage such as this.

The changes to nfstop would include something like this:

this->str4 = inet_ntoa(&((struct sockaddr_in *)self->ca)->sin_addr.S_un.S_addr);
[...]
this->str6 = inet_ntoa6(&((struct sockaddr_in6 *)self->ca)->sin6_addr);

Brendan

-- 
Brendan
[CA, USA]
_______________________________________________
dtrace-discuss mailing list
[email protected]

Reply via email to