Guest User

Untitled

a guest
Dec 16th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package ingo.commons.util
  2.  
  3. import com.amazonaws.services.cloudwatch.{AmazonCloudWatch, AmazonCloudWatchClientBuilder}
  4. import com.amazonaws.services.cloudwatch.model.{Dimension, MetricDatum, PutMetricDataRequest, StandardUnit}
  5.  
  6. import ingo.commons.props.DefaultProperties
  7.  
  8. object CloudWatch {
  9. var client: AmazonCloudWatch = _
  10.  
  11. def init() = {
  12. client = AmazonCloudWatchClientBuilder.standard
  13. .withRegion(DefaultProperties.awsRegionName)
  14. .build
  15. }
  16.  
  17. def envDimension =
  18. new Dimension()
  19. .withName("Env")
  20. .withValue(DefaultProperties.env)
  21.  
  22. def eventDimension(eventId: String) =
  23. new Dimension()
  24. .withName("EventId")
  25. .withValue(eventId)
  26.  
  27. def widgetDimension(widgetId: String) =
  28. new Dimension()
  29. .withName("WidgetId")
  30. .withValue(widgetId)
  31.  
  32. def putMetric(namespace: String)(name: String, unit: StandardUnit, value: Double, dimensions: Dimension*) = {
  33. val datum = new MetricDatum()
  34. .withMetricName(name)
  35. .withUnit(unit)
  36. .withValue(value)
  37. .withDimensions(dimensions: _*)
  38.  
  39. val request = new PutMetricDataRequest()
  40. .withNamespace(namespace)
  41. .withMetricData(datum)
  42.  
  43. client.putMetricData(request)
  44. }
  45. }
Add Comment
Please, Sign In to add comment