Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ug.cgi?id=282 set to be disabled by default.
  • Loading branch information
jbuchbinder committed May 28, 2012
1 parent 3c3cda4 commit 4aa9dc4
Show file tree
Hide file tree
Showing 12 changed files with 1,195 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bootstrap
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cd ..
echo "Create distribution timestamp" echo "Create distribution timestamp"
touch Makefile.am touch Makefile.am
echo "Running aclocal" && echo "Running aclocal" &&
aclocal && aclocal -I m4 &&
echo "Running autoheader" && echo "Running autoheader" &&
autoheader && autoheader &&
echo "Creating build" && echo "Creating build" &&
Expand Down
82 changes: 82 additions & 0 deletions configure.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ AC_ARG_WITH( python,
[ --with-python=PATH Specify prefix for python or full path to interpreter], [ --with-python=PATH Specify prefix for python or full path to interpreter],
[if test x"$withval" != xno; then enable_python="yes"; PYTHON_BIN="$withval"; fi]) [if test x"$withval" != xno; then enable_python="yes"; PYTHON_BIN="$withval"; fi])


AC_ARG_WITH( php,
[ --with-php=PATH Specify prefix for php or full path to php-config],
[if test x"$withval" != xno; then enable_php="yes"; PHP_BIN="$withval"; fi])

AC_ARG_WITH( librrd, AC_ARG_WITH( librrd,
[ --with-librrd=DIR Specify location for librrd], [ --with-librrd=DIR Specify location for librrd],
[if test x"$withval" != xno; then librrd="yes"; librrdpath="$withval"; fi]) [if test x"$withval" != xno; then librrd="yes"; librrdpath="$withval"; fi])
Expand Down Expand Up @@ -238,6 +242,10 @@ AC_ARG_ENABLE( python,
[ --disable-python exclude mod_python and support for metric modules written in python], [ --disable-python exclude mod_python and support for metric modules written in python],
[ if test x"$enableval" != xyes; then enable_python="no"; fi ], [ enable_python="yes" ] ) [ if test x"$enableval" != xyes; then enable_python="no"; fi ], [ enable_python="yes" ] )


AC_ARG_ENABLE( php,
[ --enable-php include mod_php and support for metric modules written in php],
[ if test x"$enableval" != xno; then enable_php="yes"; fi ], [ enable_php="no" ] )

AC_ARG_ENABLE( status, AC_ARG_ENABLE( status,
[ --enable-status compile and install modgstatus to enable gmond status metric module support], [ --enable-status compile and install modgstatus to enable gmond status metric module support],
[ enable_status="yes" [ enable_status="yes"
Expand Down Expand Up @@ -337,6 +345,77 @@ AC_MSG_CHECKING(Python support)
AC_MSG_RESULT($enable_python) AC_MSG_RESULT($enable_python)
AM_CONDITIONAL(BUILD_PYTHON, test x"$enable_python" = xyes) AM_CONDITIONAL(BUILD_PYTHON, test x"$enable_python" = xyes)


if test x"$enable_php" = xyes; then
echo
echo "Checking for php"

# check for php-config executable
if test -e "$PHP_BIN"; then
AC_MSG_CHECKING([for php-config])
if test -d "$PHP_BIN"; then
if test -x "$PHP_BIN/bin/php-config"; then
PHP_CONFIG_BIN="$PHP_BIN/bin/php-config"
elif test -x "$PHP_BIN/php-config"; then
PHP_CONFIG_BIN="$PHP_BIN/php-config"
fi
elif test -x "$PHP_BIN"; then
PHP_CONFIG_BIN=$PHP_BIN
fi
if test -z "$PHP_CONFIG_BIN"; then
AC_MSG_RESULT([not found using $PHP_BIN])
else
AC_MSG_RESULT([$PHP_CONFIG_BIN])
fi
fi
if test -z "$PHP_CONFIG_BIN"; then
AC_PATH_PROG([PHP_CONFIG_BIN], [php-config])
fi

if test -n "$PHP_CONFIG_BIN"; then
# find out php version
PHP_FULL_VERSION=`$PHP_CONFIG_BIN --version`
AC_CACHE_CHECK([PHP version >= 5.3], [php_cv_version_5],
[AX_COMPARE_VERSION([$PHP_FULL_VERSION], [ge], [5.3],
[php_cv_version_5="yes"],
[php_cv_version_5="no"])])
if test "$php_cv_version_5" = "yes"; then
PHP_VERSION=5
else
AC_MSG_ERROR([PHP version >= 5.3 required])
fi
AC_SUBST(PHP_VERSION)

AC_MSG_CHECKING(PHP Include dir)
PHP_INCLUDE_DIR=`$PHP_CONFIG_BIN --include-dir`
AC_MSG_RESULT($PHP_INCLUDE_DIR)

if test -f "$PHP_INCLUDE_DIR/sapi/embed/php_embed.h"; then
PHP_INCLUDES=`$PHP_CONFIG_BIN --includes`
CPPFLAGS+=$PHP_INCLUDES
LDFLAGS+=" -L`$PHP_CONFIG_BIN --prefix`/lib"
else
PHP_INCLUDES=""
fi
AC_CHECK_HEADER([sapi/embed/php_embed.h], [],
[
AC_MSG_ERROR([your system is missing the PHP SAPI headers.])
enable_php="no"
],
[#ifdef _PHP_EMBED_H_
# include <sapi/embed/php_embed.h>
#endif
])
AC_SUBST(PHP_INCLUDES)
else
AC_MSG_ERROR("php-config not found")
enable_php="no"
fi
fi

AC_MSG_CHECKING(PHP support)
AC_MSG_RESULT($enable_php)
AM_CONDITIONAL(BUILD_PHP, test x"$enable_php" = xyes)

LIB_SUFFIX=lib LIB_SUFFIX=lib
case $host in case $host in
x86_64*linux*) x86_64*linux*)
Expand Down Expand Up @@ -802,9 +881,12 @@ AC_OUTPUT(Makefile
gmond/modules/disk/Makefile gmond/modules/disk/Makefile
gmond/modules/memory/Makefile gmond/modules/memory/Makefile
gmond/modules/network/Makefile gmond/modules/network/Makefile
gmond/modules/php/Makefile
gmond/modules/python/Makefile gmond/modules/python/Makefile
gmond/modules/status/Makefile gmond/modules/status/Makefile
gmond/modules/system/Makefile gmond/modules/system/Makefile
gmond/php_modules/Makefile
gmond/php_modules/example/Makefile
gmond/python_modules/Makefile gmond/python_modules/Makefile
gmond/python_modules/apache_status/Makefile gmond/python_modules/apache_status/Makefile
gmond/python_modules/db/Makefile gmond/python_modules/db/Makefile
Expand Down
6 changes: 5 additions & 1 deletion gmond/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@


include $(top_srcdir)/ganglia.inc include $(top_srcdir)/ganglia.inc


SUBDIRS = modules python_modules SUBDIRS = modules python_modules php_modules


EXTRA_DIST = gmond.aix.init gmond.solaris.init.in gmond.init gmond.init.SuSE gmond.conf.5 gmond.conf.html conf.pod cmdline.sh EXTRA_DIST = gmond.aix.init gmond.solaris.init.in gmond.init gmond.init.SuSE gmond.conf.5 gmond.conf.html conf.pod cmdline.sh
if STATIC_BUILD if STATIC_BUILD
Expand All @@ -20,6 +20,10 @@ if BUILD_PYTHON
GLDADD += modules/python/mod_python.lo GLDADD += modules/python/mod_python.lo
GLDFLAGS += -lpython@PYTHON_VERSION@ GLDFLAGS += -lpython@PYTHON_VERSION@
endif endif
if BUILD_PHP
GLDADD += modules/php/mod_php.lo
GLDFLAGS += -lphp@PHP_VERSION@
endif
else else
GCFLAGS = -D_LARGEFILE64_SOURCE GCFLAGS = -D_LARGEFILE64_SOURCE
GLDADD = GLDADD =
Expand Down
10 changes: 7 additions & 3 deletions gmond/modules/Makefile.am
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ if BUILD_PYTHON
PYTHON_SUBDIR = python PYTHON_SUBDIR = python
endif endif


if BUILD_PHP
PHP_SUBDIR = php
endif

if BUILD_STATUS if BUILD_STATUS
STATUS_SUBDIR = status STATUS_SUBDIR = status
endif endif


DIST_SUBDIRS = example cpu disk memory network system status python DIST_SUBDIRS = example cpu disk memory network system status python php
if STATIC_BUILD if STATIC_BUILD
SUBDIRS = cpu disk memory network system $(STATUS_SUBDIR) $(PYTHON_SUBDIR) SUBDIRS = cpu disk memory network system $(STATUS_SUBDIR) $(PYTHON_SUBDIR) $(PHP_SUBDIR)
else else
SUBDIRS = example cpu disk memory network system $(STATUS_SUBDIR) $(PYTHON_SUBDIR) SUBDIRS = example cpu disk memory network system $(STATUS_SUBDIR) $(PYTHON_SUBDIR) $(PHP_SUBDIR)


install: install-recursive install: install-recursive
@rm -rf $(DESTDIR)$(pkglibdir)/*.a @rm -rf $(DESTDIR)$(pkglibdir)/*.a
Expand Down
27 changes: 27 additions & 0 deletions gmond/modules/conf.d/modphp.conf.in
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
param php_modules_path
path to the directory where mod_php
should look for php metric modules

param php_ini_path
path to the php.ini used by the php engine

the "phpconf" files in the include directory below
will be scanned for configurations for those modules
*/
modules {
module {
name = "php_module"
path = "modphp.so"
param php_modules_path {
value = "@moduledir@/php_modules"
}
/*
param php_ini_path {
value = "/etc/php.ini"
}
*/
}
}

include ("@sysconfdir@/conf.d/*.phpconf")
30 changes: 30 additions & 0 deletions gmond/modules/php/Makefile.am
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,30 @@

include $(top_srcdir)/ganglia.inc

AM_CFLAGS = -D_LARGEFILE64_SOURCE -I$(top_builddir)/include -I$(top_builddir)/lib

if STATIC_BUILD
noinst_LTLIBRARIES = libmodphp.la
libmodphp_la_SOURCES = mod_php.c
libmodphp_la_LDFLAGS = -export-all-symbols
else
pkglib_LTLIBRARIES = modphp.la
modphp_la_SOURCES = mod_php.c
modphp_la_LDFLAGS = -module -avoid-version -lphp@PHP_VERSION@

EXTRA_DIST = README.in ../conf.d/modphp.conf.in
endif

README: README.in $(FIXCONFIG)
$(FIXCONFIG) README.in

../conf.d/modphp.conf: ../conf.d/modphp.conf.in $(FIXCONFIG)
$(FIXCONFIG) ../conf.d/modphp.conf.in

# Note that README is listed as a dependency to be generated, but it
# is not currently installed anywhere
install-exec-hook: ../conf.d/modphp.conf README
mkdir -p $(DESTDIR)$(sysconfdir)/conf.d && \
$(INSTALL_DATA) ../conf.d/modphp.conf $(DESTDIR)$(sysconfdir)/conf.d/modphp.conf

INCLUDES = @APR_INCLUDES@ @PHP_INCLUDES@
161 changes: 161 additions & 0 deletions gmond/modules/php/README.in
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,161 @@
How To Write And Use A PHP Metric
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The following sections will describe how to develop and deploy
new metric modules using php. The PHP Embed is required, if you
installed php from the sources make sure you compiled it with
the configure option --enable-embed.

Note : the current implementation of the PHP module for ganglia
parse the php script each time a metric is gathered.

Writing a php metric module
~~~~~~~~~~~~~~~~~~~~~~~~~~~

There are two functions that must be included in every php based
metric module as well as at least one callback handler.
These functions are:

function metric_init($params) { ... }

This function will be called once at initialization time. It
can be used to do any kind of initialization that the module
requires in order to properly gather the intended metric. This
function also takes a single array type parameter which
contains configuration directives that were designated for
this module in the gmond.conf file. In addition to any other
initialization that is done, the function must also create,
populate and return the metric description array.
Each metric description array, must supply at least the
following elements:

$d = array(
'name' => '<your_metric_name>',
'call_back' => '<metric_handler_function>',
'time_max' => int(<your_time_max>),
'value_type' => '<string | uint | float | double>',
'units' => '<your_units>',
'slope' => '<zero | positive | negative | both>',
'format' => '<your_format>',
'description' => '<your_description>'
);

These elements are basically the same type of data that must be
supplied to the gmetric commandline utility with the exception
of the call_back function. See the gmetric help document for
more information. The call_back entry designates a function
that will be called whenever the data for this metric needs to
be gathered. The format of this function is very simple. It
is just a function name with a 'name' parameter

function My_Metric_Handler($name) { ... }

The value of the name parameter will be the name of the metric
that is being gathered. This allows a call_back function to
handle more than one metric and to be able to determine which
metric is being handled when called. This function implements the
code that handles the gathering of the metric data. The return
value from this function must match the data value type that was
specified in the corresponding metric description that was defined
during the metric_init() function.

function metric_cleanup() { ... }

This function will be called once when gmond is shutting down.
Any module clean up code can be executed here and the function
must not return a value.

Other than the mandatory functions and metric description array as
specified above, the metric module is free to do whatever it needs
in order to appropriately gather the intended metric data. Each
metric description array can also contain additional user defined
elements outside of the mandatory elements listed above. Any additional
elements in the array will be ignored by mod_php but can to used by
the php module itself to hold additional data that should correspond
to the metric.

Deploying a php metric module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Once a php metric module has been developed, deploying the module is as
easy as copying a file to a specific directory. In the configuration of
the mod_php module that is part of gmond.conf, a php metric module
directory must have been specified (see next section). To deploy a
php module, simply copy the .php file to the specified php module
directory. Once the php module has been copied, start gmond using the
-m parameter. This will show a list of all of the available metrics that
gmond is capable of gathering. The list should include the name of the
php module that was just deployed. Add this metric to a collection
group, just like any other gmond metric.

Configuring Gmond for php support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Configuring Gmond to support php based modules is as easy as loading
any other type of gmond dynamically loadable metric module. The name of
the php support module is modphp.so. A base configuration file
is included in the Ganglia source code and should have been installed
automatically if done through an RPM. The basic configuration that
should be added to or included by gmond.conf in your system is as
follows:

modules {
module {
name = "php_module"
path = "modphp.so"
param php_modules_path {
value = "@moduledir@/php_modules"
}
/*
param php_ini_path {
value = "/etc/php.ini"
}
*/
}
}

include ("@sysconfdir@/conf.d/*.phpconf")

The php module use two config parameters. The most important one is the
php_modules_path. The path that has been assigned to this directive will
be passed down to the mod_php module and used to search for .php
php modules. Any php module that is found in this location will be loaded
and assumed to be a metric gathering module. If the collection groups that
include metrics that are implemented in php, are put into separate
configuration files and the file extension of the configuration files are
.phpconf, they will automatically be loaded and read whenever the mod_php
module is included.

Configuring a Gmond php module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The configuration of a Gmond php module is really no different
than any other module. Most php modules will not require any
specialized configuration at all. However, support has been
provided to allow for parameters to be passed from the gmond.conf
file to a php module. The syntax for passing parameters to
a specific php module is at follows:

modules {
module {
name = "example"
language = "python"
param YouNameIt {
value = Whatever
}
param Another {
value = NewValue
}
}
}

The "module" section must contain a "name" directive and a
"language" directive. The value of the "name" directive must
match the file name of the php module's .php file and the
value of the "language" directive must be "php". The section
can take multiple "param" sections. Each "param" section must
include a name which will be the name of the value when it is
passed to the php module, and a "value" directive. The
"value" directive will always be passed as a string to the
php module. It is up to the module itself to determine the
actual value type.
Loading

0 comments on commit 4aa9dc4

Please sign in to comment.