Skip to content

Commit

Permalink
#73 influxdb spike
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyweston committed Jun 26, 2019
1 parent 8dfcce4 commit 3d9e88c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ libraryDependencies ++= Seq(
"org.apache.logging.log4j" % "log4j-slf4j-impl" % log4j,
"org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.0",
"io.verizon.knobs" %% "core" % "6.0.33",
"com.paulgoldbaum" %% "scala-influxdb-client" % "0.6.0",
"org.specs2" %% "specs2-core" % "3.9.5" % "test"
)

Expand Down
43 changes: 43 additions & 0 deletions src/test/scala/bad/robot/temperature/InfluxSpike.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package bad.robot.temperature

import bad.robot.temperature.rrd.{Host, Seconds}
import com.paulgoldbaum.influxdbclient.{InfluxDB, QueryResult, Record}

import scala.concurrent.Await
import scala.concurrent.duration.Duration

object InfluxSpike extends App {

import scala.concurrent.ExecutionContext.Implicits.global

val influx = InfluxDB.connect("telephone.local", 8086)

val database = influx.selectDatabase("temperatures")

val future = database.query("SELECT * from temperature")
private val result: QueryResult = Await.result(future, Duration("10 seconds"))
println(result.series.head.records.map(toThing).mkString("\n"))

influx.close()

def toThing(record: Record): String = {
val host = record("host").asInstanceOf[String]
val timezone = record("timezone").asInstanceOf[String]
val temperature1: Double = record("sensor-1").asInstanceOf[BigDecimal].toDouble
val temperature2 = record("sensor-2").asInstanceOf[BigDecimal].toDouble
val temperature3 = record("sensor-3").asInstanceOf[BigDecimal].toDouble
val temperature4 = record("sensor-4").asInstanceOf[BigDecimal].toDouble

val m = Measurement(
Host(host, None, Some(timezone)),
Seconds(0),
List(
SensorReading("sensor-1", Temperature(temperature1)),
SensorReading("sensor-2", Temperature(temperature2)),
SensorReading("sensor-3", Temperature(temperature3)),
SensorReading("sensor-4", Temperature(temperature4))
)
)
m.toString
}
}

0 comments on commit 3d9e88c

Please sign in to comment.