mondbd.in 16.1 KB
Newer Older
Gary Wong's avatar
Gary Wong committed
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
#!/usr/bin/perl -w
#
# Copyright (c) 2014 University of Utah and the Flux Group.
# 
# {{{GENIPUBLIC-LICENSE
# 
# GENI Public License
# 
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and/or hardware specification (the "Work") to
# deal in the Work without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Work, and to permit persons to whom the Work
# is furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Work.
# 
# THE WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE WORK OR THE USE OR OTHER DEALINGS
# IN THE WORK.
# 
# }}}
#
use strict;
use English;
Gary Wong's avatar
Gary Wong committed
32
use Getopt::Std;
Gary Wong's avatar
Gary Wong committed
33
34
35
36
37

#
# Populate the monitoring database.
# 

Gary Wong's avatar
Gary Wong committed
38
39
40
41
42
43
44
45
sub usage()
{
    print "Usage: mondbd [-d] [-i]\n";
    exit(1);
}
my $optlist   = "d";
my $debug     = 0;

Gary Wong's avatar
Gary Wong committed
46
47
48
49
50
51
52
53
54
55
56
#
# Configure variables
#
my $TB		 = "@prefix@";
my $TBOPS        = "@TBOPSEMAIL@";
my $DBNAME	 = "@TBDBNAME@";
my $DOMAIN       = "@OURDOMAIN@";
my $URL          = "https://www.$DOMAIN:5001";
my $PGENISUPPORT = @PROTOGENI_SUPPORT@;
my $NICKNAME	 = "@PROTOGENI_NICKNAME@";
my $LOGFILE      = "$TB/log/expire_daemon.log";
Gary Wong's avatar
Gary Wong committed
57
58
59
my $PORTSTATS    = "$TB/bin/portstats";

my $INTERVAL     = 120;
Gary Wong's avatar
Gary Wong committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

# un-taint path
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin:/usr/site/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

# Protos
sub fatal($);
	  
#
# Turn off line buffering on output
#
$| = 1; 

if ($UID != 0) {
    fatal("Must be root to run this script\n");
}

#
# Exit if not a protogeni site.
#
if (! $PGENISUPPORT) {
    exit(0);
}

Gary Wong's avatar
Gary Wong committed
84
85
86
87
88
89
90
91
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"d"})) {
    $debug++;
}

Gary Wong's avatar
Gary Wong committed
92
93
94
95
96
97
98
99
100
# Load the Testbed support stuff.
use lib "@prefix@/lib";
use libaudit;
use libdb;
use libtestbed;
use emdbi;
use emutil;
use Experiment;
use Interface;
Gary Wong's avatar
Gary Wong committed
101
use Lan;
Gary Wong's avatar
Gary Wong committed
102
103
use Node;
use OSinfo;
Gary Wong's avatar
Gary Wong committed
104
use GeniHRN;
Gary Wong's avatar
Gary Wong committed
105
106
107
108
109
110
111
112

# Connect to the monitoring DB.
my $db = emdbi::NewTBDBHandle( "monitoring" );
my $tbdb = emdbi::NewTBDBHandle( $DBNAME );

if (CheckDaemonRunning("mondbd")) {
    fatal("Not starting another monitoring daemon!");
}
Gary Wong's avatar
Gary Wong committed
113
114
115
116
117
118

if( !$debug) {
    # Go to background.
    if (TBBackGround($LOGFILE)) {
	exit(0);
    }
Gary Wong's avatar
Gary Wong committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
}

if (MarkDaemonRunning("mondbd")) {
    fatal("Could not mark daemon as running!");
}

#
# Setup a signal handler for newsyslog.
#
sub handler()
{
    my $SAVEEUID = $EUID;
    
    $EUID = 0;
    ReOpenLog($LOGFILE);
    $EUID = $SAVEEUID;
}
$SIG{HUP} = \&handler;

Gary Wong's avatar
Gary Wong committed
138
sub AddInterfaces($$$) {
Gary Wong's avatar
Gary Wong committed
139

140
    my ($n, $node, $ts) = @_;
Gary Wong's avatar
Gary Wong committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
    my @interfaces;

    Interface->LookupAll( $node, \@interfaces );

    foreach my $interface( @interfaces ) {
	my $i = $interface->iface();
	my $addr = $interface->IP();
	my $role = $interface->role();
	my $speed;
	my $packets;

	if( $interface->TypeCapability( "ethernet_defspeed", \$speed ) < 0 ) {
	    $speed = 1000000;
	}

	$speed *= 100;
	$packets = $speed / 80;

	emdbi::DBQueryWarnN( $db, "INSERT INTO ops_interface SET " .
160
			     "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/interface#', " .
Gary Wong's avatar
Gary Wong committed
161
162
163
164
165
166
167
168
			     "id='${DOMAIN}_interface_$n:$i'," .
			     "selfRef='$URL/info/interface/${DOMAIN}_interface_$n:$i'," .
			     "urn='urn:publicid:IDN+$DOMAIN+interface+$n:$i'," .
			     "ts='$ts'," .
			     "properties\$role='$role'," .
			     "properties\$max_bps='$speed'," .
			     "properties\$max_pps='$packets'" );

169
170
171
172
173
	emdbi::DBQueryWarnN( $db, "INSERT INTO ops_interface_addresses SET " .
			     "interface_id='${DOMAIN}_interface_$n:$i'," .
			     "addrtype='ipv4'," .
			     "address='$addr'" );

Gary Wong's avatar
Gary Wong committed
174
175
176
177
178
179
180
181
	emdbi::DBQueryWarnN( $db, "INSERT INTO ops_node_interface SET " .
			     "id='${DOMAIN}_interface_$n:$i'," .
			     "node_id='${DOMAIN}_node_$n'," .
			     "urn='urn:publicid:IDN+$DOMAIN+interface+$n:$i'," .
			     "selfRef='$URL/info/interface/${DOMAIN}_interface_$n:$i'" );
    }
}

Gary Wong's avatar
Gary Wong committed
182
183
184
185
sub AddLink($$) {

    my ($name, $ts) = @_;

186
187
188
    # FIXME would be nice to set layer, too
    emdbi::DBQueryWarnN( $db, "REPLACE INTO ops_link SET " .
			 "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/link#', " .
Gary Wong's avatar
Gary Wong committed
189
190
191
192
193
			 "id='${DOMAIN}_link_$name', " .
			 "selfRef='$URL/info/link/${DOMAIN}_link_$name'," .
			 "urn='urn:publicid:IDN+$DOMAIN+link+$name'," .
			 "ts='$ts'" );

194
    emdbi::DBQueryWarnN( $db, "REPLACE INTO ops_aggregate_resource SET " .
Gary Wong's avatar
Gary Wong committed
195
196
197
198
199
200
201
202
203
204
205
			 "id='${DOMAIN}_link_$name'," .
			 "aggregate_id='$NICKNAME'," .
			 "urn='urn:publicid:IDN+$DOMAIN+link+$name'," .
			 "selfRef='$URL/info/link/${DOMAIN}_link_$name'" );
}

sub AddInterfaceVlan($$$$$) {

    my ($linkid,$idomain,$iface,$tag,$ts) = @_;
    my $url;

206
    $url = "$URL/info/interfacevlan/${idomain}_interface_${iface}:${tag}";
Gary Wong's avatar
Gary Wong committed
207

208
209
    # FIXME would be nice to give interface_href, but in general we don't know
    emdbi::DBQueryWarnN( $db, "REPLACE INTO ops_interfacevlan SET " .
210
			 "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/interfacevlan#', " .
Gary Wong's avatar
Gary Wong committed
211
212
			 "id='${idomain}_interface_${iface}:${tag}', " .
			 "selfRef='$url', " .
213
			 "urn='urn:publicid:IDN+$idomain+interfacevlan+$iface:$tag', " .
Gary Wong's avatar
Gary Wong committed
214
			 "ts='$ts', " .
215
			 "tag=$tag," .
216
			 "interface_urn='urn:publicid:IDN+$idomain+interface+$iface'" );
Gary Wong's avatar
Gary Wong committed
217
218
219

    emdbi::DBQueryWarnN( $db, "INSERT INTO ops_link_interfacevlan SET " .
			 "id='${idomain}_interface_${iface}:${tag}', " .
220
			 "link_id='${DOMAIN}_link_$linkid'" );
Gary Wong's avatar
Gary Wong committed
221
222
}

Gary Wong's avatar
Gary Wong committed
223
224
my %portcounters;

Gary Wong's avatar
Gary Wong committed
225
while (1) {
226
227
228
    my $ts = time() . "000000";
    my $expire = ( time() - 24 * 60 * 60 ) . "000000";

Gary Wong's avatar
Gary Wong committed
229
    # Add the local CM.
230
231
232
    # FIXME would be nice to add routable_ip_poolsize
    emdbi::DBQueryWarnN( $db, "LOCK TABLES ops_aggregate WRITE" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_aggregate" );
Gary Wong's avatar
Gary Wong committed
233
    emdbi::DBQueryWarnN( $db, "INSERT INTO ops_aggregate SET " .
234
			 "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/aggregate#', " .
Gary Wong's avatar
Gary Wong committed
235
236
237
238
			 "id='$NICKNAME'," .
			 "selfRef='$URL/info/aggregate/$NICKNAME'," .
			 "urn='urn:publicid:IDN+$DOMAIN+authority+cm'," .
			 "ts='$ts'," .
239
240
241
			 "measRef='$URL/data/'," .
			 "operational_status='development'" );
    emdbi::DBQueryWarnN( $db, "UNLOCK TABLES" );
Gary Wong's avatar
Gary Wong committed
242
243

    # Add local XEN nodes and interfaces from the shared pool.
244
245
246
247
248
249
250
251
    # NB: it would be nice to delete only very old entries from timestamped
    # tables (to retain some historical data), but ts is not part of the
    # primary key for them so we must discard the old state before we're
    # permitted to update with the current.
#    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_node WHERE ts < $expire" );
#    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_interface WHERE ts < $expire" );
#    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_link WHERE ts < $expire" );
#    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_interfacevlan WHERE ts < $expire" );
Gary Wong's avatar
Gary Wong committed
252
253
    emdbi::DBQueryWarnN( $db, "LOCK TABLES ops_node WRITE, " .
			 "ops_interface WRITE, " .
254
255
256
			 "ops_interfacevlan WRITE, " .
			 "ops_interface_addresses WRITE, " .
			 "ops_link WRITE, " .
Gary Wong's avatar
Gary Wong committed
257
258
			 "ops_aggregate_resource WRITE, " .
			 "ops_node_interface WRITE" );
259
260
261
262
263
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_node" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_interface" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_link" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_interfacevlan" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_interface_addresses" );
Gary Wong's avatar
Gary Wong committed
264
265
266
267
268
269
270
271
272
273
274
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_aggregate_resource" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_node_interface" );
    # The shared pool experiment isn't named consistently across sites.
    # Rather than fixing it, let's just grab everything we can find and
    # hope for the best.
    my @nodes = ExpNodes( "emulab-ops", "shared-node", 1, 1 );
    my @morenodes = ExpNodes( "emulab-ops", "shared-nodes", 1, 1 );
    push( @nodes, @morenodes );

    foreach my $n ( @nodes ) {
	my $node = Node->Lookup( $n );
275
276
	my $os = OSinfo->Lookup( $node->def_boot_osid(),
				 $node->def_boot_osid_vers() );
Gary Wong's avatar
Gary Wong committed
277
278
279
280
281
282

	next unless $os->osname =~ /XEN/;

	my $mem = $node->memory() * 1024;

	emdbi::DBQueryWarnN( $db, "INSERT INTO ops_node SET " .
283
			     "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/node#', " .
Gary Wong's avatar
Gary Wong committed
284
285
286
287
			     "id='${DOMAIN}_node_$n'," .
			     "selfRef='$URL/info/node/${DOMAIN}_node_$n'," .
			     "urn='urn:publicid:IDN+$DOMAIN+node+$n'," .
			     "ts='$ts'," .
288
			     "node_type='server'," .
Gary Wong's avatar
Gary Wong committed
289
			     "properties\$mem_total_kb='$mem'," .
290
			     "virtualization_type='xen'" );
Gary Wong's avatar
Gary Wong committed
291
292
293
294
295
296
297

	emdbi::DBQueryWarnN( $db, "INSERT INTO ops_aggregate_resource SET " .
			     "id='${DOMAIN}_node_$n'," .
			     "aggregate_id='$NICKNAME'," .
			     "urn='urn:publicid:IDN+$DOMAIN+node+$n'," .
			     "selfRef='$URL/info/node/${DOMAIN}_node_$n'" );

298
	AddInterfaces( $n, $node, $ts );
Gary Wong's avatar
Gary Wong committed
299
300
    }

Gary Wong's avatar
Gary Wong committed
301
    my @fakenodenames = ();
302
303
304
305
306
307
308
    my @switchnodenames = ();
    my %fakenodemap = ();
    my $query_result = emdbi::DBQueryWarnN( $tbdb, "SELECT e.node_id, w.node_id1, w.card1, w.port1, w.node_id2, w.card2, w.port2 " .
					    "FROM external_networks as e, " .
					    "wires as w WHERE " .
					    "e.node_id=w.node_id1 OR " .
					    "e.node_id=w.node_id2" );
Gary Wong's avatar
Gary Wong committed
309
310
311
312
    if( $query_result && $query_result->numrows) {
	my @fakenodes;

	while( @fakenodes = $query_result->fetchrow_array() ) {
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
	    my ($external, $node1, $card1, $port1, $node2, $card2, $port2) = @fakenodes;
	    my $extnode = $external eq $node1 ? $node1 : $node2;
	    my $extcard = $external eq $node1 ? $card1 : $card2;
	    my $extport = $external eq $node1 ? $port1 : $port2;
	    my $switchnode = $external eq $node1 ? $node2 : $node1;
	    my $switchcard = $external eq $node1 ? $card2 : $card1;
	    my $switchport = $external eq $node1 ? $port2 : $port1;

	    my $iface = Interface->Lookup( $extnode, $extcard, $extport );
	    my $ifacename = $iface->iface();
	    
	    $fakenodemap{ "$extnode:$ifacename" } =
		"$switchnode:$switchcard:$switchport";
	    
	    next if grep { $_ eq $switchnode } @switchnodenames;
	    
	    push( @switchnodenames, ($switchnode) );

	    push( @fakenodenames, ($external) )
		unless grep { $_ eq $external } @fakenodenames;
	    
	    my $node = Node->Lookup( $switchnode );
Gary Wong's avatar
Gary Wong committed
335
336

	    emdbi::DBQueryWarnN( $db, "INSERT INTO ops_node SET " .
337
				 "\$schema='http://www.gpolab.bbn.com/monitoring/schema/20140828/node#', " .
338
339
340
				 "id='${DOMAIN}_node_$switchnode'," .
				 "selfRef='$URL/info/node/${DOMAIN}_node_$switchnode'," .
				 "urn='urn:publicid:IDN+$DOMAIN+node+$switchnode'," .
341
342
				 "ts='$ts'," .
				 "node_type='switch'" );
Gary Wong's avatar
Gary Wong committed
343
344

	    emdbi::DBQueryWarnN( $db, "INSERT INTO ops_aggregate_resource SET " .
345
				 "id='${DOMAIN}_node_$switchnode'," .
Gary Wong's avatar
Gary Wong committed
346
				 "aggregate_id='$NICKNAME'," .
347
348
				 "urn='urn:publicid:IDN+$DOMAIN+node+$switchnode'," .
				 "selfRef='$URL/info/node/${DOMAIN}_node_$switchnode'" );
Gary Wong's avatar
Gary Wong committed
349
	    
350
	    AddInterfaces( $switchnode, $node, $ts );
Gary Wong's avatar
Gary Wong committed
351
352
353
354
355
	}
    }

    emdbi::DBQueryWarnN( $db, "UNLOCK TABLES" );

Gary Wong's avatar
Gary Wong committed
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
    emdbi::DBQueryWarnN( $db, "LOCK TABLES ops_link WRITE, " .
			 "ops_interfacevlan WRITE, " .
			 "ops_link_interfacevlan WRITE, " .
			 "ops_aggregate_resource WRITE" );
    emdbi::DBQueryWarnN( $db, "DELETE FROM ops_link_interfacevlan" );

    $query_result = emdbi::DBQueryWarnN( $tbdb, "SELECT DISTINCT lanid " .
					    "FROM lan_members AS l, " .
					    "external_networks AS e WHERE " .
					    "l.node_id=e.node_id" );
    if( $query_result && $query_result->numrows ) {
	my @lanids;

	while( @lanids = $query_result->fetchrow_array() ) {
	    my ($lanid) = @lanids;
	    
	    my $lan = VLan->Lookup( $lanid );

	    next if( !defined( $lan ) );

	    my $tag = $lan->GetTag();

378
379
	    next if( !defined( $tag ) || $tag <= 0 );

Gary Wong's avatar
Gary Wong committed
380
381
382
383
384
385
386
	    my @members;

	    next if( $lan->MemberList( \@members ) != 0 );

	    next if( ( scalar @members ) < 2 );

	    my $edomain;
387
388
	    my $enode = undef;
	    my $inode = undef;
Gary Wong's avatar
Gary Wong committed
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
	    my $snode;

	    foreach my $member ( @members ) {
		my $noderef;
		my $nodeid;
		my $iface;

		next if( $member->GetNodeIface( \$noderef, \$iface ) != 0 );
		$nodeid = $noderef->node_id();		

		if( !defined( $enode ) &&
		    grep { $_ eq $nodeid } @fakenodenames ) {

		    my $peer;
		    # Figuring out the other end of an external interface of
		    # a fake node seems to be inconsistent.  Sometimes it's
		    # in the external_interface column of the wires table.
		    # Sometimes it's in the external_interface of the
		    # external_networks table.  So we try both...
		    my $pquery_result = emdbi::DBQueryWarnN(
			$tbdb, "SELECT external_interface FROM " .
			"external_networks WHERE node_id='$nodeid' AND " .
			"external_interface IS NOT NULL" );
		    if( $pquery_result && $pquery_result->numrows ) {
			($peer) = $pquery_result->fetchrow_array();
		    } else {
			$pquery_result = emdbi::DBQueryWarnN(
			    $tbdb, "SELECT external_interface FROM " .
			    "wires AS w, interfaces AS i WHERE " .
			    "( ( w.node_id1='$nodeid' AND w.card1=i.card " .
			    "AND w.port1=i.port ) OR " .
			    "( w.node_id2='$nodeid' AND w.card2=i.card " .
			    "AND w.port2=i.port ) ) AND " .
			    "i.node_id='$nodeid' AND i.iface='$iface'" );

			if( $pquery_result && $pquery_result->numrows ) {
			    ($peer) = $pquery_result->fetchrow_array();
			} else {
			    next;
			}
		    }

		    my $type;
		    ( $edomain, $type, $enode ) = GeniHRN::Parse( $peer );
		    $enode = GeniHRN::Transcribe( $enode );
434
		    $snode = $fakenodemap{ "$nodeid:$iface" };
Gary Wong's avatar
Gary Wong committed
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
		} else {
		    $inode = "$nodeid:$iface";
		}
	    }

	    next if( !defined( $enode ) || !defined( $inode ) );

	    AddLink( "${lanid}e", $ts );
	    AddLink( "${lanid}i", $ts );

	    AddInterfaceVlan( "${lanid}e", $DOMAIN, $snode, $tag, $ts );
	    AddInterfaceVlan( "${lanid}e", $edomain, $enode, $tag, $ts );

	    AddInterfaceVlan( "${lanid}i", $DOMAIN, $snode, $tag, $ts );
	    AddInterfaceVlan( "${lanid}i", $DOMAIN, $inode, $tag, $ts );
	}
    }

    emdbi::DBQueryWarnN( $db, "UNLOCK TABLES" );

Gary Wong's avatar
Gary Wong committed
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
    # Add traffic counters for the (fake) switch nodes.  Do this after
    # unlocking the database, because we invoke portstats, which is slow.
    # We lose atomicity, but since we're only doing appends, it doesn't
    # really matter.
    foreach my $n ( @fakenodenames ) {
	open( P, "$PORTSTATS -s $n:eth0|" );
	# ignore 3 lines of headers
	<P>;
	<P>;
	<P>;
	# Do any fake nodes we care about have more than one interface?  Let's
	# assume not.
	if( <P> =~ /(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ ) {
	    my @counts = ( $2, $3 + $4, $5, $6 + $7 );

	    if( exists( $portcounters{$n} ) ) {
		my $oldcounts = $portcounters{$n};

		my $rx_b = ( $counts[ 0 ] - $$oldcounts[ 0 ] ) / $INTERVAL;
		my $rx_p = ( $counts[ 1 ] - $$oldcounts[ 1 ] ) / $INTERVAL;
		my $tx_b = ( $counts[ 2 ] - $$oldcounts[ 2 ] ) / $INTERVAL;
		my $tx_p = ( $counts[ 3 ] - $$oldcounts[ 3 ] ) / $INTERVAL;

		if( ( $rx_b >= 0 ) && ( $rx_p >= 0 ) &&
		    ( $rx_b >= 0 ) && ( $rx_p >= 0 ) ) {
		    emdbi::DBQueryWarnN( $db, "INSERT INTO " .
					 "ops_interface_rx_bps SET " .
					 "id='${DOMAIN}_interface_$n:eth0'," .
					 "ts='$ts'," .
					 "v=$rx_b;" );
		    emdbi::DBQueryWarnN( $db, "INSERT INTO " .
					 "ops_interface_rx_pps SET " .
					 "id='${DOMAIN}_interface_$n:eth0'," .
					 "ts='$ts'," .
					 "v=$rx_p;" );
		    emdbi::DBQueryWarnN( $db, "INSERT INTO " .
					 "ops_interface_tx_bps SET " .
					 "id='${DOMAIN}_interface_$n:eth0'," .
					 "ts='$ts'," .
					 "v=$tx_b;" );
		    emdbi::DBQueryWarnN( $db, "INSERT INTO " .
					 "ops_interface_tx_pps SET " .
					 "id='${DOMAIN}_interface_$n:eth0'," .
					 "ts='$ts'," .
					 "v=$tx_p;" );
		    # We don't count errors.  Does anybody care?  If they
		    # do, we could insert rows of zeroes.
		}
	    }

	    $portcounters{$n} = \@counts;
	}
	close( P );
    }

    sleep( $INTERVAL );
Gary Wong's avatar
Gary Wong committed
511

Gary Wong's avatar
Gary Wong committed
512
    # FIXME add slice, sliver, user information
Gary Wong's avatar
Gary Wong committed
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
}

sub fatal($)
{
    my ($msg) = @_;

    #
    # Send a message to the testbed list. 
    #
    SENDMAIL($TBOPS,
	     "ProtoGENI monitoring daemon died",
	     $msg,
	     $TBOPS);
    MarkDaemonStopped("mondbd");
    die("*** $0:\n".
	"    $msg\n");
}