Skip to content
andyk edited this page Jan 15, 2011 · 2 revisions

The various components of the RAD Lab stack will be dumping relevant metrics (which are specified in the RAD Lab demo Google doc) into a mySQL database which is being administered by Ari Rabkin.

To dump records to this database from a Scala program, do something like the following:

  import java.sql.{Connection, DriverManager, ResultSet, SQLException}
...
   //set up mysql connection for statistics
  val statement = statsServer.map(connString => {
    try {
      val conn = DriverManager.getConnection(connString)
      Some(conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE))
    } catch {
      case e: SQLException => logger.warning("Connection to SQL Database failed with connection string %s.".format(connString))
      None
    }
  })
...
  statement.foreach(s => {
    val now = new Date
    val sqlInsertCmd = "INSERT INTO appReqRate (timestamp, webAppID, aggRequestRate, targetNumServers) VALUES (%d, '%s', %f, %d)".format(now.getTime, name, aggregateReqRate, targetNumServers)
    try { 
      val numResults = s.map(_.executeUpdate(sqlInsertCmd))
      if (numResults.getOrElse(0) != 1) 
        logger.warning("SQL INSERT statment failed.")
    } catch {
      case e: SQLException => logger.warning("SQL INSERT statement failed: %s.".format(sqlInsertCmd))
    }
  })