├── debian ├── compat ├── dirs ├── docs ├── source │ └── format ├── watch ├── README.source ├── README.Debian ├── rules ├── control ├── postrm ├── postinst ├── changelog └── copyright ├── AUTHORS ├── conf.d ├── mod_user.conf ├── mod_fs.conf ├── mod_multicpu.conf ├── mod_example.conf └── mod_io.conf ├── Makefile.am ├── user ├── Makefile.am └── mod_user.c ├── example ├── Makefile.am └── mod_example.c ├── .travis.yml ├── fs ├── Makefile.am └── mod_fs.c ├── io ├── Makefile.am └── mod_io.c ├── multicpu ├── Makefile.am └── mod_multicpu.c ├── COPYING ├── README ├── configure.ac └── gpl-3.0.txt /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/dirs: -------------------------------------------------------------------------------- 1 | etc/ganglia/conf.d 2 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | gpl-3.0.txt 2 | README 3 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Modules and code contributed by: 2 | * Daniel Pocock 3 | * Anders Björklund 4 | 5 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | version=3 2 | https://github.com/ganglia/ganglia-modules-linux/tags .*/tarball/(\d[\d\.]+) 3 | -------------------------------------------------------------------------------- /debian/README.source: -------------------------------------------------------------------------------- 1 | 2 | Contributions from other developers are welcome, instead of making an 3 | NMU, please consider joining pkg-monitoring. 4 | 5 | Whether you are making an NMU or adding yourself in the pkg-monitoring 6 | team, please make sure any changes you make are pushed into the 7 | Git repository on alioth before you upload. 8 | 9 | -------------------------------------------------------------------------------- /debian/README.Debian: -------------------------------------------------------------------------------- 1 | 2 | 3 | Note: 4 | 5 | - mod_multicpu is not enabled by default, you must rename the config: 6 | 7 | cd /etc/ganglia/conf.d && mv mod_multicpu.conf-sample mod_multicpu.conf 8 | 9 | - mod_fs is not enabled by default, you must rename the config: 10 | 11 | cd /etc/ganglia/conf.d && mv mod_fs.conf-sample mod_fs.conf 12 | -------------------------------------------------------------------------------- /conf.d/mod_user.conf: -------------------------------------------------------------------------------- 1 | modules { 2 | module { 3 | name = "user_module" 4 | path = "/usr/lib/ganglia/moduser.so" 5 | } 6 | } 7 | 8 | 9 | collection_group { 10 | collect_every = 10 11 | time_threshold = 30 12 | metric { 13 | name = "user_total" 14 | title = "Total users" 15 | } 16 | metric { 17 | name = "user_unique" 18 | title = "Unique users" 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | DIST_SUBDIRS = example fs multicpu io user 3 | 4 | AUTOMAKE_OPTIONS = foreign dist-tarZ 5 | ACLOCAL_AMFLAGS = -I m4 6 | 7 | if STATIC_BUILD 8 | 9 | else 10 | 11 | SUBDIRS = example fs multicpu io user 12 | 13 | GCFLAGS = -D_LARGEFILE64_SOURCE 14 | GLDFLAGS = -export-dynamic 15 | 16 | install: install-recursive 17 | @rm -rf $(DESTDIR)$(pkglibdir)/*.a 18 | @rm -rf $(DESTDIR)$(pkglibdir)/*.la 19 | 20 | endif 21 | 22 | #EXTRA_DIST = ganglia-gmond-modules.spec 23 | 24 | EXTRA_DIST = COPYING gpl-3.0.txt 25 | 26 | 27 | -------------------------------------------------------------------------------- /user/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -I$(top_builddir)/include -I$(top_builddir)/libmetrics -I$(top_builddir)/lib 2 | 3 | if STATIC_BUILD 4 | 5 | noinst_LTLIBRARIES = libmoduser.la 6 | libmoduser_la_SOURCES = mod_user.c 7 | libmoduser_la_LDFLAGS = -export-all-symbols 8 | 9 | else 10 | 11 | pkglib_LTLIBRARIES = moduser.la 12 | moduser_la_SOURCES = mod_user.c 13 | moduser_la_LDFLAGS = -module -avoid-version 14 | 15 | EXTRA_DIST = ../conf.d/mod_user.conf 16 | 17 | endif 18 | 19 | #INCLUDES = @APR_INCLUDES@ 20 | 21 | pkglibdir = $(libdir)/ganglia 22 | 23 | -------------------------------------------------------------------------------- /example/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -I$(top_builddir)/include -I$(top_builddir)/lib 2 | 3 | if STATIC_BUILD 4 | 5 | noinst_LTLIBRARIES = libmodexample.la 6 | libmodexample_la_SOURCES = mod_example.c 7 | 8 | else 9 | 10 | pkglib_LTLIBRARIES = modexample.la 11 | modexample_la_SOURCES = mod_example.c 12 | modexample_la_LDFLAGS = -module -avoid-version 13 | 14 | EXTRA_DIST = ../conf.d/mod_example.conf 15 | 16 | endif 17 | 18 | #INCLUDES = @APR_INCLUDES@ 19 | 20 | install: 21 | @echo 22 | @echo "Examples should be installed manually" 23 | @echo 24 | 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | addons: 3 | apt: 4 | packages: 5 | - libapr1-dev 6 | - libconfuse-dev 7 | 8 | before_install: 9 | - sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe" 10 | - sudo apt-get update -q 11 | - sudo apt-get install -y -q libganglia1-dev 12 | 13 | install: 14 | - mkdir m4 15 | - autoreconf --install 16 | 17 | script: 18 | - ./configure --enable-shared --disable-static CFLAGS="`apr-1-config --cflags --includes` -I`pwd`/monitor-core/include -I`pwd`/monitor-core/lib" 19 | - make 20 | 21 | -------------------------------------------------------------------------------- /conf.d/mod_fs.conf: -------------------------------------------------------------------------------- 1 | modules { 2 | module { 3 | name = "fs_module" 4 | path = "/usr/lib/ganglia/modfs.so" 5 | } 6 | } 7 | 8 | 9 | #/* Filesystem DSO metric */ 10 | #/* Additional metrics should be added to the 11 | # collection group to represent each mount 12 | # discovered on the system. See available 13 | # discovered metrics through ./gmond -m command. */ 14 | collection_group { 15 | collect_every = 10 16 | time_threshold = 50 17 | metric { 18 | name_match = "fs_([a-z]+_[a-z]+)_(.+)$" 19 | value_threshold = 1.0 20 | title = "FS \\1: \\2" 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /fs/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -D_LARGEFILE64_SOURCE -I$(top_builddir)/include -I$(top_builddir)/libmetrics -I$(top_builddir)/lib 2 | 3 | if STATIC_BUILD 4 | noinst_LTLIBRARIES = libmodfs.la 5 | libmodfs_la_SOURCES = mod_fs.c 6 | libmodfs_la_LDFLAGS = -export-all-symbols 7 | else 8 | pkglib_LTLIBRARIES = modfs.la 9 | 10 | modfs_la_SOURCES = mod_fs.c 11 | modfs_la_LDFLAGS = -module -avoid-version 12 | #modfs_la_LIBADD = $(top_builddir)/libmetrics/libmetrics.la 13 | 14 | EXTRA_DIST = ../conf.d/mod_fs.conf 15 | endif 16 | 17 | #INCLUDES = @APR_INCLUDES@ 18 | 19 | pkglibdir = $(libdir)/ganglia 20 | 21 | -------------------------------------------------------------------------------- /io/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -D_LARGEFILE64_SOURCE -I$(top_builddir)/include -I$(top_builddir)/libmetrics -I$(top_builddir)/lib 2 | 3 | if STATIC_BUILD 4 | noinst_LTLIBRARIES = libmodio.la 5 | libmodio_la_SOURCES = mod_io.c 6 | libmodio_la_LDFLAGS = -export-all-symbols 7 | else 8 | pkglib_LTLIBRARIES = modio.la 9 | 10 | modio_la_SOURCES = mod_io.c 11 | modio_la_LDFLAGS = -module -avoid-version 12 | #modio_la_LIBADD = $(top_builddir)/libmetrics/libmetrics.la 13 | 14 | EXTRA_DIST = ../conf.d/mod_io.conf 15 | endif 16 | 17 | #INCLUDES = @APR_INCLUDES@ 18 | 19 | pkglibdir = $(libdir)/ganglia 20 | 21 | -------------------------------------------------------------------------------- /conf.d/mod_multicpu.conf: -------------------------------------------------------------------------------- 1 | modules { 2 | module { 3 | name = "multicpu_module" 4 | path = "/usr/lib/ganglia/modmulticpu.so" 5 | } 6 | } 7 | 8 | 9 | #/* Multi CPU DSO metric */ 10 | #/* Additional metrics should be added to the 11 | # collection group to represent each CPU 12 | # discovered on the system. See available 13 | # discovered metrics through ./gmond -m command. */ 14 | collection_group { 15 | collect_every = 10 16 | time_threshold = 50 17 | metric { 18 | name_match = "multicpu_([a-z]+)([0-9]+)" 19 | value_threshold = 1.0 20 | title = "CPU-\\2 \\1" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /multicpu/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CFLAGS = -D_LARGEFILE64_SOURCE -I$(top_builddir)/include -I$(top_builddir)/libmetrics -I$(top_builddir)/lib 2 | 3 | if STATIC_BUILD 4 | noinst_LTLIBRARIES = libmodmulticpu.la 5 | libmodmulticpu_la_SOURCES = mod_multicpu.c 6 | libmodmulticpu_la_LDFLAGS = -export-all-symbols 7 | else 8 | pkglib_LTLIBRARIES = modmulticpu.la 9 | 10 | modmulticpu_la_SOURCES = mod_multicpu.c 11 | modmulticpu_la_LDFLAGS = -module -avoid-version 12 | #modmulticpu_la_LIBADD = $(top_builddir)/libmetrics/libmetrics.la 13 | 14 | EXTRA_DIST = ../conf.d/mod_multicpu.conf 15 | endif 16 | 17 | #INCLUDES = @APR_INCLUDES@ 18 | 19 | pkglibdir = $(libdir)/ganglia 20 | 21 | -------------------------------------------------------------------------------- /conf.d/mod_example.conf: -------------------------------------------------------------------------------- 1 | modules { 2 | module { 3 | name = "example_module" 4 | path = "/usr/lib/ganglia/modexample.so" 5 | params = "An extra raw parameter" 6 | param RandomMax { 7 | value = 75 8 | } 9 | param ConstantValue { 10 | value = 25 11 | } 12 | } 13 | } 14 | 15 | 16 | #/* Test DSO metric */ 17 | collection_group { 18 | collect_every = 10 19 | time_threshold = 50 20 | metric { 21 | name = "Random_Numbers" 22 | title = "Random Numbers Metric" 23 | value_threshold = 1.0 24 | } 25 | } 26 | 27 | collection_group { 28 | collect_once = yes 29 | time_threshold = 20 30 | metric { 31 | name = "Constant_Number" 32 | title = "Constant Number Metric" 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | include /usr/share/cdbs/1/rules/debhelper.mk 4 | include /usr/share/cdbs/1/class/autotools.mk 5 | include /usr/share/cdbs/1/rules/autoreconf.mk 6 | 7 | 8 | # Add here any variable or target overrides you need. 9 | 10 | CFLAGS = `apr-1-config --cflags --cppflags --includes` 11 | 12 | install/ganglia-modules-linux:: 13 | mkdir -p debian/ganglia-modules-linux/etc/ganglia/conf.d 14 | cp conf.d/mod_fs.conf debian/ganglia-modules-linux/etc/ganglia/conf.d/mod_fs.conf-sample 15 | cp conf.d/mod_io.conf debian/ganglia-modules-linux/etc/ganglia/conf.d 16 | cp conf.d/mod_multicpu.conf debian/ganglia-modules-linux/etc/ganglia/conf.d/mod_multicpu.conf-sample 17 | rm debian/ganglia-modules-linux/usr/lib/ganglia/modmulticpu.so 18 | rm debian/ganglia-modules-linux/usr/lib/ganglia/*.a 19 | rm debian/ganglia-modules-linux/usr/lib/ganglia/*.la 20 | 21 | 22 | -------------------------------------------------------------------------------- /conf.d/mod_io.conf: -------------------------------------------------------------------------------- 1 | modules { 2 | module { 3 | name = "io_module" 4 | path = "/usr/lib/ganglia/modio.so" 5 | } 6 | } 7 | 8 | 9 | #/* IO DSO metric */ 10 | #/* Additional metrics should be added to the 11 | # collection group to represent each storage device 12 | # discovered on the system. See available 13 | # discovered metrics through ./gmond -m command. */ 14 | #collection_group { 15 | # collect_every = 10 16 | # time_threshold = 50 17 | # metric { 18 | # name_match = "io_([a-z_]+)_([a-z0-9]+)" 19 | # value_threshold = 1.0 20 | # title = "IO \\1 \\2" 21 | # } 22 | #} 23 | 24 | collection_group { 25 | collect_every = 10 26 | time_threshold = 30 27 | metric { 28 | name = "io_reads" 29 | title = "Total reads" 30 | } 31 | metric { 32 | name = "io_nread" 33 | title = "Total read" 34 | } 35 | metric { 36 | name = "io_writes" 37 | title = "Total writes" 38 | } 39 | metric { 40 | name = "io_nwrite" 41 | title = "Total written" 42 | } 43 | metric { 44 | name = "io_max_svc_time" 45 | title = "max service time seen across disks" 46 | } 47 | metric { 48 | name = "io_max_wait_time" 49 | title = "max queue time seen across disks" 50 | } 51 | metric { 52 | name = "io_busymax" 53 | title = "max io busy time seen across disks" 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: ganglia-modules-linux 2 | Section: admin 3 | Priority: extra 4 | Maintainer: Debian Monitoring Maintainers 5 | Uploaders: Daniel Pocock 6 | Build-Depends: cdbs, debhelper (>= 7.0.50~), dh-autoreconf, libganglia1-dev (>= 3.3.5), libconfuse-dev, libapr1-dev 7 | Standards-Version: 3.9.5 8 | Homepage: https://github.com/ganglia/ganglia-modules-linux 9 | Vcs-Git: git://anonscm.debian.org/pkg-monitoring/ganglia-modules-linux.git 10 | Vcs-Browser: https://anonscm.debian.org/cgit/pkg-monitoring/ganglia-modules-linux.git 11 | 12 | Package: ganglia-modules-linux 13 | Architecture: any 14 | Depends: ${shlibs:Depends}, ${misc:Depends}, ganglia-monitor 15 | Description: Ganglia extra modules for Linux (IO, filesystems, multicpu) 16 | Ganglia's core modules provide essential metrics like RAM and CPU load 17 | and most of them are implemented for any platform where Ganglia runs. 18 | The ganglia-modules-linux project is not constrained by the requirements 19 | to support all the Ganglia platforms: these modules are implemented 20 | exclusively for Linux users. The implementations are high-performance 21 | C code. The exact modules currently included are IO statistics 22 | (similar to the statistics from iostat), individual filesystem capacity 23 | statistics and per-core CPU metrics. 24 | -------------------------------------------------------------------------------- /debian/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postrm script for ganglia-modules-linux 3 | # 4 | # see: dh_installdeb(1) 5 | 6 | set -e 7 | 8 | # summary of how this script can be called: 9 | # * `remove' 10 | # * `purge' 11 | # * `upgrade' 12 | # * `failed-upgrade' 13 | # * `abort-install' 14 | # * `abort-install' 15 | # * `abort-upgrade' 16 | # * `disappear' 17 | # 18 | # for details, see http://www.debian.org/doc/debian-policy/ or 19 | # the debian-policy package 20 | 21 | 22 | case "$1" in 23 | purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) 24 | INIT_GMOND=/etc/init.d/ganglia-monitor 25 | if which invoke-rc.d >/dev/null 2>&1; then 26 | invoke-rc.d ganglia-monitor status >/dev/null 2>&1 && \ 27 | invoke-rc.d ganglia-monitor restart 28 | else 29 | [ -x ${INIT_GMOND} ] && \ 30 | ${INIT_GMOND} status >/dev/null 2>&1 && \ 31 | ${INIT_GMOND} restart 32 | fi 33 | # call `true' to conceal the return status of the gmond restart 34 | # as we don't want an unrelated error in gmond to suggest 35 | # that the dpkg operation has completely failed 36 | true 37 | ;; 38 | 39 | *) 40 | echo "postrm called with unknown argument \`$1'" >&2 41 | exit 1 42 | ;; 43 | esac 44 | 45 | # dh_installdeb will replace this with shell code automatically 46 | # generated by other debhelper scripts. 47 | 48 | #DEBHELPER# 49 | 50 | exit 0 51 | -------------------------------------------------------------------------------- /debian/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # postinst script for ganglia-modules-linux 3 | # 4 | # see: dh_installdeb(1) 5 | 6 | set -e 7 | 8 | # summary of how this script can be called: 9 | # * `configure' 10 | # * `abort-upgrade' 11 | # * `abort-remove' `in-favour' 12 | # 13 | # * `abort-remove' 14 | # * `abort-deconfigure' `in-favour' 15 | # `removing' 16 | # 17 | # for details, see http://www.debian.org/doc/debian-policy/ or 18 | # the debian-policy package 19 | 20 | 21 | case "$1" in 22 | configure) 23 | INIT_GMOND=/etc/init.d/ganglia-monitor 24 | if which invoke-rc.d >/dev/null 2>&1; then 25 | invoke-rc.d ganglia-monitor status >/dev/null 2>&1 && \ 26 | invoke-rc.d ganglia-monitor restart 27 | else 28 | [ -x ${INIT_GMOND} ] && \ 29 | ${INIT_GMOND} status >/dev/null 2>&1 && \ 30 | ${INIT_GMOND} restart 31 | fi 32 | # call `true' to conceal the return status of the gmond restart 33 | # as we don't want an unrelated error in gmond to suggest 34 | # that the dpkg operation has completely failed 35 | true 36 | ;; 37 | 38 | abort-upgrade|abort-remove|abort-deconfigure) 39 | ;; 40 | 41 | *) 42 | echo "postinst called with unknown argument \`$1'" >&2 43 | exit 1 44 | ;; 45 | esac 46 | 47 | # dh_installdeb will replace this with shell code automatically 48 | # generated by other debhelper scripts. 49 | 50 | #DEBHELPER# 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | ganglia-modules-linux (1.3.6-2) unstable; urgency=medium 2 | 3 | * Only restart service if already running. (Closes: #790951) 4 | 5 | -- Daniel Pocock Fri, 03 Jul 2015 11:29:54 +0200 6 | 7 | ganglia-modules-linux (1.3.6-1) unstable; urgency=low 8 | 9 | * New upstream release. 10 | * Use b_avail instead of b_free for free space. (Closes: #772481) 11 | 12 | -- Daniel Pocock Sun, 07 Dec 2014 18:14:22 +0100 13 | 14 | ganglia-modules-linux (1.3.5-1) unstable; urgency=low 15 | 16 | * New upstream release. 17 | * Add a free space percentage metric. 18 | * Fix truncation of name for root filesystem metric. (Closes: #771521) 19 | 20 | -- Daniel Pocock Sun, 30 Nov 2014 14:04:33 +0100 21 | 22 | ganglia-modules-linux (1.3.4-7) unstable; urgency=low 23 | 24 | * Migrate from collab-maint to pkg-monitoring. 25 | 26 | -- Daniel Pocock Sun, 14 Sep 2014 10:21:53 +0200 27 | 28 | ganglia-modules-linux (1.3.4-6) unstable; urgency=low 29 | 30 | * Add VCS locations to control file. 31 | * Update copyright file to DEP-5 format, clarify BSD terms 32 | * Upstream move to github (update home page and watch file) 33 | 34 | -- Daniel Pocock Mon, 05 Nov 2012 14:53:57 +0100 35 | 36 | ganglia-modules-linux (1.3.4-5) unstable; urgency=low 37 | 38 | * Eliminate issues relating to ganglia-monitor 39 | restart during remove/purge (Closes: #669860) 40 | 41 | -- Daniel Pocock Sat, 21 Apr 2012 15:49:38 +0200 42 | 43 | ganglia-modules-linux (1.3.4-4) unstable; urgency=low 44 | 45 | * Add ganglia-monitor to Depends (Closes: #669329) 46 | 47 | -- Daniel Pocock Thu, 19 Apr 2012 10:33:41 +0200 48 | 49 | ganglia-modules-linux (1.3.4-2) unstable; urgency=low 50 | 51 | * Initial Release (Closes: #665829). 52 | 53 | -- Daniel Pocock Sat, 07 Apr 2012 14:33:04 +0100 54 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | ----------------------------------------------------------------------------- 2 | ganglia-modules-linux: modules for collecting metrics on Linux 3 | Copyright (C) 2007 Brad Nicholes, Novell (BSD license) 4 | Copyright (C) 2008 JB Kim (BSD license) 5 | Copyright (C) 2011 Daniel Pocock 6 | 7 | This program is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program. If not, see . 19 | 20 | ---------------------------------------------------------------------------- 21 | 22 | Exceptions to the license: 23 | - any code that is not marked explicitly or mentioned in this list 24 | of exceptions is copyright and licensed under the terms of the GPLv3 25 | as described above 26 | - the contents of the `example' directory (for building the 27 | example module) have been copied as-is from the main Ganglia 28 | distribution and retain the original BSD-like copyright 29 | - the contents of the `multicpu' directory are loosely based on 30 | the module contributed (under a BSD license) to the main Ganglia 31 | distribution by Brad Nicholes (bnicholes novell.com) 32 | - the contents of the `io' directory are based on the 33 | module contributed to the Ganglia mailing list (under a BSD license) 34 | by JB Kim (jbremnant gmail.com) adapted to resemble the metric names 35 | used in ganglia-modules-solaris 36 | - the modules implement the Ganglia metric module interface. 37 | Ganglia is distributed under a BSD-like license at http://ganglia.info 38 | The Ganglia copyright notice is applicable to the API: 39 | "Copyright (c) 2001 by Matt Massie and The Regents of the University 40 | of California. All rights reserved." 41 | 42 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: ganglia-modules-linux 3 | Upstream-Contact: ganglia developers 4 | Source: git://github.com/ganglia/ganglia-modules-linux.git 5 | 6 | Files: * 7 | Copyright: 2011-2012, Daniel Pocock 8 | License: GPL-3 9 | 10 | Files: io/* 11 | Copyright: 2008, JB Kim 12 | 2011-2012, Daniel Pocock 13 | License: GPL-3 14 | 15 | Files: example/* 16 | Copyright: 2007, Novell 17 | License: BSD-Novell 18 | 19 | Files: multicpu/* 20 | Copyright: 2007, Novell 21 | 2011-2012, Daniel Pocock 22 | License: GPL-3 23 | 24 | Files: fs/* 25 | Copyright: 2012, Daniel Pocock 26 | License: GPL-3 27 | 28 | Files: debian/* 29 | Copyright: 2011-2012, Daniel Pocock 30 | License: GPL-3 31 | 32 | License: GPL-3 33 | The GPL-3 can be found in /usr/share/common-licenses/GPL-3 on your 34 | Debian system. 35 | 36 | License: BSD-Novell 37 | Portions Copyright (C) 2007 Novell, Inc. All rights reserved. 38 | . 39 | Redistribution and use in source and binary forms, with or without 40 | modification, are permitted provided that the following conditions are met: 41 | . 42 | - Redistributions of source code must retain the above copyright notice, 43 | this list of conditions and the following disclaimer. 44 | . 45 | - Redistributions in binary form must reproduce the above copyright notice, 46 | this list of conditions and the following disclaimer in the documentation 47 | and/or other materials provided with the distribution. 48 | . 49 | - Neither the name of Novell, Inc. nor the names of its 50 | contributors may be used to endorse or promote products derived from this 51 | software without specific prior written permission. 52 | . 53 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 54 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 | ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS 57 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 | POSSIBILITY OF SUCH DAMAGE. 64 | 65 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | 2 | Changelog 3 | ========= 4 | 5 | v1.3.5: Add a free space metric. 6 | Correct metric name for root filesystem. 7 | v1.3.4: Explicitly define some buffer sizes. 8 | v1.3.3: Tweak README: requires ganglia headers > 3.3.1 9 | v1.3.2: Adapt to use gm_file.h instead of local copies of Ganglia 10 | helper functions (requires ganglia headers > 3.3.2) 11 | v1.3.1: Tweak to build without a local copy of the full Ganglia source tree 12 | v1.3.0: add filesystem capacity metrics 13 | v1.2.0: improve multiCPU metric performance 14 | v1.1.0: rename metric names for IO to follow ganglia-modules-solaris 15 | conventions and units 16 | v1.0.0: initial release with IO module code developed by JB Kim and 17 | multiCPU code contributed to Ganglia by Brad Nicholes 18 | 19 | Updated metric names and units 20 | ============================== 21 | 22 | v1.0.0: 23 | - metric names follow the original naming convention for mod_iostat 24 | - values reported are in KB not Bytes, so you might see `K' twice in the 25 | rrd graph (and if you see K twice, it means you are looking at MBytes) 26 | 27 | v1.1.0: 28 | - metric names follow the convention of ganglia-modules-solaris 29 | (similar to names in kstat, e.g. io_nwrite = number of bytes written) 30 | - values reported in unscaled units (bytes and seconds) rather than 31 | in KB and milliseconds 32 | 33 | When does a module belong in ganglia-modules-linux? 34 | =================================================== 35 | 36 | Does a module belong in ganglia-modules-linux or in the main gmond 37 | repository (monitor-core on Github)? 38 | 39 | If the answers to these questions is YES, the module probably belongs 40 | in this repository: 41 | - does the module access files under /proc that only exist on Linux? 42 | - does it depend on C libraries that only exist on Linux? 43 | - does it use syscalls or special parameters to syscalls that only 44 | exist on Linux? 45 | 46 | If the C library calls made by the module are POSIX, then the module 47 | probably belongs in the main monitor-core repository as it 48 | may work for users on other platforms, even if you can't test 49 | those platforms yourself. 50 | 51 | modmulticpu 52 | =========== 53 | 54 | This version of modmulticpu is based on the original module contributed 55 | by Brad Nicholes to the main Ganglia tree. 56 | 57 | It has been enhanced to access the array of CPU data in a more efficient 58 | manner. 59 | 60 | Building (if using code from git) 61 | ================================= 62 | 63 | Prepare the tree with this command: 64 | 65 | mkdir m4 && autoreconf --install 66 | 67 | Then follow the steps below to build. 68 | 69 | You will need the source code for the main monitor-core repository in 70 | order to compile this code. 71 | 72 | Building 73 | ======== 74 | 75 | Sample configure command for building the modules: 76 | 77 | GANGLIA_INCLUDES="-I/some/path/to/monitor-core/include -I/some/path/to/monitor-core/lib" 78 | ./configure \ 79 | CFLAGS="`apr-1-config --cflags --includes` $GANGLIA_INCLUDES" \ 80 | --enable-shared --disable-static 81 | 82 | make 83 | 84 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | dnl ganglia-modules-linux: modules for collecting metrics on Linux 2 | dnl Copyright (C) 2011 Daniel Pocock 3 | dnl 4 | dnl This program is free software: you can redistribute it and/or modify 5 | dnl it under the terms of the GNU General Public License as published by 6 | dnl the Free Software Foundation, either version 3 of the License, or 7 | dnl (at your option) any later version. 8 | dnl 9 | dnl This program is distributed in the hope that it will be useful, 10 | dnl but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | dnl GNU General Public License for more details. 13 | dnl 14 | dnl You should have received a copy of the GNU General Public License 15 | dnl along with this program. If not, see . 16 | 17 | AC_INIT(ganglia-modules-linux,1.3.6) 18 | AC_CONFIG_SRCDIR(example/mod_example.c) 19 | AM_INIT_AUTOMAKE 20 | 21 | AC_CONFIG_MACRO_DIR([m4]) 22 | 23 | AC_CANONICAL_HOST 24 | AM_CONFIG_HEADER(config.h) 25 | 26 | dnl The following cpu_vendor_os string goes into config.h 27 | dnl 28 | AC_DEFINE_UNQUOTED(HOST_OS, "$HOST_OS", HOST_OS) 29 | AC_DEFINE_UNQUOTED(CPU_VENDOR_OS, "$HOST", CPU_VENDOR_OS) 30 | dnl AC_CYGWIN 31 | 32 | AC_ARG_ENABLE( static-build, 33 | [ --enable-static-build Generate objects for static linking to gmond ], 34 | [ enable_static_build=yes ],[ enable_static_build=no ]) 35 | 36 | AM_CONDITIONAL(STATIC_BUILD, test x"$enable_static_build" = xyes) 37 | 38 | AC_PROG_CC 39 | 40 | AC_PROG_INSTALL 41 | 42 | AC_PROG_LIBTOOL 43 | 44 | dnl default VARSTATEDIR to /var/lib since that's the traditional location. 45 | dnl 46 | varstatedir="/var/lib" 47 | 48 | OS="unknown" 49 | EXPORT_SYMBOLS="-export-dynamic" 50 | case "$host" in 51 | *linux*) 52 | CFLAGS="$CFLAGS -D_REENTRANT" 53 | AC_DEFINE(LINUX, 1, LINUX) 54 | OS="linux" 55 | dnl 56 | dnl For fsuage.c - disk usage. 57 | dnl 58 | AC_DEFINE(STAT_STATVFS, 1, STAT_STATVFS) 59 | AC_DEFINE(SUPPORT_GEXEC, 1, SUPPORT_GEXEC) 60 | ;; 61 | *solaris*) AC_DEFINE(SUPPORT_GEXEC, 0, SUPPORT_GEXEC) 62 | CFLAGS="$CFLAGS -D__EXTENSIONS__ -DHAVE_STRERROR" 63 | if test x"$ac_cv_prog_cc_c99" = x -o x"$ac_cv_prog_cc_c99" = xno; then 64 | CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=199506L" 65 | else 66 | CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L" 67 | fi 68 | if test x"$ac_cv_prog_gcc" != xyes; then 69 | LIBS="-lm $LIBS" 70 | fi 71 | AC_DEFINE(SOLARIS,1,SOLARIS) 72 | OS="solaris" 73 | ;; 74 | *cygwin*) LDFLAGS="-L/bin" 75 | EXPORT_SYMBOLS="-export-all-symbols" 76 | AC_DEFINE(CYGWIN, 1, CYGWIN) 77 | ;; 78 | esac 79 | 80 | AC_SUBST(OS) 81 | 82 | AC_SUBST(EXPORT_SYMBOLS) 83 | dnl Define VARSTATEDIR in config.h 84 | dnl 85 | AC_SUBST(varstatedir) 86 | AC_DEFINE_UNQUOTED(VARSTATEDIR, "$varstatedir", VARSTATEDIR) 87 | 88 | if test x"$libdir" = x"\${exec_prefix/lib"; then 89 | if test x"$exec_prefix" = xNONE; then 90 | if test x"$prefix" = xNONE; then 91 | exec_prefix="$ac_default_prefix" 92 | else 93 | exec_prefix="$prefix" 94 | fi 95 | fi 96 | cfg_libdir=`eval echo "$libdir"` 97 | fi 98 | AC_SUBST(cfg_libdir) 99 | 100 | ganglia_sysconfdir="${sysconfdir}/ganglia" 101 | AC_SUBST(ganglia_sysconfdir) 102 | 103 | #AC_OUTPUT(Makefile ganglia-gmond-modules.spec etc/Makefile etc/conf.d/module1.conf io/Makefile) 104 | 105 | AC_OUTPUT(Makefile example/Makefile fs/Makefile multicpu/Makefile io/Makefile user/Makefile) 106 | 107 | 108 | -------------------------------------------------------------------------------- /user/mod_user.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* #include */ 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | mmodule user_module; 10 | 11 | static apr_pool_t *pool; 12 | static apr_thread_mutex_t *mutex; 13 | 14 | static int user_metric_init ( apr_pool_t *p ) 15 | { 16 | int i; 17 | 18 | libmetrics_init(); 19 | 20 | pool = p; 21 | apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_UNNESTED, pool); 22 | 23 | for (i = 0; user_module.metrics_info[i].name != NULL; i++) { 24 | /* Initialize the metadata storage for each of the metrics and then 25 | * store one or more key/value pairs. The define MGROUPS defines 26 | * the key for the grouping attribute. */ 27 | MMETRIC_INIT_METADATA(&(user_module.metrics_info[i]),p); 28 | MMETRIC_ADD_METADATA(&(user_module.metrics_info[i]),MGROUP,"user"); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | static void user_metric_cleanup ( void ) 35 | { 36 | apr_thread_mutex_destroy(mutex); 37 | } 38 | 39 | /* count the number of users */ 40 | static int get_users ( void ) 41 | { 42 | int numuser; 43 | struct utmp *utmpstruct; 44 | 45 | numuser = 0; 46 | 47 | apr_thread_mutex_lock(mutex); 48 | setutent(); 49 | while ((utmpstruct = getutent())) { 50 | if ((utmpstruct->ut_type == USER_PROCESS) && 51 | (utmpstruct->ut_name[0] != '\0')) 52 | numuser++; 53 | } 54 | endutent(); 55 | apr_thread_mutex_unlock(mutex); 56 | 57 | return numuser; 58 | } 59 | 60 | /* count the number of users */ 61 | static int get_unique ( void ) 62 | { 63 | apr_pool_t *subpool; 64 | apr_hash_t *hashuser; 65 | char *name; 66 | void *user; 67 | unsigned int numunique = 0; 68 | struct utmp *utmpstruct; 69 | 70 | apr_pool_create(&subpool, pool); 71 | hashuser = apr_hash_make(subpool); 72 | apr_thread_mutex_lock(mutex); 73 | setutent(); 74 | while ((utmpstruct = getutent())) { 75 | if ((utmpstruct->ut_type == USER_PROCESS) && 76 | (utmpstruct->ut_name[0] != '\0')) { 77 | name = apr_pstrndup(subpool, utmpstruct->ut_name, UT_NAMESIZE); 78 | user = name; /* use key for value, not interested in it anyway */ 79 | apr_hash_set(hashuser, name, APR_HASH_KEY_STRING, user); 80 | } 81 | } 82 | endutent(); 83 | apr_thread_mutex_unlock(mutex); 84 | numunique = apr_hash_count(hashuser); 85 | apr_pool_destroy(subpool); 86 | 87 | return numunique; 88 | } 89 | 90 | static g_val_t user_metric_handler ( int metric_index ) 91 | { 92 | g_val_t val; 93 | 94 | /* The metric_index corresponds to the order in which 95 | the metrics appear in the metric_info array 96 | */ 97 | switch (metric_index) { 98 | case 0: 99 | val.uint32 = get_users(); 100 | return val; 101 | case 1: 102 | val.uint32 = get_unique(); 103 | return val; 104 | } 105 | 106 | /* default case */ 107 | val.uint32 = 0; 108 | return val; 109 | } 110 | 111 | static Ganglia_25metric user_metric_info[] = 112 | { 113 | {0, "user_total", 950, GANGLIA_VALUE_UNSIGNED_INT, " ", "both", "%u", UDP_HEADER_SIZE+8, "Total number of users logged in"}, 114 | {0, "user_unique", 950, GANGLIA_VALUE_UNSIGNED_INT, " ", "both", "%u", UDP_HEADER_SIZE+8, "Number of unique users logged in"}, 115 | {0, NULL} 116 | 117 | }; 118 | 119 | mmodule user_module = 120 | { 121 | STD_MMODULE_STUFF, 122 | user_metric_init, 123 | user_metric_cleanup, 124 | user_metric_info, 125 | user_metric_handler, 126 | }; 127 | 128 | -------------------------------------------------------------------------------- /example/mod_example.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (C) 2007 Novell, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * - Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * - Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * - Neither the name of Novell, Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Author: Brad Nicholes (bnicholes novell.com) 31 | ******************************************************************************/ 32 | 33 | /* 34 | * The ganglia metric "C" interface, required for building DSO modules. 35 | */ 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | /* 43 | * Declare ourselves so the configuration routines can find and know us. 44 | * We'll fill it in at the end of the module. 45 | */ 46 | extern mmodule example_module; 47 | 48 | static unsigned int random_max = 50; 49 | static unsigned int constant_value = 20; 50 | 51 | static int ex_metric_init ( apr_pool_t *p ) 52 | { 53 | const char* str_params = example_module.module_params; 54 | apr_array_header_t *list_params = example_module.module_params_list; 55 | mmparam *params; 56 | int i; 57 | 58 | srand(time(NULL)%99); 59 | 60 | /* Read the parameters from the gmond.conf file. */ 61 | /* Single raw string parameter */ 62 | if (str_params) { 63 | debug_msg("[mod_example]Received string params: %s", str_params); 64 | } 65 | /* Multiple name/value pair parameters. */ 66 | if (list_params) { 67 | debug_msg("[mod_example]Received following params list: "); 68 | params = (mmparam*) list_params->elts; 69 | for(i=0; i< list_params->nelts; i++) { 70 | debug_msg("\tParam: %s = %s", params[i].name, params[i].value); 71 | if (!strcasecmp(params[i].name, "RandomMax")) { 72 | random_max = atoi(params[i].value); 73 | } 74 | if (!strcasecmp(params[i].name, "ConstantValue")) { 75 | constant_value = atoi(params[i].value); 76 | } 77 | } 78 | } 79 | 80 | /* Initialize the metadata storage for each of the metrics and then 81 | * store one or more key/value pairs. The define MGROUPS defines 82 | * the key for the grouping attribute. */ 83 | MMETRIC_INIT_METADATA(&(example_module.metrics_info[0]),p); 84 | MMETRIC_ADD_METADATA(&(example_module.metrics_info[0]),MGROUP,"random"); 85 | MMETRIC_ADD_METADATA(&(example_module.metrics_info[0]),MGROUP,"example"); 86 | /* 87 | * Usually a metric will be part of one group, but you can add more 88 | * if needed as shown above where Random_Numbers is both in the random 89 | * and example groups. 90 | */ 91 | 92 | MMETRIC_INIT_METADATA(&(example_module.metrics_info[1]),p); 93 | MMETRIC_ADD_METADATA(&(example_module.metrics_info[1]),MGROUP,"example"); 94 | 95 | return 0; 96 | } 97 | 98 | static void ex_metric_cleanup ( void ) 99 | { 100 | } 101 | 102 | static g_val_t ex_metric_handler ( int metric_index ) 103 | { 104 | g_val_t val; 105 | 106 | /* The metric_index corresponds to the order in which 107 | the metrics appear in the metric_info array 108 | */ 109 | switch (metric_index) { 110 | case 0: 111 | val.uint32 = rand()%random_max; 112 | break; 113 | case 1: 114 | val.uint32 = constant_value; 115 | break; 116 | default: 117 | val.uint32 = 0; /* default fallback */ 118 | } 119 | 120 | return val; 121 | } 122 | 123 | static Ganglia_25metric ex_metric_info[] = 124 | { 125 | {0, "Random_Numbers", 90, GANGLIA_VALUE_UNSIGNED_INT, "Num", "both", "%u", UDP_HEADER_SIZE+8, "Example module metric (random numbers)"}, 126 | {0, "Constant_Number", 90, GANGLIA_VALUE_UNSIGNED_INT, "Num", "zero", "%u", UDP_HEADER_SIZE+8, "Example module metric (constant number)"}, 127 | {0, NULL} 128 | }; 129 | 130 | mmodule example_module = 131 | { 132 | STD_MMODULE_STUFF, 133 | ex_metric_init, 134 | ex_metric_cleanup, 135 | ex_metric_info, 136 | ex_metric_handler, 137 | }; 138 | -------------------------------------------------------------------------------- /fs/mod_fs.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | ganglia-modules-linux: modules for collecting metrics on Linux 3 | Copyright (C) 2011 Daniel Pocock 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program. If not, see . 17 | ******************************************************************************/ 18 | 19 | #include 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #ifndef NAN 32 | #define NAN (0.0f/0.0f) /* only includes in C99 */ 33 | #endif 34 | 35 | /* 36 | * Declare ourselves so the configuration routines can find and know us. 37 | * We'll fill it in at the end of the module. 38 | */ 39 | mmodule fs_module; 40 | 41 | 42 | 43 | 44 | /* 45 | * /proc/mounts = device_node mountpoint fs opts dump passno (same as /etc/fstab) 46 | * - we use this to get a list of filesystems 47 | * 48 | * statvfs() 49 | * - we use this function to get the statistics for an FS 50 | * 51 | */ 52 | 53 | 54 | typedef struct fs_info { 55 | char *device; 56 | char *mount_point; 57 | char *fs_type; 58 | char *ganglia_name; 59 | } fs_info_t; 60 | 61 | 62 | /* Linux Specific, but we are in the Linux machine file. */ 63 | #define MOUNTS "/proc/mounts" 64 | 65 | 66 | 67 | /* --------------------------------------------------------------------------- */ 68 | int remote_mount(const char *device, const char *type) 69 | { 70 | /* From ME_REMOTE macro in mountlist.h: 71 | A file system is `remote' if its Fs_name contains a `:' 72 | or if (it is of type smbfs and its Fs_name starts with `//'). */ 73 | return ((strchr(device,':') != 0) 74 | || (!strcmp(type, "smbfs") && device[0]=='/' && device[1]=='/') 75 | || (!strncmp(type, "nfs", 3)) || (!strcmp(type, "autofs")) 76 | || (!strcmp(type,"gfs")) || (!strcmp(type,"none")) ); 77 | } 78 | 79 | typedef g_val_t (*fs_func_t)(fs_info_t *fs); 80 | 81 | static g_val_t fs_capacity_bytes_func (fs_info_t *fs) 82 | { 83 | g_val_t val; 84 | 85 | struct statvfs svfs; 86 | unsigned long blocksize; 87 | 88 | fsblkcnt_t size; 89 | 90 | val.f = (float) NAN; 91 | 92 | if (statvfs(fs->mount_point, &svfs)) { 93 | /* Ignore funky devices... */ 94 | return val; 95 | } 96 | 97 | 98 | size = svfs.f_blocks; 99 | blocksize = svfs.f_frsize; 100 | 101 | val.f = (float) size * blocksize; 102 | return val; 103 | 104 | } 105 | 106 | 107 | static g_val_t fs_used_bytes_func (fs_info_t *fs) 108 | { 109 | g_val_t val; 110 | 111 | struct statvfs svfs; 112 | unsigned long blocksize; 113 | fsblkcnt_t free; 114 | fsblkcnt_t size; 115 | fsblkcnt_t used; 116 | 117 | val.f = (float) NAN; 118 | 119 | if (statvfs(fs->mount_point, &svfs)) { 120 | /* Ignore funky devices... */ 121 | return val; 122 | } 123 | 124 | 125 | size = svfs.f_blocks; 126 | free = svfs.f_bavail; 127 | used = size - free; 128 | blocksize = svfs.f_frsize; 129 | 130 | val.f = (float) used * blocksize; 131 | return val; 132 | 133 | } 134 | 135 | static g_val_t fs_free_func (fs_info_t *fs) 136 | { 137 | g_val_t val; 138 | 139 | struct statvfs svfs; 140 | fsblkcnt_t blocks_free; 141 | fsblkcnt_t total_blocks; 142 | 143 | val.f = (float) NAN; 144 | 145 | if (statvfs(fs->mount_point, &svfs)) { 146 | /* Ignore funky devices... */ 147 | err_msg("statvfs failed for %s: %s", fs->mount_point, strerror(errno)); 148 | return val; 149 | } 150 | 151 | total_blocks = svfs.f_blocks; 152 | blocks_free = svfs.f_bavail; 153 | 154 | val.f = (float)100.0 * blocks_free / total_blocks; 155 | return val; 156 | 157 | } 158 | 159 | typedef struct metric_spec { 160 | fs_func_t fs_func; 161 | const char *name; 162 | const char *units; 163 | const char *desc; 164 | const char *fmt; 165 | } metric_spec_t; 166 | 167 | 168 | #define NUM_FS_METRICS 3 169 | metric_spec_t metrics[] = { 170 | 171 | { fs_capacity_bytes_func, "capacity_bytes", "bytes", "capacity in bytes", "%.0f" }, 172 | { fs_used_bytes_func, "used_bytes", "bytes", "space used in bytes", "%.0f" }, 173 | { fs_free_func, "free_pct", "%", "percentage space free", "%.0f" }, 174 | 175 | { NULL, NULL, NULL, NULL, NULL } 176 | }; 177 | 178 | 179 | void create_metrics_for_device(apr_pool_t *p, apr_array_header_t *ar, fs_info_t *fs) { 180 | metric_spec_t *metric; 181 | Ganglia_25metric *gmi; 182 | char *metric_name; 183 | 184 | for (metric = metrics; metric->fs_func != NULL; metric++) { 185 | gmi = apr_array_push(ar); 186 | 187 | /* gmi->key will be automatically assigned by gmond */ 188 | metric_name = apr_psprintf(p, "fs_%s_%s", metric->name, 189 | fs->ganglia_name); 190 | debug_msg("fs: creating metric %s", metric_name); 191 | gmi->name = metric_name; 192 | gmi->tmax = 90; 193 | gmi->type = GANGLIA_VALUE_FLOAT; 194 | gmi->units = apr_pstrdup(p, metric->units); 195 | gmi->slope = apr_pstrdup(p, "both"); 196 | gmi->fmt = apr_pstrdup(p, metric->fmt); 197 | gmi->msg_size = UDP_HEADER_SIZE + 8; 198 | gmi->desc = apr_pstrdup(p, metric->desc); 199 | } 200 | } 201 | 202 | void set_ganglia_name(apr_pool_t *p, fs_info_t *fs) { 203 | int i, j=0; 204 | 205 | if(strcmp(fs->mount_point, "/") == 0) { 206 | fs->ganglia_name = apr_pstrdup(p, "root"); 207 | return; 208 | } 209 | fs->ganglia_name = apr_pstrdup(p, fs->mount_point); 210 | for (i = 0; fs->mount_point[i] != 0; i++) { 211 | if(fs->mount_point[i] == '/') { 212 | if(i > 0) 213 | fs->ganglia_name[j++] = '_'; 214 | } else { 215 | fs->ganglia_name[j++] = fs->mount_point[i]; 216 | } 217 | } 218 | fs->ganglia_name[j] = 0; 219 | } 220 | 221 | apr_array_header_t *filesystems = NULL; 222 | apr_array_header_t *metric_info = NULL; 223 | 224 | int scan_mounts(apr_pool_t *p) { 225 | FILE *mounts; 226 | char procline[256]; 227 | char mount[128], device[128], type[32], mode[128]; 228 | int rc; 229 | fs_info_t *fs; 230 | 231 | filesystems = apr_array_make(p, 2, sizeof(fs_info_t)); 232 | metric_info = apr_array_make(p, 2, sizeof(Ganglia_25metric)); 233 | 234 | mounts = fopen(MOUNTS, "r"); 235 | if (!mounts) { 236 | debug_msg("Df Error: could not open mounts file %s. Are we on the right OS?\n", MOUNTS); 237 | return -1; 238 | } 239 | while ( fgets(procline, sizeof(procline), mounts) ) { 240 | rc=sscanf(procline, "%s %s %s %s ", device, mount, type, mode); 241 | if (!rc) continue; 242 | //if (!strncmp(mode, "ro", 2)) continue; 243 | if (remote_mount(device, type)) continue; 244 | if (strncmp(device, "/dev/", 5) != 0 && 245 | strncmp(device, "/dev2/", 6) != 0) continue; 246 | 247 | fs = apr_array_push(filesystems); 248 | bzero(fs, sizeof(fs_info_t)); 249 | 250 | fs->device = apr_pstrdup(p, device); 251 | fs->mount_point = apr_pstrdup(p, mount); 252 | fs->fs_type = apr_pstrdup(p, type); 253 | set_ganglia_name(p, fs); 254 | 255 | create_metrics_for_device(p, metric_info, fs); 256 | 257 | //thispct = device_space(mount, device, total_size, total_free); 258 | debug_msg("Found device %s (%s)", device, type); 259 | 260 | } 261 | fclose(mounts); 262 | 263 | return 0; 264 | } 265 | 266 | apr_pool_t *pool = NULL; 267 | 268 | static int ex_metric_init (apr_pool_t *p) 269 | { 270 | int i; 271 | Ganglia_25metric *gmi; 272 | 273 | /* Allocate a pool that will be used by this module */ 274 | apr_pool_create(&pool, p); 275 | 276 | /* Initialize each metric */ 277 | scan_mounts(pool); 278 | 279 | /* Add a terminator to the array and replace the empty static metric definition 280 | array with the dynamic array that we just created 281 | */ 282 | gmi = apr_array_push(metric_info); 283 | memset (gmi, 0, sizeof(*gmi)); 284 | 285 | fs_module.metrics_info = (Ganglia_25metric *)metric_info->elts; 286 | 287 | for (i = 0; fs_module.metrics_info[i].name != NULL; i++) { 288 | /* Initialize the metadata storage for each of the metrics and then 289 | * store one or more key/value pairs. The define MGROUPS defines 290 | * the key for the grouping attribute. */ 291 | MMETRIC_INIT_METADATA(&(fs_module.metrics_info[i]),p); 292 | MMETRIC_ADD_METADATA(&(fs_module.metrics_info[i]),MGROUP,"disk"); 293 | } 294 | 295 | return 0; 296 | } 297 | 298 | static void ex_metric_cleanup ( void ) 299 | { 300 | } 301 | 302 | static g_val_t ex_metric_handler(int metric_index) { 303 | g_val_t val; 304 | int fs_index; 305 | int _metric_index; 306 | fs_info_t *all_fs = (fs_info_t *)filesystems->elts, *fs; 307 | 308 | fs_index = metric_index / NUM_FS_METRICS; 309 | _metric_index = metric_index % NUM_FS_METRICS; 310 | 311 | fs = &all_fs[fs_index]; 312 | 313 | debug_msg("fs: handling read for metric %d fs %d idx %d (%s)", 314 | metric_index, fs_index, _metric_index, fs->mount_point); 315 | val = metrics[_metric_index].fs_func(fs); 316 | 317 | return val; 318 | } 319 | 320 | mmodule fs_module = 321 | { 322 | STD_MMODULE_STUFF, 323 | ex_metric_init, 324 | ex_metric_cleanup, 325 | NULL, /* defined dynamically */ 326 | ex_metric_handler, 327 | }; 328 | -------------------------------------------------------------------------------- /multicpu/mod_multicpu.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Portions Copyright (C) 2007 Novell, Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * 7 | * - Redistributions of source code must retain the above copyright notice, 8 | * this list of conditions and the following disclaimer. 9 | * 10 | * - Redistributions in binary form must reproduce the above copyright notice, 11 | * this list of conditions and the following disclaimer in the documentation 12 | * and/or other materials provided with the distribution. 13 | * 14 | * - Neither the name of Novell, Inc. nor the names of its 15 | * contributors may be used to endorse or promote products derived from this 16 | * software without specific prior written permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 | * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS 22 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 | * POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Author: Brad Nicholes (bnicholes novell.com) 31 | ******************************************************************************/ 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "gm_file.h" 41 | 42 | #include 43 | #include 44 | 45 | /* 46 | * Declare ourselves so the configuration routines can find and know us. 47 | * We'll fill it in at the end of the module. 48 | */ 49 | mmodule multicpu_module; 50 | 51 | #define MCPU_BUFFSIZE 16384 52 | 53 | static timely_file proc_stat = { {0,0} , 1., "/proc/stat", NULL, MCPU_BUFFSIZE }; 54 | 55 | struct cpu_util { 56 | g_val_t val; 57 | struct timeval stamp; 58 | double last_jiffies; 59 | double curr_jiffies; 60 | double last_total_jiffies; 61 | double curr_total_jiffies; 62 | double diff; 63 | }; 64 | typedef struct cpu_util cpu_util; 65 | 66 | 67 | #define NUM_CPUSTATES_24X 4 68 | #define NUM_CPUSTATES_26X 7 69 | static unsigned int num_cpustates; 70 | static unsigned int cpu_count = 0; 71 | static apr_pool_t *pool; 72 | static cpu_util *cpu_user = NULL; 73 | static cpu_util *cpu_nice = NULL; 74 | static cpu_util *cpu_system = NULL; 75 | static cpu_util *cpu_idle = NULL; 76 | static cpu_util *cpu_wio = NULL; 77 | static cpu_util *cpu_intr = NULL; 78 | static cpu_util *cpu_sintr = NULL; 79 | 80 | float timediff(const struct timeval *thistime, const struct timeval *lasttime) 81 | { 82 | float diff; 83 | 84 | diff = ((double) thistime->tv_sec * 1.0e6 + 85 | (double) thistime->tv_usec - 86 | (double) lasttime->tv_sec * 1.0e6 - 87 | (double) lasttime->tv_usec) / 1.0e6; 88 | 89 | return diff; 90 | } 91 | 92 | /* 93 | * A helper function to determine the number of cpustates in /proc/stat (MKN) 94 | * Count how many cpus there are in the system 95 | */ 96 | static void init_cpu_info (void) 97 | { 98 | char *p; 99 | unsigned int i=0; 100 | 101 | proc_stat.last_read.tv_sec=0; 102 | proc_stat.last_read.tv_usec=0; 103 | p = update_file(&proc_stat); 104 | proc_stat.last_read.tv_sec=0; 105 | proc_stat.last_read.tv_usec=0; 106 | 107 | /* 108 | ** Skip initial "cpu" token 109 | */ 110 | p = skip_token(p); 111 | p = skip_whitespace(p); 112 | 113 | /* 114 | ** Loop over file until next "cpu" token is found. 115 | ** i=4 : Linux 2.4.x 116 | ** i=7 : Linux 2.6.x 117 | */ 118 | while (strncmp(p,"cpu",3)) { 119 | p = skip_token(p); 120 | p = skip_whitespace(p); 121 | i++; 122 | } 123 | num_cpustates = i; 124 | 125 | for (i=1; strlen(p) > 0;) { 126 | p = skip_token(p); 127 | p = skip_whitespace(p); 128 | if (strncmp(p,"cpu",3) == 0) { 129 | i++; 130 | } 131 | } 132 | cpu_count = i; 133 | 134 | return; 135 | } 136 | 137 | 138 | static double total_jiffies_func (char *p); 139 | 140 | /* 141 | * Find the correct cpu info with the buffer, 142 | * given a cpu index 143 | */ 144 | static char *find_cpu (char *p, int cpu_index, double *total_jiffies) 145 | { 146 | int i; 147 | 148 | /* 149 | ** Skip initial "cpu" token 150 | */ 151 | p = skip_token(p); 152 | p = skip_whitespace(p); 153 | 154 | for (i=0; i<=cpu_index; i++) { 155 | while (strlen(p) > 0) { 156 | p = skip_token(p); 157 | p = skip_whitespace(p); 158 | if (strncmp(p,"cpu",3) == 0) { 159 | break; 160 | } 161 | } 162 | } 163 | 164 | /* 165 | ** Skip last "cpu" token 166 | */ 167 | p = skip_token(p); 168 | p = skip_whitespace(p); 169 | 170 | *total_jiffies = total_jiffies_func(p); 171 | 172 | return p; 173 | } 174 | 175 | /* 176 | * A helper function to return the total number of cpu jiffies 177 | * Assumes that "p" has been aligned already to the CPU line to evaluate 178 | */ 179 | static double total_jiffies_func (char *p) 180 | { 181 | unsigned long user_jiffies, nice_jiffies, system_jiffies, idle_jiffies, 182 | wio_jiffies, irq_jiffies, sirq_jiffies; 183 | 184 | user_jiffies = strtod( p, &p ); 185 | p = skip_whitespace(p); 186 | nice_jiffies = strtod( p, &p ); 187 | p = skip_whitespace(p); 188 | system_jiffies = strtod( p , &p ); 189 | p = skip_whitespace(p); 190 | idle_jiffies = strtod( p , &p ); 191 | 192 | if (num_cpustates == NUM_CPUSTATES_24X) 193 | return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies; 194 | 195 | p = skip_whitespace(p); 196 | wio_jiffies = strtod( p , &p ); 197 | p = skip_whitespace(p); 198 | irq_jiffies = strtod( p , &p ); 199 | p = skip_whitespace(p); 200 | sirq_jiffies = strtod( p , &p ); 201 | 202 | return user_jiffies + nice_jiffies + system_jiffies + idle_jiffies + 203 | wio_jiffies + irq_jiffies + sirq_jiffies; 204 | } 205 | 206 | /* Common function to calculate the utilization */ 207 | static void calculate_utilization (char *p, cpu_util *cpu) 208 | { 209 | cpu->curr_jiffies = strtod(p, (char **)NULL); 210 | 211 | cpu->diff = (cpu->curr_jiffies - cpu->last_jiffies); 212 | 213 | if (cpu->diff) 214 | cpu->val.f = (cpu->diff/(cpu->curr_total_jiffies - cpu->last_total_jiffies))*100; 215 | else 216 | cpu->val.f = 0.0; 217 | 218 | cpu->last_jiffies = cpu->curr_jiffies; 219 | cpu->last_total_jiffies = cpu->curr_total_jiffies; 220 | 221 | return; 222 | } 223 | 224 | /* typedef g_val_t (*mcpu_func_t)(cpu_data_t *cpu); */ 225 | typedef g_val_t (*mcpu_func_t)(int cpu_index); 226 | 227 | static g_val_t multi_cpu_user_func (int cpu_index) 228 | { 229 | char *p; 230 | cpu_util *cpu = &(cpu_user[cpu_index]); 231 | 232 | p = update_file(&proc_stat); 233 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 234 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 235 | cpu->stamp = proc_stat.last_read; 236 | 237 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 238 | calculate_utilization (p, cpu); 239 | } 240 | 241 | return cpu->val; 242 | } 243 | 244 | static g_val_t multi_cpu_nice_func (int cpu_index) 245 | { 246 | char *p; 247 | cpu_util *cpu = &(cpu_nice[cpu_index]); 248 | 249 | p = update_file(&proc_stat); 250 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 251 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 252 | cpu->stamp = proc_stat.last_read; 253 | 254 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 255 | p = skip_token(p); 256 | p = skip_whitespace(p); 257 | 258 | calculate_utilization (p, cpu); 259 | } 260 | 261 | return cpu->val; 262 | } 263 | 264 | static g_val_t multi_cpu_system_func (int cpu_index) 265 | { 266 | char *p; 267 | cpu_util *cpu = &(cpu_system[cpu_index]); 268 | 269 | p = update_file(&proc_stat); 270 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 271 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 272 | cpu->stamp = proc_stat.last_read; 273 | 274 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 275 | p = skip_token(p); 276 | p = skip_token(p); 277 | p = skip_whitespace(p); 278 | cpu->curr_jiffies = strtod(p , (char **)NULL); 279 | if (num_cpustates > NUM_CPUSTATES_24X) { 280 | p = skip_token(p); 281 | p = skip_token(p); 282 | p = skip_token(p); 283 | p = skip_whitespace(p); 284 | 285 | cpu->curr_jiffies += strtod(p , (char **)NULL); /* "intr" counted in system */ 286 | p = skip_token(p); 287 | cpu->curr_jiffies += strtod(p , (char **)NULL); /* "sintr" counted in system */ 288 | } 289 | 290 | cpu->diff = cpu->curr_jiffies - cpu->last_jiffies; 291 | 292 | if (cpu->diff) 293 | cpu->val.f = (cpu->diff/(cpu->curr_total_jiffies - cpu->last_total_jiffies))*100; 294 | else 295 | cpu->val.f = 0.0; 296 | 297 | cpu->last_jiffies = cpu->curr_jiffies; 298 | cpu->last_total_jiffies = cpu->curr_total_jiffies; 299 | } 300 | 301 | return cpu->val; 302 | } 303 | 304 | static g_val_t multi_cpu_idle_func (int cpu_index) 305 | { 306 | char *p; 307 | cpu_util *cpu = &(cpu_idle[cpu_index]); 308 | 309 | p = update_file(&proc_stat); 310 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 311 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 312 | cpu->stamp = proc_stat.last_read; 313 | 314 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 315 | p = skip_token(p); 316 | p = skip_token(p); 317 | p = skip_token(p); 318 | p = skip_whitespace(p); 319 | 320 | calculate_utilization (p, cpu); 321 | } 322 | 323 | return cpu->val; 324 | } 325 | 326 | static g_val_t multi_cpu_wio_func (int cpu_index) 327 | { 328 | char *p; 329 | cpu_util *cpu = &(cpu_wio[cpu_index]); 330 | 331 | if (num_cpustates == NUM_CPUSTATES_24X) { 332 | cpu->val.f = 0.; 333 | return cpu->val; 334 | } 335 | 336 | p = update_file(&proc_stat); 337 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 338 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 339 | cpu->stamp = proc_stat.last_read; 340 | 341 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 342 | p = skip_token(p); 343 | p = skip_token(p); 344 | p = skip_token(p); 345 | p = skip_token(p); 346 | p = skip_whitespace(p); 347 | 348 | calculate_utilization (p, cpu); 349 | } 350 | 351 | return cpu->val; 352 | } 353 | 354 | static g_val_t multi_cpu_intr_func (int cpu_index) 355 | { 356 | char *p; 357 | cpu_util *cpu = &(cpu_intr[cpu_index]); 358 | 359 | if (num_cpustates == NUM_CPUSTATES_24X) { 360 | cpu->val.f = 0.; 361 | return cpu->val; 362 | } 363 | 364 | p = update_file(&proc_stat); 365 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 366 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 367 | cpu->stamp = proc_stat.last_read; 368 | 369 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 370 | p = skip_token(p); 371 | p = skip_token(p); 372 | p = skip_token(p); 373 | p = skip_token(p); 374 | p = skip_token(p); 375 | p = skip_whitespace(p); 376 | 377 | calculate_utilization (p, cpu); 378 | } 379 | 380 | return cpu->val; 381 | } 382 | 383 | static g_val_t multi_cpu_sintr_func (int cpu_index) 384 | { 385 | char *p; 386 | cpu_util *cpu = &(cpu_sintr[cpu_index]); 387 | 388 | if (num_cpustates == NUM_CPUSTATES_24X) { 389 | cpu->val.f = 0.; 390 | return cpu->val; 391 | } 392 | 393 | p = update_file(&proc_stat); 394 | if((proc_stat.last_read.tv_sec != cpu->stamp.tv_sec) && 395 | (proc_stat.last_read.tv_usec != cpu->stamp.tv_usec)) { 396 | cpu->stamp = proc_stat.last_read; 397 | 398 | p = find_cpu (p, cpu_index, &cpu->curr_total_jiffies); 399 | p = skip_token(p); 400 | p = skip_token(p); 401 | p = skip_token(p); 402 | p = skip_token(p); 403 | p = skip_token(p); 404 | p = skip_token(p); 405 | p = skip_whitespace(p); 406 | 407 | calculate_utilization (p, cpu); 408 | } 409 | 410 | return cpu->val; 411 | } 412 | 413 | static apr_array_header_t *metric_info = NULL; 414 | 415 | 416 | typedef struct metric_spec { 417 | mcpu_func_t func; 418 | const char *name; 419 | const char *units; 420 | const char *desc; 421 | const char *fmt; 422 | cpu_util **cpu; 423 | } metric_spec_t; 424 | 425 | #define NUM_CPU_METRICS 7 426 | metric_spec_t my_metrics[] = { 427 | { multi_cpu_user_func, "multicpu_user", "%", 428 | "Percentage of CPU utilization that occurred while " 429 | "executing at the user level", "%.1f", &cpu_user }, 430 | { multi_cpu_nice_func, "multicpu_nice", "%", 431 | "Percentage of CPU utilization that occurred while " 432 | "executing at the nice level", "%.1f", &cpu_nice }, 433 | { multi_cpu_system_func, "multicpu_system", "%", 434 | "Percentage of CPU utilization that occurred while " 435 | "executing at the system level", "%.1f", &cpu_system }, 436 | { multi_cpu_idle_func, "multicpu_idle", "%", 437 | "Percentage of CPU utilization that occurred while " 438 | "executing at the idle level", "%.1f", &cpu_idle }, 439 | { multi_cpu_wio_func, "multicpu_wio", "%", 440 | "Percentage of CPU utilization that occurred while " 441 | "executing at the wio level", "%.1f", &cpu_wio }, 442 | { multi_cpu_intr_func, "multicpu_intr", "%", 443 | "Percentage of CPU utilization that occurred while " 444 | "executing at the intr level", "%.1f", &cpu_intr }, 445 | { multi_cpu_sintr_func, "multicpu_sintr", "%", 446 | "Percentage of CPU utilization that occurred while " 447 | "executing at the sintr level", "%.1f", &cpu_sintr }, 448 | { NULL, NULL, NULL, NULL, NULL, NULL} }; 449 | 450 | 451 | void init_metrics_for_cpu(apr_pool_t *p, apr_array_header_t *ar, int cpu_num) { 452 | metric_spec_t *metric; 453 | Ganglia_25metric *gmi; 454 | 455 | debug_msg("multicpu: init for cpu instance %d", cpu_num); 456 | for (metric = my_metrics; metric->func != NULL; metric++) { 457 | gmi = apr_array_push(ar); 458 | 459 | /* gmi->key will be automatically assigned by gmond */ 460 | gmi->name = apr_psprintf(p, "%s%d", metric->name, cpu_num); 461 | gmi->tmax = 90; 462 | gmi->type = GANGLIA_VALUE_FLOAT; 463 | gmi->units = apr_pstrdup(p, metric->units); 464 | gmi->slope = apr_pstrdup(p, "both"); 465 | gmi->fmt = apr_pstrdup(p, metric->fmt); 466 | gmi->msg_size = UDP_HEADER_SIZE + 8; 467 | gmi->desc = apr_pstrdup(p, metric->desc); 468 | } 469 | } 470 | 471 | 472 | static int ex_metric_init (apr_pool_t *p) 473 | { 474 | int i; 475 | Ganglia_25metric *gmi; 476 | 477 | init_cpu_info (); 478 | 479 | /* Allocate a pool that will be used by this module */ 480 | apr_pool_create(&pool, p); 481 | 482 | metric_info = apr_array_make(pool, 2, sizeof(Ganglia_25metric)); 483 | 484 | /* Initialize each metric */ 485 | for(i = 0; i < cpu_count; i++) { 486 | init_metrics_for_cpu(p, metric_info, i); 487 | } 488 | 489 | for(i = 0; i < NUM_CPU_METRICS; i++) { 490 | *(my_metrics[i].cpu) = apr_pcalloc (p, sizeof(cpu_util)*cpu_count); 491 | } 492 | 493 | /* Add a terminator to the array and replace the empty static metric definition 494 | array with the dynamic array that we just created 495 | */ 496 | gmi = apr_array_push(metric_info); 497 | memset (gmi, 0, sizeof(*gmi)); 498 | 499 | multicpu_module.metrics_info = (Ganglia_25metric *)metric_info->elts; 500 | 501 | for (i = 0; multicpu_module.metrics_info[i].name != NULL; i++) { 502 | /* Initialize the metadata storage for each of the metrics and then 503 | * store one or more key/value pairs. The define MGROUPS defines 504 | * the key for the grouping attribute. */ 505 | MMETRIC_INIT_METADATA(&(multicpu_module.metrics_info[i]),p); 506 | MMETRIC_ADD_METADATA(&(multicpu_module.metrics_info[i]),MGROUP,"cpu"); 507 | } 508 | 509 | return 0; 510 | } 511 | 512 | static void ex_metric_cleanup ( void ) 513 | { 514 | } 515 | 516 | static g_val_t ex_metric_handler(int metric_index) { 517 | g_val_t val; 518 | int cpu_index; 519 | int _metric_index; 520 | 521 | cpu_index = metric_index / NUM_CPU_METRICS; 522 | _metric_index = metric_index % NUM_CPU_METRICS; 523 | 524 | debug_msg("multicpu: handling read for metric %d CPU %d idx %d", 525 | metric_index, cpu_index, _metric_index); 526 | val = my_metrics[_metric_index].func(cpu_index); 527 | 528 | return val; 529 | } 530 | 531 | mmodule multicpu_module = 532 | { 533 | STD_MMODULE_STUFF, 534 | ex_metric_init, 535 | ex_metric_cleanup, 536 | NULL, /* defined dynamically */ 537 | ex_metric_handler, 538 | }; 539 | -------------------------------------------------------------------------------- /io/mod_io.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Ported the disk IO metric work I had done on 3.0.x to 3.1.x. 3 | * The code I originally had in libmetric/linux/metric.c was stripped and 4 | * placed in its own module. 5 | * 6 | * Author: JB Kim (jbremnant gmail.com) 7 | ******************************************************************************/ 8 | 9 | /* 10 | * The ganglia metric "C" interface, required for building DSO modules. 11 | */ 12 | #include 13 | /* #include */ 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | #include "gm_file.h" 22 | 23 | /* Iostat related info from jbkim 24 | * The contents of /proc/partitions is different from kernel 2.4 to 2.6. 25 | * Also new to 2.6 kernel is /proc/diskstats. The field descriptions can be found here: 26 | * http://devresources.linux-foundation.org/dev/robustmutexes/src/fusyn.hg/Documentation/iostats.txt 27 | * The io metrics are aggreagted for all the disks on the host. 28 | * The partition specific info is best supplied via gmetric. 29 | */ 30 | #ifndef IDE_DISK_MAJOR 31 | #define IDE_DISK_MAJOR(M) ((M) == IDE0_MAJOR || (M) == IDE1_MAJOR || \ 32 | (M) == IDE2_MAJOR || (M) == IDE3_MAJOR || \ 33 | (M) == IDE4_MAJOR || (M) == IDE5_MAJOR || \ 34 | (M) == IDE6_MAJOR || (M) == IDE7_MAJOR || \ 35 | (M) == IDE8_MAJOR || (M) == IDE9_MAJOR) 36 | #endif /* !IDE_DISK_MAJOR */ 37 | 38 | #ifndef SCSI_DISK_MAJOR 39 | #ifndef SCSI_DISK8_MAJOR 40 | #define SCSI_DISK8_MAJOR 128 41 | #endif 42 | #ifndef SCSI_DISK15_MAJOR 43 | #define SCSI_DISK15_MAJOR 135 44 | #endif 45 | #define SCSI_DISK_MAJOR(M) ((M) == SCSI_DISK0_MAJOR || \ 46 | ((M) >= SCSI_DISK1_MAJOR && \ 47 | (M) <= SCSI_DISK7_MAJOR) || \ 48 | ((M) >= SCSI_DISK8_MAJOR && \ 49 | (M) <= SCSI_DISK15_MAJOR)) 50 | #endif /* !SCSI_DISK_MAJOR */ 51 | 52 | 53 | /* Since vd? and xvd devices are dynamically assigned, we have to get 54 | the major/minor information out of /proc/devices */ 55 | 56 | #ifndef VD_DISK_MAJOR 57 | unsigned int VD_DISK_MAJOR = 0; 58 | #endif /* !VD_DISK_MAJOR */ 59 | 60 | #ifndef XVD_DISK_MAJOR 61 | unsigned int XVD_DISK_MAJOR = 0; 62 | #endif /* !XDA_DISK_MAJOR */ 63 | 64 | #define MAX_PARTITIONS 64 65 | #define PER_SEC(x) (1000.0 * (x) / deltams) 66 | 67 | /* Kernel: 2.4 uses /proc/partitions and 2.6 uses /proc/diskstats) */ 68 | unsigned int kernel_type; 69 | unsigned int n_partitions; 70 | unsigned int print_device = 1; 71 | unsigned int print_partition = 0; // don't print the partitions 72 | 73 | struct part_info { 74 | unsigned int major; /* Device major number */ 75 | unsigned int minor; /* Device minor number */ 76 | char name[64]; 77 | } partition[MAX_PARTITIONS]; 78 | 79 | struct blkio_info { 80 | unsigned int rd_ios; /* Read I/O operations */ 81 | unsigned int rd_merges; /* Reads merged */ 82 | unsigned long long rd_sectors; /* Sectors read */ 83 | unsigned int rd_ticks; /* Time in queue + service for read */ 84 | unsigned int wr_ios; /* Write I/O operations */ 85 | unsigned int wr_merges; /* Writes merged */ 86 | unsigned long long wr_sectors; /* Sectors written */ 87 | unsigned int wr_ticks; /* Time in queue + service for write */ 88 | unsigned int ticks; /* Time of requests in queue */ 89 | unsigned int aveq; /* Average queue length */ 90 | } new_blkio[MAX_PARTITIONS], old_blkio[MAX_PARTITIONS]; 91 | 92 | struct cpu_info { 93 | unsigned long long user; 94 | unsigned long long system; 95 | unsigned long long idle; 96 | unsigned long long iowait; 97 | } new_cpu, old_cpu; 98 | 99 | void init_partition_info(char **wanted_partitions, int wanted_partitions_n); 100 | void print_io_info(void); 101 | 102 | #define IO_BUFFSIZE 65535 103 | 104 | timely_file proc_stat = { {0,0} , 1., "/proc/stat", NULL, IO_BUFFSIZE }; 105 | timely_file proc_partitions = { {0,0} , 1., "/proc/partitions", NULL, IO_BUFFSIZE }; 106 | timely_file proc_diskstats = { {0,0} , 1., "/proc/diskstats", NULL, IO_BUFFSIZE }; 107 | timely_file proc_devices = { {0,0} , 1., "/proc/devices", NULL, IO_BUFFSIZE }; 108 | 109 | 110 | 111 | float timediff(const struct timeval *thistime, const struct timeval *lasttime) 112 | { 113 | float diff; 114 | 115 | diff = ((double) thistime->tv_sec * 1.0e6 + 116 | (double) thistime->tv_usec - 117 | (double) lasttime->tv_sec * 1.0e6 - 118 | (double) lasttime->tv_usec) / 1.0e6; 119 | 120 | return diff; 121 | } 122 | 123 | /* 124 | ** A helper function to determine the number of cpustates in /proc/stat (MKN) 125 | */ 126 | #define NUM_CPUSTATES_24X 4 127 | #define NUM_CPUSTATES_26X 7 128 | static unsigned int num_cpustates; 129 | 130 | unsigned int 131 | num_cpustates_func ( void ) 132 | { 133 | char *p; 134 | unsigned int i=0; 135 | 136 | proc_stat.last_read.tv_sec=0; 137 | proc_stat.last_read.tv_usec=0; 138 | p = update_file(&proc_stat); 139 | proc_stat.last_read.tv_sec=0; 140 | proc_stat.last_read.tv_usec=0; 141 | 142 | /* 143 | ** Skip initial "cpu" token 144 | */ 145 | p = skip_token(p); 146 | p = skip_whitespace(p); 147 | /* 148 | ** Loop over file until next "cpu" token is found. 149 | ** i=4 : Linux 2.4.x 150 | ** i=7 : Linux 2.6.x 151 | */ 152 | while (strncmp(p,"cpu",3)) { 153 | p = skip_token(p); 154 | p = skip_whitespace(p); 155 | i++; 156 | } 157 | 158 | return i; 159 | } 160 | 161 | 162 | unsigned int get_device_major(char *dev) { 163 | unsigned int major = 0; 164 | char device[128]; 165 | char major_str[8]; 166 | char * text = NULL; 167 | 168 | text = update_file(&proc_devices); 169 | 170 | debug_msg("getting device major for %s", dev); 171 | 172 | /* loop over text, searching for pairs of non-witespace */ 173 | while ( text != NULL) { 174 | 175 | int scan_code = sscanf(text, "%s %s", major_str, device); 176 | if (2 == scan_code) { 177 | text = index(text, '\n'); 178 | /* printf(">>> %s %s\n", major_str, device); */ 179 | if (NULL != text) { 180 | text++; 181 | } 182 | } else if (EOF == scan_code) { 183 | /* end of file before finished parsing, bail out */ 184 | break; 185 | } 186 | 187 | /* does it match? */ 188 | if (!strncmp(device, dev, 16)) { 189 | /* debug_msg("found %s", dev); */ 190 | major = strtoul(major_str, NULL, 10); 191 | break; 192 | } 193 | 194 | /* very last (nul) byte of text, bail out */ 195 | if (text == NULL) 196 | break ; 197 | } 198 | 199 | return major; 200 | } 201 | 202 | 203 | int valid_disk(int major) { 204 | debug_msg("major=%d", major); 205 | if ((IDE_DISK_MAJOR(major)) || 206 | (SCSI_DISK_MAJOR(major)) || 207 | (major == VD_DISK_MAJOR) || 208 | (major == XVD_DISK_MAJOR)) { 209 | return 1; 210 | } 211 | return 0; 212 | } 213 | 214 | 215 | 216 | /* 217 | * From here starts the subroutines that implement disk io metric 218 | * functions for ganglia linux libmetric. I borrowed bulk of the logic 219 | * from iostat v2.2. (not part of the sysstat pkg), 220 | * 221 | * The source code was modified to fit the ganglia libmetric framework. 222 | * Note also that the IO metrics are aggregated (sum or max) over the 223 | * physical disks. This is _not_ the default behavior of iostat v2.2 pkg. 224 | * If you need granular, disk-by-disk or partition-by-partition io stats, 225 | * you should stay with using gmetric. 226 | * 227 | * - jbkim - 228 | */ 229 | 230 | /* nifty wrapper to return buffer for either diskstats or partitions 231 | * depending on the kernel version 232 | */ 233 | char * update_file_iostat(unsigned int kernel_type) 234 | { 235 | if(kernel_type == 4) 236 | return update_file(&proc_partitions); 237 | else 238 | return update_file(&proc_diskstats); 239 | } 240 | 241 | /* to filter out the physical disks from the entire list */ 242 | int printable(unsigned int major, unsigned int minor) 243 | { 244 | if (IDE_DISK_MAJOR(major)) { 245 | return (!(minor & 0x3F) && print_device) || 246 | ((minor & 0x3F) && print_partition); 247 | } else if (SCSI_DISK_MAJOR(major)) { 248 | return (!(minor & 0x0F) && print_device) || 249 | ((minor & 0x0F) && print_partition); 250 | } else if (major == VD_DISK_MAJOR) { 251 | return print_device; 252 | } else if (major == XVD_DISK_MAJOR) { 253 | return print_device; 254 | } else { 255 | return 1; /* if uncertain, print it */ 256 | } 257 | } 258 | 259 | 260 | /* registers disks (can also work with partitions, but we don't use it here) */ 261 | void init_partition_info(char **wanted_partitions, int wanted_partitions_n) 262 | { 263 | const char *scan_fmt = NULL; 264 | char * buf; 265 | 266 | debug_msg("initializing partition info for mod_iostat"); 267 | 268 | // supposedly older kernels don't have this file 269 | if(access("/proc/diskstats", R_OK)) { 270 | kernel_type = 4; 271 | scan_fmt = "%4d %4d %*d %31s %u"; 272 | } else { 273 | kernel_type = 6; 274 | scan_fmt = "%4d %4d %31s %u"; 275 | } 276 | 277 | if(!scan_fmt) 278 | err_msg("logic error in initialize(). cannot set scan_fmt"); 279 | 280 | buf = update_file_iostat(kernel_type); 281 | 282 | while ( buf != NULL ) { 283 | unsigned int reads = 0; 284 | struct part_info curr; 285 | 286 | if (sscanf(buf, scan_fmt, &curr.major, &curr.minor, 287 | curr.name, &reads) == 4) { 288 | unsigned int p; 289 | 290 | // skip invalid device types 291 | if (!valid_disk(curr.major)) { 292 | buf = index(buf, '\n'); 293 | if(buf != NULL) buf++; 294 | debug_msg("Skipping %s", curr.name); 295 | continue; 296 | } 297 | 298 | // to skip over the ones that exist and register a new one 299 | for (p = 0; p < n_partitions 300 | && (partition[p].major != curr.major 301 | || partition[p].minor != curr.minor); 302 | p++); 303 | 304 | if (p == n_partitions && p < MAX_PARTITIONS) { 305 | // if user specified the partition names 306 | if (wanted_partitions_n) { 307 | unsigned int j; 308 | 309 | for (j = 0; 310 | j < wanted_partitions_n && wanted_partitions[j]; j++) { 311 | if (!strcmp(curr.name, wanted_partitions[j])) { // if they match 312 | partition[p] = curr; 313 | n_partitions = p + 1; 314 | } 315 | } 316 | } else if (reads && printable(curr.major, curr.minor)) { 317 | partition[p] = curr; 318 | n_partitions = p + 1; 319 | } 320 | } 321 | } // sscanf 322 | // printf("looping with buf:\n%s\n", buf); 323 | 324 | // buf = index(buf, '\n')+1; // next line 325 | buf = index(buf, '\n'); 326 | if(buf != NULL) buf++; 327 | } 328 | } 329 | 330 | 331 | /* this is where we process the contents of the /proc file line by line and 332 | * save them to our old and new structs 333 | */ 334 | void get_kernel_io_stats() 335 | { 336 | const char *scan_fmt = NULL; 337 | const char * buffer; 338 | static struct timeval stamp= {0,0}; // permanent var for this func 339 | static int entry_count; // to detect the first count 340 | int i; 341 | 342 | buffer = update_file_iostat(kernel_type); 343 | 344 | if(kernel_type == 4) 345 | if ((proc_partitions.last_read.tv_sec != stamp.tv_sec) && 346 | (proc_partitions.last_read.tv_usec != stamp.tv_usec)) { 347 | stamp = proc_partitions.last_read; 348 | } else { 349 | return; 350 | } 351 | else 352 | if ((proc_diskstats.last_read.tv_sec != stamp.tv_sec) && 353 | (proc_diskstats.last_read.tv_usec != stamp.tv_usec)) { 354 | stamp = proc_diskstats.last_read; 355 | } else { 356 | return; 357 | } 358 | 359 | // save the new to old 360 | for (i = 0; i < n_partitions; i++) 361 | old_blkio[i] = new_blkio[i]; 362 | 363 | old_cpu = new_cpu; 364 | 365 | 366 | // notice it skips the part names with %*s 367 | if(kernel_type == 4) 368 | scan_fmt = "%4d %4d %*d %*s %u %u %llu %u %u %u %llu %u %*u %u %u"; 369 | else 370 | scan_fmt = "%4d %4d %*s %u %u %llu %u %u %u %llu %u %*u %u %u"; 371 | 372 | if(!scan_fmt) 373 | err_msg("logic error in get_kernel_io_stats(): can't set scan_fmt"); 374 | 375 | 376 | while ( buffer != NULL ) { 377 | int items; 378 | struct part_info curr; 379 | struct blkio_info blkio; 380 | 381 | items = sscanf(buffer, scan_fmt, 382 | &curr.major, &curr.minor, 383 | &blkio.rd_ios, &blkio.rd_merges, 384 | &blkio.rd_sectors, &blkio.rd_ticks, 385 | &blkio.wr_ios, &blkio.wr_merges, 386 | &blkio.wr_sectors, &blkio.wr_ticks, 387 | &blkio.ticks, &blkio.aveq); 388 | 389 | 390 | /* 391 | * Unfortunately, we can report only transfer rates 392 | * for partitions in 2.6 kernels, all other I/O 393 | * statistics are unavailable. 394 | * For more info: 395 | * http://devresources.linux-foundation.org/dev/robustmutexes/src/fusyn.hg/Documentation/iostats.txt 396 | */ 397 | if (items == 6) { 398 | blkio.rd_sectors = blkio.rd_merges; 399 | blkio.wr_ios = blkio.rd_sectors; 400 | blkio.wr_sectors = blkio.rd_ticks; 401 | // blkio.rd_ios = 0; 402 | blkio.rd_merges = 0; 403 | blkio.rd_ticks = 0; 404 | // blkio.wr_ios = 0; 405 | blkio.wr_merges = 0; 406 | blkio.wr_ticks = 0; 407 | blkio.ticks = 0; 408 | blkio.aveq = 0; 409 | items = 12; 410 | } 411 | 412 | if (items == 12) { 413 | unsigned int p; 414 | 415 | /* Locate partition in data table */ 416 | for (p = 0; p < n_partitions; p++) { 417 | if (partition[p].major == curr.major 418 | && partition[p].minor == curr.minor) { 419 | new_blkio[p] = blkio; // set it to the new block 420 | break; 421 | } 422 | } 423 | } 424 | buffer = index(buffer, '\n'); 425 | if(buffer != NULL) buffer++; 426 | } 427 | 428 | // now read in the cpu info at the "same" time so we can calculate 429 | // time passed 430 | buffer = update_file(&proc_stat); 431 | 432 | while ( buffer != NULL ) { 433 | // "cpu " is the line containing aggregated total 434 | if (!strncmp(buffer, "cpu ", 4)) { 435 | int items; 436 | unsigned long long nice, irq, softirq; 437 | 438 | items = sscanf(buffer, 439 | "cpu %llu %llu %llu %llu %llu %llu %llu", 440 | &new_cpu.user, &nice, 441 | &new_cpu.system, 442 | &new_cpu.idle, 443 | &new_cpu.iowait, 444 | &irq, &softirq); 445 | 446 | new_cpu.user += nice; 447 | if (items == 4) 448 | new_cpu.iowait = 0; 449 | if (items == 7) 450 | new_cpu.system += irq + softirq; 451 | } 452 | buffer = index(buffer, '\n'); 453 | if(buffer != NULL) buffer++; 454 | } 455 | 456 | if(entry_count == 0) 457 | { 458 | // save the new to old 459 | for (i = 0; i < n_partitions; i++) 460 | old_blkio[i] = new_blkio[i]; 461 | old_cpu = new_cpu; 462 | entry_count = 1; 463 | } 464 | } 465 | 466 | 467 | // just to make sure we collected everything 468 | void print_io_info(void) 469 | { 470 | int i; 471 | 472 | debug_msg("printing partition info"); 473 | for(i=0;i svct_max) svct_max = svct; 615 | } 616 | 617 | val.f = (float) svct_max / 1000.0; 618 | return val; 619 | } 620 | 621 | /* --------------------------------------------------------------------------- */ 622 | g_val_t 623 | io_queuemax_func( void ) 624 | { 625 | g_val_t val; 626 | int p; 627 | double queue, queue_max; 628 | double deltams = get_deltams(); 629 | queue_max = 0.0; 630 | 631 | get_kernel_io_stats(); 632 | 633 | for (p = 0; p < n_partitions; p++) { 634 | queue = (new_blkio[p].aveq - old_blkio[p].aveq) / deltams; 635 | if(queue > queue_max) queue_max = queue; 636 | } 637 | 638 | val.f = (float) queue_max / 1000.0; 639 | return val; 640 | } 641 | 642 | 643 | g_val_t 644 | io_busymax_func( void ) 645 | { 646 | g_val_t val; 647 | int p; 648 | double ticks, busy, busy_max; 649 | double deltams = get_deltams(); 650 | busy_max = 0.0; 651 | 652 | get_kernel_io_stats(); 653 | 654 | for (p = 0; p < n_partitions; p++) { 655 | ticks = new_blkio[p].ticks - old_blkio[p].ticks; 656 | busy = 100.0 * ticks / deltams; 657 | if(busy > 100.0) busy = 100.0; 658 | if(busy > busy_max) busy_max = busy; 659 | } 660 | 661 | val.f = (float) busy_max; 662 | return val; 663 | } 664 | 665 | 666 | 667 | 668 | /* 669 | * Declare ourselves so the configuration routines can find and know us. 670 | * We'll fill it in at the end of the module. 671 | */ 672 | extern mmodule io_module; 673 | 674 | static int iostat_metric_init ( apr_pool_t *p ) 675 | { 676 | const char* str_params = io_module.module_params; 677 | apr_array_header_t *list_params = io_module.module_params_list; 678 | mmparam *params; 679 | int i; 680 | 681 | if (!VD_DISK_MAJOR) 682 | VD_DISK_MAJOR = get_device_major("virtblk"); 683 | 684 | if (!XVD_DISK_MAJOR) 685 | XVD_DISK_MAJOR = get_device_major("xvd"); 686 | 687 | //libmetrics_init(); 688 | num_cpustates = num_cpustates_func(); 689 | init_partition_info(NULL, 0); 690 | 691 | print_io_info(); // prints debug msg 692 | 693 | 694 | /* Read the parameters from the gmond.conf file. */ 695 | /* Single raw string parameter */ 696 | if (str_params) { 697 | debug_msg("[mod_iostat] Received string params: %s", str_params); 698 | } 699 | /* Multiple name/value pair parameters. */ 700 | if (list_params) { 701 | debug_msg("[mod_iostat] Received following params list: "); 702 | params = (mmparam*) list_params->elts; 703 | for(i=0; i< list_params->nelts; i++) { 704 | debug_msg("\tParam: %s = %s", params[i].name, params[i].value); 705 | } 706 | } 707 | 708 | for (i = 0; io_module.metrics_info[i].name != NULL; i++) { 709 | MMETRIC_INIT_METADATA(&(io_module.metrics_info[i]),p); 710 | MMETRIC_ADD_METADATA(&(io_module.metrics_info[i]),MGROUP,"disk"); 711 | } 712 | 713 | return 0; 714 | } 715 | 716 | 717 | static void iostat_metric_cleanup ( void ) 718 | { 719 | } 720 | 721 | static g_val_t iostat_metric_handler ( int metric_index ) 722 | { 723 | g_val_t val; 724 | val.f = 0; // default 725 | 726 | /* The metric_index corresponds to the order in which 727 | the metrics appear in the metric_info array 728 | */ 729 | switch (metric_index) { 730 | case 0: 731 | return io_readtot_func(); 732 | case 1: 733 | return io_nreadtot_func(); 734 | case 2: 735 | return io_writetot_func(); 736 | case 3: 737 | return io_nwritetot_func(); 738 | case 4: 739 | return io_svctmax_func(); 740 | case 5: 741 | return io_queuemax_func(); 742 | case 6: 743 | return io_busymax_func(); 744 | default: 745 | return val; /* default fallback */ 746 | } 747 | return val; 748 | } 749 | 750 | static Ganglia_25metric iostat_metric_info[] = 751 | { 752 | {0, "io_reads", 120, GANGLIA_VALUE_FLOAT, "reads/sec", "both", "%.2f",UDP_HEADER_SIZE+8, "total number of reads"}, 753 | {0, "io_nread", 120, GANGLIA_VALUE_FLOAT, "bytes/sec", "both", "%.1f",UDP_HEADER_SIZE+8, "total bytes read"}, 754 | {0, "io_writes", 120, GANGLIA_VALUE_FLOAT, "writes/sec", "both", "%.2f",UDP_HEADER_SIZE+8, "total number of writes"}, 755 | {0, "io_nwrite",120, GANGLIA_VALUE_FLOAT, "bytes/sec", "both", "%.1f",UDP_HEADER_SIZE+8, "total bytes written"}, 756 | {0, "io_max_svc_time", 120, GANGLIA_VALUE_FLOAT, "s", "both", "%.6f",UDP_HEADER_SIZE+8, "max service time across disks"}, 757 | {0, "io_max_wait_time", 120, GANGLIA_VALUE_FLOAT, "s", "both", "%.6f",UDP_HEADER_SIZE+8, "max queue time across disks"}, 758 | {0, "io_busymax", 120, GANGLIA_VALUE_FLOAT, "%", "both", "%.3f",UDP_HEADER_SIZE+8, "max busy time across disks"}, 759 | {0, NULL} 760 | }; 761 | 762 | mmodule io_module = 763 | { 764 | STD_MMODULE_STUFF, 765 | iostat_metric_init, 766 | iostat_metric_cleanup, 767 | iostat_metric_info, 768 | iostat_metric_handler, 769 | }; 770 | -------------------------------------------------------------------------------- /gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------