Skip to content

Commit

Permalink
- adding scripts contributed by Uwe Steinmann <uwe@steinmann.cx>
Browse files Browse the repository at this point in the history
  for monitoring linux load w/o SNMP and Apple systems battery status
  with a PMU
- incorporating modifications to linux26diskaccess.pl
  (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=412549)
  • Loading branch information
Douglas E. Warner committed May 29, 2007
1 parent 77087ad commit 8b1ac12
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 54 deletions.
13 changes: 13 additions & 0 deletions contrib/linuxpmu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# Author: Uwe Steinmann <uwe@steinmann.cx>

# usage linuxpmu.sh <battery number> <command>
# battery number can be 0 or 1
# command can be 'charge', 'max_charge', 'current', 'voltage'

if [ -f /proc/pmu/battery_$1 ]; then
cat /proc/pmu/battery_$1 | grep "^$2 *:" | awk -F: '{print $2}'
else
echo "U"
fi
101 changes: 51 additions & 50 deletions libexec/linux26diskaccess.pl
Original file line number Diff line number Diff line change
@@ -1,81 +1,82 @@
#!/usr/bin/perl
#
# linux26diskaccess.pl
#
# reports some disk access counters
#
# # reads issued, # writes issued
#

use strict;

### config variables
my $sysblock = "/sys/block";
### status variables
my $partition = "";
my $blockdev = "";
my @fields = ();
my $blockdev = "/sys/block";


### argument processing
if (scalar(@ARGV) != 2
|| ($ARGV[0] ne "-r" && $ARGV[0] ne "-w")
|| ($ARGV[1] !~ /^\w+(\d+)?$/)
)
if (@ARGV != 2 or
$ARGV[0] !~ /^-[rw]b?$/ or
$ARGV[1] !~ /^\w+(?:\d+)?$/)
{
print "U\n";
print "\n";
print "$0 [-r|-w] <blockDev(N)>\n";
print " -r: Report Reads\n";
print " -w: Report Writes\n";
print "$0 [-r|-rb|-w|-wb] <dev(N)>\n";
print "\n";
exit(1);
} # end if not enough parameters
print "Reports disk I/O statistics counters for use as a NetMRG test script.\n";
print "\n";
print "Options:\n";
print " -r Report the number of read operations\n";
print " -rb Report the number of read blocks\n";
print " -w Report the number of write operations\n";
print " -wb Report the number of written blocks\n";
print " dev(n) Is a relative block device or partition name.\n";
print " For instance hda, hda1 or md0\n";
print "\n";
exit 1;
}


### define partitions
$partition = $ARGV[1];
$blockdev = $1 if ($partition =~ /^(\w+)\d+$/);
### figure out device/partitions
my ($hd, $partition);
if ($ARGV[1] =~ /^(hd\w)\d+$/)
{
$partition = $ARGV[1];
$hd = $1;
} # end if hd has a partition
else
{
$hd = $ARGV[1];
} # end else hd is just the drive


### read info from system block

# read the data from the correct path
my $path = "";
if (-e "$sysblock/$blockdev/$partition/stat")
{
$path = "$sysblock/$blockdev/$partition/stat";
}
elsif (-e "$sysblock/$partition/stat")
my $path = "$blockdev/$hd";
$path .= "/$partition" if ($partition ne "");
$path .= "/stat";
open(STAT, $path) || die ("U\nERROR: couldn't open $path\n\n");
my $line = <STAT>;
close(STAT);
chomp($line);
$line =~ s/^\s+//;
my ($read, $readb, $write, $writeb);
if ($partition eq "")
{
$path = "$sysblock/$partition/stat";
($read, $readb, $write, $writeb)=(split /\s+/, $line)[0, 2, 4, 6];
}
else
{
die ("U\nERROR: couldn't find $partition\n\n");
($read, $readb, $write, $writeb)=split /\s+/, $line;
}

# open the path and read the status info
open(STAT, $path) || die ("U\nERROR: couldn't open $path\n\n");
my $line = <STAT>;
chomp($line);
@fields = split /\s+/, $line;
close(STAT);


### output the data
if ($ARGV[0] eq "-r")
{
print $fields[1]."\n";
} # end if read statistics
print "$read\n";
}
elsif ($ARGV[0] eq "-w")
{
print $fields[5]."\n" if ($partition eq "");
print $fields[3]."\n" if ($partition ne "");
} # end if write statistics
else
print "$write\n";
}
elsif ($ARGV[0] eq "-rb")
{
print "U\n";
} # else we don't know what happened


print "$readb\n";
}
elsif ($ARGV[0] eq "-wb")
{
print "$writeb\n";
}
12 changes: 12 additions & 0 deletions libexec/linuxload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Author: Uwe Steinmann <uwe@steinmann.cx>

# usage linuxload.sh <item>
# item can be 1, 2, or 3

if [ -f /proc/loadavg -a "$1" != "" -a $1 -ge 1 -a $1 -le 3 ]; then
cut -d' ' -f$1 /proc/loadavg
else
echo "U"
fi
7 changes: 7 additions & 0 deletions share/doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2007.05.29 v0.20cvs silfreed
- adding scripts contributed by Uwe Steinmann <uwe@steinmann.cx>
for monitoring linux load w/o SNMP and Apple systems battery status
with a PMU
- incorporating modifications to linux26diskaccess.pl
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=412549)

2007.05.14 v0.20cvs silfreed
- updated wiki.netmrg.net to mediawiki 1.10.0

Expand Down
111 changes: 107 additions & 4 deletions www/lib/graphing.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ function monitor_graph_command($id, $timeframe)
" --title=" . escapeshellarg(get_monitor_name($id) . " (#" . $id . ")") . " --imgformat PNG -g -w 575 -h 100 " .
"DEF:data1=" . $GLOBALS['netmrg']['rrdroot'] . "/mon_" . $id . ".rrd:mon_" . $id . ":AVERAGE " .
"AREA:data1#151590");

}

function tiny_monitor_graph_command($id, $timeframe)
Expand Down Expand Up @@ -234,9 +233,12 @@ function custom_graph_command($id, $timeframe, $templated, $single_ds)

// initial definition
$command = $GLOBALS['netmrg']['rrdtool'] . " graph - " . rrd_slope() . rrd_watermark() . " -s " . $timeframe['start_time'] .
" -e " . $timeframe['end_time'] . $boundary . " --title " . $graph_row["title"] . " -w " .
$graph_row["width"] . " -h " . $graph_row["height"] . $options . "-b " . $graph_row["base"] . " -v " .
$graph_row["vert_label"] . " --imgformat PNG $options";
" -e " . $timeframe['end_time'] . $boundary .
" --title " . $graph_row["title"] .
" -w " . $graph_row["width"] . " -h " . $graph_row["height"] .
$options .
"-b " . $graph_row["base"] . " -v " . $graph_row["vert_label"] .
" --imgformat PNG $options";

// setup condition to only display non-AVERAGE items on graphs
$ew = "";
Expand Down Expand Up @@ -486,4 +488,105 @@ function custom_graph_command($id, $timeframe, $templated, $single_ds)
return($command);
}

/**
* Gets the graph view
*/
function get_graph_view($graph_data)
{
case "graph":
echo ' <div class="viewgraph">'."\n";
$local_graph_type = 'custom';
echo ' <div class="viewgraph-title">'.$row['title']."</div>\n";
echo ' <div class="viewgraph-image">' . "\n";
echo ' <a href="enclose_graph.php?type=custom&amp;id='.$row["graph_id"].'">'."\n";
echo ' <img src="get_graph.php?type=custom&amp;id='.$row["graph_id"].$hist.'" alt="" />'."\n";
echo " </a>\n";
echo ' </div>' . "\n";
echo ' <div class="viewgraph-controls">'."\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=history">' . "\n" .
' <img src="'.get_image_by_name("slideshow").'" width="15" height="15" ' .
'border="0" alt="History" title="History" />' . "\n" .
' </a>'."\n";
echo " </div>\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=dissect">' . "\n" .
' <img src="'.get_image_by_name('disk').'" width="15" height="15" ' .
'border="0" alt="Dissect" title="Dissect" />' . "\n" .
' </a>' . "\n";
echo " </div>\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=advanced">' . "\n" .
' <img src="'.get_image_by_name('duplicate').'" width="15" height="15" ' .
'border="0" alt="Advanced" title="Advanced" />' . "\n" .
' </a>' . "\n";
echo " </div>\n";
echo " </div>\n";
echo " </div>\n";
break;

case "template":
$nh_res = db_query("SELECT value FROM sub_dev_variables WHERE sub_dev_id={$row['subdev_id']} AND name='nexthop'");
$link = "";
if ($nh_row = db_fetch_array($nh_res)) // next hop located
{
$nhd_res = db_query("SELECT dev_id FROM sub_devices WHERE id = {$nh_row['value']}");
if ($nhd_row = db_fetch_array($nhd_res))
{
$link = "Next Hop: <a href=\"view.php?action=view&object_type=device&object_id={$nhd_row['dev_id']}\">" . get_dev_sub_device_name($nh_row['value']) . "</a>";
}
}
echo ' <div class="viewgraph">'."\n";
$local_graph_type = 'template';
echo ' <div class="viewgraph-title">'.expand_parameters($row['title'], $row['subdev_id'])."</div>\n";
echo ' <div class="viewgraph-image">' . "\n";
echo ' <a href="enclose_graph.php?type=template&amp;id='.$row["graph_id"].'&amp;subdev_id='.$row["subdev_id"].'">'."\n";
echo ' <img src="get_graph.php?type=template&amp;id='.$row["graph_id"].'&amp;subdev_id='.$row["subdev_id"].$hist.'" alt="" />'."\n";
echo " </a>\n";
echo ' </div>' . "\n";
echo ' <div class="viewgraph-controls">'."\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"subdev_id={$row['subdev_id']}&" .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=history">' . "\n" .
' <img src="'.get_image_by_name("slideshow").'" width="15" height="15" ' .
'border="0" alt="History" title="History" />' . "\n" .
' </a>'."\n";
echo " </div>\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"subdev_id={$row['subdev_id']}&" .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=dissect">' . "\n" .
' <img src="'.get_image_by_name('disk').'" width="15" height="15" ' .
'border="0" alt="Dissect" title="Dissect" />' . "\n" .
' </a>' . "\n";
echo " </div>\n";
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' <a href="enclose_graph.php?' .
"subdev_id={$row['subdev_id']}&" .
"type=$local_graph_type&id={$row['graph_id']}" .
'&action=advanced">' . "\n" .
' <img src="'.get_image_by_name('duplicate').'" width="15" height="15" ' .
'border="0" alt="Advanced" title="Advanced" />' . "\n" .
' </a>' . "\n";
echo " </div>\n";
if (!empty($link))
{
echo ' <div class="viewgraph-shortcut">'."\n";
echo ' ' . $link . "\n";
echo ' </div>' . "\n";
}
echo " </div>\n";
echo " </div>\n";
break;
}

?>

0 comments on commit 8b1ac12

Please sign in to comment.