summaryrefslogtreecommitdiff
path: root/net/cacti
diff options
context:
space:
mode:
authortron <tron>2014-01-16 21:10:00 +0000
committertron <tron>2014-01-16 21:10:00 +0000
commit44a52d7cf3be2d85aa19b2b62a87bed091e0bc3f (patch)
tree2d274a29410c5bd9d51845bfd3842ef9f0fa6623 /net/cacti
parent7f77fcf2311a80af90dbb6e20866ac9b7cfe9331 (diff)
downloadpkgsrc-44a52d7cf3be2d85aa19b2b62a87bed091e0bc3f.tar.gz
Improve packaging of this package:
1.) Handle installation of the script to determine the amount of free memory and swap space on the local machine automatically. 2.) Fix the NetBSD implementation of the above script. 3.) Create a wrapper shell script for invoking Cacti's poller. 4.) Simplify the installation instrunctions using the above enhancements. 5.) Don't included the log file in the package list. It doesn't belong there and "pkg_delete" will correctly complain that it has been modified. ToDo: - The log file and the "rrdtool" database still need to be moved to a directory under "${VARBASE}". - "config.php" should really be a config file to allow using a non-default password for the MySQL database. But the file would have to be readable by both the user of the webserver and that cacti user.
Diffstat (limited to 'net/cacti')
-rw-r--r--net/cacti/INSTALL9
-rw-r--r--net/cacti/MESSAGE28
-rw-r--r--net/cacti/Makefile27
-rw-r--r--net/cacti/PLIST5
-rw-r--r--net/cacti/files/cacti-poller7
-rw-r--r--net/cacti/files/netbsd_memory.pl122
6 files changed, 150 insertions, 48 deletions
diff --git a/net/cacti/INSTALL b/net/cacti/INSTALL
new file mode 100644
index 00000000000..30d73ea774a
--- /dev/null
+++ b/net/cacti/INSTALL
@@ -0,0 +1,9 @@
+# $NetBSD: INSTALL,v 1.1 2014/01/16 21:10:00 tron Exp $
+
+case ${STAGE} in
+POST-INSTALL)
+ ${TOUCH} @CACTI_LOGDIR@/cacti.log
+ ${CHOWN} cacti:cacti @CACTI_LOGDIR@/cacti.log
+ ${CHMOD} 640 @CACTI_LOGDIR@/cacti.log
+ ;;
+esac
diff --git a/net/cacti/MESSAGE b/net/cacti/MESSAGE
index 2d7f8d4d9c4..d3cacadf8a7 100644
--- a/net/cacti/MESSAGE
+++ b/net/cacti/MESSAGE
@@ -1,29 +1,23 @@
===========================================================================
-$NetBSD: MESSAGE,v 1.1.1.1 2011/11/22 22:23:13 tez Exp $
+$NetBSD: MESSAGE,v 1.2 2014/01/16 21:10:00 tron Exp $
cacti is now installed.
To get cacti up and running asap, you have to complete these steps:
-- Install & Configure mysql-server
+- Install & Configure MySQL database server.
-- Add a cacti database and cactiuser user to mysql
+- Add a cacti database and cactiuser user to MySQL and create the cacti
+ database layout (${CACTIDIR}/cacti.sql) to MySQL:
mysql> CREATE DATABASE cacti;
mysql> GRANT ALL PRIVILEGES ON cacti.* TO 'cactiuser'@'localhost'
-> IDENTIFIED BY 'cactiuser';
+ mysql> FLUSH PRIVILEGES;
+ mysql> USE cacti;
+ mysql> SOURCE ${CACTIDIR}/cacti.sql;
-- Add the cacti database layout (${CACTIDIR}/cacti.sql) to mysql
-
- shell> mysql [-p] cacti < ${CACTIDIR}/cacti.sql
-
-- Add a symlink from ${CACTIDIR}/scripts/local_memory.pl to the appropriate
- *_memory.pl script (or create one if none for your OS exists)
-
- shell> ln -s ${CACTIDIR}/scripts/netbsd_memory.pl \
- ${CACTIDIR}/scripts/local_memory.pl
-
-- Install & Configure an apache webserver
+- Install & Configure an Apache webserver.
- If you have not already done so, add these lines to enable php extensions
required by cacti in ${PKG_SYSCONFBASE}/etc/php.ini
@@ -32,14 +26,14 @@ To get cacti up and running asap, you have to complete these steps:
extension=snmp.so
extension=sockets.so
-- Append this to apache's httpd.conf and restart apache
+- Append this to Apache webserver's "httpd.conf" and restart the server.
Include etc/httpd/httpd-cacti.conf
- Add the following lines to ${CACTI_USER}'s crontab
-# Invoke poller.php to collect snmp-statistics
-*/5 * * * * ${PREFIX}/bin/php ${CACTIDIR}/poller.php > ${CACTI_LOGDIR}/poller.log 2>&1
+# Invoke poller.php to collect SNMP statistics.
+*/5 * * * * ${PREFIX}/bin/cacti-poller
Please read the included README (${CACTIDIR}/docs/README) file,
for more information about configuring and starting cacti.
diff --git a/net/cacti/Makefile b/net/cacti/Makefile
index 97ba50face0..50a569ee026 100644
--- a/net/cacti/Makefile
+++ b/net/cacti/Makefile
@@ -1,6 +1,7 @@
-# $NetBSD: Makefile,v 1.21 2014/01/08 20:51:28 tron Exp $
+# $NetBSD: Makefile,v 1.22 2014/01/16 21:10:00 tron Exp $
DISTNAME= cacti-0.8.8b
+PKGREVISION= 1
CATEGORIES= net
MASTER_SITES= http://www.cacti.net/downloads/
@@ -46,19 +47,22 @@ REPLACE_FILES.php= cli/*.php
REPLACE_PERL+= scripts/*.pl
MESSAGE_SUBST+= CACTIDIR=${CACTIDIR}
-MESSAGE_SUBST+= CACTI_LOGDIR=${CACTI_LOGDIR}
MESSAGE_SUBST+= CACTI_USER=${CACTI_USER}
MESSAGE_SUBST+= EGDIR=${EGDIR}
MESSAGE_SUBST+= PREFIX=${PREFIX}
MESSAGE_SUBST+= PKG_SYSCONFBASE=${PKG_SYSCONFBASE}
FILES_SUBST+= CACTIDIR=${CACTIDIR}
+FILES_SUBST+= CACTI_GROUP=${CACTI_GROUP}
+FILES_SUBST+= CACTI_USER=${CACTI_USER}
+FILES_SUBST+= CACTI_LOGDIR=${CACTI_LOGDIR}
SUBST_CLASSES+= paths
SUBST_STAGE.paths= pre-configure
SUBST_FILES.paths= ${WRKDIR}/httpd-cacti.conf install/index.php
SUBST_FILES.paths+= include/global.php include/global_settings.php
+SUBST_FILES.paths+= ${WRKDIR}/cacti-poller
SUBST_VARS.paths= CACTIDIR PREFIX CACTI_USER CACTI_LOGDIR CACTI_RRADIR
-SUBST_VARS.paths+= PKG_PHP_MAJOR_VERS
+SUBST_VARS.paths+= PKG_PHP_MAJOR_VERS SH
SUBST_CLASSES+= docs
SUBST_STAGE.docs= pre-configure
@@ -67,22 +71,33 @@ SUBST_SED.docs= -e 's,/var/www/html/cacti,${CACTIDIR},g'
OWN_DIRS_PERMS+= ${CACTI_LOGDIR} ${CACTI_USER} ${CACTI_GROUP} 755
OWN_DIRS_PERMS+= ${CACTI_RRADIR} ${CACTI_USER} ${CACTI_GROUP} 755
-SPECIAL_PERMS+= share/cacti/log/cacti.log ${CACTI_USER} ${CACTI_GROUP} 755
-INSTALLATION_DIRS= share/examples/cacti
+INSTALLATION_DIRS= bin
+INSTALLATION_DIRS+= share/examples/cacti
INSTALLATION_DIRS+= share/cacti
+PLIST_VARS+= localmemory
+.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "Linux" || \
+ ${OPSYS} == "NetBSD" || ${OPSYS} == "SunOS"
+PLIST.localmemory= yes
+.endif
+
post-extract:
${CP} ${FILESDIR}/httpd-cacti.conf ${WRKDIR}/
+ ${CP} ${FILESDIR}/cacti-poller ${WRKDIR}/
${CP} ${FILESDIR}/freebsd_memory.pl ${WRKSRC}/scripts/
${CP} ${FILESDIR}/netbsd_memory.pl ${WRKSRC}/scripts/
${CP} ${FILESDIR}/solaris_memory.pl ${WRKSRC}/scripts/
+ cd ${WRKSRC}/scripts; \
+ if [ -f ${LOWER_OPSYS}_memory.pl ]; then \
+ ${LN} -fs ${LOWER_OPSYS}_memory.pl local_memory.pl; \
+ fi
do-install:
${INSTALL_DATA} ${WRKDIR}/httpd-cacti.conf ${DESTDIR}${EGDIR}/httpd-cacti.conf
${FIND} ${WRKSRC} -type f -name '*.orig' -exec ${RM} -f {} \;
cd ${WRKSRC} && ${PAX} -wr * ${DESTDIR}${CACTIDIR}
-
+ ${INSTALL_SCRIPT} ${WRKDIR}/cacti-poller ${DESTDIR}${PREFIX}/bin
.include "../../databases/rrdtool/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
diff --git a/net/cacti/PLIST b/net/cacti/PLIST
index 254c0c28fb8..57f3f0cec81 100644
--- a/net/cacti/PLIST
+++ b/net/cacti/PLIST
@@ -1,4 +1,5 @@
-@comment $NetBSD: PLIST,v 1.4 2014/01/08 20:51:28 tron Exp $
+@comment $NetBSD: PLIST,v 1.5 2014/01/16 21:10:00 tron Exp $
+bin/cacti-poller
share/cacti/LICENSE
share/cacti/README
share/cacti/about.php
@@ -444,7 +445,6 @@ share/cacti/lib/utility.php
share/cacti/lib/variables.php
share/cacti/lib/xml.php
share/cacti/log/.htaccess
-share/cacti/log/cacti.log
share/cacti/logout.php
share/cacti/plugins.php
share/cacti/plugins/index.php
@@ -473,6 +473,7 @@ share/cacti/scripts/freebsd_memory.pl
share/cacti/scripts/linux_memory.pl
share/cacti/scripts/loadavg.pl
share/cacti/scripts/loadavg_multi.pl
+${PLIST.localmemory}share/cacti/scripts/local_memory.pl
share/cacti/scripts/netbsd_memory.pl
share/cacti/scripts/ping.pl
share/cacti/scripts/query_host_cpu.php
diff --git a/net/cacti/files/cacti-poller b/net/cacti/files/cacti-poller
new file mode 100644
index 00000000000..8c122e27228
--- /dev/null
+++ b/net/cacti/files/cacti-poller
@@ -0,0 +1,7 @@
+#!@SH@
+#
+# $NetBSD: cacti-poller,v 1.1 2014/01/16 21:10:00 tron Exp $
+#
+
+LOGFILE=@CACTI_LOGDIR@/cacti.log
+exec @PREFIX@/bin/php @CACTIDIR@/poller.php >>$LOGFILE 2>&1
diff --git a/net/cacti/files/netbsd_memory.pl b/net/cacti/files/netbsd_memory.pl
index 13befcb45cb..7dcbf4288bc 100644
--- a/net/cacti/files/netbsd_memory.pl
+++ b/net/cacti/files/netbsd_memory.pl
@@ -1,23 +1,99 @@
-#!/usr/bin/perl
-
-if (($ARGV[0] =~ /Cached:/) || ($ARGV[0] =~ /SwapFree:/)) {
- open(PROCESS, "pstat -ks |");
- $s = 0;
- while (<PROCESS>) {
- if (!/^Device/) {
- split();
- $s += $_[3];
- }
- }
- print "$s";
-}
-else { # $ARGV[0] is Buffers:, MemFree:, or anything else
- open(PROCESS, "vmstat |");
- while (<PROCESS>) {
- if (!/p/) { # the numbers line happens not to have "p"
- split();
- print("$_[4]");
- }
- }
-}
-close(PROCESS);
+#!/usr/bin/perl
+#
+# $NetBSD: netbsd_memory.pl,v 1.2 2014/01/16 21:10:00 tron Exp $
+#
+# Copyright (c) 2014 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Matthias Scheler.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+use warnings;
+use strict;
+
+use POSIX;
+
+# Use vmstat(1) to get memory usage information. "vmstat -s" produces
+# output lines like these:
+#
+# 2034763 pages managed
+# 28953 pages free
+#
+# This function creates a hash using the description as a key to the value.
+
+sub get_vm_stats()
+{
+ my %vm_stats;
+
+ my $vmstat_fh;
+ if (!open($vmstat_fh, '-|', '/usr/bin/vmstat -s')) {
+ die('Cannot start vmstat.');
+ }
+
+ while (my $line = <$vmstat_fh>) {
+ $line =~ s/^\s+//;
+ $line =~ s/\s+$//;
+ my @words = split(/\s+/, $line, 2);
+ if (scalar(@words) < 2) {
+ next;
+ }
+ my ($value, $descr) = @words;
+
+ $vm_stats{$descr} = $value;
+ }
+
+ close($vmstat_fh);
+ return %vm_stats;
+}
+
+if (scalar(@ARGV) < 1) {
+ die('Please provide a field name');
+}
+
+my $page_size = POSIX::sysconf(&POSIX::_SC_PAGESIZE);
+my %vm_stats = get_vm_stats();
+
+# Calculate metrics using the stats reported by vmstat(1).
+# Cacti only uses "MemFree" and "SwapFree" at the moment.
+my $value = 0;
+if ($ARGV[0] =~ 'MemTotal') {
+ $value = $vm_stats{'pages managed'};
+} elsif ($ARGV[0] =~ 'MemFree') {
+ $value = $vm_stats{'pages free'};
+} elsif ($ARGV[0] =~ 'Buffers') {
+ $value = $vm_stats{'cached file pages'};
+} elsif ($ARGV[0] =~ 'Cached') {
+ $value = $vm_stats{'anonymous pages'} +
+ $vm_stats{'cached file pages'} +
+ $vm_stats{'cached executable pages'};
+} elsif ($ARGV[0] =~ 'SwapTotal') {
+ $value = $vm_stats{'swap pages'};
+} elsif ($ARGV[0] =~ 'SwapFree') {
+ $value = $vm_stats{'swap pages'} -
+ $vm_stats{'swap pages in use'};
+}
+
+print $value * ($page_size / 1024);
+exit(0);