Printing previous dates with the FreeBSD date utility

In a previous post, I described how to get the date for a day in the past. This method unfortunately doesn’t work on FreeBSD hosts, since FreeBSD doesn’t come with the GNU date utility. As an alternative to GNU date, you can pass a time value to the date utilities “-v” option to print a date in the past:

$ date -v-2d
Mon Jan 1 13:02:57 EST 2007

I think I prefer the GNU date syntax, but this seems to work pretty well.

Using Linux extended attributes

The Linux EXT2/EXT3 file systems comes with support for extended attributes. Extended attributes can be used to enforce administrative policies beyond standard permissions on individual files, which allows things like compression, secure deletion, no atime updates, file immutability, etc. to be controlled on a per file basis. Each extended attribute has a unique character associated to it, and the current set of supported attributes are described in the following table (you can also view these in the chattr(1) man page):

a - Append only
c - Compress file
d - Exclude from dump
i - Make the file immutable
j - Journal file data 
s - Securely delete file 
u - When a file is deleted, save it's contents
A - Don't update the files atime
S - When a file is written, it is written to disk synchronously

To check if one of the extended attributes has been assigned to a file, the lsattr command can be run without any arguments to see if extended attributes are assigned to files in the current directory, or with a file name or regular expression to check if those files contain extended attributes:

$ lsattr foo

------------- foo

To set an extended attribute, the chattr command can be run with a file name, or a regular expression to indicate the files the attributes should be applied to:

$ chattr +cs foo

$ lsattr foo
s——-c—- foo

Extended attributes are super useful, but unfortunately a few attributes like secure delete and compression are not yet supported w/o additional kernel patches ( hopefully this will be one of the items added in ext4 and a future kernel release!). If you would like to use compression now, Solaris 10 and ZFS is the way to go.

Measuring Apache request processing time

I support a fair number of Apache web server instances, and periodically need to measure the time it takes Apache (and it’s various modules) to process a request. On Solaris 10 hosts, I can use DTrace to retrieve this information on the fly. Since Solaris 9 and CentOS and Redhat Linux don’t come with DTrace, I use a different approach on these platforms.

To get the time when each request was received by Apache, I used mod_header’s “Header” directive, and “%t” option (time when a request was received, measured in milliseconds from the epoch), to add a response header with the time each request was received:

Header set X-Request-Received: %t

To get the total time Apache spent processing a request, I use mod_header’s “Header” directive, and “%D” option (milliseconds spent processing the request), to add a response header with the total time Apache spent processing each request:

Header set X-Request-Processing-Time: %D

Since I don’t always need the headers to be present, I like to be able to enable and disable them from the command line. The easiest way to do this is by enclosing the directives in a conditional block similar to the following:

<IfDefine RequestTime>
     Header set X-Request-Received: %t
     Header set X-Request-Processing-Time: %D
</IfDefine>

And using the httpd “-D” option to enable them:

$ httpd -k start -DRequestTime

After the headers are enabled, you will see entries similar to the following in each HTTP response:

$ curl -v http://192.168.1.13:8080/

* About to connect() to 192.168.1.13 port 8080

< ..... >

< HTTP/1.1 200 OK
< Date: Tue, 02 Jan 2007 17:59:42 GMT
< Server: Apache/2.2.3 (Unix) DAV/2
< Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
< ETag: "34d37-2c-4c23b600"
< Accept-Ranges: bytes
< Content-Length: 44
< X-Request-Received: t=1167760782452525
< X-Request-Processing-Time: D=3513
< Content-Type: text/html
* Connection #0 to host 192.168.1.13 left intact
* Closing connection #0

Similar capabilities are available for measuring request processing time on the client. Total time is helpful, but knowing how much of that time was consumed by Apache is invaluable!