get system cpu frequency in ruby

To get the system CPU frequency in Ruby, you can use the sys-cpu gem. Once you have installed it using gem install sys-cpu, you can use the following code:

main.rb
require 'sys/cpu'

frequency_in_mhz = Sys::CPU::Clock.get
58 chars
4 lines

This will return the current CPU frequency in MHz as a float. You can then use this value for monitoring or any other task as needed.

gistlibby LogSnag