-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph-osrel-gvis.pl
379 lines (333 loc) · 14.8 KB
/
graph-osrel-gvis.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
#!/usr/bin/perl
#
# Description: Show OS release distribution via google motion charts
#
# SVN ID: $Id: graph-osrel-gvis.pl 210800 2014-08-25 06:59:42Z warbjoh $
#
# SVN Rev: $Rev: 210800 $
#
# SVN Source: $HeadURL: https://puppet-svn.bfm.com/svn-repo/puppet/tags/prod_blk/modules/osbuild_stats/files/opt/local/sbin/graph-osrel-gvis.pl $
#
# Notes: * HTML is a bit messy as it is really two html files
# munged into one
# * This code should probably be in the server stats script
#
use strict;
use warnings;
$|++;
# warbjoh@corcadm011% for i in /local/puppet-databases/dashboard-dump/inventory/invhostinfo.all.2013*.gz ; do
# DATE=`echo $i | sed -e 's/.*all.\(....\)\(..\)\(..\).gz/\1-\2-\3/'`
# zcat $i| awk -F, '$8 ~ /Sun|Solaris/ && $7 ~/a|m/ {print $10}' | ./which-os-release.pl | sort | uniq -c | awk '{printf "%s,%s,%s\n", $2, "'"$DATE"'", $1}' | sort -rn
# zcat $i| awk -F, '$8 ~ /Linux/ && $7 ~/a|m/ {print $9}' | ./which-os-release.pl | sort | uniq -c | awk '{printf "%s,%s,%s\n", $2, "'"$DATE"'", $1}' | sort -rn
# done | awk -F, '{printf "['\''%s'\'', new Date (\"%s\"), %d],\n", $1, $2, $3}' | sed -e 's/_/ /g' > 2013
#
use DBI;
use DBD::mysql;
my $platform = "mysql";
my $db = "osbuild_stats";
my $host = "localhost";
my $port = "3306";
my $stats_user = "stats_user";
my $stats_pass = "stats";
my $dsn = "DBI:mysql:database=$db;host=$host;port=$port;mysql_multi_statements=1";
my $summary = "/local/apache-infra/htdocs/stats/osrel-gvis.html";
open(SUMMARY, "> $summary") or die "Cannot create ${summary} for writing: $!\n";
my (
$hostname, $serial_no, $geo, $asset_loc, $aladdin_client,
$declared_function, $server_state, $os_nm, $os_release, $kernel_patch_no,
$architecture_nm, $cpu_count, $cpu_speed_mhz, $ram_amt_mb, $swap_amt_mb,
$extract_dt, $comments
);
my ( $date, $total, $linux, $solaris, $other, $active, $estate_memory, $maint );
my ( %OSREL, @dumps, $dump, $server_insert, @have_dates, $have_dates, $query, $minor_rel, $values );
# Use approximations using lookup tables derived from
# http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux#Version_history
# https://access.redhat.com/site/articles/3078
# https://blogs.oracle.com/patch/entry/solaris_10_kernel_patchid_progression
# https://blogs.oracle.com/patch/entry/solaris_8_and_solaris_9
my %SOLARIS_OS_LEVELS = (
'106541' => '7',
'117350|117000|108528' => '8',
'122300|118558|117171|112233' => '9',
'Generic' => '10_u00',
'118822' => '10_u01',
'118833|118855' => '10_u02',
'125100' => '10_u03',
'127111|120011' => '10_u04',
'127127|137111' => '10_u05',
'137137|138888' => '10_u06',
'141414|139555' => '10_u07',
'141444|142900' => '10_u08',
'144488|142909' => '10_u09',
'147440|144500' => '10_u10',
'147147|148888|150400' => '10_u11',
);
my %LINUX_OS_LEVELS = (
'2.6.9-11' => 'RHEL 4.1',
'2.6.9-22' => 'RHEL 4.2',
'2.6.9-34' => 'RHEL 4.3',
'2.6.9-42' => 'RHEL 4.4',
'2.6.9-55' => 'RHEL 4.5',
'2.6.9-67|2.6.9-68.5' => 'RHEL 4.6',
'2.6.9-78' => 'RHEL 4.7',
'2.6.9-89' => 'RHEL 4.8',
'2.6.9-100' => 'RHEL 4.9',
'2.6.18-53' => 'RHEL 5.1',
'2.6.18-92' => 'RHEL 5.2',
'2.6.18-128' => 'RHEL 5.3',
'2.6.18-164' => 'RHEL 5.4',
'2.6.18-194' => 'RHEL 5.5',
'2.6.18-238' => 'RHEL 5.6',
'2.6.18-274' => 'RHEL 5.7',
'2.6.18-308' => 'RHEL 5.8',
'2.6.18-348' => 'RHEL 5.9',
'2.6.18-371' => 'RHEL 5.10',
'2.6.32-131' => 'RHEL 6.1',
'2.6.32-220' => 'RHEL 6.2',
'2.6.32-279' => 'RHEL 6.3',
'2.6.32-358' => 'RHEL 6.4',
'2.6.32-431' => 'RHEL 6.5',
#
# JAMF NetSUS appliances run Ubuntu
# http://people.canonical.com/~kernel/info/kernel-version-map.html
# https://wiki.ubuntu.com/Releases
'3.5.0' => 'Ubuntu 12.0.4',
'3.13' => 'Ubuntu 14.04.1',
);
my $thishost = `hostname`;
chomp($thishost);
my $now = sprintf scalar localtime;
my $gvis_header = <<"HEREDOC";
<html>
<!--
Automatically generated by $0
on $thishost by $ENV{'USER'} at $now
-->
<head>
<title>Unix Operating System Releases</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load('visualization', '1', {'packages':['motionchart']});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'OS Release');
data.addColumn('date', 'Date');
data.addColumn('number', 'Servers');
data.addRows([
HEREDOC
# manually derived
# https://developers.google.com/chart/interactive/docs/gallery/motionchart#Motion_Chart_initial_state
my $options_detail = <<"HEREDOC";
'{"duration":{"timeUnit":"D","multiplier":1},"xAxisOption":"_ALPHABETICAL","colorOption":"_UNIQUE_COLOR","xZoomedDataMax":29,"dimensions":{"iconDimensions":["dim0"]},"uniColorForNonSelected":false,"showTrails":false,"orderedByY":false,"yAxisOption":"2","yLambda":1,"iconKeySettings":[{"key":{"dim0":"Solaris 10_u04"}},{"key":{"dim0":"RHEL 5.3"}},{"key":{"dim0":"Solaris 10_u09"}},{"key":{"dim0":"Solaris 10_u10"}},{"key":{"dim0":"RHEL 6.4"}},{"key":{"dim0":"RHEL 5.6"}},{"key":{"dim0":"Solaris 10_u11"}},{"key":{"dim0":"RHEL 5.8"}}],"xZoomedIn":false,"nonSelectedAlpha":0.4,"yZoomedDataMin":0,"sizeOption":"_UNISIZE","yZoomedIn":false,"orderedByX":true,"xLambda":1,"playDuration":15000,"xZoomedDataMin":0,"time":"2013-03-11","yZoomedDataMax":1006,"iconType":"VBAR"}';
HEREDOC
my $gvis_footer = <<"HEREDOC";
]);
var chart = new google.visualization.MotionChart(document.getElementById('chart_detail'));
var options = {};
options['state'] = $options_detail;
options['width'] = 1000;
options['height'] = 500;
chart.draw(data, options);
}
</script>
</head>
HEREDOC
my $options_summary = <<"HEREDOC";
'{"xZoomedDataMin":0,"colorOption":"_UNIQUE_COLOR","yZoomedIn":false,"xZoomedDataMax":7,"iconKeySettings":[{"key":{"dim0":"Solaris 7"}},{"key":{"dim0":"Solaris 8"}},{"key":{"dim0":"RHEL 4"}},{"key":{"dim0":"RHEL 5"}},{"key":{"dim0":"RHEL 6"}},{"key":{"dim0":"AIX"}},{"key":{"dim0":"Ubuntu 12"}},{"key":{"dim0":"Solaris 10"}}],"sizeOption":"_UNISIZE","orderedByX":true,"xLambda":1,"xAxisOption":"2","nonSelectedAlpha":0.4,"yZoomedDataMax":2000,"iconType":"VBAR","orderedByY":false,"yZoomedDataMin":0,"yAxisOption":"2","yLambda":1,"dimensions":{"iconDimensions":["dim0"]},"showTrails":false,"uniColorForNonSelected":false,"duration":{"multiplier":1,"timeUnit":"D"},"time":"2013-03-10","playDuration":15000,"xZoomedIn":false}';
HEREDOC
my $gvis_summary_footer = <<"HEREDOC";
]);
var chart = new google.visualization.MotionChart(document.getElementById('chart_summary'));
var options = {};
options['state'] = $options_summary;
options['width'] = 1000;
options['height'] = 500;
chart.draw(data, options);
}
</script>
</head>
<body>
<h2>Unix Operating System Releases</h2>
<div>
<p> The graphs below are motion charts using the <a
href="https://developers.google.com/chart/interactive/docs/gallery/motionchart">Google
Charts JavaScript classes</a> and show the number of Unix servers
broken down by Major OS Release and Minor OS Release</p>
<p>Because these are "motion" charts you will need to press the "play"
button on the bottom left of each chart to see changes over time</p>
<p>How the information is displayed can be modified by selecting different
chart types (top right - bubbles / columns / lines) or the order in which
OS releases are displayed (Order section bottom left). Hovering over
objects will show their value</p>
<p>It is possible to choose the OS Releases you are interested in by
selecting / deselecting from the box to the right. When viewing in line
mode, it is possible to hover over lines to see values at points in time</p>
<p>Notes on the data:
<ul>
<li>Historical server data from the comp_asset_hist database does not
contain enough information for data analysis. A full "Unix inventory"
dump is performed each day to capture that information. The first
dump started on 10 March 2013</li>
<li>There was a data anomaly on 20 May 2013 when M&M took over
populating parts of comp_asset, and there was confusion over
SunOS or Solaris as the OS name for Solaris servers
</ul>
</div>
<h3>Major Operating System Releases</h2>
<div id="chart_summary" style="width: 1000px; height: 500px;"></div>
<h3>Minor Operating System Releases</h2>
<div id="chart_detail" style="width: 1000px; height: 500px;"></div>
</body>
</html>
HEREDOC
my ($osrel, $major_release, $num, $kernel_rev, @releases, $release, %SUMMARY);
my $inventory_dump = "/local/puppet-databases/dashboard-dump/inventory";
print SUMMARY $gvis_header;
opendir( DUMP_DIR, $inventory_dump )
or die "Cannot open $inventory_dump for readdir: $!\n";
@dumps = grep { ( !/^\./ ) } readdir(DUMP_DIR);
closedir(DUMP_DIR);
#
# Find out what dates we already have data for and filter out
#
$query = qq{
select date from server_osrel_stats;
};
my $dbh = DBI->connect( $dsn, $stats_user, $stats_pass )
or die "Could not connect:\n" . DBI->errstr;
my $query_handle = $dbh->prepare($query)
or die "Can't prepare statement: $DBI::errstr";
$query_handle->execute();
# http://www.perlmonks.org/?node=DBI%20Recipes#fetching
@have_dates = @{ $dbh->selectcol_arrayref($query) };
$query_handle->finish;
$dbh->disconnect;
@have_dates = map { $_ =~ s/-//g; $_ } @have_dates;
# turn into a regexp to grep against
$have_dates = join( '|', @have_dates );
@dumps = grep { !/$have_dates/ } @dumps;
foreach $dump ( sort @dumps ) {
$date = $dump;
$date =~ s/invhostinfo.all.(\d\d\d\d)(\d\d)(\d\d).gz/$1-$2-$3/;
open(DUMP, "zcat $inventory_dump/$dump |" )
or die "Cannot open $inventory_dump/$dump for reading: $!\n";
LINE: while (<DUMP>) {
(
$hostname, $serial_no, $geo, $asset_loc, $aladdin_client,
$declared_function, $server_state, $os_nm, $os_release,
$kernel_patch_no,
$architecture_nm, $cpu_count, $cpu_speed_mhz, $ram_amt_mb,
$swap_amt_mb,
$extract_dt, $comments
) = split(',');
next if ( $server_state !~ /m|a/ );
next if ( !defined($kernel_patch_no) ); # MnM stuff up
next if ( $kernel_patch_no =~ /^$/ ); # MnM stuff up
next if ( $kernel_patch_no eq "v1.9.2" ); # console servers
next if ( $os_release =~ /UNKNOWN/ );
next if ( $kernel_patch_no =~ /UNKNOWN/ );
next if ( $hostname =~ /rdcftp/ ); # tumbleweed
next if ( $hostname =~ /^was[_|-]/ );
next if ( $hostname =~ /_CNFLCT_/ );
# I can't believe this, the kernel data is in different fields
# for different OS - nice one
# this was 'fixed' on 18 June 2014, to make Linux consistet with solaris
# so now have to code for different OS releases and dates having different fields
if ($os_nm =~ /SunOS|Solaris/) {
if ($kernel_patch_no =~ /\d\d\d\d-\d\d/) {
foreach $kernel_rev (keys %SOLARIS_OS_LEVELS) {
if ($kernel_patch_no =~ m/$kernel_rev/) {
#print "Solaris $SOLARIS_OS_LEVELS{$kernel_rev}\n";
$OSREL{$date}{"Solaris $SOLARIS_OS_LEVELS{$kernel_rev}"}++;
next LINE;
}
}
}
# We've had quite a few data gathering anomolies where the kernel
# revision doesn't get set, so here we make a best guess and drop
# it into a generic bucket - like "Solaris 10"
if ($os_release =~ /5\./) {
($minor_rel) = ($os_release =~ /5\.(\d+)/);
$OSREL{$date}{"Solaris $minor_rel"}++;
next LINE;
}
}
elsif ($os_nm =~ /Linux/) {
# kernel rev and is release swapped for Linux on 2014-06-18
if ($date lt '2014-06-18') {
foreach $kernel_rev (keys %LINUX_OS_LEVELS) {
if ($os_release =~ m/$kernel_rev/) {
#print "$LINUX_OS_LEVELS{$kernel_rev}\n";
$OSREL{$date}{"$LINUX_OS_LEVELS{$kernel_rev}"}++;
next LINE;
}
}
}
else {
foreach $kernel_rev (keys %LINUX_OS_LEVELS) {
if ($kernel_patch_no =~ m/$kernel_rev/) {
#print "$LINUX_OS_LEVELS{$kernel_rev}\n";
$OSREL{$date}{"$LINUX_OS_LEVELS{$kernel_rev}"}++;
next LINE;
}
}
}
}
elsif ($os_nm =~ /AIX/) {
$OSREL{$date}{"AIX"}++;
next LINE;
}
print "### Shouldn't be here $date: $hostname os_release: $os_release kernel_patch_no: $kernel_patch_no $os_nm\n";
}
close(DUMP);
}
foreach $date (sort keys %OSREL) {
$values = join('|', map { "$_,$OSREL{$date}{$_}" } sort keys %{$OSREL{$date}});
$server_insert = qq{
INSERT INTO server_osrel_stats (date, release_values)
VALUES ('$date', '$values');
};
# add an entry into the change table
dbInsert($server_insert);
}
$query = qq{ select * from server_osrel_stats order by date; };
$dbh = DBI->connect( $dsn, $stats_user, $stats_pass )
or die "Could not connect:\n" . DBI->errstr;
$query_handle = $dbh->prepare($query)
or die "Can't prepare statement: $DBI::errstr";
$query_handle->execute();
while (($date, $values) = $query_handle->fetchrow_array) {
@releases = split('\|', $values);
foreach $release (@releases) {
($osrel, $num) = split(',', $release);
print SUMMARY " [\'$osrel\', new Date (\"$date\"), $num],\n";
}
# remove minor release information
$values =~ s/\.\d+|_u\d+//g;
@releases = split('\|', $values);
# we can't simple map into a hash as we have duplicate keys
foreach $release (@releases) {
($major_release, $num) = split(',', $release);
$SUMMARY{$date}{$major_release} += $num;
}
}
$query_handle->finish;
$dbh->disconnect;
print SUMMARY $gvis_footer;
print SUMMARY $gvis_header;
foreach $date (sort keys %SUMMARY) {
foreach $major_release (sort keys %{$SUMMARY{$date}}) {
print SUMMARY " [\'$major_release\', new Date (\"$date\"), $SUMMARY{$date}{$major_release}],\n";
}
}
print SUMMARY $gvis_summary_footer;
close(SUMMARY);
chmod(0664, $summary);
sub dbInsert {
my ($query) = @_;
my $dbh = DBI->connect( $dsn, $stats_user, $stats_pass )
or die "Could not connect:\n" . DBI->errstr;
$dbh->do($query);
$dbh->disconnect;
}