ZFS: managing filesystems

It’s been quite a while since I’ve cleared one of internal disks in my Netra t105 to bring it under ZFS control. As a result, I now have a 33Gb zfs-pool to experiment with. Today I had some spare time, so I decided to share with you the very basics of managing ZFS filesystems.

So this is the ZFS pool I have:

solaris# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
stock                  33.8G   2.40G   31.4G     7%  ONLINE     -

[Read more…]

DTrace: mod_auth_pam and apache2

One of our users has asked me to help with PAM authentication for Apache 2 on one of our remote servers.

Note: going with mod_auth_pam was decision made without me, and I was only asked to help get the chosen solution work. This being said, the recommended way to do external authentication for Apache 2 now is to use the mod_authz_external module and pwauth password authenticator.

It did seem like a rather trivial task – download mod_auth_pam, compile it for Apache 2, make sure everything works. The remote server uses NIS, I could freely log onto it.

And you know what? It didn’t work!

[Read more…]

Debugging PHP with DTrace, part 2

Your next step in observing PHP with DTrace could easily be the following script. It times how much time (in nanoseconds) each Apache process has spent running a particular PHP function.

This script generates a table of Apache PIDs and PHP scripts started within, and later you’ll get a table of all the functions with PIDs which ran them and the time spent.

[Read more…]

Basic ZFS example

I just couldn’t wait any longer, and decided to try something with ZFS. And what do you know? I’ve found a very useful advice from Ben Rockwood, which allows us use regular files created with mkfile as virtual disks for ZFS. VERY useful, especially when you really want to play with such a great technology and maybe try various configurations, but there are no spare physical disks for such experiments.

I will, of course, read and understand all the inner workings of ZFS later, but the first impression of it is this – too easy to be true! 🙂

[Read more…]

Passing command line parameters to DTrace scripts

When you’re writing a DTrace script, often you’d like to pass some parameter in command line. Such an easy task might be really hard unless you read a docs.sun.com section about DTrace scripting, particularly a section about command line parameters macros.

As with sh or bash, you can access command line parameters via $0..$9 macroses. But there’s a catch. Values of these macroses should match a certain definition – a number, an identifier or a string. If there isn’t a match here, you’ll get an error.

Let’s start with a simple script. [Read more…]

Solaris 10 zones: part one – a working example

Many of you have already heard about Solaris 10 zones – it’s a virtualization technology which allows you to create isolated and secure environments for running applications. For end-users these environments look just like separate abstract machines with Solaris 10 installed on them. Inside each zone, all the processes don’t see anything happening in all the other zones on a system. Isolation is done on such a level that processes of one zone can’t see or affect processes of any other zone.

All of this is done on a software level, and by default every Solaris 10 machine has a global zone – only from this zone you can view processes of all the rest zones on your system. You probably didn’t even notice, but upon the completion of your Solaris 10 install, you’re immediately put into the global zone. It’s very easy to see this zone:

solaris# zoneadm list -vc
ID NAME             STATUS         PATH
0 global           running        /

[Read more…]

DTrace: Aggregations

Quite often it is more important for you to see the whole picture, rather than to know each case when a particular probe fires. For instance, observing a process which consumes a lot of CPU time according to prstat, we ask ourselves: what is this process doing? And often we think about the overall number of system calls executed by this process, and not every particular one of these system calls.

DTrace aggregations are created specifically for answering such questions. Working with sets of numerical data, aggregation functions help us to easily determing average, min and max values of data sets, count numbers and sums of elements in these data sets, and even build frequency distributions.

[Read more…]

DTrace: $target macro variable

Macro variables are meant to make your life MUCH easier when scripting with DTrace. Names of such variables must begin with a $ sign, and DTrace will automatically replace all the macro variables with the appropriate values when parsing your script.

Full list of macro variables can be found here, I will only talk about $target variable this time.

$target specifies the PID of the process you associate with your DTrace script.

[Read more…]

DTrace options: flowindent

One of the most useful (for me) options in DTrace is flowindent. All it does is indent the entry to each function with “->”, and mark the return from this function with “<-“. Doesn’t seem like much, does it? But just look at the results!

The following example catches all the probes of the fbt provided. By default (that’s our case since we’re not changing any other options but flowindent), DTrace registers and prints to the standard output all the probes matched in the tracing process.

[Read more…]

DTrace: count system calls for any process

One more variation of using DTrace allows to track which system calls are made from a certain process. Or do the same for lots of processes, if you use execname and not PIDs…

Such a command line will show you all system calls made by Xorg in the last 5 seconds:

solaris# dtrace -n 'syscall:::entry /execname == "Xorg"/ {@[probefunc] = count(); } tick-5sec {printa(@); clear(@);}'
dtrace: description 'syscall:::entry ' matched 227 probes
CPU     ID                    FUNCTION:NAME
0  36588                       :tick-5sec
writev                                                           20
lwp_sigmask                                                      38
setcontext                                                       38
setitimer                                                        75
read                                                            422
pollsys                                                         426

pS: some time later I’ll hopefully write more about what DTrace and D language are