Skip to content

Instantly share code, notes, and snippets.

@btd
Created December 16, 2018 18:27
Show Gist options
  • Save btd/49079c38ddb0e06b0641c1d0d74ae3bb to your computer and use it in GitHub Desktop.
Save btd/49079c38ddb0e06b0641c1d0d74ae3bb to your computer and use it in GitHub Desktop.
package ingo.commons.util
import com.amazonaws.services.cloudwatch.{AmazonCloudWatch, AmazonCloudWatchClientBuilder}
import com.amazonaws.services.cloudwatch.model.{Dimension, MetricDatum, PutMetricDataRequest, StandardUnit}
import ingo.commons.props.DefaultProperties
object CloudWatch {
var client: AmazonCloudWatch = _
def init() = {
client = AmazonCloudWatchClientBuilder.standard
.withRegion(DefaultProperties.awsRegionName)
.build
}
def envDimension =
new Dimension()
.withName("Env")
.withValue(DefaultProperties.env)
def eventDimension(eventId: String) =
new Dimension()
.withName("EventId")
.withValue(eventId)
def widgetDimension(widgetId: String) =
new Dimension()
.withName("WidgetId")
.withValue(widgetId)
def putMetric(namespace: String)(name: String, unit: StandardUnit, value: Double, dimensions: Dimension*) = {
val datum = new MetricDatum()
.withMetricName(name)
.withUnit(unit)
.withValue(value)
.withDimensions(dimensions: _*)
val request = new PutMetricDataRequest()
.withNamespace(namespace)
.withMetricData(datum)
client.putMetricData(request)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment