mon-core


License

License

GroupId

GroupId

ml.milkov
ArtifactId

ArtifactId

mon-core_2.11
Last Version

Last Version

0.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

mon-core
mon-core
Project URL

Project URL

https://github.com/amilkov3/mon
Project Organization

Project Organization

ml.milkov
Source Code Management

Source Code Management

https://github.com/amilkov3/mon

Download mon-core_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/ml.milkov/mon-core_2.11/ -->
<dependency>
    <groupId>ml.milkov</groupId>
    <artifactId>mon-core_2.11</artifactId>
    <version>0.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/ml.milkov/mon-core_2.11/
implementation 'ml.milkov:mon-core_2.11:0.2.1'
// https://jarcasting.com/artifacts/ml.milkov/mon-core_2.11/
implementation ("ml.milkov:mon-core_2.11:0.2.1")
'ml.milkov:mon-core_2.11:jar:0.2.1'
<dependency org="ml.milkov" name="mon-core_2.11" rev="0.2.1">
  <artifact name="mon-core_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='ml.milkov', module='mon-core_2.11', version='0.2.1')
)
libraryDependencies += "ml.milkov" % "mon-core_2.11" % "0.2.1"
[ml.milkov/mon-core_2.11 "0.2.1"]

Dependencies

compile (7)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.12
org.scoverage : scalac-scoverage-runtime_2.11 jar 1.3.1
com.typesafe.scala-logging : scala-logging_2.11 jar 3.5.0
io.estatico : newtype_2.11 jar 0.1.0
org.typelevel : cats-core_2.11 jar 1.0.1
org.typelevel : cats-effect_2.11 jar 0.8
org.typelevel : mouse_2.11 jar 0.16

test (2)

Group / Artifact Type Version
org.scalacheck : scalacheck_2.11 jar 1.13.4
org.scalatest : scalatest_2.11 jar 3.0.1

Project Modules

There are no modules declared in this project.

Mon

Build status codecov Maven metadata URI

alt

Metrics management and associated metric client implementations

Supported clients:

  • AWS Cloudwatch. For credential configuration instructions click here (I recommend you download the AWS CLI and then let it generate the necessary config files via aws configure)
"ml.milkov" %% "mon-cloudwatch" % "0.2.0"

Supported metric architectures:

  • When you send metrics they are placed in an in-memory concurrent queue. A watcher (java.util.Timer task) sends a configured quantity of metrics to the upstream service at a configured interval. This is facilitated by a hash map manager, which drains the queue and places the metrics in an intermediate hashmap which is necessary in order to track aggregate metrics (more about this below). All of this happens on a single long running thread (the timer task) so there are no race conditions

Say you send the following metrics:

("ametric", aggregate=false, timestamp1, 1.0), ("ametric", aggregate=false, timestamp2, 2.0),
("bmetric", aggregate=true, timestamp3, 1.0), (("bmetric", aggregate=true, timestamp4, 2.0),
("bmetric", aggregate=true, timestamp5, -1.0)

These will go in the hashmap as:

"ametric" -> [(timestamp1, 1.0), (timestamp2, 2.0)]
"bmetric" -> [(timestamp3, 1.0), (timestamp4, 3.0), (timestamp5, 2.0)]

And will be subsequently sent upstream as such

Usage

Every metric key must extend mon.metrickey.MetricK and have an instance of cats.Show. There is a default key type: mon.metrickey.MetricKey if you want to just use that. It should be more than sufficient for most use cases

Here's how to instantiate a watcher and start sending metrics:

import mon._

/** instantiate a metric */
val metricKey = MetricKey.createKey(
  MetricPrefix.tag("testPrefix"),
  MetricDomain.tag("testDomain"),
  MetricName.tag("testName", aggregate = true)
)

import mon.cloudwatch._

/** your Cloudwatch conf */
val cwConf = new CloudwatchConf {
  override val namespace = "myNamespace"
}

import cats.effect.IO

/** You can use just the client wrapper */
val cc = new CloudwatchClient[IO, MetricKey](cwConf)

/** You can call send directly which will send whatever metrics you provide sync or async
(depending on how you run the `cats.effect.Effect` instance) */
cc.send(
  (metricKey, Timestamp.now(), 1.0),
  (metricKey, Timestamp.now(), 2.0)
).unsafeRunSync()


//To use the full architecture

import scala.concurrent.duration._

val buffConf = new MetricBufferConf[MetricKey]{
  override val flushMetricsCount: Int = 50
  override def bufferSizeMetricName: Option[MetricKey] = None
}

val mwConf = new MonitorWatcherConf {
  override val sendMetricsInterval = 2.minutes
}

/** spin up architecture (`client` here is simply a convenience
* if you want to make raw metrics pushes)
 *  */
val (monitorWatcher, client, buffer) = CloudwatchTimerWatcher[IO, MetricKey](
  mwConf,
  buffConf,
  cwConf,
  Async // execution style for sending the metrics upstream, either Sync or Async
)

/** start the watcher */
monitorWatcher.run()

/** push metrics to the queue which will eventually
* be sent upstream to your metrics service by the watcher */
buffer.push(
  (metricKey, Timestamp.now(), 1.0),
  (metricKey, Timestamp.now(), 2.0)
)

Versions

Version
0.2.1
0.1.2