Skip to content

Commit

Permalink
Fix issues kamon-io#872 and kamon-io#860
Browse files Browse the repository at this point in the history
Bring back classloading metrics that were forgotten during migration.
Express memory/swap/disk usage as percentage, simplifying some
dashboards
  • Loading branch information
SimunKaracic committed Oct 23, 2020
1 parent 9d2c603 commit cbbe051
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ kamon.modules {
description = "Collects CPU, Garbage Collection, Memory, Class Loading and Threads metrics from the local JVM"
factory = "kamon.instrumentation.system.jvm.JvmMetricsCollector$Factory"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,127 +4,145 @@ import kamon.Kamon
import kamon.instrumentation.system.host.HostMetrics.StorageDeviceInstruments.DeviceInstruments
import kamon.instrumentation.system.host.HostMetrics.StorageMountInstruments.MountInstruments
import kamon.instrumentation.system.host.HostMetrics.NetworkActivityInstruments.InterfaceInstruments
import kamon.metric.{Counter, Gauge, InstrumentGroup, MeasurementUnit}
import kamon.metric.{Counter, Gauge, Histogram, InstrumentGroup, MeasurementUnit}
import kamon.tag.TagSet

import scala.collection.mutable

object HostMetrics {

val CpuUsage = Kamon.histogram (
val CpuUsage = Kamon.histogram(
name = "host.cpu.usage",
description = "Samples the CPU usage percentage",
unit = MeasurementUnit.percentage
)

val MemoryUsed = Kamon.gauge (
val MemoryUsed = Kamon.gauge(
name = "host.memory.used",
description = "Tracks the amount of used memory",
unit = MeasurementUnit.information.bytes
)

val MemoryFree = Kamon.gauge (
val MemoryUsage = Kamon.histogram(
name = "host.memory.usage",
description = "Tracks the percetange of memory used",
unit = MeasurementUnit.percentage
)

val MemoryFree = Kamon.gauge(
name = "host.memory.free",
description = "Tracks the amount of free memory",
unit = MeasurementUnit.information.bytes
)

val MemoryTotal = Kamon.gauge (
val MemoryTotal = Kamon.gauge(
name = "host.memory.total",
description = "Tracks the total memory available",
unit = MeasurementUnit.information.bytes
)

val SwapUsed = Kamon.gauge (
val SwapUsed = Kamon.gauge(
name = "host.swap.used",
description = "Tracks the used Swap space",
unit = MeasurementUnit.information.bytes
)

val SwapFree = Kamon.gauge (
val SwapUsage = Kamon.histogram(
name = "host.swap.usage",
description = "Tracks the percentage of swap used",
unit = MeasurementUnit.percentage
)

val SwapFree = Kamon.gauge(
name = "host.swap.free",
description = "Tracks the free Swap space",
unit = MeasurementUnit.information.bytes
)

val SwapTotal = Kamon.gauge (
val SwapTotal = Kamon.gauge(
name = "host.swap.total",
description = "Tracks the total Swap space",
unit = MeasurementUnit.information.bytes
)

val LoadAverage = Kamon.gauge (
val LoadAverage = Kamon.gauge(
name = "host.load.average",
description = "Tracks the system load average"
)

val FileSystemMountSpaceUsed = Kamon.gauge (
val FileSystemMountSpaceUsed = Kamon.gauge(
name = "host.storage.mount.space.used",
description = "Tracks the used space on a file system mount/volume",
unit = MeasurementUnit.information.bytes
)

val FileSystemMountSpaceFree = Kamon.gauge (
val FileSystemMountSpaceUsage = Kamon.histogram(
name = "host.storage.mount.space.usage",
description = "Tracks the usage of space on a file system mount/volume",
unit = MeasurementUnit.percentage
)

val FileSystemMountSpaceFree = Kamon.gauge(
name = "host.storage.mount.space.free",
description = "Tracks the free space on a file system mount/volume",
unit = MeasurementUnit.information.bytes
)

val FileSystemMountSpaceTotal = Kamon.gauge (
val FileSystemMountSpaceTotal = Kamon.gauge(
name = "host.storage.mount.space.total",
description = "Tracks the total space on a file system mount/volume",
unit = MeasurementUnit.information.bytes
)

val StorageDeviceRead = Kamon.counter (
val StorageDeviceRead = Kamon.counter(
name = "host.storage.device.data.read",
description = "Counts the amount of byes that have been read from a storage device",
unit = MeasurementUnit.information.bytes
)

val StorageDeviceWrite = Kamon.counter (
val StorageDeviceWrite = Kamon.counter(
name = "host.storage.device.data.write",
description = "Counts the amount of byes that have been written to a storage device",
unit = MeasurementUnit.information.bytes
)

val StorageDeviceReadOps = Kamon.counter (
val StorageDeviceReadOps = Kamon.counter(
name = "host.storage.device.ops.read",
description = "Counts the number of read operations executed on a storage device"
)

val StorageDeviceWriteOps = Kamon.counter (
val StorageDeviceWriteOps = Kamon.counter(
name = "host.storage.device.ops.write",
description = "Counts the number of write operations executed on a storage device"
)

val NetworkPacketsRead = Kamon.counter (
val NetworkPacketsRead = Kamon.counter(
name = "host.network.packets.read.total",
description = "Counts how many packets have been read from a network interface"
)

val NetworkPacketsWrite = Kamon.counter (
val NetworkPacketsWrite = Kamon.counter(
name = "host.network.packets.write.total",
description = "Counts how many packets have been written to a network interface"
)

val NetworkPacketsReadFailed = Kamon.counter (
val NetworkPacketsReadFailed = Kamon.counter(
name = "host.network.packets.read.failed",
description = "Counts how many packets failed to be read from a network interface"
)

val NetworkPacketsWriteFailed = Kamon.counter (
val NetworkPacketsWriteFailed = Kamon.counter(
name = "host.network.packets.write.failed",
description = "Counts how many packets failed to be written to a network interface"
)

val NetworkDataRead = Kamon.counter (
val NetworkDataRead = Kamon.counter(
name = "host.network.data.read",
description = "Counts how many bytes have been read from a network interface",
unit = MeasurementUnit.information.bytes
)

val NetworkDataWrite = Kamon.counter (
val NetworkDataWrite = Kamon.counter(
name = "host.network.data.write",
description = "Counts how many bytes have been written to a network interface",
unit = MeasurementUnit.information.bytes
Expand All @@ -142,11 +160,13 @@ object HostMetrics {
class MemoryInstruments(tags: TagSet) extends InstrumentGroup(tags) {
val used = register(MemoryUsed)
val free = register(MemoryFree)
val usage = register(MemoryUsage)
val total = register(MemoryTotal)
}

class SwapInstruments(tags: TagSet) extends InstrumentGroup(tags) {
val used = register(SwapUsed)
val usage = register(SwapUsage)
val free = register(SwapFree)
val total = register(SwapTotal)
}
Expand All @@ -166,20 +186,24 @@ object HostMetrics {
_mountsCache.getOrElseUpdate(mountName, {
val mount = TagSet.of("mount", mountName)

MountInstruments (
MountInstruments(
register(FileSystemMountSpaceUsed, mount),
register(FileSystemMountSpaceUsage, mount),
register(FileSystemMountSpaceFree, mount),
register(FileSystemMountSpaceTotal, mount)
)
})
}

object StorageMountInstruments {
case class MountInstruments (

case class MountInstruments(
used: Gauge,
usage: Histogram,
free: Gauge,
total: Gauge
)

}

class StorageDeviceInstruments(tags: TagSet) extends InstrumentGroup(tags) {
Expand All @@ -191,7 +215,7 @@ object HostMetrics {
_deviceInstrumentsCache.getOrElseUpdate(deviceName, {
val device = TagSet.of("device", deviceName)

DeviceInstruments (
DeviceInstruments(
DiffCounter(register(StorageDeviceReadOps, device)),
DiffCounter(register(StorageDeviceRead, device)),
DiffCounter(register(StorageDeviceWriteOps, device)),
Expand All @@ -201,12 +225,14 @@ object HostMetrics {
}

object StorageDeviceInstruments {
case class DeviceInstruments (

case class DeviceInstruments(
reads: DiffCounter,
readBytes: DiffCounter,
writes: DiffCounter,
writeBytes: DiffCounter
)

}

class NetworkActivityInstruments(tags: TagSet) extends InstrumentGroup(tags) {
Expand All @@ -230,7 +256,7 @@ object HostMetrics {
}

object NetworkActivityInstruments {
case class InterfaceInstruments (
case class InterfaceInstruments(
receivedBytes: DiffCounter,
receivedPackets: DiffCounter,
receiveErrorPackets: DiffCounter,
Expand All @@ -239,7 +265,6 @@ object HostMetrics {
sendErrorPackets: DiffCounter
)
}

/**
* A modified Counter that keeps track of a monotonically increasing value and only records the difference between
* the current and previous value on the target counter.
Expand All @@ -248,14 +273,15 @@ object HostMetrics {
private var _previous = 0L

def diff(current: Long): Unit = {
if(_previous > 0L) {
if (_previous > 0L) {
val delta = current - _previous
if(delta > 0)
if (delta > 0)
counter.increment(delta)

}

_previous = current
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,23 @@ class HostMetricsCollector(ec: ExecutionContext) extends Module {
}

private def recordMemoryUsage(): Unit = {
val memory = _hal.getMemory
_memoryInstruments.total.update(memory.getTotal())
_memoryInstruments.free.update(memory.getAvailable())
_memoryInstruments.used.update(memory.getTotal() - memory.getAvailable())

_swapInstruments.total.update(memory.getVirtualMemory.getSwapTotal())
_swapInstruments.used.update(memory.getVirtualMemory.getSwapUsed())
_swapInstruments.free.update(memory.getVirtualMemory.getSwapTotal() - memory.getVirtualMemory.getSwapUsed())
val memory = _hal.getMemory
val totalMemory = memory.getTotal
val availableMemory = memory.getAvailable
val usedMemory = totalMemory - availableMemory

_memoryInstruments.total.update(totalMemory)
_memoryInstruments.free.update(availableMemory)
_memoryInstruments.used.update(usedMemory)
_memoryInstruments.usage.record(toPercent(usedMemory, totalMemory))

val usedSwap = memory.getVirtualMemory.getSwapUsed
val totalSwap = memory.getVirtualMemory.getSwapTotal
_swapInstruments.total.update(totalSwap)
_swapInstruments.used.update(usedSwap)
_swapInstruments.usage.record(toPercent(usedSwap, totalSwap))
_swapInstruments.free.update(totalSwap - usedSwap)
}

private def recordLoadAverage(): Unit = {
Expand All @@ -166,13 +175,19 @@ class HostMetricsCollector(ec: ExecutionContext) extends Module {
fileStores.foreach(fs => {
if(_settings.trackedMounts.accept(fs.getType)) {
val mountInstruments = _fileSystemUsageInstruments.mountInstruments(fs.getMount)
val totalSpace = fs.getTotalSpace
val usedSpace = totalSpace - fs.getUsableSpace

mountInstruments.free.update(fs.getUsableSpace)
mountInstruments.total.update(fs.getTotalSpace)
mountInstruments.used.update(fs.getTotalSpace - fs.getUsableSpace)
mountInstruments.total.update(totalSpace)
mountInstruments.used.update(usedSpace)
mountInstruments.usage.record(toPercent(usedSpace, totalSpace))
}
})
}

private def toPercent(value: Long, total: Long): Long = ((100D * value.toDouble) / total.toDouble).toLong

private def recordStorageActivity(): Unit = {
val devices = _hal.getDiskStores

Expand Down
Loading

0 comments on commit cbbe051

Please sign in to comment.