summaryrefslogtreecommitdiffstats
path: root/pcp
diff options
context:
space:
mode:
authorCVS Import User <samba-bugs@samba.org>2004-04-04 09:21:52 +0000
committerCVS Import User <samba-bugs@samba.org>2004-04-04 09:21:52 +0000
commit9f765b7406282904ce56f2535dcd929a9aefc5ca (patch)
treedbdff78b624ac7c1afcb8851f395df3d99eb1f84 /pcp
parent111b4e05ab96eafc4212f38dc5977538907187c7 (diff)
downloadsamba-9f765b7406282904ce56f2535dcd929a9aefc5ca.tar.gz
samba-9f765b7406282904ce56f2535dcd929a9aefc5ca.tar.xz
samba-9f765b7406282904ce56f2535dcd929a9aefc5ca.zip
r2: import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
metze
Diffstat (limited to 'pcp')
-rwxr-xr-xpcp/Install64
-rw-r--r--pcp/Makefile74
-rw-r--r--pcp/README94
-rwxr-xr-xpcp/Remove52
-rw-r--r--pcp/domain.h4
-rw-r--r--pcp/help77
-rwxr-xr-xpcp/mkheader.pl63
-rw-r--r--pcp/pmns45
-rw-r--r--pcp/root10
-rw-r--r--pcp/samba.c390
10 files changed, 873 insertions, 0 deletions
diff --git a/pcp/Install b/pcp/Install
new file mode 100755
index 00000000000..c2087fc01e3
--- /dev/null
+++ b/pcp/Install
@@ -0,0 +1,64 @@
+#! /bin/sh
+#
+# Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Further, this software is distributed without any warranty that it is
+# free of the rightful claim of any third person regarding infringement
+# or the like. Any license provided herein, whether implied or
+# otherwise, applies only to this software file. Patent licenses, if
+# any, provided herein do not apply to combinations of this program with
+# other software, or any other product whatsoever.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston MA 02111-1307, USA.
+#
+# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+# Mountain View, CA 94043, or:
+#
+# http://www.sgi.com
+#
+# For further information regarding this notice, see:
+#
+# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+#
+# Install the samba PMDA and/or PMNS
+#
+
+# source the PCP configuration environment variables
+. /etc/pcp.env
+
+# Get the common procedures and variable assignments
+#
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+# The name of the PMDA
+#
+iam=samba
+
+# override interactive dialog from pmdaproc.sh
+#
+__choose_mode()
+{
+ echo "Installing the \"$iam\" Performance Metrics Domain Agent (PMDA) ..."
+ echo
+}
+
+# Using libpcp_pmda.so.2 and PMDA_INTERFACE_2
+#
+pmda_interface=2
+
+# Do it
+#
+pmdaSetup
+pmdaInstall
+
+exit 0
diff --git a/pcp/Makefile b/pcp/Makefile
new file mode 100644
index 00000000000..e4b5fb75064
--- /dev/null
+++ b/pcp/Makefile
@@ -0,0 +1,74 @@
+#!make
+#
+# Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Further, this software is distributed without any warranty that it is
+# free of the rightful claim of any third person regarding infringement
+# or the like. Any license provided herein, whether implied or
+# otherwise, applies only to this software file. Patent licenses, if
+# any, provided herein do not apply to combinations of this program with
+# other software, or any other product whatsoever.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston MA 02111-1307, USA.
+#
+# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+# Mountain View, CA 94043, or:
+#
+# http://www.sgi.com
+#
+# For further information regarding this notice, see:
+#
+# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+#
+
+SHELL = sh
+
+include /etc/pcp.conf
+
+IAM = samba
+CFILES = $(IAM).c
+
+LIBTARGET = pmda_$(IAM).so
+CMDTARGET = pmda$(IAM)
+TARGETS = $(LIBTARGET) $(CMDTARGET)
+
+DEBUG = -DDEBUG
+CFLAGS = $(DEBUG)
+LDOPTS =
+LDLIBS = -lpcp_pmda -lpcp
+DSOOPTS = -shared
+LDIRT = profile.h metrics.h so_locations *.log help.dir help.pag *.pmda_$(IAM).so
+
+PROFILEHEADER = ../source/include/smbprofile.h
+
+INSTALL = install
+CC = cc
+
+default: $(TARGETS)
+
+install: default
+
+$(CMDTARGET): profile.h metrics.h $(CFILES)
+ $(CC) $(CFLAGS) $(CFILES) $(LDOPTS) $(LDLIBS) -o $@
+
+$(LIBTARGET): profile.h metrics.h $(CFILES)
+ $(CC) $(CFLAGS) $(DSOOPTS) $(LDOPTS) $(CFILES) $(LDLIBS) -o $@
+
+metrics.h: profile.h mkheader.pl
+ ./mkheader.pl
+
+profile.h: $(PROFILEHEADER)
+ ln -s $(PROFILEHEADER) $@
+
+clobber clean:
+ rm -f $(LDIRT) $(TARGETS)
diff --git a/pcp/README b/pcp/README
new file mode 100644
index 00000000000..97d8125a53e
--- /dev/null
+++ b/pcp/README
@@ -0,0 +1,94 @@
+samba PMDA
+===========
+
+This PMDA is a sample that illustrates how a simple samba monitor
+PMDA might be constructed, using a shared memory segment to transfer
+information about transaction activity from the smb daemon.
+
+Note:
+ This PMDA may be remade from source and hence requires
+ a C compiler and Perl to be installed.
+
+ Uses of make(1) may fail (without removing or clobbering files)
+ if the C compiler cannot be found. This is most likely to
+ happen when running the PMDA ./Install script.
+
+ The only remedial action is to install the C compiler, or
+ hand-craft changes to the Makefile.
+
+Metrics
+=======
+
+The file ./help contains descriptions for all of the metrics exported
+by this PMDA.
+
+Once the PMDA has been installed, the following command will list all
+the available metrics and their explanatory "help" text:
+
+ $ pminfo -fT samba
+
+Installation
+============
+
+ + # mkdir /var/pcp/pmdas/samba
+ + # cp * /var/pcp/pmdas/samba
+ + # cp ../source/include/profile.h /var/pcp/pmdas/samba
+ + # cd /var/pcp/pmdas/samba
+
+ + Check that there is no clash in the Performance Metrics Domain
+ defined in ./domain.h and the other PMDAs currently in use
+ (/etc/pmcd.conf). If there is, edit ./domain.h to choose another
+ domain number.
+
+ + If you are not installing on an IRIX system, edit samba.c and
+ comment out the
+
+ #define IRIX 1
+
+ + Then simply use
+
+ # ./Install
+
+ + Alternatively, to install just the Performance Metrics Name Space
+ for the samba metrics on the local system, but not the samba PMDA
+ (presumably because the local system is running PCP 1.x and you
+ wish to connect to a remote system where PCP 2.0 and the samba PMDA
+ is running), make sure the Performance Metrics Domain defined in
+ ./domain.h matches the domain chosen for the samba PMDA on the
+ remote system (check the second field in the corresponding line of
+ the pmcd.conf file on the remote system - located in /etc on IRIX
+ and /var/pcp/config/pmcd on Linux), then
+
+ # ./Install -N
+
+De-installation
+===============
+
+ + Simply use
+
+ # cd /var/pcp/pmdas/samba
+ # ./Remove
+
+ + If you also want to remove the sources use
+
+ # cd /
+ # rm -rf /var/pcp/pmdas/samba
+
+Making something happen
+=======================
+
+The application "smbd" updates the shared memory segment to add
+profile information about smbd. By default updating is disabled.
+To start updating of the shared memory segment you need to run the
+smbcontrol command to turn on profiling for one or more smbd processes
+(see the man page for smbcontrol).
+
+
+
+Troubleshooting
+===============
+
+ + After installing or restarting the agent, the PMCD log file
+ (pmcd.log) and the PMDA log file (samba.log) should be checked
+ for any warnings or errors. These logs are located in
+ /var/log/pcp/pmcd on Linux and /var/adm/pcplog on IRIX.
diff --git a/pcp/Remove b/pcp/Remove
new file mode 100755
index 00000000000..3f7434d2553
--- /dev/null
+++ b/pcp/Remove
@@ -0,0 +1,52 @@
+#! /bin/sh
+#
+# Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of version 2 of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# Further, this software is distributed without any warranty that it is
+# free of the rightful claim of any third person regarding infringement
+# or the like. Any license provided herein, whether implied or
+# otherwise, applies only to this software file. Patent licenses, if
+# any, provided herein do not apply to combinations of this program with
+# other software, or any other product whatsoever.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write the Free Software Foundation, Inc., 59
+# Temple Place - Suite 330, Boston MA 02111-1307, USA.
+#
+# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+# Mountain View, CA 94043, or:
+#
+# http://www.sgi.com
+#
+# For further information regarding this notice, see:
+#
+# http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+#
+# Remove the samba PMDA
+#
+
+# source the PCP configuration environment variables
+. /etc/pcp.env
+
+# Get the common procedures and variable assignments
+#
+. $PCP_SHARE_DIR/lib/pmdaproc.sh
+
+# The name of the PMDA
+#
+iam=samba
+
+# Do it
+#
+pmdaSetup
+pmdaRemove
+
+exit 0
diff --git a/pcp/domain.h b/pcp/domain.h
new file mode 100644
index 00000000000..3cf0bc6ce97
--- /dev/null
+++ b/pcp/domain.h
@@ -0,0 +1,4 @@
+/*
+ * built from /var/pcp/pmns/stdpmid
+ */
+#define SAMBA 123
diff --git a/pcp/help b/pcp/help
new file mode 100644
index 00000000000..dc3b02f03bd
--- /dev/null
+++ b/pcp/help
@@ -0,0 +1,77 @@
+#
+# samba PMDA help file in the ASCII format
+#
+# lines beginning with a # are ignored
+# lines beginning @ introduce a new entry of the form
+# @ metric_name oneline-text
+# help test goes
+# here over multiple lines
+# ...
+#
+# the metric_name is decoded against the default PMNS -- as a special case,
+# a name of the form NNN.MM (for numeric NNN and MM) is interpreted as an
+# instance domain identification, and the text describes the instance domain
+#
+# blank lines before the @ line are ignored
+#
+
+@ SAMBA.0 Count and Time Instance Domain
+Contains count and time information for system calls and smb transactions.
+Counts shows the number of times each transaction was called. Times
+indicates the time spent in each transaction.
+
+@ SAMBA.1 Byte Instance Domain
+This domain contains instances for the number of bytes transferred
+using the read and write system call.
+
+@ samba.counts Count of calls to this function
+
+@ samba.times Time required to complete call
+
+@ samba.bytes Number of bytes processed by this call
+
+@ samba.smbd.smb_count Count of SMB packets processed
+
+@ samba.smbd.uid_changes Count of times effective uid changed
+
+@ samba.statcache.lookups Number of lookups in stat cache
+
+@ samba.statcache.misses Number of times stat cache lookup missed
+
+@ samba.statcache.hits Number of times stat cache lookup hit
+
+@ samba.writecache.num_caches Number of write caches available
+
+@ samba.writecache.allocated_caches Number of write caches allocated
+
+@ samba.writecache.read_hits Number of times read request found in write cache
+
+@ samba.writecache.total_writes Number of writes to write cache
+
+@ samba.writecache.init_writes Number of initial writes to write cache
+
+@ samba.writecache.abutted_writes
+
+@ samba.writecache.perfect_writes
+
+@ samba.writecache.direct_writes
+
+@ samba.writecache.non_oplock_writes
+
+@ samba.writecache.seek_flush
+
+@ samba.writecache.read_flush
+
+@ samba.writecache.write_flush
+
+@ samba.writecache.readraw_flush
+
+@ samba.writecache.oplock_rel_flush
+
+@ samba.writecache.close_flush
+
+@ samba.writecache.sync_flush
+
+@ samba.writecache.size_change_flush
+
+@ samba.bytes cumulative number of bytes read or written
diff --git a/pcp/mkheader.pl b/pcp/mkheader.pl
new file mode 100755
index 00000000000..ad069c544a8
--- /dev/null
+++ b/pcp/mkheader.pl
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+
+open(PROFILE,"profile.h") || die "Unable to open profile.h\n";
+@profile = <PROFILE>;
+close PROFILE;
+
+open(METRICS,"> metrics.h") || die "Unable to open metrics.h for output\n";
+
+print METRICS "#define COUNT_TIME_INDOM 0\n";
+print METRICS "#define BYTE_INDOM 1\n\n";
+print METRICS "#define FIELD_OFF(x) (unsigned)\&(((struct profile_stats *)NULL)->x)\n\n";
+print METRICS "typedef struct {\n";
+print METRICS "\tchar *name;\n";
+print METRICS "\tunsigned offset;\n";
+print METRICS "} samba_instance;\n\n";
+
+@instnames = grep(/unsigned .*_time;/,@profile);
+foreach $instnames (@instnames) {
+ chomp $instnames;
+ $instnames =~ s/^.*unsigned (.*)_time.*$/$1/;
+}
+
+print METRICS "static samba_instance samba_counts[] = {";
+$first = 1;
+foreach $1 (@instnames) {
+ if ($first == 1) {
+ $first = 0;
+ print METRICS "\n";
+ } else {
+ print METRICS ",\n";
+ }
+ print METRICS "\t{\"$1\", FIELD_OFF($1_count)}";
+}
+print METRICS "\n};\n\n";
+print METRICS "static samba_instance samba_times[] = {";
+$first = 1;
+foreach $1 (@instnames) {
+ if ($first == 1) {
+ $first = 0;
+ print METRICS "\n";
+ } else {
+ print METRICS ",\n";
+ }
+ print METRICS "\t{\"$1\", FIELD_OFF($1_time)}";
+}
+print METRICS "\n};\n\n";
+print METRICS "static samba_instance samba_bytes[] = {";
+@instnames = grep(/unsigned .*_bytes;/,@profile);
+$first = 1;
+foreach $_ (@instnames) {
+ if ($first == 1) {
+ $first = 0;
+ print METRICS "\n";
+ } else {
+ print METRICS ",\n";
+ }
+ /^.*unsigned (.*)_bytes.*$/;
+ print METRICS "\t{\"$1\", FIELD_OFF($1_bytes)}";
+}
+print METRICS "\n};\n";
+
+close METRICS
diff --git a/pcp/pmns b/pcp/pmns
new file mode 100644
index 00000000000..1f3dd3934ee
--- /dev/null
+++ b/pcp/pmns
@@ -0,0 +1,45 @@
+/*
+ * Metrics for samba PMDA
+ *
+ */
+
+samba {
+ smbd
+ statcache
+ writecache
+ counts SAMBA:3:0
+ times SAMBA:4:0
+ bytes SAMBA:5:0
+}
+
+samba.smbd {
+ smb_count SAMBA:0:0
+ uid_changes SAMBA:0:1
+}
+
+samba.statcache {
+ lookups SAMBA:1:0
+ misses SAMBA:1:1
+ hits SAMBA:1:2
+}
+
+samba.writecache {
+ num_caches SAMBA:2:0
+ allocated_caches SAMBA:2:1
+ read_hits SAMBA:2:2
+ total_writes SAMBA:2:3
+ init_writes SAMBA:2:4
+ abutted_writes SAMBA:2:5
+ perfect_writes SAMBA:2:6
+ direct_writes SAMBA:2:7
+ non_oplock_writes SAMBA:2:8
+ seek_flush SAMBA:2:9
+ read_flush SAMBA:2:10
+ write_flush SAMBA:2:11
+ readraw_flush SAMBA:2:12
+ oplock_rel_flush SAMBA:2:13
+ close_flush SAMBA:2:14
+ sync_flush SAMBA:2:15
+ size_change_flush SAMBA:2:16
+}
+
diff --git a/pcp/root b/pcp/root
new file mode 100644
index 00000000000..d5137bc7ddd
--- /dev/null
+++ b/pcp/root
@@ -0,0 +1,10 @@
+/*
+ * fake "root" for validating the local PMNS subtree
+ */
+
+#include "/var/pcp/pmns/stdpmid"
+
+root { samba }
+
+#include "pmns"
+
diff --git a/pcp/samba.c b/pcp/samba.c
new file mode 100644
index 00000000000..07a6ce2e169
--- /dev/null
+++ b/pcp/samba.c
@@ -0,0 +1,390 @@
+/*
+ * Samba, configurable PMDA
+ *
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+typedef int BOOL;
+
+#define IRIX 1
+
+#include <stdio.h>
+#include <sys/shm.h>
+#include <pcp/pmapi.h>
+#ifdef IRIX
+#include <pcp/impl.h>
+#endif
+#include <pcp/pmda.h>
+#include "domain.h"
+#include "profile.h"
+#include "metrics.h"
+
+static pmdaInstid *counttime = NULL;
+static pmdaInstid *bytes = NULL;
+
+/*
+ * List of instance domains
+ */
+
+static pmdaIndom indomtab[] = {
+ {COUNT_TIME_INDOM,0,NULL},
+ {BYTE_INDOM,0,NULL}
+};
+/*
+ * all metrics supported in this PMDA - one table entry for each
+ */
+
+static pmdaMetric metrictab[] = {
+/* smbd.smb_count */
+ { NULL, { PMDA_PMID(0,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* smbd.uid_changes */
+ { NULL, { PMDA_PMID(0,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* statcache.lookups */
+ { NULL, { PMDA_PMID(1,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* statcache.misses */
+ { NULL, { PMDA_PMID(1,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* statcache.hits */
+ { NULL, { PMDA_PMID(1,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.num_caches */
+ { NULL, { PMDA_PMID(2,0), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.allocated_caches */
+ { NULL, { PMDA_PMID(2,1), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_INSTANT,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.read_hits */
+ { NULL, { PMDA_PMID(2,2), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.total_writes */
+ { NULL, { PMDA_PMID(2,3), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.init_writes */
+ { NULL, { PMDA_PMID(2,4), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.abutted_writes */
+ { NULL, { PMDA_PMID(2,5), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.perfect_writes */
+ { NULL, { PMDA_PMID(2,6), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.direct_writes */
+ { NULL, { PMDA_PMID(2,7), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.non_oplock_writes */
+ { NULL, { PMDA_PMID(2,8), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.seek_flush */
+ { NULL, { PMDA_PMID(2,9), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.read_flush */
+ { NULL, { PMDA_PMID(2,10), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.write_flush */
+ { NULL, { PMDA_PMID(2,11), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.readraw_flush */
+ { NULL, { PMDA_PMID(2,12), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.oplock_rel_flush */
+ { NULL, { PMDA_PMID(2,13), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.close_flush */
+ { NULL, { PMDA_PMID(2,14), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.sync_flush */
+ { NULL, { PMDA_PMID(2,15), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* writecache.size_change_flush */
+ { NULL, { PMDA_PMID(2,16), PM_TYPE_U32, PM_INDOM_NULL, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* counts instance domain */
+ { NULL, { PMDA_PMID(3,0), PM_TYPE_U32, COUNT_TIME_INDOM, PM_SEM_COUNTER,
+ { 0,0,1,0,0,PM_COUNT_ONE} }, },
+/* times instance domain */
+ { NULL, { PMDA_PMID(4,0), PM_TYPE_U32, COUNT_TIME_INDOM, PM_SEM_COUNTER,
+ { 0,1,0,0,PM_TIME_USEC,0} }, },
+/* bytes instance domain */
+ { NULL, { PMDA_PMID(5,0), PM_TYPE_U32, BYTE_INDOM, PM_SEM_COUNTER,
+ { 1,0,0,PM_SPACE_BYTE,0,0} }, }
+
+};
+
+extern int errno;
+struct profile_stats *stats;
+struct profile_header *shmheader;
+int shmid = -1;
+
+
+int
+samba_fetchCallBack(pmdaMetric *mdesc, unsigned int inst, pmAtomValue *atom)
+{
+ __pmID_int *idp = (__pmID_int *)&(mdesc->m_desc.pmid);
+
+
+ if (inst != PM_IN_NULL && mdesc->m_desc.indom == PM_INDOM_NULL)
+ return PM_ERR_INST;
+
+ if (idp->cluster == 0) {
+ switch (idp->item) {
+ case 0: /* smbd.smb_count */
+ atom->ul = stats->smb_count;
+ break;
+ case 1: /* smb.uid_changes */
+ atom->ul = stats->uid_changes;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+ }
+ else if (idp->cluster == 1) { /* statcache */
+ switch (idp->item) {
+ case 0: /* statcache.lookups */
+ atom->ul = stats->statcache_lookups;
+ break;
+ case 1: /* statcache.misses */
+ atom->ul = stats->statcache_misses;
+ break;
+ case 2: /* statcache.hits */
+ atom->ul = stats->statcache_hits;
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+ }
+ else if (idp->cluster == 2) { /* writecache */
+ switch (idp->item) {
+ case 0: /* writecache.num_caches */
+ atom->ul = stats->writecache_num_write_caches;
+ break;
+ case 1: /* writecache.allocated_caches */
+ atom->ul = stats->writecache_allocated_write_caches;
+ break;
+ case 2: /* writecache.read_hits */
+ atom->ul = stats->writecache_read_hits;
+ break;
+ case 3: /* writecache.total_writes */
+ atom->ul = stats->writecache_total_writes;
+ break;
+ case 4: /* writecache.init_writes */
+ atom->ul = stats->writecache_init_writes;
+ break;
+ case 5: /* writecache.abutted_writes */
+ atom->ul = stats->writecache_abutted_writes;
+ break;
+ case 6: /* writecache.perfect_writes */
+ atom->ul = stats->writecache_num_perfect_writes;
+ break;
+ case 7: /* writecache.direct_writes */
+ atom->ul = stats->writecache_direct_writes;
+ break;
+ case 8: /* writecache.non_oplock_writes */
+ atom->ul = stats->writecache_non_oplock_writes;
+ break;
+ case 9: /* writecache.seek_flush */
+ atom->ul = stats->writecache_flushed_writes[SEEK_FLUSH];
+ break;
+ case 10: /* writecache.read_flush */
+ atom->ul = stats->writecache_flushed_writes[READ_FLUSH];
+ break;
+ case 11: /* writecache.write_flush */
+ atom->ul = stats->writecache_flushed_writes[WRITE_FLUSH];
+ break;
+ case 12: /* writecache.readraw_flush */
+ atom->ul = stats->writecache_flushed_writes[READRAW_FLUSH];
+ break;
+ case 13: /* writecache.oplock_rel_flush */
+ atom->ul = stats->writecache_flushed_writes[OPLOCK_RELEASE_FLUSH];
+ break;
+ case 14: /* writecache.close_flush */
+ atom->ul = stats->writecache_flushed_writes[CLOSE_FLUSH];
+ break;
+ case 15: /* writecache.sync_flush */
+ atom->ul = stats->writecache_flushed_writes[SYNC_FLUSH];
+ break;
+ case 16: /* writecache.size_change_flush */
+ atom->ul = stats->writecache_flushed_writes[SIZECHANGE_FLUSH];
+ break;
+ default:
+ return PM_ERR_PMID;
+ }
+ }
+ else if (idp->cluster == 3) { /* counts */
+ if (idp->item == 0) {
+ if (inst < indomtab[COUNT_TIME_INDOM].it_numinst) {
+ unsigned *p;
+
+ p = (unsigned *)((unsigned)stats + samba_counts[inst].offset);
+ atom->ul = *p;
+ }
+ else
+ return PM_ERR_INST;
+ }
+ else
+ return PM_ERR_PMID;
+ }
+ else if (idp->cluster == 4) { /* times */
+ if (idp->item == 0) {
+ if (inst < indomtab[COUNT_TIME_INDOM].it_numinst) {
+ unsigned *p;
+
+ p = (unsigned *)((unsigned)stats + samba_times[inst].offset);
+ atom->ul = *p;
+ }
+ else
+ return PM_ERR_INST;
+ }
+ else
+ return PM_ERR_PMID;
+ }
+ else if (idp->cluster == 5) { /* bytes */
+ if (idp->item == 0) {
+ if (inst < indomtab[BYTE_INDOM].it_numinst) {
+ unsigned *p;
+
+ p = (unsigned *)((unsigned)stats + samba_bytes[inst].offset);
+ atom->ul = *p;
+ }
+ else
+ return PM_ERR_INST;
+ }
+ else
+ return PM_ERR_PMID;
+ }
+ else
+ return PM_ERR_PMID;
+ return 0;
+}
+
+
+void
+samba_init(pmdaInterface *dp)
+{
+ int inst_count, i;
+
+ if (dp->status != 0)
+ return;
+
+ if ((shmid = shmget(PROF_SHMEM_KEY, 0, 0)) == -1) {
+ fprintf(stderr, "shmid: %s\n", strerror(errno));
+ fprintf(stderr, "samba not compiled with profile support or not running\n");
+ exit(1);
+ }
+ shmheader = (struct profile_header *)shmat(shmid, NULL, SHM_RDONLY);
+ if ((int)shmheader == -1) {
+ fprintf(stderr, "shmat: %s\n", strerror(errno));
+ exit(1);
+ }
+
+/*
+ * Initialize lists of instances
+ */
+
+ inst_count = sizeof(samba_counts)/sizeof(samba_counts[0]);
+ counttime = (pmdaInstid *)malloc(inst_count * sizeof(pmdaInstid));
+ if (counttime == NULL) {
+ __pmNoMem("count&time",inst_count * sizeof(pmdaInstid),PM_FATAL_ERR);
+ /* NOTREACHED*/
+ }
+ for (i = 0; i < inst_count; i++) {
+ counttime[i].i_inst = i;
+ counttime[i].i_name = samba_counts[i].name;
+ }
+ indomtab[COUNT_TIME_INDOM].it_numinst = inst_count;
+ indomtab[COUNT_TIME_INDOM].it_set = counttime;
+
+ inst_count = sizeof(samba_bytes)/sizeof(samba_bytes[0]);
+ bytes = (pmdaInstid *)malloc(inst_count * sizeof(pmdaInstid));
+ if (bytes == NULL) {
+ __pmNoMem("bytes",inst_count * sizeof(pmdaInstid),PM_FATAL_ERR);
+ /* NOTREACHED*/
+ }
+ for (i = 0; i < inst_count; i++) {
+ bytes[i].i_inst = i;
+ bytes[i].i_name = samba_bytes[i].name;
+ }
+ indomtab[BYTE_INDOM].it_numinst = inst_count;
+ indomtab[BYTE_INDOM].it_set = bytes;
+
+
+ pmdaSetFetchCallBack(dp, samba_fetchCallBack);
+ pmdaInit(dp, indomtab, sizeof(indomtab)/sizeof(indomtab[0]),
+ metrictab, sizeof(metrictab)/sizeof(metrictab[0]));
+
+ /* validate the data */
+ if (!shmheader) /* not mapped yet */
+ fprintf(stderr, "samba_init: shmem not mapped\n");
+ else if (shmheader->prof_shm_magic != PROF_SHM_MAGIC)
+ fprintf(stderr, "samba_init: bad magic\n");
+ else if (shmheader->prof_shm_version != PROF_SHM_VERSION)
+ fprintf(stderr, "samba_init: bad version %X\n",
+ shmheader->prof_shm_version);
+ else {
+ stats = &shmheader->stats;
+ return; /* looks OK */
+ }
+ exit(1);
+}
+
+
+int
+main(int argc, char **argv)
+{
+ int err = 0;
+ char *p;
+ pmdaInterface dispatch;
+
+ for (p = pmProgname = argv[0]; *p; p++)
+ if (*p == '/') pmProgname = p+1;
+
+ pmdaDaemon(&dispatch, PMDA_INTERFACE_2, pmProgname, SAMBA,
+ "samba.log", "/var/pcp/pmdas/samba/help");
+
+ if (pmdaGetOpt(argc, argv, "D:d:l:?", &dispatch, &err) != EOF) {
+ fprintf(stderr, "Usage: %s [options]\n\n\
+Options:\n\
+ -d domain use domain (numeric) for metrics domain of PMDA\n\
+ -l logfile write log into logfile rather than using default log name\n",
+ pmProgname);
+ exit(1);
+ }
+
+ pmdaOpenLog(&dispatch);
+ samba_init(&dispatch);
+ pmdaConnect(&dispatch);
+ pmdaMain(&dispatch);
+
+ exit(0);
+ /*NOTREACHED*/
+}