Created
September 12, 2019 15:01
-
-
Save NomadBlacky/2c56814a1993e327ed2c2e3d8da01eed to your computer and use it in GitHub Desktop.
esa.ioのStatsをDatadogに送信する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
| 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