Skip to content

Commit

Permalink
Track number of context switches in system metrics snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
vekterli committed Oct 29, 2024
1 parent 3a96f4c commit 28028f5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/performance/stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ def get_forks(metrics)
metrics[:cpu]['processes'][0]
end

def get_context_switches(metrics)
metrics[:cpu]['ctxt'][0]
end

def get_network(metrics)
net = metrics[:net]
{
Expand Down Expand Up @@ -221,11 +225,12 @@ def get_disks(metrics)

def host_to_internal(metrics)
{
:cpu_util => get_cpu_util(metrics),
:fork => get_forks(metrics),
:network => get_network(metrics),
:swap => get_swap(metrics),
:disk => get_disks(metrics)
:cpu_util => get_cpu_util(metrics),
:context_switches => get_context_switches(metrics),
:fork => get_forks(metrics),
:network => get_network(metrics),
:swap => get_swap(metrics),
:disk => get_disks(metrics)
}
end

Expand Down Expand Up @@ -332,6 +337,7 @@ def printable_result(params={})
if filter.include? :sys
rb.open_group('System')
rb.single_metric('CPU utilization', m[:cpu_util] * 100.0, :suffix => '%')
rb.avg_metric('Number of context switches', m[:context_switches])
rb.avg_metric('Number of forks done', m[:fork])
rb.avg_metric('Pages swapped out', m[:swap][:swapped_out], :warn_if_exceeding => 0)
rb.avg_metric('Pages swapped in', m[:swap][:swapped_in], :warn_if_exceeding => 0)
Expand Down

0 comments on commit 28028f5

Please sign in to comment.