Feature requestED: monitoring Nginx from the outside

Grzegorz Nosek grzegorz.nosek at gmail.com
Thu May 1 22:35:24 MSD 2008


On Thu, May 01, 2008 at 11:39:50AM +0200, Manlio Perillo wrote:
> Each variable will be correct, but since you are writing the value to a 
> shared memory location not atomically, the variable as read by the 
> client will not be correct.

Why? Reading several variables at once will not be atomic (unless
protected by a lock) but individual reads will, as long as the variables
in shm will fit into a sig_atomic_t each (e.g. 4 bytes on x86).

> It can happen that when the client is reading the shared memory, Nginx 
> concurrently writes this memory.
> 

The worst you can expect is that e.g. "requests ok" + "requests failed"
won't be equal to "total requests". A sig_atomic_t is effectively atomic
on most architectures (don't know whether POSIX guarantees it
everywhere).

> Moreover it really does not make sense to write in a shared memory if 
> you want to support monitoring tools!
> 
> Just write a module like the stub_status module!

... which has to get its data from somewhere so it's going to face
essentially the same problem.

> Finally there is one last problem.
> Nginx uses only a few shared variables (the one handled the the 
> stub_status module).
> 
> All other variables are private to each worker process.
> This means that probably your shared memory location will contain values 
> not very useful.

You could always add more information to a shared segment (like
upstream_fair does).

Best regards,
 Grzegorz Nosek





More information about the nginx mailing list