diff options
author | Diego <diegolparra@gmail.com> | 2014-07-27 15:48:00 -0300 |
---|---|---|
committer | Diego <diegolparra@gmail.com> | 2014-07-27 15:48:00 -0300 |
commit | f366ce56f60e8df06f943fe48a861c7883bb606f (patch) | |
tree | b5a96eaa09f354bcb1861cb515cfc11148b519c7 /kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala | |
parent | e00ee2d4a782e348ab79de4c0f00fa8e1b2ad9d6 (diff) | |
download | Kamon-f366ce56f60e8df06f943fe48a861c7883bb606f.tar.gz Kamon-f366ce56f60e8df06f943fe48a861c7883bb606f.tar.bz2 Kamon-f366ce56f60e8df06f943fe48a861c7883bb606f.zip |
= kamon-system-metrics: system metrics loaded banner + some OS info with system load average and uptime
Diffstat (limited to 'kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala')
-rw-r--r-- | kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala index 5f858b42..0d6c2410 100644 --- a/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala +++ b/kamon-system-metrics/src/main/scala/kamon/system/sigar/SigarLoader.scala @@ -19,9 +19,9 @@ package kamon.system.sigar import java.io._ import java.util import java.util.logging.Logger -import java.util.{ ArrayList, List } +import java.util.{ Date, ArrayList, List } -import org.hyperic.sigar.{ Sigar, SigarProxy } +import org.hyperic.sigar.{ OperatingSystem, CpuPerc, Sigar, SigarProxy } import scala.annotation.tailrec import scala.collection.JavaConversions._ @@ -47,7 +47,7 @@ object SigarLoader { try { val sigar = new Sigar() - sigar.getPid + printBanner(sigar) sigar } catch { case t: Throwable ⇒ { @@ -127,5 +127,40 @@ object SigarLoader { transfer() } + private[sigar] def printBanner(sigar: Sigar) = { + def loadAverage(sigar: Sigar) = { + val average = sigar.getLoadAverage + (average(0), average(1), average(2)) + } + + def uptime(sigar: Sigar) = { + val uptime = sigar.getUptime + val now = System.currentTimeMillis() + new Date(now - (uptime.getUptime() * 1000).toLong) + } + def osInfo() = { + val NewLine = "\n" + val os = OperatingSystem.getInstance + val osInfo = new StringBuilder("------ OS Information ------").append(NewLine) + osInfo.append("Description: ").append(os.getDescription).append(NewLine) + .append("Name: ").append(os.getName).append(NewLine) + .append("Version: ").append(os.getVersion).append(NewLine) + .append("Arch: ").append(os.getArch).append(NewLine) + .toString() + } + + val message = """ + | + | _____ _ __ __ _ _ _ _ _ + | / ____| | | | \/ | | | (_) | | | | | | + || (___ _ _ ___| |_ ___ _ __ ___ | \ / | ___| |_ _ __ _ ___ ___| | ___ __ _ __| | ___ __| | + | \___ \| | | / __| __/ _ \ '_ ` _ \| |\/| |/ _ \ __| '__| |/ __/ __| | / _ \ / _` |/ _` |/ _ \/ _` | + | ____) | |_| \__ \ || __/ | | | | | | | | __/ |_| | | | (__\__ \ |___| (_) | (_| | (_| | __/ (_| | + ||_____/ \__, |___/\__\___|_| |_| |_|_| |_|\___|\__|_| |_|\___|___/______\___/ \__,_|\__,_|\___|\__,_| + | __/ | + | |___/ + """.stripMargin + s"\nBoot Time: ${uptime(sigar)} \nLoad Average: ${loadAverage(sigar)} \n${osInfo()}" + log.info(message) + } class Loader private[sigar] } |