Permalink
Browse files

Moved basedir to config environment variable, fixed line endings

  • Loading branch information...
1 parent e7909b4 commit e9d5515c2cc58422166b3ef2cd695e6d819c2b02 @aaronpk committed Jul 10, 2011
Showing with 64 additions and 60 deletions.
  1. +64 −60 apache_vhosts.php
View
@@ -1,60 +1,64 @@
-#!/usr/bin/php
-<?php
-/**
- * README
- *
- * Add an additional line to each vhost you want to track with the domain name of the host
- * This will write a period for every hit to the vhost
- * CustomLog /web/logs/munin/example.com "."
- */
-
-$basedir = '/web/logs/munin';
-
-$files = scandir($basedir);
-
-// arg1 is blank or 'config' when munin runs it
-$mode = array_key_exists(1, $argv) ? $argv[1] : '';
-
-
-if($mode == 'config')
-{
- echo 'graph_title Apache vhosts' . "\n";
-
- echo 'graph_info Shows the requests per second for each vhost.' . "\n";
- echo 'graph_vlabel requests / ${graph_period}' . "\n";
- echo 'graph_category apache' . "\n";
- echo 'graph_args --lower-limit 0' . "\n";
- echo 'graph_scale yes' . "\n";
-
- $first = TRUE;
- foreach($files as $domain)
- {
- if(substr($domain, 0, 1) != '.')
- {
- $key = generate_munin_key($domain);
- echo $key . '.label ' . $domain . "\n";
- echo $key . '.min 0' . "\n";
- echo $key . '.type DERIVE' . "\n";
- echo $key . '.draw ' . ($first ? 'AREA' : 'STACK') . "\n";
- $first = FALSE;
- }
- }
-}
-else
-{
- foreach($files as $domain)
- {
- if(substr($domain, 0, 1) != '.')
- {
- $key = generate_munin_key($domain);
- $value = filesize($basedir . '/' . $domain) / 2;
- echo $key . '.value ' . $value . "\n";
- }
- }
-}
-
-function generate_munin_key($domain)
-{
- return preg_replace(array('/\./', '/[^a-z0-9_]/'), array('_', ''), $domain);
-}
-?>
+#!/usr/bin/php
+<?php
+/**
+ * README
+ *
+ * Add an additional line to each vhost you want to track with the domain name of the host
+ * This will write a period for every hit to the vhost
+ * CustomLog /web/logs/munin/example.com "."
+ */
+
+if(!array_key_exists('basedir', $_SERVER)) {
+ echo "Add configuration for basedir:\n\t[apache_vhosts]\n\tenv.basedir /web/logs/munin\n";
+ die(2);
+}
+
+$basedir = $_SERVER['basedir'];
+$files = scandir($basedir);
+
+// arg1 is blank or 'config' when munin runs it
+$mode = array_key_exists(1, $argv) ? $argv[1] : '';
+
+
+if($mode == 'config')
+{
+ echo 'graph_title Apache vhosts' . "\n";
+
+ echo 'graph_info Shows the requests per second for each vhost.' . "\n";
+ echo 'graph_vlabel requests / ${graph_period}' . "\n";
+ echo 'graph_category apache' . "\n";
+ echo 'graph_args --lower-limit 0' . "\n";
+ echo 'graph_scale yes' . "\n";
+
+ $first = TRUE;
+ foreach($files as $domain)
+ {
+ if(substr($domain, 0, 1) != '.')
+ {
+ $key = generate_munin_key($domain);
+ echo $key . '.label ' . $domain . "\n";
+ echo $key . '.min 0' . "\n";
+ echo $key . '.type DERIVE' . "\n";
+ echo $key . '.draw ' . ($first ? 'AREA' : 'STACK') . "\n";
+ $first = FALSE;
+ }
+ }
+}
+else
+{
+ foreach($files as $domain)
+ {
+ if(substr($domain, 0, 1) != '.')
+ {
+ $key = generate_munin_key($domain);
+ $value = filesize($basedir . '/' . $domain) / 2;
+ echo $key . '.value ' . $value . "\n";
+ }
+ }
+}
+
+function generate_munin_key($domain)
+{
+ return preg_replace(array('/\./', '/[^a-z0-9_]/'), array('_', ''), $domain);
+}
+?>

0 comments on commit e9d5515

Please sign in to comment.