Last active
December 13, 2015 21:29
-
-
Save helena/4977942 to your computer and use it in GitHub Desktop.
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
class ClusterMetricsElasticScaleListener extends Actor with ActorLogging { | |
val selfAddress = Cluster(context.system).selfAddress | |
override def preStart(): Unit = | |
Cluster(context.system).subscribe(self, classOf[ClusterMetricsChanged]) | |
override def postStop(): Unit = | |
Cluster(context.system).unsubscribe(self) | |
def receive = { | |
case ClusterMetricsChanged(metrics) ⇒ | |
metrics filter (_.address == selfAddress) foreach { nodeMetrics ⇒ | |
elasticScaleForHeap(nodeMetrics) | |
elasticScaleForCpu(nodeMetrics) | |
} | |
case state: CurrentClusterState ⇒ // ignore | |
} | |
def elasticScaleForHeap(metrics: NodeMetrics): Unit = metrics match { | |
case HeapMemory(address, timestamp, used, committed, max) ⇒ | |
log.info("Used heap: {} MB", used.doubleValue / 1024 / 1024) | |
// pipeTo elasticScale API | |
case _ ⇒ // complete head data not available | |
} | |
def elasticScaleForCpu(metrics: NodeMetrics): Unit = metrics match { | |
case Cpu(address, timestamp, Some(systemLoadAverage), cpuCombined, processors) ⇒ | |
log.info("Load: {} ({} processors)", systemLoadAverage, processors) | |
// pipeTo elasticScale API | |
case _ ⇒ // complete cpu data not available | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment