Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
esa.ioのStatsをDatadogに送信するScalaスクリプト
import $ivy.`dev.nomadblacky::scaladog:0.2.0`
import scala.util.chaining._
import scaladog._
import java.time.Instant
@main def main(team: String): Unit = {
val esaToken =
sys.env.getOrElse("ESA_TOKEN", throw new IllegalArgumentException("Not found the environment variable: ESA_TOKEN"))
val ddclient = scaladog.Client()
val now = Instant.now()
println(s"Get $team.esa.io stats ...")
val esaStats = requests
.get(
url = s"https://api.esa.io/v1/teams/$team/stats",
headers = Seq("Authorization" -> s"Bearer $esaToken")
)
.tap(res => if (!res.is2xx) throw new IllegalStateException(res.toString))
.text()
.pipe(ujson.read(_))
println(esaStats.render(2))
val series: Seq[Series] = esaStats.obj.map { case (key, value) =>
Series(
metric = s"esa_io.$key",
points = Seq(
Point(now, value.num.intValue)
),
host = s"esa_io.$team",
tags = Seq(Tag(s"team:$team"))
)
}.toSeq
println("Post stats to Datadog ...")
ddclient.postMetrics(series)
println("Done!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.