On Tue 04 Dec 2007 at 04:12PM, Brendan Gregg - Sun Microsystems wrote:
> 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. :)
I'm eagerly awaiting them :)
> >
> > 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);
Absolutely perfect. Thanks.
I've attached the updated script, in case anyone else finds it useful.
-dp
--
Daniel Price - Solaris Kernel Engineering - [EMAIL PROTECTED] - blogs.sun.com/dp
#!/usr/sbin/dtrace -FCs
#define AF_INET 2
#define AF_INET6 26
fbt::common_dispatch:entry
{
self->ca = (struct sockaddr *)(args[0]->rq_xprt->xp_xpc.xpc_rtaddr.buf);
self->in = 1;
}
fbt::common_dispatch:return
/self->in && self->ca->sa_family == AF_INET/
{
self->sin_addr = &((struct sockaddr_in *)self->ca)->sin_addr.S_un.S_addr;
@hosts[inet_ntoa(self->sin_addr)] = count();
total++;
self->in = 0;
self->ca = 0;
}
fbt::common_dispatch:return
/self->in && self->ca->sa_family == AF_INET6/
{
self->sin6 = &((struct sockaddr_in6 *)self->ca)->sin6_addr;
total++;
@hosts6[inet_ntoa6(self->sin6)] = count();
self->in = 0;
self->ca = 0;
}
END
{
trunc (@hosts, 20);
trunc (@hosts6, 20);
printf("Interrupt.\n\n");
printf("HOST%56sOPS", "");
printa("\n%-40s [EMAIL PROTECTED]", @hosts);
printa("\n%-40s [EMAIL PROTECTED]", @hosts6);
printf("\nTOTAL%55s%d", "", total);
}
tick-3s
{
trunc (@hosts, 20);
trunc (@hosts6, 20);
printf("\033[H\033[2J");
printf("HOST%56sOPS", "");
printa("\n%-40s [EMAIL PROTECTED]", @hosts);
printa("\n%-40s [EMAIL PROTECTED]", @hosts6);
printf("\nTOTAL%55s%d", "", total);
total = 0;
trunc (@hosts);
trunc (@hosts6);
}
_______________________________________________
dtrace-discuss mailing list
[email protected]