Skip to content

Instantly share code, notes, and snippets.

@EwanDawson
Last active July 18, 2017 18:08
Show Gist options
  • Save EwanDawson/63a7130b0adacbe242aa22f8eadb9b7c to your computer and use it in GitHub Desktop.
Save EwanDawson/63a7130b0adacbe242aa22f8eadb9b7c to your computer and use it in GitHub Desktop.
Writes one or more data poins to an instance of InfluxDB running on localhost port 8086
@Grapes([
@Grab("com.jcabi:jcabi-http:1.17.1"),
@Grab("javax.json:javax.json-api:1.0"),
@Grab("org.glassfish:javax.json:1.0.4"),
@Grab("org.hamcrest:hamcrest-library:1.3"),
@Grab("org.hamcrest:hamcrest-core:1.3"),
@Grab("javax.ws.rs:javax.ws.rs-api:2.0.1")
])
import com.jcabi.http.request.JdkRequest
import com.jcabi.http.response.RestResponse
import java.time.Instant
def (db, data) = payload
new JdkRequest("http://localhost:8086/write?db=$db")
.method("POST")
.body().set(data.join('\n')).back()
.fetch().as(RestResponse).assertStatus(204)
.body()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment