This file is indexed.

/usr/share/munin/plugins/nvidia_ is in munin-node 1.4.6-3ubuntu3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/usr/bin/perl -w
# -*- cperl -*-

use strict;

use Munin::Plugin;

my @dircomponents = split('/',$0);
my $me = pop(@dircomponents);

my @suggest=qw(temp clock volt);

=head1 NAME

nvidia_ - Munin wildcard plugin to monitor nvidia graphics cards with
the help of the nvclock command.

Run as nvidia_temp, nvidia_clock or nvidia_volt

=cut

=head1 APPLICABLE SYSTEMS

Any system with a nvclock command.  Currently this is available on
Linux, FreeBSD and Windows.

=head1 CONFIGURATION

Usually none is needed.  This shows the default configuration:

  [nvidia_*]
     env.nvclock = /usr/bin/nvclock

=cut

my $nvclock = $ENV{nvclock} || '/usr/bin/nvclock';

=head1 INTERPRETATION

The plugin invoked under the different aliases listed above will run
the nvclock command and show the different measurements as found in
the output of the program.

=head1 VERSION

  $Id: nvidia_.in 3283 2010-01-04 13:26:14Z knan $

Tested with nvclock version 0.8b3a on a nVidia Geforce 8600GT.

=head1 BUGS

None known

=head1 FEATURES

Requires Munin::Plugin as supplied in Munin 1.3.3 and 1.2.5.  If the
plugin complains about "Use of uninitialized value in string eq at
/usr/lib/perl/5.8/lib.pm line 29." and so on please make this plugin
configuration:

  [*]
	env.MUNIN_LIBDIR /usr/share/munin

using the correct LIBDIR for your installation of course (the other
standard value is /opt/munin/lib).


=head1 AUTHOR

Copyright (C) 2008-2009 Nicolai Langfeldt / Linpro AS, Oslo

=head1 LICENSE

GPLv2

=head1 MAGIC MARKERS

  #%# family=auto
  #%# capabilities=autoconf suggest

=cut

delete $ENV{'DISPLAY'};

sub collect_and_print ($$) {

  my ($todo,$function)=@_;

  my $cardinfo;

  my $config = $todo eq 'config';

  my $NVC;

  open($NVC,"$nvclock -i |") or die "Could not run $nvclock: $!\n";

  my @nvclock;

  @nvclock = <$NVC>;
  close($NVC) or die "Could not close command $nvclock: $!\n";

  my $section;

  foreach (@nvclock) {

    if (/^-- (.*) --/) {
      $section=$1;

      # Remove the "info" or "informaiton" part
      $section =~ s/\s+info.*//;

      next;
    }

    my ($key,$value);
    ( $key,$value ) = split(':\s+',$_,2);

    next if ! defined($value);

    chomp $value;

    # Preprocessing special cases
    ($key eq 'Clock'  ) && do { $key = "$section $key"; };
    ($key eq 'Card'   ) && do { $cardinfo = $value; };
    ($key eq 'Version') && do { $cardinfo .= " Version $value"; };
    ($key =~ /^Signon/) && do { $cardinfo .= " $value"; };
    ($key eq 'Amount' ) &&
      ($section eq 'Memory') && do { $cardinfo .= ", with $value"; };
    ($key =~ 'Type'   ) &&
      ($section eq 'Memory') && do { $cardinfo .= " $value memory"; };

    # Yes, the apperance of the $cardinfo related things will be
    # fairly order sensitive, tell me if it breaks.

    my $label = clean_fieldname($key);

    # Processing each case of the plugin

    ($key =~ /voltage/i) && ($function eq 'volt') && do {
      if ($config) {
	print "$label.label $key\n";
	print "$label.type GAUGE\n";
      } else {
	my ($volt) = $value =~ m/\s*(\d+\.\d+)V/;
	$volt = 'U' unless defined $volt;
	print "$label.value $volt\n";
      }
      next;
    };

    ($key =~ /clock/i) && ($function eq 'clock') && do {
      if ($config) {
	print "$label.label $key\n";
	print "$label.type GAUGE\n";
      } else {
	my ($hz,$scale) = $value =~ m/\s*(\d+\.\d+)\s*([Mk]?)Hz/;
	if (defined($hz)) {
	  $scale = '' unless defined($scale);
	  $hz=$hz*1000*1000 if $scale eq 'M';
	  $hz=$hz*1000 if $scale eq 'k';
	} else {
	  $hz='U';
	}
	print "$label.value $hz\n";
      }
      next;
    };

    ($key =~ /temp/i) && ($function eq 'temp') && do {
      if ($config) {
	print "$label.label $key\n";
	print "$label.type GAUGE\n";
      } else {
	my ($temp) = $value =~ m/\s*(\d+(\.\d+)?)C/;
	$temp='U' unless defined($temp);
	print "$label.value $temp\n";
      }
      next;
    }
  }

  if ($config) {
    if ($function eq 'volt') {
      print "graph_title Voltages of NVidia graphics card\n";
      print "graph_vtitle Voltage\n";
    } elsif ($function eq 'clock') {
      print "graph_title Clock speeds of NVidia graphics card\n";
      print "graph_vtitle Hz\n";
    } elsif ($function eq 'temp') {
      print "graph_title Temperatures of NVidia graphics card\n";
      print "graph_vtitle Degrees Celcius\n";
    } else {
      die "$me: Unknown function!\n";
    }
    print "graph_category sensors\n";
    print "graph_info Graphics card is a $cardinfo\n";
  }
}


# Main

my ($function) = ( $me =~ m/.*_(.*)/ );

if (defined($ARGV[0])) {
  if ($ARGV[0] eq 'autoconf') {
    if (-x $nvclock) {
      print "yes\n";
      exit 0;
    } else {
      print "no (no nvclock executable at $nvclock, please configure)\n";
      exit 0;
    }
  } elsif ($ARGV[0] eq 'suggest') {
    print join("\n",@suggest),"\n";
    exit 0;
  } elsif ($ARGV[0] eq 'config') {
    collect_and_print('config',$function);
    exit 0;
  } elsif ($ARGV[0] eq '') {
    collect_and_print('fetch',$function);
    exit 0;
  } else {
    die "$me: Unknown argument: $ARGV[0]\n";
  }
} else {
  collect_and_print('fetch',$function);
  exit 0;
}

die "$me: Running over the edge of the plugin.  Why?"