-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_netapp.pl
executable file
·2613 lines (1907 loc) · 113 KB
/
check_netapp.pl
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -X
#
# Nagios probe for checking a NetApp filer
#
# Copyright (c) 2016 Piotr Kasprzak
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Installation:
# -------------
#
# 1.) perl module dependencies:
#
# - lwp-useragent
# - xml-parser
# - Monitoring::Plugin
# - Log::Log4perl
# - Net::SSLeay
#
# e.g.:
#
# port install p5.16-lwp-useragent-determined
# port install p5.16-xml-parser
#
# perl -MCPAN -e shell
# cpan> install Monitoring::Plugin (For Nagios stuff)
# cpan> install Log::Log4perl (For logging)
# cpan> install JSON (For json rendering in caching files)
# cpan> install File::Slurp
# cpan> install Switch (CHORNY/Switch-2.17.tar.gz)
# cpan> install Clone (GARU/Clone-0.37.tar.gz)
# cpan> install Net::Graphite (v0.16)
# cpan> install IO::Async (For Timer loop: IO::Async::Timer::Periodic, v0.70)
# cpan> install Time::HiRes (For high resolution (ms) times, v1.9732)
#
# 2.) Get NetApp perl SDK
#
# - Download netapp-manageability-sdk-5.3 from http://support.netapp.com/NOW/cgi-bin/software
# - Copy lib/perl/NetApp directory with the perl modules to somewhere where it can be found by perl
#
# - Find API documentation here:
# ./netapp-manageability-sdk-5.4P1/doc/perldoc/Ontap7ModeAPI.html#perf_object_get_instances
#
#
# Range format (for -w or -c):
# ----------------------------
#
# Generate an alert if x...
# 10 < 0 or > 10, (outside the range of {0 .. 10})
# 10: < 10, (outside {10 .. ∞})
# ~:10 > 10, (outside the range of {-∞ .. 10})
# 10:20 < 10 or > 20, (outside the range of {10 .. 20})
# @10:20 ≥ 10 and ≤ 20, (inside the range of {10 .. 20})
#
#
# Examples:
# ---------
#
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -s aggregate=<aggregate-name> -s nfsv3
#
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -s volume=<vol1-name> -s volume=<vol2-name> -s sis=use_volumes
#
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -s interface=all
#
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -l objects
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -l counters=<object-name>
# check_netapp.pl -H <filer-ip> -U <user> -P <password> -l instances=<object-name>
#
# To do:
# -----
#
# -
# - Make it possible to filter counter (white list)
# - Set units for processor performance counter and equivalent definitions
#
use strict;
use warnings;
#no warnings;
use locale;
use Data::Dumper;
use Switch;
use Clone qw(clone);
# Need to be installed from CPAN
use File::Slurp;
use Monitoring::Plugin;
use Log::Log4perl;
use JSON;
use Net::Graphite;
use IO::Async::Timer::Periodic;
use IO::Async::Loop;
use Time::HiRes;
# NetApp SDK
use lib "./NetApp";
use NaServer;
use NaElement;
# How often to retry to connect when failing to connect to NetApp API endpoint
use constant MAX_RETRIES => 3;
# How long to wait between reconnects in ms
use constant SLEEP_ON_ERROR_MS => 1000;
# Standard variables used in Monitoring::Plugin constructor
my $PROGNAME = 'check_netapp';
my $VERSION = '2.0';
my $DESCRIPTION = 'Probe for checking a NetApp filer. Examples:\n' .
'check_netapp.pl -H <filer-ip> -U <user> -P <password> -s aggregate=<aggregate-name>\n' .
'check_netapp.pl -H <filer-ip> -U <user> -P <password> -s processor\n' .
'check_netapp.pl -H <filer-ip> -U <user> -P <password> -s nfsv3\n' .
'check_netapp.pl -H <filer-ip> -U <user> -P <password> -s system';
my $EXTRA_DESC = '';
my $SHORTNAME = 'CHECK_NETAPP';
my $LICENSE = 'This nagios plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Copyright 2016 Piotr Kasprzak';
# ---------------------------------------------------------------------------------------------------------------------
# Initialize logger
my $log4j_conf = q(
log4perl.category.GWDG.NetApp = INFO, Screen, Logfile
# log4perl.category.GWDG.NetApp = DEBUG, Logfile
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = /var/log/check_netapp.log
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern = [%d %F:%M:%L] %m%n
log4perl.appender.Screen = Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 0
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = [%d %F:%M:%L] %m%n
);
Log::Log4perl::init(\$log4j_conf);
our $log = Log::Log4perl::get_logger("GWDG::NetApp");
# ---------------------------------------------------------------------------------------------------------------------
# Unit map
our %unit_map = ( 'none' => '',
'per_sec' => 'op/s',
'millisec' => 'ms',
'microsec' => 'us',
'percent' => '%',
'kb_per_sec' => 'KB/s',
'sec' => 's'
);
# ---------------------------------------------------------------------------------------------------------------------
# Helper functions
sub trim {
my $s = shift;
if ($s) {
$s =~ s/^\s+|\s+$//g;
}
return $s
};
# ---------------------------------------------------------------------------------------------------------------------
# Create tmp file name from some identifiers
sub get_tmp_file {
our $plugin;
# Array of identifiers to be concatenated in the file name
my $identifiers = shift;
# Instance to use (i.e. aggregate / volume name, etc.)
my $instance = shift;
my $prefix = 'check_netapp_fas';
my $postfix = '.json';
my $separator = '_';
my $tmp_file = $plugin->opts->tmp_dir . '/' . $prefix . '.' . $plugin->opts->hostname . '.';
foreach my $identifier (@$identifiers) {
$tmp_file .= $identifier . $separator;
}
# Remove last separator
$tmp_file = substr($tmp_file, 0, length($tmp_file) - 1);
if ($instance) {
$tmp_file .= '.' . $instance;
}
$tmp_file .= $postfix;
$log->debug("Created tmp file name: $tmp_file");
return $tmp_file;
}
# ---------------------------------------------------------------------------------------------------------------------
# Establish connection to filer
sub connect_to_filer {
# Get server context
our $plugin;
our $filer = NaServer->new($plugin->opts->hostname, 1, 15);
$filer->set_admin_user($plugin->opts->user, $plugin->opts->password);
$filer->set_bindings_family('7-Mode');
$filer->set_transport_type($plugin->opts->protocol);
}
# ---------------------------------------------------------------------------------------------------------------------
# Print list of perf objects (perf-object-list-info)
sub call_api {
my $request = shift;
$log->info("API request: " . $request->{name});
if ($log->is_debug()) {
$log->debug("API request content:\n" . $request->sprintf());
}
my $i = 1;
while ($i <= MAX_RETRIES) {
my $result = $main::filer->invoke_elem($request);
if ($log->is_debug()) {
$log->debug("API response content:\n" . $result->sprintf())
}
# Check for error
if ($result->results_status() eq 'failed') {
$log->error("API request failed: " . $result->results_reason());
$log->error("=> Reconnecting and retrying (try $i of " . MAX_RETRIES . ")");
Time::HiRes::usleep(SLEEP_ON_ERROR_MS);
connect_to_filer();
$i++;
} else {
# Success
return $result;
}
}
# Nothing we can do
return;
}
# ---------------------------------------------------------------------------------------------------------------------
# Print list of perf objects (perf-object-list-info)
sub list_perf_objects {
$log->info("Listing all performance objects:");
my $request = NaElement->new('perf-object-list-info');
my $result = call_api($request) || return;
foreach ($result->child_get('objects')->children_get()) {
my $name = $_->child_get_string('name');
my $level = $_->child_get_string('privilege-level');
$log->info(sprintf("%30s: %10s", $name, $level));
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Print list of perf objects instances (perf_object_instance_list_info)
sub list_perf_object_instances {
# Perf. object to list all instances of
my $perf_object = shift;
$log->info("Listing all instances of performance object [$perf_object]:");
my $request = NaElement->new('perf-object-instance-list-info');
$request->child_add_string('objectname', $perf_object);
my $result = call_api($request) || return;
foreach ($result->child_get('instances')->children_get()) {
my $name = $_->child_get_string('name');
$log->info(sprintf("%30s", $name));
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Print list of perf objects counter instances (perf_object_instance_list_info)
sub list_perf_object_counter_instances {
# Perf. object to list all instances of
my $perf_object = shift;
$log->info("Listing all counter descriptions of performance object [$perf_object]:");
my $request = NaElement->new('perf-object-counter-list-info');
$request->child_add_string('objectname', $perf_object);
my $result = call_api($request) || return;
foreach my $na_element ($result->child_get('counters')->children_get()) {
$log->info(sprintf("%20s: %30s", 'name', $na_element->child_get_string('name')));
$log->info(sprintf("%20s: %30s", 'desc', $na_element->child_get_string('desc')));
$log->info(sprintf("%20s: %30s", 'privilege-level', $na_element->child_get_string('privilege-level')));
$log->info(sprintf("%20s: %30s", 'properties', $na_element->child_get_string('properties')));
$log->info(sprintf("%20s: %30s", 'unit', $na_element->child_get_string('unit')));
$log->info(sprintf("%20s: %30s", 'base-counter', $na_element->child_get_string('base-counter')));
$log->info(sprintf("%20s: %30s", 'type', $na_element->child_get_string('type')));
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Print list of perf objects (perf-object-list-info)
sub load_perf_object_counter_descriptions {
my $perf_object = shift;
our $perf_object_counter_descriptions;
$log->info("Loading performance counter descriptions for object: $perf_object");
# Try to load from file first
my @identifiers = ('perf', 'object', 'counter', 'descriptions');
my $cache_file = get_tmp_file (\@identifiers, $perf_object);
my $counter_descriptions = read_hash_from_file($cache_file, 0);
if (! %$counter_descriptions) {
# No cache file yet -> load data from API and persist in file for later.
$log->info("No cache file found, loading from API...");
my $request = NaElement->new('perf-object-counter-list-info');
$request->child_add_string('objectname', $perf_object);
my $result = call_api($request) || return;
foreach my $na_element ($result->child_get('counters')->children_get()) {
my $counter_description = {};
$counter_description->{'name'} = $na_element->child_get_string('name');
$counter_description->{'privilege_level'} = $na_element->child_get_string('privilege-level');
$counter_description->{'desc'} = $na_element->child_get_string('desc');
$counter_description->{'properties'} = $na_element->child_get_string('properties');
$counter_description->{'unit'} = $na_element->child_get_string('unit');
$counter_description->{'base_counter'} = $na_element->child_get_string('base-counter');
$counter_description->{'type'} = $na_element->child_get_string('type');
# Need special processing stuff for processor objects
if (! ($perf_object eq 'processor')) {
# Standard counter description
$counter_descriptions->{$counter_description->{'name'}} = $counter_description;
} else {
# Get number of processors
our $static_system_stats;
my $processor_count = $static_system_stats->{'num_processors'};
# Create for each processor instance a set of counter descriptions
foreach my $processor (0 .. $processor_count - 1) {
unless (defined $counter_description->{'type'} and $counter_description->{'type'} eq 'array') {
my $new_counter_name = 'processor' . $processor . '_' . $counter_description->{'name'};
my $new_counter_description = clone($counter_description);
$new_counter_description->{'name'} = $new_counter_name;
$counter_descriptions->{$new_counter_description->{'name'}} = $new_counter_description;
} else {
# For type == array we need to process the labels
my @labels = split(',', $na_element->child_get('labels')->child_get_string('label-info'));
foreach my $label (@labels) {
my $new_counter_name = 'processor' . $processor . '_' . $counter_description->{'name'} . '_' . $label;
my $new_base_counter = 'processor' . $processor . '_' . $counter_description->{'base_counter'};
my $new_counter_description = clone($counter_description);
$new_counter_description->{'name'} = $new_counter_name;
$new_counter_description->{'base_counter'} = $new_base_counter;
delete $new_counter_description->{'type'};
$counter_descriptions->{$new_counter_description->{'name'}} = $new_counter_description;
}
}
}
}
}
# Persist to file
write_hash_to_file($cache_file, $counter_descriptions);
}
# Make descriptions available for later
$perf_object_counter_descriptions->{$perf_object} = $counter_descriptions;
}
# ---------------------------------------------------------------------------------------------------------------------
# Calc counter value based on it's description and values at times t-1 and t
sub calc_counter_value {
my $counter_name = shift;
my $perf_object = shift;
my $current_perf_data = shift;
my $old_perf_data = shift;
our $perf_object_counter_descriptions;
$log->debug("Calculating value of counter [$counter_name] of perf object [$perf_object]");
# Get counter descriptions. If no descriptions available yet, load them!
if (! $perf_object_counter_descriptions->{$perf_object}) {
load_perf_object_counter_descriptions($perf_object);
}
my $counter_descriptions = $perf_object_counter_descriptions->{$perf_object};
my $counter_description = $counter_descriptions->{$counter_name};
# Check, if there is a description for the selected counter
if (! defined $counter_description or ! %$counter_description) {
$log->debug("No description found for counter [$counter_name] of perf object [$perf_object]!");
return;
} else {
$log->debug("Using description:\n" . Dumper($counter_description));
}
# Finally, calculate the value depending on the description
switch (lc($counter_description->{'properties'})) {
case 'raw' {
# Just return raw value
return $current_perf_data->{$counter_name};
}
case 'rate' {
# (c2 - c1) / (t2 - t1)
my $time_delta = $current_perf_data->{'timestamp'} - $old_perf_data->{'timestamp'};
my $counter_value = ($current_perf_data->{$counter_name} - $old_perf_data->{$counter_name}) / $time_delta;
return $counter_value;
}
case 'delta' {
# c2 - c1
my $counter_value = $current_perf_data->{$counter_name} - $old_perf_data->{$counter_name};
return $counter_value;
}
case 'average' {
# (c2 - c1) / (b2 - b1)
my $base_counter_name = $counter_description->{'base_counter'};
$log->debug("Using base counter [$base_counter_name] for calculation for counter [$counter_name].");
unless ($current_perf_data->{$base_counter_name} and $old_perf_data->{$base_counter_name}) {
$log->debug("Base counter [$base_counter_name] not available in perf data (needed for calculation of counter [$counter_name])!");
return 0;
}
my $current_base_counter_data = $current_perf_data->{$base_counter_name};
my $old_base_counter_data = $old_perf_data->{$base_counter_name};
if ($current_base_counter_data == $old_base_counter_data) {
$log->warn("Old and new base counter [$base_counter_name] equal -> returning 0 to prevent division by zero.");
return 0;
}
my $counter_value = ($current_perf_data->{$counter_name} - $old_perf_data->{$counter_name}) /
($current_base_counter_data - $old_base_counter_data);
return $counter_value;
}
case 'percent' {
# 100 * (c2 - c1) / (b2 - b1)
my $base_counter_name = $counter_description->{'base_counter'};
$log->debug("Using base counter [$base_counter_name] for calculation for counter [$counter_name].");
unless ($current_perf_data->{$base_counter_name} and $old_perf_data->{$base_counter_name}) {
$log->debug("Base counter [$base_counter_name] not available in perf data (needed for calculation of counter [$counter_name])!");
return 0;
}
my $current_base_counter_data = $current_perf_data->{$base_counter_name};
my $old_base_counter_data = $old_perf_data->{$base_counter_name};
my $counter_value = ($current_perf_data->{$counter_name} - $old_perf_data->{$counter_name}) /
($current_base_counter_data - $old_base_counter_data);
return 100 * $counter_value;
}
case 'text' {
# Just text
return $current_perf_data->{$counter_name};
}
case 'string' {
# Just text
return $current_perf_data->{$counter_name};
}
case 'nodisp' {
# Used for calculations (average, percent), should not be displayed directly
$log->warn("This counter has the 'nodisp' property and should not be displayed directly!");
return $current_perf_data->{$counter_name};
}
else {
# Unknown properties value
$log->error("Unkown properties value, just returning the current counter value!");
return $current_perf_data->{$counter_name};
}
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Get unit of a counter value based on it's description
sub get_unit {
our $perf_object_counter_descriptions;
our %unit_map;
my $counter_name = shift;
my $perf_object = shift;
my $orig_unit_name = $perf_object_counter_descriptions->{$perf_object}->{$counter_name}->{'unit'};
my $transformed_unit_name = '?';
if (exists($unit_map{$orig_unit_name})) {
$transformed_unit_name = $unit_map{$orig_unit_name};
}
return $transformed_unit_name;
}
# ---------------------------------------------------------------------------------------------------------------------
# Read hash from file (in JSON format)
sub read_hash_from_file {
my $file = shift;
my $delete_file_after_reading = shift;
our $json_parser;
my $hash_data = {};
if (-f $file) {
$log->debug("Loading data from file: $file");
my $hash_data_json = read_file($file);
# Convert JSON to array
$hash_data = $json_parser->decode($hash_data_json);
if ($log->is_debug()) {
$log->debug(Dumper($hash_data));
}
# Delete old file
if ($delete_file_after_reading) {
unlink $file;
}
}
return $hash_data;
}
# ---------------------------------------------------------------------------------------------------------------------
# Write perf data to file (in JSON format)
sub write_hash_to_file {
my $file = shift;
my $hash_data = shift;
our $json_parser;
# Encode hash in JSON string
my $hash_data_json = $json_parser->pretty->encode($hash_data);
# Write to file
write_file($file, $hash_data_json);
}
# ---------------------------------------------------------------------------------------------------------------------
# Check perf metrics in hash for warning / critical ranges
sub check_perf_data {
our $probe_status_output;
our $plugin;
our (%warning_defs, %critical_defs);
our (@warning, @critical);
my $perf_data = shift;
my $perf_data_count = scalar @$perf_data;
$log->debug("Checking [$perf_data_count] perf counter metrics for critical / warning ranges...");
foreach my $counter (@$perf_data) {
# Check for warning ranges
if (exists($warning_defs{$counter->{'name'}})) {
$plugin->set_thresholds(warning => $warning_defs{$counter->{'name'}});
my $check_result = $plugin->check_threshold($counter->{'value'});
if ($check_result == WARNING) {
my $message = $counter->{'name'} . ' (' . $counter->{'value'} . ') in range "' . $warning_defs{$counter->{'name'}} . '"';
$log->debug('Warning: ' . $message);
push(@warning, $message);
}
}
# Check for critical ranges
if (exists($critical_defs{$counter->{'name'}})) {
$plugin->set_thresholds(critical => $critical_defs{$counter->{'name'}});
my $check_result = $plugin->check_threshold($counter->{'value'});
if ($check_result == CRITICAL) {
my $message = $counter->{'name'} . ' (' . $counter->{'value'} . ') in range "' . $critical_defs{$counter->{'name'}} . '"';
$log->debug('Critical: ' . $message);
push(@critical, $message);
}
}
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Get basic system stats
sub get_static_system_stats {
$log->info("Getting basic system stats...");
my @identifiers = ('static', 'system', 'stats');
my $tmp_file = get_tmp_file (\@identifiers);
# Try to load old counters from file and persist new ones insted
my $static_system_stats = read_hash_from_file($tmp_file, 0);
if (%$static_system_stats) {
return $static_system_stats;
}
# No cache file -> get data from API
my $request = NaElement->new('perf-object-get-instances');
$request->child_add_string('objectname', 'system');
my $counters = NaElement->new('counters');
# ----- Static system description information -----
$counters->child_add_string('counter', 'hostname');
$counters->child_add_string('counter', 'instance_name');
$counters->child_add_string('counter', 'instance_uuid');
$counters->child_add_string('counter', 'node_name');
$counters->child_add_string('counter', 'num_processors');
$counters->child_add_string('counter', 'ontap_version');
$counters->child_add_string('counter', 'serial_no');
$counters->child_add_string('counter', 'system_id');
$counters->child_add_string('counter', 'system_model');
$request->child_add($counters);
my $result = call_api($request) || return;
$static_system_stats = {};
$static_system_stats->{'timestamp'} = $result->child_get_int('timestamp');
foreach ($result->child_get('instances')->child_get('instance-data')->child_get('counters')->children_get()) {
my $counter_name = $_->child_get_string('name');
my $counter_value = $_->child_get_string('value');
$static_system_stats->{$counter_name} = $counter_value;
}
# Persits data for next time
write_hash_to_file($tmp_file, $static_system_stats);
return $static_system_stats;
}
# ---------------------------------------------------------------------------------------------------------------------
# Get nfs v3 performance stats
sub get_system_perf_stats {
$log->info("Getting performance stats for system...");
my @identifiers = ('system', 'perf', 'stats');
my $tmp_file = get_tmp_file (\@identifiers);
my $request = NaElement->new('perf-object-get-instances');
$request->child_add_string('objectname', 'system');
my $counters = NaElement->new('counters');
# ----- Global system counter -----
$counters->child_add_string('counter', 'uptime');
$counters->child_add_string('counter', 'time');
# ----- Global CPU stats -----
$counters->child_add_string('counter', 'total_processor_busy');
$counters->child_add_string('counter', 'cpu_busy');
$counters->child_add_string('counter', 'cpu_elapsed_time');
$counters->child_add_string('counter', 'cpu_elapsed_time1');
$counters->child_add_string('counter', 'cpu_elapsed_time2');
$counters->child_add_string('counter', 'avg_processor_busy');
# ----- Global HDD stats -----
$counters->child_add_string('counter', 'hdd_data_written');
$counters->child_add_string('counter', 'hdd_data_read');
$counters->child_add_string('counter', 'sys_read_latency');
$counters->child_add_string('counter', 'sys_avg_latency');
$counters->child_add_string('counter', 'sys_write_latency');
$counters->child_add_string('counter', 'disk_data_written');
$counters->child_add_string('counter', 'disk_data_read');
# ----- Global network stats -----
$counters->child_add_string('counter', 'net_data_sent');
$counters->child_add_string('counter', 'net_data_recv');
# ----- Global protocol ops -----
$counters->child_add_string('counter', 'total_ops');
$counters->child_add_string('counter', 'cifs_ops');
$counters->child_add_string('counter', 'nfs_ops');
$counters->child_add_string('counter', 'write_ops');
$counters->child_add_string('counter', 'iscsi_ops');
$counters->child_add_string('counter', 'read_ops');
$request->child_add($counters);
my $result = call_api($request) || return;
my $current_perf_data = {};
$current_perf_data->{'timestamp'} = $result->child_get_int('timestamp');
foreach ($result->child_get('instances')->child_get('instance-data')->child_get('counters')->children_get()) {
my $counter_name = $_->child_get_string('name');
my $counter_value = $_->child_get_string('value');
$current_perf_data->{$counter_name} = $counter_value;
}
# Load old counters from file and persist new ones insted
my $old_perf_data = read_hash_from_file($tmp_file, 1);
write_hash_to_file($tmp_file, $current_perf_data);
# Calculate latencies / op rates
if (%$old_perf_data) {
my @derived_perf_data = ();
# ----- Global system counter -----
push (@derived_perf_data, { 'name' => 'uptime',
'value' => calc_counter_value('uptime', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('uptime', 'system')});
push (@derived_perf_data, { 'name' => 'time',
'value' => calc_counter_value('time', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('time', 'system')});
# ----- Global CPU stats -----
push (@derived_perf_data, { 'name' => 'total_processor_busy',
'value' => calc_counter_value('total_processor_busy', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('total_processor_busy', 'system')});
push (@derived_perf_data, { 'name' => 'cpu_busy',
'value' => calc_counter_value('cpu_busy', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('cpu_busy', 'system')});
push (@derived_perf_data, { 'name' => 'cpu_elapsed_time',
'value' => calc_counter_value('cpu_elapsed_time', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('cpu_elapsed_time', 'system')});
push (@derived_perf_data, { 'name' => 'cpu_elapsed_time1',
'value' => calc_counter_value('cpu_elapsed_time1', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('cpu_elapsed_time1', 'system')});
push (@derived_perf_data, { 'name' => 'cpu_elapsed_time2',
'value' => calc_counter_value('cpu_elapsed_time2', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('cpu_elapsed_time2', 'system')});
push (@derived_perf_data, { 'name' => 'avg_processor_busy',
'value' => calc_counter_value('avg_processor_busy', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('avg_processor_busy', 'system')});
# ----- Global HDD stats -----
push (@derived_perf_data, { 'name' => 'hdd_data_written',
'value' => calc_counter_value('hdd_data_written', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('hdd_data_written', 'system')});
push (@derived_perf_data, { 'name' => 'hdd_data_read',
'value' => calc_counter_value('hdd_data_read', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('hdd_data_read', 'system')});
push (@derived_perf_data, { 'name' => 'total_processor_busy',
'value' => calc_counter_value('total_processor_busy', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('total_processor_busy', 'system')});
push (@derived_perf_data, { 'name' => 'sys_read_latency',
'value' => calc_counter_value('sys_read_latency', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('sys_read_latency', 'system')});
push (@derived_perf_data, { 'name' => 'sys_write_latency',
'value' => calc_counter_value('sys_write_latency', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('sys_write_latency', 'system')});
push (@derived_perf_data, { 'name' => 'disk_data_written',
'value' => calc_counter_value('disk_data_written', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('disk_data_written', 'system')});
push (@derived_perf_data, { 'name' => 'disk_data_read',
'value' => calc_counter_value('disk_data_read', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('disk_data_read', 'system')});
# ----- Global network stats -----
push (@derived_perf_data, { 'name' => 'net_data_sent',
'value' => calc_counter_value('net_data_sent', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('net_data_sent', 'system')});
push (@derived_perf_data, { 'name' => 'net_data_recv',
'value' => calc_counter_value('net_data_recv', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('net_data_recv', 'system')});
# ----- Global protocol ops -----
push (@derived_perf_data, { 'name' => 'total_ops',
'value' => calc_counter_value('total_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('total_ops', 'system')});
push (@derived_perf_data, { 'name' => 'cifs_ops',
'value' => calc_counter_value('cifs_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('cifs_ops', 'system')});
push (@derived_perf_data, { 'name' => 'nfs_ops',
'value' => calc_counter_value('nfs_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfs_ops', 'system')});
push (@derived_perf_data, { 'name' => 'write_ops',
'value' => calc_counter_value('write_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('write_ops', 'system')});
push (@derived_perf_data, { 'name' => 'iscsi_ops',
'value' => calc_counter_value('iscsi_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('iscsi_ops', 'system')});
push (@derived_perf_data, { 'name' => 'read_ops',
'value' => calc_counter_value('read_ops', 'system', $current_perf_data, $old_perf_data),
'unit' => get_unit('read_ops', 'system')});
# render_perf_data(\@derived_perf_data);
our %probe_metric_hash;
$probe_metric_hash{'system'} = \@derived_perf_data;
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Get nfs v3 performance stats
sub get_nfsv3_perf_stats {
$log->info("Getting performance stats for nfsv3...");
my @identifiers = ('nfsv3', 'perf', 'stats');
my $tmp_file = get_tmp_file (\@identifiers);
my $request = NaElement->new('perf-object-get-instances');
$request->child_add_string('objectname', 'nfsv3');
my $counters = NaElement->new('counters');
$counters->child_add_string('counter', 'nfsv3_ops');
# ----- nfs v3 reads -----
$counters->child_add_string('counter', 'nfsv3_read_latency');
$counters->child_add_string('counter', 'nfsv3_avg_read_latency_base');
$counters->child_add_string('counter', 'nfsv3_read_ops');
# ----- nfs v3 writes -----
$counters->child_add_string('counter', 'nfsv3_write_latency');
$counters->child_add_string('counter', 'nfsv3_avg_write_latency_base');
$counters->child_add_string('counter', 'nfsv3_write_ops');
$request->child_add($counters);
my $result = call_api($request) || return;
my $current_perf_data = {};
$current_perf_data->{'timestamp'} = $result->child_get_int('timestamp');
foreach ($result->child_get('instances')->child_get('instance-data')->child_get('counters')->children_get()) {
my $counter_name = $_->child_get_string('name');
my $counter_value = $_->child_get_string('value');
$current_perf_data->{$counter_name} = $counter_value;
}
# Load old counters from file and persist new ones insted
my $old_perf_data = read_hash_from_file($tmp_file, 1);
write_hash_to_file($tmp_file, $current_perf_data);
# Calculate latencies / op rates
if (%$old_perf_data) {
my @derived_perf_data = ();
push (@derived_perf_data, { 'name' => 'read_latency',
'value' => calc_counter_value('nfsv3_read_latency', 'nfsv3', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfsv3_read_latency', 'nfsv3')});
push (@derived_perf_data, { 'name' => 'write_latency',
'value' => calc_counter_value('nfsv3_write_latency', 'nfsv3', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfsv3_write_latency', 'nfsv3')});
push (@derived_perf_data, { 'name' => 'ops_rate',
'value' => calc_counter_value('nfsv3_ops', 'nfsv3', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfsv3_ops', 'nfsv3')});
push (@derived_perf_data, { 'name' => 'read_ops_rate',
'value' => calc_counter_value('nfsv3_read_ops', 'nfsv3', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfsv3_read_ops', 'nfsv3')});
push (@derived_perf_data, { 'name' => 'write_ops_rate',
'value' => calc_counter_value('nfsv3_write_ops', 'nfsv3', $current_perf_data, $old_perf_data),
'unit' => get_unit('nfsv3_write_ops', 'nfsv3')});
# render_perf_data(\@derived_perf_data);
our %probe_metric_hash;
$probe_metric_hash{'nfsv3'} = \@derived_perf_data;
}
}
# ---------------------------------------------------------------------------------------------------------------------
# Get cifs performance stats
sub get_cifs_perf_stats {
$log->info("Getting performance stats for cifs...");
my @identifiers = ('cifs', 'perf', 'stats');
my $tmp_file = get_tmp_file (\@identifiers);
my $request = NaElement->new('perf-object-get-instances');