From 3d9e88c7f088762781215bcff497015b9ae6cd40 Mon Sep 17 00:00:00 2001 From: Toby Date: Wed, 26 Jun 2019 21:33:41 +0100 Subject: [PATCH] #73 influxdb spike --- build.sbt | 1 + .../bad/robot/temperature/InfluxSpike.scala | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/test/scala/bad/robot/temperature/InfluxSpike.scala diff --git a/build.sbt b/build.sbt index 8ae7297..1b16697 100644 --- a/build.sbt +++ b/build.sbt @@ -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" ) diff --git a/src/test/scala/bad/robot/temperature/InfluxSpike.scala b/src/test/scala/bad/robot/temperature/InfluxSpike.scala new file mode 100644 index 0000000..2d43bba --- /dev/null +++ b/src/test/scala/bad/robot/temperature/InfluxSpike.scala @@ -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 + } +}