Created
December 16, 2018 18:27
-
-
Save btd/49079c38ddb0e06b0641c1d0d74ae3bb to your computer and use it in GitHub Desktop.
This file contains 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
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