iStats 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/ext/osx_stats/smc.c +16 -2
- data/ext/osx_stats/smc.h +2 -2
- data/iStats.gemspec +4 -2
- data/lib/iStats.rb +1 -0
- data/lib/iStats/battery.rb +11 -19
- data/lib/iStats/command.rb +2 -0
- data/lib/iStats/cpu.rb +2 -20
- data/lib/iStats/fan.rb +2 -20
- data/lib/iStats/printer.rb +33 -0
- data/lib/iStats/symbols.rb +1 -0
- data/lib/iStats/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbfee43c97edf5782f5620706731a0dc1c3b4656
|
4
|
+
data.tar.gz: e3817ed49ea0fdc535fd75b3c6d6ae870a268263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cae62708411610e2524f755f8e205430b9b6900745c4b24495ce58f05d8b42dd6afa95b9fa0df1968798be7348895e6eea30c059fb3018e5ac5d59012abe4f7
|
7
|
+
data.tar.gz: 225efcd7c7b5bfeaccbcd519c3f38e02ee6178a99b8c4765f64a566f404fe4f115445c32cf38674183ff7b5100c62967ef99e14e8b2e6fcea02a7aa14b6d3496
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
iStats [![Gem Version](https://badge.fury.io/rb/iStats.svg)](http://badge.fury.io/rb/iStats)
|
2
2
|
======
|
3
3
|
|
4
|
-
|
4
|
+
iStats is a command-line tool that allows you to easily grap the CPU temperature, fan speeds and battery information on OS X. If you'd like to see more data available feel free to open an issue.
|
5
5
|
|
6
6
|
#### Warning
|
7
|
-
A [bug in Ruby](https://bugs.ruby-lang.org/issues/9624) and Apple XCode 5.1 onwards (new CLANG version) might make it impossible to install this gem if you are using Ruby from the Xcode command-line tools package. If you are using RVM or homebrew to manage your Ruby installation you should be fine.
|
7
|
+
A [bug in Ruby](https://bugs.ruby-lang.org/issues/9624) and Apple XCode 5.1 onwards (new CLANG version) might make it impossible to install this gem if you are using Ruby from the Xcode command-line tools package. If you are using RVM or homebrew to manage your Ruby installation you should be fine.
|
8
8
|
|
9
9
|
#### Tested on
|
10
10
|
MacBook Pro 2012<br>
|
@@ -17,7 +17,7 @@ Ruby: 1.9.3, 2.0.0, 2.1.1<br>
|
|
17
17
|
|
18
18
|
## Screenshot
|
19
19
|
#### All Stats
|
20
|
-
![](http://i.imgur.com/
|
20
|
+
![](http://i.imgur.com/f3tCnnW.png)
|
21
21
|
|
22
22
|
#### Sparkline levels
|
23
23
|
![](http://i.imgur.com/ht2NZCL.gif)
|
@@ -35,6 +35,10 @@ Ruby: 1.9.3, 2.0.0, 2.1.1<br>
|
|
35
35
|
istats cpu [temp | temperature] Print CPU temperature
|
36
36
|
istats fan Print all fan stats
|
37
37
|
istats fan [speed] Print fan speed
|
38
|
+
istats battery Print all battery stats
|
39
|
+
istats battery [health] Print battery health
|
40
|
+
istats battery [cycleCount | cc] Print battery cycle count info
|
41
|
+
istats battery [temp | temperature] Print battery temperature
|
38
42
|
|
39
43
|
for more help see: https://github.com/Chris911/iStats
|
40
44
|
```
|
data/ext/osx_stats/smc.c
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
|
20
20
|
#include <stdio.h>
|
21
21
|
#include <string.h>
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <CoreFoundation/CoreFoundation.h>
|
22
24
|
#include <IOKit/IOKitLib.h>
|
23
25
|
|
24
26
|
#include "smc.h"
|
@@ -235,9 +237,9 @@ CFDictionaryRef powerSourceInfo(int Debug)
|
|
235
237
|
// Should only get one source. But in practice, check for > 0 sources
|
236
238
|
if (CFArrayGetCount(powerSourcesList))
|
237
239
|
{
|
238
|
-
|
240
|
+
powerSourceInformation = IOPSGetPowerSourceDescription(powerInfo, CFArrayGetValueAtIndex(powerSourcesList, 0));
|
239
241
|
|
240
|
-
|
242
|
+
if (Debug) dumpDict (powerSourceInformation);
|
241
243
|
|
242
244
|
//CFRelease(powerInfo);
|
243
245
|
//CFRelease(powerSourcesList);
|
@@ -275,6 +277,9 @@ const char* getBatteryHealth() {
|
|
275
277
|
|
276
278
|
const char *batteryHealth = CFStringGetCStringPtr(batteryHealthRef, // CFStringRef theString,
|
277
279
|
kCFStringEncodingMacRoman); //CFStringEncoding encoding);
|
280
|
+
if(batteryHealth == NULL)
|
281
|
+
return "unknown";
|
282
|
+
|
278
283
|
return batteryHealth;
|
279
284
|
}
|
280
285
|
|
@@ -299,6 +304,7 @@ void Init_osx_stats() {
|
|
299
304
|
BATTERY_STATS = rb_define_module("BATTERY_STATS");
|
300
305
|
rb_define_method(BATTERY_STATS, "get_battery_health", method_get_battery_health, 0);
|
301
306
|
rb_define_method(BATTERY_STATS, "get_battery_design_cycle_count", method_get_battery_design_cycle_count, 0);
|
307
|
+
rb_define_method(BATTERY_STATS, "get_battery_temp", method_get_battery_temp, 0);
|
302
308
|
}
|
303
309
|
|
304
310
|
VALUE method_get_cpu_temp(VALUE self) {
|
@@ -336,6 +342,14 @@ VALUE method_get_battery_design_cycle_count(VALUE self) {
|
|
336
342
|
return INT2NUM(cc);
|
337
343
|
}
|
338
344
|
|
345
|
+
VALUE method_get_battery_temp(VALUE self) {
|
346
|
+
SMCOpen();
|
347
|
+
double temp = SMCGetTemperature(SMC_KEY_BATTERY_TEMP);
|
348
|
+
SMCClose();
|
349
|
+
|
350
|
+
return rb_float_new(temp);
|
351
|
+
}
|
352
|
+
|
339
353
|
/* Main method used for test */
|
340
354
|
// int main(int argc, char *argv[])
|
341
355
|
// {
|
data/ext/osx_stats/smc.h
CHANGED
@@ -19,8 +19,6 @@
|
|
19
19
|
|
20
20
|
#ifndef __SMC_H__
|
21
21
|
#define __SMC_H__
|
22
|
-
#include "ruby.h"
|
23
|
-
#include <CoreFoundation/CoreFoundation.h>
|
24
22
|
#endif
|
25
23
|
|
26
24
|
#define VERSION "0.01"
|
@@ -44,6 +42,7 @@
|
|
44
42
|
#define SMC_KEY_CPU_TEMP "TC0P"
|
45
43
|
#define SMC_KEY_FAN_SPEED "F%dAc"
|
46
44
|
#define SMC_KEY_FAN_NUM "FNum"
|
45
|
+
#define SMC_KEY_BATTERY_TEMP "TB0T"
|
47
46
|
|
48
47
|
|
49
48
|
typedef struct {
|
@@ -108,3 +107,4 @@ VALUE method_get_fan_speed(VALUE self, VALUE num);
|
|
108
107
|
VALUE method_get_fan_number(VALUE self);
|
109
108
|
VALUE method_get_battery_health(VALUE self);
|
110
109
|
VALUE method_get_battery_design_cycle_count(VALUE self);
|
110
|
+
VALUE method_get_battery_temp(VALUE self);
|
data/iStats.gemspec
CHANGED
@@ -10,7 +10,7 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
s.version = IStats::VERSION
|
11
11
|
s.authors = ["Chris911"]
|
12
12
|
s.email = ["christophe.naud.dulude@gmail.com"]
|
13
|
-
s.description =
|
13
|
+
s.description = %q{iStats is a command-line tool that allows you to easily grap the CPU temperature, fan speeds and battery information on OS X. If you'd like to see more data available feel free to open an issue.}
|
14
14
|
s.summary = "Stats for your mac"
|
15
15
|
s.homepage = "https://github.com/Chris911/iStats"
|
16
16
|
s.license = "MIT"
|
@@ -23,7 +23,9 @@ spec = Gem::Specification.new do |s|
|
|
23
23
|
s.platform = Gem::Platform::RUBY
|
24
24
|
s.extensions = FileList["ext/**/extconf.rb"]
|
25
25
|
|
26
|
-
s.
|
26
|
+
s.required_ruby_version = ">= 1.9.3"
|
27
|
+
|
28
|
+
s.add_dependency "sparkr", "~> 0.4"
|
27
29
|
|
28
30
|
s.add_development_dependency "bundler", "~> 1.3"
|
29
31
|
s.add_development_dependency "rake"
|
data/lib/iStats.rb
CHANGED
data/lib/iStats/battery.rb
CHANGED
@@ -5,7 +5,6 @@ module IStats
|
|
5
5
|
class Battery
|
6
6
|
extend BATTERY_STATS
|
7
7
|
class << self
|
8
|
-
include IStats::Color
|
9
8
|
|
10
9
|
# Delegate CLI command to function
|
11
10
|
#
|
@@ -13,6 +12,8 @@ module IStats
|
|
13
12
|
case stat
|
14
13
|
when 'all'
|
15
14
|
all
|
15
|
+
when 'temp', 'temperature'
|
16
|
+
battery_temperature
|
16
17
|
when 'health'
|
17
18
|
battery_health
|
18
19
|
when 'cycle_count', 'cc'
|
@@ -26,6 +27,7 @@ module IStats
|
|
26
27
|
#
|
27
28
|
def all
|
28
29
|
battery_health
|
30
|
+
battery_temperature
|
29
31
|
cycle_count
|
30
32
|
end
|
31
33
|
|
@@ -39,28 +41,18 @@ module IStats
|
|
39
41
|
else
|
40
42
|
max_cycle_count = design_cycle_count
|
41
43
|
percentage = (cycle_count.to_f/max_cycle_count.to_f)*100
|
42
|
-
|
43
|
-
|
44
|
-
sparkline = Sparkr.sparkline(list) do |tick, count, index|
|
45
|
-
if index.between?(0, 5) and percentage > 95
|
46
|
-
flash_red(tick)
|
47
|
-
elsif index.between?(0, 1)
|
48
|
-
green(tick)
|
49
|
-
elsif index.between?(2, 3) and percentage > 45
|
50
|
-
light_yellow(tick)
|
51
|
-
elsif index == 4 and percentage > 65
|
52
|
-
yellow(tick)
|
53
|
-
elsif index == 5 and percentage > 85
|
54
|
-
red(tick)
|
55
|
-
else
|
56
|
-
tick
|
57
|
-
end
|
58
|
-
end
|
59
|
-
puts "Cycle count: #{cycle_count} " + sparkline
|
44
|
+
thresholds = [45, 65, 85, 95]
|
45
|
+
puts "Cycle count: #{cycle_count} " + Printer.gen_sparkline(percentage, thresholds)
|
60
46
|
puts "Max cycle count: #{max_cycle_count}"
|
61
47
|
end
|
62
48
|
end
|
63
49
|
|
50
|
+
# Get the battery temperature
|
51
|
+
#
|
52
|
+
def battery_temperature
|
53
|
+
puts "Battery temp: #{get_battery_temp.round(2)}#{Symbols.degree}C "
|
54
|
+
end
|
55
|
+
|
64
56
|
# Get the battery health
|
65
57
|
# Calls a C method from BATTERY_STATS module
|
66
58
|
#
|
data/lib/iStats/command.rb
CHANGED
@@ -89,8 +89,10 @@ module IStats
|
|
89
89
|
istats cpu [temp | temperature] Print CPU temperature
|
90
90
|
istats fan Print all fan stats
|
91
91
|
istats fan [speed] Print fan speed
|
92
|
+
istats battery Print all battery stats
|
92
93
|
istats battery [health] Print battery health
|
93
94
|
istats battery [cycleCount | cc] Print battery cycle count info
|
95
|
+
istats battery [temp | temperature] Print battery temperature
|
94
96
|
|
95
97
|
for more help see: https://github.com/Chris911/iStats
|
96
98
|
".gsub(/^ {8}/, '') # strip the first eight spaces of every line
|
data/lib/iStats/cpu.rb
CHANGED
@@ -5,7 +5,6 @@ module IStats
|
|
5
5
|
class Cpu
|
6
6
|
extend CPU_STATS
|
7
7
|
class << self
|
8
|
-
include IStats::Color
|
9
8
|
|
10
9
|
# Delegate CLI command to function
|
11
10
|
#
|
@@ -27,28 +26,11 @@ module IStats
|
|
27
26
|
end
|
28
27
|
|
29
28
|
# Print CPU temperature with sparkline
|
30
|
-
# TODO: Move sparkline function to printer class
|
31
29
|
#
|
32
30
|
def cpu_temperature
|
33
31
|
t = get_cpu_temp
|
34
|
-
|
35
|
-
|
36
|
-
sparkline = Sparkr.sparkline(list) do |tick, count, index|
|
37
|
-
if index.between?(0, 5) and t > 90
|
38
|
-
flash_red(tick)
|
39
|
-
elsif index.between?(0, 1)
|
40
|
-
green(tick)
|
41
|
-
elsif index.between?(2, 3) and t > 50
|
42
|
-
light_yellow(tick)
|
43
|
-
elsif index == 4 and t > 68
|
44
|
-
yellow(tick)
|
45
|
-
elsif index == 5 and t > 80
|
46
|
-
red(tick)
|
47
|
-
else
|
48
|
-
tick
|
49
|
-
end
|
50
|
-
end
|
51
|
-
puts message + sparkline
|
32
|
+
thresholds = [50, 68, 80, 90]
|
33
|
+
puts "CPU temp: #{t}#{Symbols.degree}C " + Printer.gen_sparkline(t, thresholds)
|
52
34
|
end
|
53
35
|
end
|
54
36
|
end
|
data/lib/iStats/fan.rb
CHANGED
@@ -5,7 +5,6 @@ module IStats
|
|
5
5
|
class Fan
|
6
6
|
extend FAN_STATS
|
7
7
|
class << self
|
8
|
-
include IStats::Color
|
9
8
|
|
10
9
|
# Delegate CLI command to function
|
11
10
|
#
|
@@ -53,30 +52,13 @@ module IStats
|
|
53
52
|
end
|
54
53
|
|
55
54
|
# Actually print fan speed with Sparkline
|
56
|
-
# TODO: Move sparkline function to printer class
|
57
55
|
#
|
58
56
|
# fanNum - The fan number
|
59
57
|
# speed - Fan speed in RPM
|
60
58
|
#
|
61
59
|
def print_fan_speed(fanNum, speed)
|
62
|
-
|
63
|
-
|
64
|
-
sparkline = Sparkr.sparkline(list) do |tick, count, index|
|
65
|
-
if index.between?(0, 5) and speed > 5500
|
66
|
-
flash_red(tick)
|
67
|
-
elsif index.between?(0, 1)
|
68
|
-
green(tick)
|
69
|
-
elsif index.between?(2, 3) and speed > 2500
|
70
|
-
light_yellow(tick)
|
71
|
-
elsif index == 4 and speed > 3500
|
72
|
-
yellow(tick)
|
73
|
-
elsif index == 5 and speed > 4500
|
74
|
-
red(tick)
|
75
|
-
else
|
76
|
-
tick
|
77
|
-
end
|
78
|
-
end
|
79
|
-
puts message + sparkline
|
60
|
+
thresholds = [2500, 3500, 4500, 5500]
|
61
|
+
puts "Fan #{fanNum} speed: #{speed} RPM " + Printer.gen_sparkline(speed, thresholds)
|
80
62
|
end
|
81
63
|
end
|
82
64
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module IStats
|
2
|
+
class Printer
|
3
|
+
class << self
|
4
|
+
include IStats::Color
|
5
|
+
|
6
|
+
# Create colored sparkline
|
7
|
+
# value - The stat value
|
8
|
+
# thresholds - must be an array of size 4 containing the threshold values
|
9
|
+
# for the sparkline colors
|
10
|
+
#
|
11
|
+
def gen_sparkline(value, thresholds)
|
12
|
+
return if thresholds.count < 4
|
13
|
+
|
14
|
+
list = [0, 30, 55, 80, 100, 130]
|
15
|
+
sparkline = Sparkr.sparkline(list) do |tick, count, index|
|
16
|
+
if index.between?(0, 5) and value > thresholds[3]
|
17
|
+
flash_red(tick)
|
18
|
+
elsif index.between?(0, 1)
|
19
|
+
green(tick)
|
20
|
+
elsif index.between?(2, 3) and value > thresholds[0]
|
21
|
+
light_yellow(tick)
|
22
|
+
elsif index == 4 and value > thresholds[1]
|
23
|
+
yellow(tick)
|
24
|
+
elsif index == 5 and value > thresholds[2]
|
25
|
+
red(tick)
|
26
|
+
else
|
27
|
+
tick
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/iStats/symbols.rb
CHANGED
data/lib/iStats/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iStats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris911
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sparkr
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '0.4'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,9 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: iStats is a command-line tool that allows you to easily grap the CPU
|
70
|
+
temperature, fan speeds and battery information on OS X. If you'd like to see more
|
71
|
+
data available feel free to open an issue.
|
70
72
|
email:
|
71
73
|
- christophe.naud.dulude@gmail.com
|
72
74
|
executables:
|
@@ -92,6 +94,7 @@ files:
|
|
92
94
|
- lib/iStats/command.rb
|
93
95
|
- lib/iStats/cpu.rb
|
94
96
|
- lib/iStats/fan.rb
|
97
|
+
- lib/iStats/printer.rb
|
95
98
|
- lib/iStats/symbols.rb
|
96
99
|
- lib/iStats/version.rb
|
97
100
|
homepage: https://github.com/Chris911/iStats
|
@@ -107,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
110
|
requirements:
|
108
111
|
- - ">="
|
109
112
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
113
|
+
version: 1.9.3
|
111
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
115
|
requirements:
|
113
116
|
- - ">="
|