Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / jenkins / jenkins_nodes_ @ 17f78427

Historique | Voir | Annoter | Télécharger (9,46 ko)

1
#!/usr/bin/env perl
2
# -*- perl -*-
3

    
4
# MAIN
5
use warnings;
6
use strict;
7
use JSON;
8
use File::Basename;
9
use Data::Dumper;
10

    
11
# VARS
12
my $url = ($ENV{'url'} || 'localhost');
13
my $port = ($ENV{'port'} || '4040');
14
my $user = ($ENV{'user'} || '');
15
my $apiToken = ($ENV{'apiToken'} || '');
16
my $context = ($ENV{'context'} || '');
17
my $wgetBin = "/usr/bin/env wget";
18

    
19
# mem_sum, mem, swap, ws, tmp, executors, arch
20
my $type = basename($0);
21
$type =~ s/jenkins_nodes_//;
22

    
23
my $auth = ( $user ne "" and $apiToken ne ""  ? " --auth-no-challenge --user=$user --password=$apiToken" : "" );
24
my $cmd = "$wgetBin $auth -qO- $url:$port$context";
25
my $monitor;
26

    
27
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
28
    my $base_config = "graph_category devel\n";
29

    
30
    if( $type eq "mem_sum" ) {
31
            print $base_config;
32
            print "graph_args --base 1000 -l 0\n";
33
            print "graph_title Jenkins Memory Summary\n";
34
            print "graph_vlabel Memory Summary\n";
35
            print "graph_info The Graph shows the Jenkins Memory Summary\n";
36
            print "mem_sum_total.draw AREA\n";
37
            print "mem_sum_total.label available\n";
38
            print "mem_sum_total.type GAUGE\n";
39
            print "mem_sum_used.label used\n";
40
            print "mem_sum_used.type GAUGE\n";
41
    }
42

    
43
    if( $type eq "mem" ) {
44
        print $base_config;
45
        print "graph_args --base 1000 -l 0\n";
46
        print "graph_title available Memory per Node\n";
47
        print "graph_vlabel available Memory per Node\n";
48
        print "graph_info The Graph shows the available Physical Memory per Node\n";
49
        my $lcount = 0;
50
        my $node;
51
        my $result = `$cmd/computer/api/json`;
52
        my $parsed = decode_json($result);
53
        foreach my $cur(@{$parsed->{'computer'}}) {
54
            if( !$cur->{'offline'} ) {
55
                my $cat = $cur->{'displayName'};
56
                $cat =~ s/\./\_/g;
57
                if( $lcount > 0 ){
58
                        print $cat,"_mem.draw STACK\n";
59
                } else {
60
                        print $cat,"_mem.draw AREA\n";
61
                }
62
                print $cat,"_mem.label $cur->{'displayName'}\n";
63
                print $cat,"_mem.type GAUGE\n";
64
                $lcount++;
65
            }
66
        }
67
    }
68

    
69
    if( $type eq "ws" ) {
70
        print $base_config;
71
        print "graph_args --base 1000 -l 0\n";
72
        print "graph_title available Workspace per Node\n";
73
        print "graph_vlabel available Workspace\n";
74
        print "graph_info The Graph shows the available Workspace per Node\n";
75
        my $lcount = 0;
76
        my $node;
77
        my $result = `$cmd/computer/api/json`;
78
        my $parsed = decode_json($result);
79
        foreach my $cur(@{$parsed->{'computer'}}) {
80
            if( !$cur->{'offline'} ) {
81
                my $cat = $cur->{'displayName'};
82
                $cat =~ s/\./\_/g;
83
                    if( $lcount > 0 ){
84
                            print $cat,"_ws.draw STACK\n";
85
                    } else {
86
                            print $cat,"_ws.draw AREA\n";
87
                    }
88
                    print $cat,"_ws.label $cur->{'displayName'}\n";
89
                    print $cat,"_ws.type GAUGE\n";
90
                $lcount++;
91
            }
92
        }
93
    }
94

    
95
    if( $type eq "tmp" ) {
96
        print $base_config;
97
        print "graph_args --base 1000 -l 0\n";
98
        print "graph_title available TMP Space per Node\n";
99
        print "graph_vlabel available TMP Space\n";
100
        print "graph_info The Graph shows the available TMP Space per Node\n";
101
        my $lcount = 0;
102
        my $node;
103
        my $result = `$cmd/computer/api/json`;
104
        my $parsed = decode_json($result);
105
        foreach my $cur(@{$parsed->{'computer'}}) {
106
            if( !$cur->{'offline'} ) {
107
                my $cat = $cur->{'displayName'};
108
                $cat =~ s/\./\_/g;
109
                    if( $lcount > 0 ){
110
                            print $cat,"_tmp.draw STACK\n";
111
                    } else {
112
                            print $cat,"_tmp.draw AREA\n";
113
                    }
114
                    print $cat,"_tmp.label $cur->{'displayName'}\n";
115
                    print $cat,"_tmp.type GAUGE\n";
116
                $lcount++;
117
            }
118
        }
119
    }
120

    
121
    if( $type eq "arch" ) {
122
        print $base_config;
123
        print "graph_args --base 1000 -l 0\n";
124
        print "graph_title available Node Architectures\n";
125
        print "graph_vlabel available Node Architectures\n";
126
        print "graph_info The Graph shows the available Node Architectures\n";
127
        my $lcount = 0;
128
        my $result = `$cmd/computer/api/json`;
129
        my $parsed = decode_json($result);
130
        my %archs = ();
131
        my $cat;
132
        foreach my $cur(@{$parsed->{'computer'}}) {
133
            if( !$cur->{'offline'} ) {
134
                $cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
135
                if (exists $archs{$cat} ) {} else {
136
                    $archs{$cat} = 0;
137
                }
138
            }
139
        }
140
        foreach my $cur (keys %archs) {
141
            $cat = clean_name($cur);
142
            if( $lcount > 0 ){
143
                print $cat,".draw STACK\n";
144
            } else {
145
                print $cat,".draw AREA\n";
146
            }
147
            print $cat,".label $cur\n";
148
            print $cat,".type GAUGE\n";
149
            $lcount++;
150
        }
151
    }
152

    
153
    if( $type eq "executors" ) {
154
            print $base_config;
155
            print "graph_args --base 1000 -l 0\n";
156
            print "graph_title Jenkins Executors\n";
157
            print "graph_vlabel Executors\n";
158
            print "graph_info The Graph shows the Jenkins Executors\n";
159
             print "executors_offline.label offline\n";
160
            print "executors_offline.type GAUGE\n";
161
            print "executors_offline.draw AREA\n";
162
            print "executors_offline.colour 8A8A8A\n";
163
            print "executors_busy.label busy\n";
164
            print "executors_busy.type GAUGE\n";
165
            print "executors_busy.draw STACK\n";
166
            print "executors_idle.label idle\n";
167
            print "executors_idle.type GAUGE\n";
168
            print "executors_idle.draw STACK\n";
169
    }
170

    
171
} else {
172
    # CODE
173
    my $result = `$cmd/computer/api/json`;
174
    my $parsed = decode_json($result);
175

    
176
    if( $type eq "mem_sum" ) {
177
        my $avail_mem = 0;
178
        my $total_mem = 0;
179
        my $used_mem = 0;
180
        foreach my $cur(@{$parsed->{'computer'}}) {
181
            if( !$cur->{'offline'} ) {
182
                $monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
183
                $avail_mem += $monitor->{'availablePhysicalMemory'};
184
                $total_mem += $monitor->{'totalPhysicalMemory'};
185
            }
186
        }
187
        $used_mem = $total_mem - $avail_mem;
188
        print "mem_sum_total.value $total_mem\n";
189
        print "mem_sum_used.value $used_mem\n";
190
    }
191

    
192
    if( $type eq "mem" ) {
193
        my $result = `$cmd/computer/api/json`;
194
        my $parsed = decode_json($result);
195
        foreach my $cur(@{$parsed->{'computer'}}) {
196
            if( !$cur->{'offline'} ) {
197
                $monitor = $cur->{'monitorData'}{'hudson.node_monitors.SwapSpaceMonitor'};
198
                my $cat = $cur->{'displayName'};
199
                $cat =~ s/\./\_/g;
200
                print $cat,"_mem.value ",$monitor->{'availablePhysicalMemory'},"\n";
201
            }
202
        }
203
    }
204

    
205
    if( $type eq "tmp" ) {
206
        my $result = `$cmd/computer/api/json`;
207
        my $parsed = decode_json($result);
208
        foreach my $cur(@{$parsed->{'computer'}}) {
209
            if( !$cur->{'offline'} ) {
210
                $monitor = $cur->{'monitorData'}{'hudson.node_monitors.TemporarySpaceMonitor'};
211
                my $cat = $cur->{'displayName'};
212
                $cat =~ s/\./\_/g;
213
                print $cat,"_tmp.value ",$monitor->{'size'},"\n";
214
            }
215
        }
216
    }
217

    
218
    if( $type eq "ws" ) {
219
        my $result = `$cmd/computer/api/json`;
220
        my $parsed = decode_json($result);
221
        foreach my $cur(@{$parsed->{'computer'}}) {
222
            if( !$cur->{'offline'} ) {
223
                $monitor = $cur->{'monitorData'}{'hudson.node_monitors.DiskSpaceMonitor'};
224
                my $cat = $cur->{'displayName'};
225
                $cat =~ s/\./\_/g;
226
                print $cat,"_ws.value ",$monitor->{'size'},"\n";
227
            }
228
        }
229
    }
230

    
231
    if( $type eq "arch" ) {
232
        my $parsed = decode_json($result);
233
        my %archs = ();
234
        my $cat;
235
        foreach my $cur(@{$parsed->{'computer'}}) {
236
            if( !$cur->{'offline'} ) {
237
                $cat = $cur->{'monitorData'}{'hudson.node_monitors.ArchitectureMonitor'};
238
                if (exists $archs{$cat} ) {
239
                    $archs{$cat} += 1;
240
                } else {
241
                    $archs{$cat} = 1;
242
                }
243
            }
244
        }
245
        foreach my $cur (keys %archs) {
246
            $cat = clean_name($cur);
247
            print $cat,".value ", $archs{$cur}, "\n";
248
        }
249
    }
250

    
251
    if( $type eq "executors" ) {
252
    	my $busyExecutors = $parsed->{'busyExecutors'};
253
    	my $totalExecutors = 0;
254
    	my $offlineExecutors = 0;
255
        foreach my $cur(@{$parsed->{'computer'}}) {
256
        	$totalExecutors += $cur->{'numExecutors'};
257
	        if( $cur->{'offline'} =~ /true$/ ) {
258
	        	$offlineExecutors += $cur->{'numExecutors'};
259
	        }
260
        }
261
        print "executors_idle.value ", ($totalExecutors - $busyExecutors - $offlineExecutors), "\n";
262
        print "executors_busy.value $busyExecutors\n";
263
        print "executors_offline.value $offlineExecutors\n";
264
    }
265
}
266

    
267
sub clean_name {
268
    my $name = $_[0];
269
    $name =~ s/\./\_/g;
270
    $name =~ s/\(/\_/g;
271
    $name =~ s/\)/\_/g;
272
    $name =~ s/ //g;
273
    return $name;
274
}