The development of a monitoring solution, now called Zabbix, started way back in 1999. From the functional perspective, Zabbix is much more capable now than it was 11 years ago. However, is it possible that some of this functionality is still backed by code from those ancient times? How did the source code change over the years? In this article, we will take a look at how the software developed over time source code-wise.

Lines of code

One of the simplest metrics to start with is the lines of code per language. Different languages can be found in Zabbix repository, including Perl, Python, and a variety of shell scripts. However, Zabbix is being developed using mostly C and PHP, so here is a graph showing the number of non-empty lines of code for these languages for each stable version:

Lines of C and PHP code. Click to see a more detailed graph.

It is interesting to see that up to around 1.8, the server side and the GUI side grew in size at approximately the same rate. Since then, a lot of frontend improvements have been made. As a result, PHP has overtaken C and is now at slightly below 120,000 lines of code. The highest number C code has been at – 99,167 – is just below the 100,000 milestone. After 1.8.2, the server side has taken a couple of dives downward – the result of Zabbix developers striving to keep the code clean. As you remember from one of the previous blog posts, Zabbix now provides more performance with less code!

Oldest code

Zabbix is more than a decade old by now. How many of those lines are still there in the current 1.8? We would not know for sure, because prior to March 2001 cvs was used for version control and since then lines could be reformatted just for the sake of whitespace, but we will try to dig as much information out of svn annotate as possible.

Here is a graph which shows how many lines of code in the current 1.8 branch date back to which year:

Line percentage per year.

We can see that over 46% of PHP code date to 2010 and over 90% of PHP are no older than 2008. On the other hand, C code is much more conservative: years 2005 through 2008 each own from 11% to 16% of the current source code, year 2009 owns 19%, and year 2010 owns 23%.

The number of lines that date back to years 2001 through 2004-2005 are not as visible on the large graph as other years, but they are still there!

The oldest lines of C code that have not been changed for the last nine and a half years date back to revision 2 – the import of Zabbix source code from CVS into Subversion:

#define SUCCEED      0
#define FAIL         (-1)
#define NOTSUPPORTED (-2)

These constants are used by internal functions on the server side for indicating success and failure.

Other lines that date back to March 2001 are in the signal handler for the inetd version of Zabbix agent. It still handles signals the same way it did back then and that way, admittedly, is so embarrassing:

void    child_signal_handler( int sig )
{
        if( SIGALRM == sig )
        {
                signal( SIGALRM, child_signal_handler );
        }

        if( SIGQUIT == sig || SIGINT == sig || SIGTERM == sig )
        {
        }
        exit( FAIL );
}

Fortunately, there is an issue, ZBX-3078, that we could potentially use to fix this.

The oldest line of PHP code that is still there comes from February 2002:

$y=imagesy($im);

Isn’t that cute? This little piece of code is still being used for drawing maps.

And there is also a bunch of lines from September 2002 that are used to draw reports like this one:

Availability report for one of Zabbix development servers.

Other metrics

As conscientious developers, we like to keep our code formatted properly. One of such principles is that lines should not have trailing whitespace. Here is how trailing whitespace evolved over time:

Trailing whitespace in C and PHP code. Click to see a more detailed graph.

Apparently, a lot of effort has been put into removing trailing whitespace for the release of 1.8, but it keeps coming back!

Finally, here are a couple of miscellaneous source code statistics.

The longest line of C code is 239 characters long, has its origins in December 2005 and is intended for gathering memory statistics using vm.memory.size[total] item on Tru64 (reformatted for the purposes of this post):

return EXECUTE_INT(cmd,"vmstat -s | awk 'BEGIN{pages=0}
{gsub(\"[()]\",\"\");if($4==\"pagesize\")pgsize=($6);
if(($2==\"inactive\"||$2==\"active\"||$2==\"wired\")
&&$3==\"pages\")pages+=$1}END{printf (pages*pgsize)}'",
flags, result);

The longest line of PHP code that is a single statement and does something interesting is 364 characters long, pretty recent (May 2010), and is used in a conditional in a trigger expression parser:

zbx_substr($expression, $fbPart['openSymbolNum'],
$fbPart['closeSymbolNum']-$fbPart['openSymbolNum']+
(isset($fbPart['closeSymbol']) ? zbx_strlen($fbPart[
'closeSymbol']) : 0)) == trim(zbx_substr($expression,
$prev+($prev > $sStart ? zbx_strlen($operand): 0),
(is_int($opPos) && $opPos < $sEnd ? $opPos
-zbx_strlen($operand): $sEnd)-$prev))) {

No surprise that trigger expression parser is the last thing Zabbix PHP developers want to deal with! 🙂

This is it for today! Enjoy reading the source code!

Subscribe
Notify of
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Konstantin
Konstantin
13 years ago

Awesome stats, thanks 🙂 Trigger expression parser is the champion!

fmrapid
fmrapid
13 years ago

On a related note you can also have fun with google analytics for tracking hits on things like:
keywords like zabbix versus nagios, hyperic, tivoli, zenoss
number of downloaded files from freshmeat for zabbix, nagios, hyperic, zenoss
You might also like to add links on all your blog postings so that they can be Redd, Digg, meta-filter, etc.
You might also like getting some blog reviews on the web about Zabbix that do not date from version 1.0-1.6.

Cheers,
fmrapid

2
0
Would love your thoughts, please comment.x
()
x