#!/usr/bin/perl # # # Description: LiveSPC.com Instrument for # collecting data from MySQL. # # $Id: lspcMon.pl,v 1.5 2009/11/25 14:48:04 michaelholder Exp $ # # Copyright (C) 2007-2009 TRD Associates, LLC # # - All rights reserved. # # use strict; use DBI; use lib '/home/water-rockets/client/'; use LiveSPC; # User your MySQL database, user name, and password here: my $dbh = DBI->connect("dbi:mysql:DATABASE", 'USER_NAME', 'PASSWORD', { RaiseError => 1, AutoCommit => 0 }); my $GetValidUsers = $dbh->prepare( 'select count(_ID) from USER where validated is not null' ); my $GetSessions = $dbh->prepare( 'select count(_ID) from SESSION where userID is not null and state!=\'NewUser\'' ); my $GetLoggedIn = $dbh->prepare( 'select count(_ID) from SESSION where state=\'LoggedIn\'' ); my $validUsers = 0; if ( $GetValidUsers->execute() ) { ( $validUsers ) = $GetValidUsers->fetchrow_array; } print "Validated Users = $validUsers\n"; my $sessions = 0; if ( $GetSessions->execute() ) { ( $sessions ) = $GetSessions->fetchrow_array; } print "Sessions = $sessions\n"; my $loggedIn = 0; if ( $GetLoggedIn->execute() ) { ( $loggedIn ) = $GetLoggedIn->fetchrow_array; } print "Logged-in Users = $loggedIn\n"; $GetValidUsers->finish(); $GetSessions->finish(); $GetLoggedIn->finish(); my $rc = $dbh->disconnect; if ( not $rc ) { print STDERR "close error, result = $rc\n"; } my $date = gmtime(); my $text = "$date\t$validUsers\t$loggedIn\t$sessions"; print "$text\n"; # Use the ID and PASSCODE for your dataset here: my $success = LiveSPC::updateData(DATASETID, 'PASSCODE', 'APPEND', $text); if ($success) { print "<<\n$success\n>>\n"; print "data submitted successfully\n"; } else { print "data NOT submitted successfully\n"; }