• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ManagementFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中java.lang.management.ManagementFactory的典型用法代码示例。如果您正苦于以下问题:Scala ManagementFactory类的具体用法?Scala ManagementFactory怎么用?Scala ManagementFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ManagementFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Metrics

//设置package包名称以及导入依赖的类
package com.onur.moviedb.metric

import java.lang.management.ManagementFactory
import java.util.concurrent.TimeUnit

import com.codahale.metrics.health.HealthCheckRegistry
import com.codahale.metrics.{JmxReporter, MetricRegistry, Slf4jReporter}
import com.codahale.metrics.jvm.{BufferPoolMetricSet, GarbageCollectorMetricSet, MemoryUsageGaugeSet, ThreadStatesGaugeSet}
import org.slf4j.LoggerFactory


object Metrics {
  lazy val metricRegistry: MetricRegistry = {
    val metricRegistry: MetricRegistry = new MetricRegistry
    Slf4jReporter.forRegistry(metricRegistry)
      .outputTo(LoggerFactory.getLogger("metrics"))
      .convertRatesTo(TimeUnit.SECONDS)
      .convertDurationsTo(TimeUnit.MILLISECONDS)
      .build
      .start(30, TimeUnit.SECONDS)
    JmxReporter.forRegistry(metricRegistry).build.start()
    metricRegistry.register("jvm-gc", new GarbageCollectorMetricSet)
    metricRegistry.register("jvm-buffer", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer))
    metricRegistry.register("jvm-memory", new MemoryUsageGaugeSet)
    metricRegistry.register("jvm-threads", new ThreadStatesGaugeSet)
    metricRegistry
  }

  lazy val healthCheckRegistry = new HealthCheckRegistry
} 
开发者ID:onurzdg,项目名称:movie-db,代码行数:31,代码来源:Metrics.scala


示例2: healthRoutes

//设置package包名称以及导入依赖的类
package service.health

import java.lang.management.ManagementFactory

import akka.http.scaladsl.server.Directives._

import scala.concurrent.duration._

trait HealthRoutes {

  def healthRoutes = pathPrefix("health") {
    path("ping") {
      get {
          complete("OK")
        }
      } ~ path("uptime") {
      get {
        complete(getUptime.toString)
      }
    }
  }
  
  private def getUptime = Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toSeconds
} 
开发者ID:devknutst,项目名称:watermarkAkka,代码行数:25,代码来源:HealthRoutes.scala


示例3: Status

//设置package包名称以及导入依赖的类
// Copyright (c) Microsoft.All rights reserved.

package com.microsoft.azure.iot.iothub2cassandra.webservice

import java.lang.management.ManagementFactory

import spray.json.{JsNumber, JsObject, JsString, JsValue}

object Status {
  def get: JsValue = {
    val runtimeMXB = ManagementFactory.getRuntimeMXBean
    val osMXB = ManagementFactory.getOperatingSystemMXBean

    val runtime = JsObject(
      "startTime" ? JsNumber(runtimeMXB.getStartTime),
      "uptimeMsecs" ? JsNumber(runtimeMXB.getUptime),
      "name" ? JsString(runtimeMXB.getName),
      "vmName" ? JsString(runtimeMXB.getVmName)
    )

    val os = JsObject(
      "arch" ? JsString(osMXB.getArch),
      "name" ? JsString(osMXB.getName),
      "version" ? JsString(osMXB.getVersion),
      "processors" ? JsNumber(osMXB.getAvailableProcessors),
      "systemLoadAvg" ? JsNumber(osMXB.getSystemLoadAverage)
    )

    JsObject(
      "runtime" ? runtime,
      "os" ? os
    )
  }
} 
开发者ID:Azure,项目名称:toketi-iothub-to-cassandra,代码行数:35,代码来源:Status.scala


示例4: Profiling

//设置package包名称以及导入依赖的类
package ppl.delite.runtime
package profiler

import ppl.delite.runtime.Config
import ppl.delite.runtime.graph.DeliteTaskGraph
import java.lang.management.ManagementFactory


//front-facing interface to activate all profiling tools
object Profiling {

  private var globalStartNanos = 0L
  private var jvmUpTime = 0L

  def init(graph: DeliteTaskGraph) {
    Profiler.init(graph)
    val totalResources = Config.numThreads + Config.numCpp + Config.numCuda + Config.numOpenCL
    PerformanceTimer.initializeStats(totalResources)
    MemoryProfiler.initializeStats(totalResources)
  }

  def startRun() {
    PerformanceTimer.clearAll()
    globalStartNanos = System.nanoTime()
    jvmUpTime = ManagementFactory.getRuntimeMXBean().getUptime()
    PerformanceTimer.start("all", false)
  }

  def endRun() {
    PerformanceTimer.stop("all", false)
    PerformanceTimer.printStatsForNonKernelComps()
    if (Config.dumpProfile) Profiler.dumpProfile(globalStartNanos, jvmUpTime)  
    if (Config.dumpStats) PerformanceTimer.dumpStats()   
  }

} 
开发者ID:leratojeffrey,项目名称:OptiSDR-Compiler,代码行数:37,代码来源:Profiling.scala


示例5: ServerStatsController

//设置package包名称以及导入依赖的类
package br.com.verde.serverstats

import com.twitter.finatra.http.Controller
import com.google.inject.Inject
import com.twitter.finatra.validation._
import com.google.inject.Singleton
import com.twitter.finagle.http.Request
import java.lang.management.ManagementFactory
import java.lang.management.OperatingSystemMXBean
import java.io.File

@Singleton
class ServerStatsController @Inject() extends Controller {

  val runtime = Runtime.getRuntime

  val osBean = ManagementFactory.getOperatingSystemMXBean
  val runtimeBean = ManagementFactory.getRuntimeMXBean
  val memoryBean = ManagementFactory.getMemoryMXBean

  val megabyte = 1024 * 1024
  val second = 1000 // milisecond

  get("/serverStats") {
    request: Request =>

      val jvmTotalRam = runtime.maxMemory
      val jvmFreeRam = runtime.freeMemory
      val availableProcessors = osBean.getAvailableProcessors

      val freeSpace = File.listRoots.head.getFreeSpace

      val serverSystemLoad = osBean.getSystemLoadAverage
      val serverUptime = runtimeBean.getUptime

      val param = request.getParam("onlyRam")
      if (param == null) {
        response
          .ok
          .json(s"""{ "jvm_total_ram": "${jvmTotalRam / megabyte} Mb",
          "jvm_free_ram": "${jvmFreeRam / megabyte} Mb",
          "free_space": "${freeSpace / megabyte} Mb",
          "server_system_load": "${serverSystemLoad} %",
          "server_uptime": "${serverUptime / second} s",
          "available_processors": "${availableProcessors}" }""")
      } else {
        response
          .ok
          .json(s"""{ "jvm_total_ram": "${jvmTotalRam / megabyte} Mb",
          "jvm_free_ram": "${jvmFreeRam / megabyte} Mb" }""")
      }
  }
} 
开发者ID:verdetecnologia,项目名称:ServerStats,代码行数:54,代码来源:ServerStatsController.scala


示例6: SbtClasspathMapper

//设置package包名称以及导入依赖的类
package org.romanowski.hoarder.core

import java.io.File
import java.lang.management.ManagementFactory
import java.nio.file.Path
import java.nio.file.Paths

import sbt.Attributed
import sbt.Keys.artifact
import sbt.Keys.moduleID

class SbtClasspathMapper(projectRoot: Path,
                         classpath: Seq[Attributed[File]],
                         includeSize: Boolean = false) {

  def read(descriptor: String): Option[File] = classpathDescriptors.get(descriptor)

  def write(f: File): Option[String] =
    classpath.find(_.data == f).flatMap(stringifyAttributes)
    .orElse(asJVMJar(f.toPath))

  private def stringifyAttributes(from: Attributed[File]): Option[String] = for {
    artifact <- from.get(artifact.key)
    module <- from.get(moduleID.key)
  } yield {
    Seq(module.organization,
      module.revision,
      module.name,
      from.data.getName,
      artifact.classifier.getOrElse("-"),
      module.configurations.getOrElse("-"),
      if (includeSize) from.data.length() else -1
    ).mkString("#")
  }

  private def asJVMJar(filePath: Path): Option[String] = for {
    javaHome <- Option(System.getProperty("java.home"))
    javaHomePath = Paths.get(javaHome)
    if filePath.startsWith(javaHomePath)
    javaVersion <- Option(System.getProperty("java.specification.version"))
    relativePath = javaHomePath.relativize(filePath)
  } yield s"##$javaVersion##$relativePath"


  private lazy val jvmClasspath: Map[String, File] = if (ManagementFactory.getRuntimeMXBean.isBootClassPathSupported)
    ManagementFactory.getRuntimeMXBean.getBootClassPath.split(File.pathSeparator).flatMap { s =>
      val path = Paths.get(s)
      val jvmJar = asJVMJar(path)
      jvmJar.map(_ -> path.toFile)
    }(collection.breakOut)
  else Map.empty

  private lazy val classpathDescriptors: Map[String, File] =
    jvmClasspath ++ classpath.map(stringifyAttributes).zip(classpath).collect {
      case (Some(k), attributted) => k -> attributted.data
    }(collection.breakOut)
} 
开发者ID:romanowski,项目名称:hoarder,代码行数:58,代码来源:SbtClasspathMapper.scala


示例7: ScastieFileUtil

//设置package包名称以及导入依赖的类
package com.olegych.scastie.util

import java.nio.file._
import java.lang.management.ManagementFactory
import java.nio.charset.StandardCharsets
import System.{lineSeparator => nl}

object ScastieFileUtil {
  def slurp(src: Path): Option[String] = {
    if (Files.exists(src)) Some(Files.readAllLines(src).toArray.mkString(nl))
    else None
  }

  def write(dst: Path,
            content: String,
            truncate: Boolean = false,
            append: Boolean = false): Unit = {
    if (!Files.exists(dst)) {
      Files.write(dst, content.getBytes, StandardOpenOption.CREATE_NEW)
      ()
    } else if (truncate) {
      Files.write(dst, content.getBytes, StandardOpenOption.TRUNCATE_EXISTING)
      ()
    } else if (append) {
      Files.write(dst, content.getBytes, StandardOpenOption.APPEND)
      ()
    }
  }

  def writeRunningPid(): String = {
    val pid = ManagementFactory.getRuntimeMXBean.getName.split("@").head
    val pidFile = Paths.get("RUNNING_PID")
    Files.write(pidFile, pid.getBytes(StandardCharsets.UTF_8))
    sys.addShutdownHook {
      Files.delete(pidFile)
    }
    pid
  }
} 
开发者ID:scalacenter,项目名称:scastie,代码行数:40,代码来源:ScastieFileUtil.scala


示例8: InfluxDBExtensionTest

//设置package包名称以及导入依赖的类
package de.choffmeister.kamon.influxdb

import java.lang.management.ManagementFactory

import akka.actor.ActorSystem
import com.typesafe.config.ConfigFactory
import kamon.Kamon

class InfluxDBExtensionTest extends UnitTest {
  Kamon.start()
  val hostname = ManagementFactory.getRuntimeMXBean.getName.split('@')(1)

  "InfluxDBExtension" should "add host tag if not given explicitly" in {
    val system = ActorSystem("InfluxDBExtensionTest1")
    val influxDB = InfluxDB(system)

    influxDB.tags("host") should be(hostname)

    system.terminate()
  }

  it should "read tags from config" in {
    val config = ConfigFactory.parseString(
      """kamon.influxdb {
        |  tags = [
        |    { host: "foobar" }
        |    { apple: "pie" }
        |  ]
        |}
      """.stripMargin)
    val system = ActorSystem("InfluxDBExtensionTest2", config)
    val influxDB = InfluxDB(system)

    influxDB.tags("host") should be("foobar")
    influxDB.tags("apple") should be("pie")

    system.terminate()
  }
} 
开发者ID:choffmeister,项目名称:kamon-influxdb,代码行数:40,代码来源:InfluxDBExtensionTest.scala


示例9: HealthRoutes

//设置package包名称以及导入依赖的类
package com.example.usecase.health

import java.lang.management.ManagementFactory

import akka.actor.{ActorRef, ActorSystem}
import akka.cluster.Cluster
import akka.http.scaladsl.server.Directives
import scala.concurrent.duration._
import scala.collection.JavaConversions._

import scala.concurrent.duration._

class HealthRoutes(clusterListener: ActorRef)(implicit val actorSystem: ActorSystem) extends Directives {

  val cluster = Cluster(actorSystem)

  val healthRoutes = pathPrefix("health") {
    path("ping") {
      get {
        complete("OK")
      }
    } ~ path("uptime") {
      get {
        complete(getUptime.toString + " seconds")
      }
    } ~ path("nodes") {
      complete(cluster.state.getMembers.toList.map(member => member.address).mkString(","))
    }
  }
  private def getUptime = Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toSeconds
} 
开发者ID:kalamara,项目名称:akka-cassandra-hazelcast-cluster,代码行数:32,代码来源:HealthRoutes.scala


示例10: ProcessMetrics

//设置package包名称以及导入依赖的类
package eu.inn.metrics

import java.lang.management.ManagementFactory
import com.sun.management.{OperatingSystemMXBean, UnixOperatingSystemMXBean}
import scala.collection.JavaConversions._

object ProcessMetrics {
  def startReporting(reporter: MetricsTracker): Unit = {
    ManagementFactory.getOperatingSystemMXBean match {
      case unix: UnixOperatingSystemMXBean ?
        reporter.gauge("system.fd.max")(unix.getMaxFileDescriptorCount)
        reporter.gauge("system.fd.open")(unix.getOpenFileDescriptorCount)

        reporter.gauge("system.cpu.time")(unix.getProcessCpuTime)
        reporter.gauge("system.cpu.load")((unix.getProcessCpuLoad * 100).toLong)

      case other: OperatingSystemMXBean ?
        reporter.gauge("system.cpu.time")(other.getProcessCpuTime)
        reporter.gauge("system.cpu.load")((other.getProcessCpuLoad * 100).toLong)
    }


    val mem = ManagementFactory.getMemoryMXBean
    reporter.gauge("system.heap.max")(mem.getHeapMemoryUsage.getMax)
    reporter.gauge("system.heap.used")(mem.getHeapMemoryUsage.getUsed)
    reporter.gauge("system.heap.committed")(mem.getHeapMemoryUsage.getCommitted)

    ManagementFactory.getGarbageCollectorMXBeans.foreach { gc ?
      reporter.gauge(s"gc.${gc.getName.replaceAll("[^\\w]+", "-")}.count")(gc.getCollectionCount)
      reporter.gauge(s"gc.${gc.getName.replaceAll("[^\\w]+", "-")}.time")(gc.getCollectionTime)
    }
  }
} 
开发者ID:InnovaCo,项目名称:service-metrics,代码行数:34,代码来源:ProcessMetrics.scala


示例11: StatusService

//设置package包名称以及导入依赖的类
package g8.akkahttp.eventsvc

import java.lang.management.ManagementFactory

import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.server.{Directives, StandardRoute}
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._

import scala.concurrent.duration._

class StatusService(system: ActorSystem) extends StatusServiceTrait {

  override protected def log      = Logging(system, "service")
  override protected def executor = system.dispatcher
}

trait StatusServiceTrait extends BaseComponent {
  import Directives._
  import g8.akkahttp.eventsvc.data._
  import io.circe.generic.auto._

  def getStatus: StandardRoute = {
    log.info("/status executed")
    complete(Status(Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toString()))
  }
} 
开发者ID:stephmajor,项目名称:eventsvc,代码行数:28,代码来源:StatusService.scala


示例12: EventService

//设置package包名称以及导入依赖的类
package g8.akkahttp.eventsvc

import java.lang.management.ManagementFactory

import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.server.{Directives, Route}
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
import g8.akkahttp.eventsvc.data.access.{DataStoreComponent, MongoDataStoreImpl}

import scala.concurrent.duration.{Duration, MILLISECONDS}

class EventService(system: ActorSystem) extends EventServiceTrait with MongoDataStoreImpl {

  override protected def log      = Logging(system, "service")
  override protected def executor = system.dispatcher
}

trait EventServiceTrait extends BaseComponent with DataStoreComponent with ResponseFactory {
  import Directives._
  import g8.akkahttp.eventsvc.data._
  import io.circe.generic.auto._

  def getStatus: Route = {
    log.info("/event executing")
    complete(Status(Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toString()))
  }

  def readEvent(eventId: String): Route = {
    log.info("/event/read executing")
    complete(s"Requesting an event by Id: $eventId")
  }

  def createEvents(ecr: EventCreationRequest): Route = {
    log.info("/event/create executing")
    sendResponse(dataStore.createEvents(ecr.howMany))
  }

  def getEventsByType(triggerType: Int): Route = {
    log.info("/event/getEventsByType executing")
    sendResponse(
      for {
        events <- dataStore.getEventsByType(triggerType)
      } yield {
        events.map(_.toJson).mkString("[", ",", "]")
      }
    )
  }
} 
开发者ID:stephmajor,项目名称:eventsvc,代码行数:50,代码来源:EventService.scala


示例13: Heng

//设置package包名称以及导入依赖的类
package org.apache.sparktest
import java.lang.management.ManagementFactory
import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.Props

class Heng(ha: ActorRef) extends Actor {
  def receive = {
    case "start" => ha ! "heng"
    case "ha" =>
      println("?")
      ha ! "heng"
    case _ => println("heng what?")
  }
}
class Ha extends Actor {
  def receive = {
    case "heng" =>
      println("?")
      sender ! "ha"
    case _ => println("ha what?")
  }
}

object HengHa {
  def main(args: Array[String]): Unit = {
    //ActorSystem???????,???1...N???,????application??ActorSystem
    val system = ActorSystem("HengHaSystem")
   //actorOf???Actor,
    val ha = system.actorOf(Props[Ha], name = "ha")
    val heng = system.actorOf(Props(new Heng(ha)), name = "heng")

    //heng ! "start"    
    
    //ManagementFactory.getGarbageCollectorMXBeans.map(_.getCollectionTime).sum
  }
} 
开发者ID:tophua,项目名称:spark1.52,代码行数:39,代码来源:HengHa.scala


示例14: ContentionSnapshot

//设置package包名称以及导入依赖的类
package com.twitter.jvm

import java.lang.Thread.State._
import java.lang.management.{ManagementFactory, ThreadInfo}


class ContentionSnapshot {
  ManagementFactory.getThreadMXBean.setThreadContentionMonitoringEnabled(true)

  case class Snapshot(
    blockedThreads: Seq[String],
    lockOwners: Seq[String],
    deadlocks: Seq[String])

  private[this] object Blocked {
    def unapply(t: ThreadInfo): Option[ThreadInfo] = {
      t.getThreadState match {
        case BLOCKED | WAITING | TIMED_WAITING => Some(t)
        case _ => None
      }
    }
  }

  def snap(): Snapshot = {
    val bean = ManagementFactory.getThreadMXBean

    val blocked = bean.getThreadInfo(bean.getAllThreadIds, true, true)
                      .filter(_ != null)
                      .collect { case Blocked(info) => info }

    val ownerIds = blocked map(_.getLockOwnerId) filter(_ != -1)
    val owners = if (ownerIds.length == 0) Seq[String]() else
      bean.getThreadInfo(ownerIds.toArray, true, true).map(_.toString).toSeq

    val deadlockThreadIds = bean.findDeadlockedThreads()
    val deadlocks = if (deadlockThreadIds == null) Array.empty[ThreadInfo] else
      deadlockThreadIds.flatMap { id =>
        blocked.find { threadInfo =>
          threadInfo.getThreadId() == id
        }
      }

    Snapshot(
      blockedThreads = blocked.map(_.toString).toSeq,
      lockOwners = owners,
      deadlocks = deadlocks.map(_.toString).toSeq)
  }
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:49,代码来源:ContentionSnapshot.scala


示例15: Opt

//设置package包名称以及导入依赖的类
package com.twitter.jvm

import java.lang.management.ManagementFactory
import javax.management.openmbean.CompositeDataSupport
import javax.management.{ObjectName, RuntimeMBeanException}


object Opt {
  private[this] val DiagnosticName =
    ObjectName.getInstance("com.sun.management:type=HotSpotDiagnostic")

  def apply(name: String): Option[String] = try Some {
    val o = ManagementFactory.getPlatformMBeanServer().invoke(
      DiagnosticName, "getVMOption",
      Array(name), Array("java.lang.String"))
    o.asInstanceOf[CompositeDataSupport].get("value").asInstanceOf[String]
  } catch {
    case _: IllegalArgumentException =>
      None
    case rbe: RuntimeMBeanException
    if rbe.getCause.isInstanceOf[IllegalArgumentException] =>
      None
  }
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:25,代码来源:Opts.scala


示例16: OptsTest

//设置package包名称以及导入依赖的类
package com.twitter.jvm

import java.lang.{Boolean => JBool}
import java.lang.management.ManagementFactory
import javax.management.ObjectName
import org.junit.runner.RunWith
import org.scalatest.FunSuite
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
class OptsTest extends FunSuite  {
  test("Opts") {
    if (System.getProperty("java.vm.name").contains("HotSpot")) {
      val DiagnosticName =
        ObjectName.getInstance("com.sun.management:type=HotSpotDiagnostic")

      val originalValue: String = Opt("MaxHeapFreeRatio").getOrElse("100")

      val option = ManagementFactory.getPlatformMBeanServer().invoke(
        DiagnosticName, "getVMOption",
        Array("MaxHeapFreeRatio"),
        Array("java.lang.String"))

      val writable = option.getClass match {
        case clazz: Class[_] if clazz.getCanonicalName == "com.sun.management.VMOption" =>
          clazz.getMethod("isWriteable").invoke(option) match {
            case bool: JBool => bool: Boolean
            case _ => fail()
          }
        case _ => false
      }

      if (writable) {
        ManagementFactory.getPlatformMBeanServer().invoke(
          DiagnosticName, "setVMOption",
          Array("MaxHeapFreeRatio", "99"),
          Array("java.lang.String", "java.lang.String"))

        assert(Opt("MaxHeapFreeRatio") == Some("99"))

        ManagementFactory.getPlatformMBeanServer().invoke(
          DiagnosticName, "setVMOption",
          Array("MaxHeapFreeRatio", originalValue),
          Array("java.lang.String", "java.lang.String"))

        assert(Opt("MaxHeapFreeRatio") == Some(originalValue))

        assert(Opt("NonexistentOption") == None)
      }
    }
  }
} 
开发者ID:lanshuijuntuan,项目名称:Java.util,代码行数:53,代码来源:OptsTest.scala


示例17:

//设置package包名称以及导入依赖的类
package sekvensa.service.healthcheck

import java.lang.management.ManagementFactory

import akka.event.Logging
import akka.http.scaladsl.server.Directives._
import sekvensa.service.ServiceBase
import sekvensa.service.healthcheck.models.Status

import scala.concurrent.duration._

trait HealthCheckService extends ServiceBase {

  private val pingRoute = path("ping") {
    get {
      logRequest("/ping", Logging.InfoLevel) {
        complete("PONG")
      }
    }
  }

  private val uptimeRoute = path("uptime") {
    get {
      logRequest("/uptime", Logging.InfoLevel) {
        val uptime = Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toSeconds
        complete(Status(uptime))
      }
    }
  }

  val routes = pingRoute ~ uptimeRoute
} 
开发者ID:kristoferB,项目名称:TransformationService,代码行数:33,代码来源:HealthCheckService.scala


示例18: healthRoutes

//设置package包名称以及导入依赖的类
package com.mz.training.health

import java.lang.management.ManagementFactory

import akka.http.scaladsl.server.Directives._

import scala.concurrent.duration._

trait HealthRoutes {

  def healthRoutes = pathPrefix("health") {
    path("ping") {
      get {
          complete("OK")
        }
      } ~ path("uptime") {
      get {
        complete(getUptime.toString)
      }
    }
  }
  
  private def getUptime = Duration(ManagementFactory.getRuntimeMXBean.getUptime, MILLISECONDS).toSeconds
} 
开发者ID:michalzeman,项目名称:angular2-training,代码行数:25,代码来源:HealthRoutes.scala


示例19: KamonPusher

//设置package包名称以及导入依赖的类
package lila.api

import akka.actor._
import java.lang.management.ManagementFactory
import scala.concurrent.duration._

import lila.hub.actorApi.round.NbRounds
import lila.socket.actorApi.NbMembers

private final class KamonPusher(
    countUsers: () => Int
) extends Actor {

  import KamonPusher._

  override def preStart() {
    scheduleTick
  }

  private val threadStats = ManagementFactory.getThreadMXBean
  private val app = lila.common.PlayApp

  private def scheduleTick =
    context.system.scheduler.scheduleOnce(1 second, self, Tick)

  def receive = {

    case NbMembers(nb) =>
      lila.mon.socket.member(nb)

    case NbRounds(nb) =>
      lila.mon.round.actor.count(nb)

    case Tick =>
      lila.mon.jvm.thread(threadStats.getThreadCount)
      lila.mon.jvm.daemon(threadStats.getDaemonThreadCount)
      lila.mon.jvm.uptime(app.uptime.toStandardSeconds.getSeconds)
      lila.mon.user.online(countUsers())
      scheduleTick
  }
}

object KamonPusher {

  private case object Tick

  def start(system: ActorSystem)(instance: => Actor) =
    system.lilaBus.subscribe(system.actorOf(Props(instance)), 'nbMembers, 'nbRounds)
} 
开发者ID:Thiediev,项目名称:lilylichessmod,代码行数:50,代码来源:KamonPusher.scala


示例20: MetricsModule

//设置package包名称以及导入依赖的类
package dcos.metronome

import java.lang.management.ManagementFactory

import com.codahale.metrics.MetricRegistry
import com.codahale.metrics.health.HealthCheckRegistry
import com.codahale.metrics.jvm.{ BufferPoolMetricSet, GarbageCollectorMetricSet, MemoryUsageGaugeSet, ThreadStatesGaugeSet }
import mesosphere.marathon.metrics.Metrics

class MetricsModule {

  lazy val healthCheckRegistry: HealthCheckRegistry = new HealthCheckRegistry()

  lazy val metricsRegistry: MetricRegistry = {
    val registry = new MetricRegistry
    registry.register("jvm.gc", new GarbageCollectorMetricSet())
    registry.register("jvm.buffers", new BufferPoolMetricSet(ManagementFactory.getPlatformMBeanServer))
    registry.register("jvm.memory", new MemoryUsageGaugeSet())
    registry.register("jvm.threads", new ThreadStatesGaugeSet())
    registry
  }

  lazy val metrics = new Metrics(metricsRegistry)
} 
开发者ID:dcos,项目名称:metronome,代码行数:25,代码来源:MetricsModule.scala



注:本文中的java.lang.management.ManagementFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala HeaderCarrier类代码示例发布时间:2022-05-23
下一篇:
Scala Broadcast类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap