Skip to content

Instantly share code, notes, and snippets.

@davepacheco
Created February 2, 2012 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davepacheco/1d99633ce16952cd4267 to your computer and use it in GitHub Desktop.
Save davepacheco/1d99633ce16952cd4267 to your computer and use it in GitHub Desktop.
#!/usr/sbin/dtrace -s
#pragma D option quiet
BEGIN
{
printf("%7s %2s %5s %20s (%5s) %8s %s (%s)\n",
"WHO", "FD", "RPORT", "REMOTE", "BUFFR", "METHOD", "URL", "FWDFOR");
}
node$1:::http-server-request
{
printf("+SERVER %2d %5d %20s (%5d) %8s %s (%s)\n",
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->fd,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->remotePort,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->remoteAddress,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->bufferSize,
(xlate <node_http_request_t*>((node_dtrace_http_server_request_t *)arg0))->method,
(xlate <node_http_request_t*>((node_dtrace_http_server_request_t *)arg0))->url,
(xlate <node_http_request_t*>((node_dtrace_http_server_request_t *)arg0))->forwardedFor);
}
node$1:::http-server-response
{
printf("-SERVER %2d %5d %20s (%5d)\n",
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->fd,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->remotePort,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->remoteAddress,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->bufferSize);
}
node$1:::http-client-request
{
printf("+CLIENT %2d %5d %20s (%5d) %8s %s\n",
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->fd,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->remotePort,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->remoteAddress,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg1))->bufferSize,
(xlate <node_http_request_t*>((node_dtrace_http_client_request_t *)arg0))->method,
(xlate <node_http_request_t*>((node_dtrace_http_client_request_t *)arg0))->url);
}
node$1:::http-client-response
{
printf("-CLIENT %2d %5d %20s (%5d)\n",
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->fd,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->remotePort,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->remoteAddress,
(xlate <node_connection_t*>((node_dtrace_connection_t *)arg0))->bufferSize);
}
#!/usr/sbin/dtrace -s
#pragma D option quiet
BEGIN
{
printf("%7s %2s %5s %20s (%5s) %8s %s (%s)\n",
"WHO", "FD", "RPORT", "REMOTE", "BUFFR", "METHOD", "URL", "FWDFOR");
}
node$1:::http-server-request
{
printf("+SERVER %2d %5d %20s (%5d) %8s %s (%s)\n",
args[1]->fd, args[1]->remotePort, args[1]->remoteAddress,
args[1]->bufferSize,
args[0]->method, args[0]->url, args[0]->forwardedFor);
}
node$1:::http-server-response
{
printf("-SERVER %2d %5d %20s (%5d)\n",
args[0]->fd, args[0]->remotePort, args[0]->remoteAddress,
args[0]->bufferSize);
}
node$1:::http-client-request
{
printf("+CLIENT %2d %5d %20s (%5d) %8s %s\n",
args[1]->fd, args[1]->remotePort, args[1]->remoteAddress,
args[1]->bufferSize,
args[0]->method, args[0]->url);
}
node$1:::http-client-response
{
printf("-CLIENT %2d %5d %20s (%5d)\n",
args[0]->fd, args[0]->remotePort, args[0]->remoteAddress,
args[0]->bufferSize);
}
@davepacheco
Copy link
Author

These scripts trace Node HTTP client and server requests, printing all available fields.

Example output:

# dtrace -L /var/tmp/node-2667/lib -s ./requests.d '*'
WHO FD RPORT               REMOTE (BUFFR)   METHOD URL (FWDFOR)
+SERVER  8 56010            127.0.0.1 (    0)      GET /foo/bar ()
-SERVER  8 56010            127.0.0.1 (    0)
+CLIENT  0     0            undefined (   66)      GET /foo/bar
-CLIENT  0     0            undefined (    0)

The "undefined" and fd0 output are due to an unrelated bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment