1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * httpdstat.d - realtime httpd statistics. Uses DTrace.
1N/A *
1N/A * $Id: httpdstat.d 2 2007-08-01 10:01:43Z brendan $
1N/A *
1N/A * USAGE: httpdstat.d [interval [count]]
1N/A *
1N/A * interval seconds
1N/A * count number of samples
1N/A *
1N/A * FIELDS:
1N/A * TIME Time, string
1N/A * NUM Number of connections
1N/A * GET Number of "GET"s
1N/A * POST Number of "POST"s
1N/A * HEAD Number of "HEAD"s
1N/A * TRACE Number of "TRACE"s
1N/A *
1N/A * All of the statistics are printed as a value per interval (not per second).
1N/A *
1N/A * NOTE: This version does not process subsequent operations on keepalives.
1N/A *
1N/A * IDEA: Ryan Matteson (who first wrote a solution to this).
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 20-Nov-2005 Brendan Gregg Created this.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A#pragma D option defaultargs
1N/A
1N/Ainline int SCREEN = 21;
1N/A
1N/A/*
1N/A * Program Start
1N/A */
1N/Adtrace:::BEGIN
1N/A{
1N/A num = 0; get = 0; head = 0; post = 0; trac = 0;
1N/A lines = SCREEN + 1;
1N/A secs = $1 ? $1 : 1;
1N/A counts = $2 ? $2 : -1;
1N/A first = 1;
1N/A}
1N/A
1N/Aprofile:::tick-1sec
1N/A{
1N/A secs--;
1N/A}
1N/A
1N/A/*
1N/A * Print Header
1N/A */
1N/Adtrace:::BEGIN,
1N/Aprofile:::tick-1sec
1N/A/first || (secs == 0 && lines > SCREEN)/
1N/A{
1N/A printf("%-20s %6s %6s %5s %5s %5s\n", "TIME",
1N/A "NUM", "GET", "POST", "HEAD", "TRACE");
1N/A lines = 0;
1N/A first = 0;
1N/A}
1N/A
1N/A/*
1N/A * Track Accept Events
1N/A */
1N/Asyscall::accept:return
1N/A/execname == "httpd"/
1N/A{
1N/A self->buf = 1;
1N/A}
1N/A
1N/Asyscall::read:entry
1N/A/self->buf/
1N/A{
1N/A self->buf = arg1;
1N/A}
1N/A
1N/A/*
1N/A * Tally Data
1N/A */
1N/Asyscall::read:return
1N/A/self->buf && arg0/
1N/A{
1N/A this->str = (char *)copyin(self->buf, arg0);
1N/A this->str[4] = '\0';
1N/A get += stringof(this->str) == "GET " ? 1 : 0;
1N/A post += stringof(this->str) == "POST" ? 1 : 0;
1N/A head += stringof(this->str) == "HEAD" ? 1 : 0;
1N/A trac += stringof(this->str) == "TRAC" ? 1 : 0;
1N/A num++;
1N/A self->buf = 0;
1N/A}
1N/A
1N/A/*
1N/A * Print Output
1N/A */
1N/Aprofile:::tick-1sec
1N/A/secs == 0/
1N/A{
1N/A printf("%-20Y %6d %6d %5d %5d %5d\n", walltimestamp,
1N/A num, get, post, head, trac);
1N/A num = 0; get = 0; head = 0; post = 0; trac = 0;
1N/A secs = $1 ? $1 : 1;
1N/A lines++;
1N/A counts--;
1N/A}
1N/A
1N/A/*
1N/A * End
1N/A */
1N/Aprofile:::tick-1sec
1N/A/counts == 0/
1N/A{
1N/A exit(0);
1N/A}