Last active
June 10, 2017 02:02
-
-
Save fancellu/ef885ead883f5bb5c17e to your computer and use it in GitHub Desktop.
Tiny bit of code emitting to InfluxDB Time Series Database in Scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Working jar not released, so using jitpack to build on the fly. | |
Be sure to create "mydb" first. e.g. CREATE DATABASE "mydb" | |
For pom.xml | |
<repository> | |
<id>jitpack.io</id> | |
<url>https://jitpack.io</url> | |
</repository> | |
<dependency> | |
<groupId>com.github.influxdb</groupId> | |
<artifactId>influxdb-java</artifactId> | |
<version>ef90bf6865</version> | |
</dependency> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package influxdb | |
import org.influxdb._ | |
import org.influxdb.dto._ | |
import java.util.concurrent.TimeUnit | |
object Influx1 extends App { | |
val influxDB = InfluxDBFactory.connect("http://localhost:8086", "root", "root"); | |
println(influxDB.describeDatabases()) | |
val batchPoints = BatchPoints.database("mydb").tag("async", "true").retentionPolicy("default").build(); | |
val point1 = Point.measurement("cpu") | |
// .time(System.currentTimeMillis(), TimeUnit.MILLISECONDS) | |
.tag("host", "serverB").tag("region", "us_south") | |
.field("value", 0.20) | |
.build(); | |
println(batchPoints) | |
batchPoints.point(point1) | |
influxDB.write(batchPoints) | |
Thread.sleep(1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment