lib.oshi

cross-platform hardware, operating-system, and process information

Read OSHI system information as raw Java objects or converted Clojure data for diagnostics and monitoring.

1    Overview

The public functions create an OSHI SystemInfo value and navigate to hardware or operating-system sections. Bind *raw* to control whether values are returned directly or converted through std.object.

2    Walkthrough

2.1    Read system information

(require '[lib.oshi :as oshi])

(binding [oshi/*raw* false]
  {:computer (oshi/computer-system)
   :cpu (oshi/cpu)
   :memory (oshi/memory)
   :operating-system (oshi/os)})

2.2    Inspect devices and interfaces

(binding [oshi/*raw* false]
  {:disks (oshi/fs)
   :network (oshi/network-ifs)
   :power (oshi/power)
   :sensors (oshi/sensors)
   :usb (oshi/usb)})

2.3    Inspect processes

(oshi/process-id)
(binding [oshi/*raw* false]
  (oshi/process (oshi/process-id)))
(binding [oshi/*raw* false]
  (oshi/list-processes 20 :cpu))

3    API



*raw* ^

NONE
(defonce ^:dynamic *raw* true)
link

all ^

[]
Added 3.0

returns the entire map of the current system

v 3.0
(defn all
  ([]
   (binding [*raw* false]
     (to-data (oshi.SystemInfo.)))))
link
(all) ;; => => (complement nil?)

computer-system ^

[]
Added 3.0

returns specs of the current system

v 3.0
(defn computer-system
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getComputerSystem)
       (to-data))))
link
(computer-system) ;; => #sys{:baseboard {:manufacturer "Apple Inc." :model "SMC"}, ;; :firmware {:description "unknown", ;; :manufacturer "Apple Inc.", ;; :name "EFI", ;; :version "MBP114.0172.B13"}, ;; :manufacturer "Apple Inc.", ;; :model "MacBook Pro (MacBookPro11,5)", :serial-number "C02RR24EG8WP"} => (complement nil?)

cpu ^

[]
Added 3.0

returns cpu information

v 3.0
(defn cpu
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getProcessor)
       (to-data))))
link
(cpu) ;; => #cpu{:vendor "GenuineIntel", ;; :physical-processor-count 4, ;; :system-serial-number "C02RR24EG8WP", ;; :system-cpu-load 0.03085702451764327, :family "6", ;; :logical-processor-count 8, ;; :name "Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz", ;; :system-cpu-load-between-ticks 0.04217839588279096, ;; :cpu64bit? true, ;; :identifier "Intel64 Family 6 Model 70 Stepping 1", ;; :system-uptime 30980, :stepping "1", ;; :system-load-average 1.19970703125, ;; :vendor-freq 2500000000, :model "70"} => (complement nil?)

displays ^

[]
Added 3.0

returns display information

v 3.0
(defn displays
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getDisplays)
       seq
       (to-data))))
link
(displays) ;; => (#display{:edid [0 -1 -1 -1 -1 -1 -1 0 6 16 46 -96 ... ;; ... ;; 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 0 ;; ... ;; 0 0 0 -48]}) => (any nil? seq?)

fs ^

[]
Added 3.0

returns disk store information

v 3.0
(defn fs
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getDiskStores)
       seq
       (to-data))))
link
(fs) ;; => (#disk{:writes 157554, :write-bytes 4209285632, ;; :name "disk0", :transfer-time 8968912, ;; :size 500277790720, :serial "S29ANYAH561132" ;; :partitions [{:identification "disk0s1", :major 1, :minor 1, ;; :mount-point "", :name "EFI", :size 209715200, ;; :type "EFI System Partition"}] ;; :time-stamp 1487147164390, :read-bytes 3176375808, ;; :reads 132357, :model "APPLE SSD SM0512G"}) => (any nil? seq?)

list-processes ^

[] [limit] [limit sort-key]
Added 3.0

returns information about all running processes on the os

v 3.0
(defn list-processes
  ([] (list-processes 50 :cpu))
  ([limit] (list-processes limit :cpu))
  ([limit sort-key]
   (-> (oshi.SystemInfo.)
       (.getOperatingSystem)
       (.getProcesses)
       seq
       (to-data))))
link
;; ordering options: #{:name :oldest :memory :pid :newest :cpu :parentpid} (list-processes (process-id) :name) ;; => (#process{:parent-process-id 1, ;; :path "/System/Library/Frameworks/Accounts.framework/Versions/A/Support/accountsd", ;; :name "accountsd", ;; :bytes-read 4450304, ;; :up-time 31524268, ;; :process-id 1276} ;; #process{:parent-process-id 1, ;; :path "/Applications/Utilities/Activity Monitor.app/Contents/MacOS/Activity Monitor", ;; :name "Activity Monitor", ;; :bytes-read 61440, ;; :up-time 31522999, ;; :process-id 1360}) => (complement nil?)

memory ^

[]
Added 3.0

returns memory information

v 3.0
(defn memory
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getMemory)
       (to-data))))
link
(memory) ;; => #memory{:available 4792446976, ;; :swap-total 0, ;; :swap-used 0, ;; :total 17179869184} => (complement nil?)

network-ifs ^

[]
Added 3.0

returns network interface information

v 3.0
(defn network-ifs
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getNetworkIFs)
       seq
       (to-data))))
link
(network-ifs) ;; => (#net{:packets-recv 0, :mtu 1484, :speed 10000000, ;; :macaddr "52:33:aa:41:86:27", ;; :packets-sent 28, :name "awdl0", :ipv4addr [], ;; :bytes-sent 6460, :out-errors 0, ;; :in-errors 0, :display-name "awdl0", ;; :ipv6addr ["fe80:0:0:0:5033:aaff:fe41:8627"], ;; :time-stamp 1487147416141, :bytes-recv 0}) => (any nil? seq?)

os ^

[]
Added 3.0

returns operating system information

v 3.0
(defn os
  ([]
   (-> (oshi.SystemInfo.)
       (.getOperatingSystem)
       (to-data))))
link
(os) ;; => #os{:family "macOS", ;; :file-system {:file-stores [{:description "Local Disk", :mount "/", ;; :name "Macintosh HD", ;; :total-space 499055067136, ;; :type "hfs", ;; :usable-space 458689961984, ;; :volume "/dev/disk1"}], ;; :max-file-descriptors 12288, ;; :open-file-descriptors 3396}, ;; :manufacturer "Apple", ;; :process-count 318, ;; :process-id 9317, ;; :thread-count 574, ;; :version {:build-number "16D32" ;; :code-name "Sierra", ;; :osx-version-number 12, ;; :version "10.12.3"}} => (complement nil?)

power ^

[]
Added 3.0

returns power information

v 3.0
(defn power
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getPowerSources)
       seq
       (to-data))))
link
(power) ;; => (#power{:name "InternalBattery-0", ;; :remaining-capacity 1.0, ;; :time-remaining -2.0}) => (any nil? seq?)

process ^

[id]
Added 3.0

returns information about a process given it's id

v 3.0
(defn process
  ([id]
   (-> (oshi.SystemInfo.)
       (.getOperatingSystem)
       (.getProcess id))))
link
(process (process-id)) ;; => #process{:parent-process-id 9314, ;; :path "/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/bin/java", ;; :kernel-time 7427, ;; :resident-set-size 1756151808, ;; :user-time 48685, ;; :virtual-size 8653258752, ;; :name "java", ;; :start-time 1487140389429, ;; :state "WAITING", ;; :thread-count 41, ;; :bytes-written 253952, ;; :priority 31, ;; :bytes-read 16384, ;; :up-time 7672182, ;; :process-id 9317} => (complement nil?)

process-id ^

[]
Added 3.0

returns the current process id

v 3.0
(defn process-id
  ([]
   (-> (oshi.SystemInfo.)
       (.getOperatingSystem)
       (.getProcessId))))
link
(process-id) ;;=> 9317 => number?

sensors ^

[]
Added 3.0

returns sensor information

v 3.0
(defn sensors
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getSensors)
       (to-data))))
link
(sensors) ;; => #sensors{:cpu-temperature 42.125, ;; :cpu-voltage 173798.992, ;; :fan-speeds [2163 1999]} => (complement nil?)

to-data ^

[obj]
Added 3.0

converts the object to a map provided *raw* is false

v 3.0
(defn to-data
  ([obj]
   (if *raw*
     obj
     (object/to-data obj))))
link
(binding [*raw* true] (to-data :value)) => :value (binding [*raw* false] (with-redefs [object/to-data (fn [_] :converted)] (to-data :value))) => :converted

usb ^

[]
Added 3.0

returns usb information

v 3.0
(defn usb
  ([]
   (-> (oshi.SystemInfo.)
       (.getHardware)
       (.getUsbDevices false)
       seq
       (to-data))))
link
(usb) ;; => (#usb{:name "Apple Internal Keyboard / Trackpad", ;; :product-id "0274" ;; :vendor "Apple Inc."} ;; #usb{:name "Bluetooth USB Host Controller", ;; :product-id "8290", ;; :vendor "Broadcom Corp."}) => (any nil? seq?)


*platform* ^

NONE
(def ^:dynamic *platform* (str (oshi.SystemInfo/getCurrentPlatform)))
link