iStats 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -11
- data/ext/osx_stats/smc.c +67 -1
- data/ext/osx_stats/smc.h +9 -3
- data/lib/iStats.rb +1 -0
- data/lib/iStats/command.rb +7 -0
- data/lib/iStats/fan.rb +66 -0
- data/lib/iStats/version.rb +1 -1
- metadata +16 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9bff6f43ceaf154fc22a175a84ab82d3f1230346
|
4
|
+
data.tar.gz: bcd0dbe5bdbf052142511505b98d8f600d0c1703
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a640c65868a3f78e2f7fb2f9221ccb1de7f7f013e8c81ba5f83fb19d208468c5b1377648a1430323e1d36528ed31100d10bc12841b01e698277665b4d1947ab0
|
7
|
+
data.tar.gz: 6d640b55b90680bdf895d685eff2b1ce2b17d3b3fc9e1d438f2dd980e10eade76cfcf87fe0eaf9fd4cb8b2ddcab7e8eae464c665ab2675daf2c8c52a5b7622cb
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,23 +3,16 @@ iStats
|
|
3
3
|
|
4
4
|
Quick attempt at writing a Ruby wrapper for a small C library that interacts with the IOKit library (apple) to get the CPU temperature. Will expand to more hardware data and stats in the future.
|
5
5
|
|
6
|
-
|
6
|
+
#### Tested on
|
7
|
+
MacBook Pro 2012<br>
|
8
|
+
OS X 10.9.2<br>
|
9
|
+
Ruby: 1.9.3, 2.0.0, 2.1.1<br>
|
7
10
|
|
8
11
|
## Screenshot
|
9
12
|
![](http://i.imgur.com/ht2NZCL.gif)
|
10
13
|
|
11
14
|
## Installation
|
12
15
|
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
gem 'iStats'
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
16
|
$ gem install iStats
|
24
17
|
|
25
18
|
## Usage
|
data/ext/osx_stats/smc.c
CHANGED
@@ -40,6 +40,24 @@ UInt32 _strtoul(char *str, int size, int base)
|
|
40
40
|
return total;
|
41
41
|
}
|
42
42
|
|
43
|
+
float _strtof(unsigned char *str, int size, int e)
|
44
|
+
{
|
45
|
+
float total = 0;
|
46
|
+
int i;
|
47
|
+
|
48
|
+
for (i = 0; i < size; i++)
|
49
|
+
{
|
50
|
+
if (i == (size - 1))
|
51
|
+
total += (str[i] & 0xff) >> e;
|
52
|
+
else
|
53
|
+
total += str[i] << (size - 1 - i) * (8 - e);
|
54
|
+
}
|
55
|
+
|
56
|
+
total += (str[size-1] & 0x03) * 0.25;
|
57
|
+
|
58
|
+
return total;
|
59
|
+
}
|
60
|
+
|
43
61
|
void _ultostr(char *str, UInt32 val)
|
44
62
|
{
|
45
63
|
str[0] = '\0';
|
@@ -167,19 +185,50 @@ double SMCGetTemperature(char *key)
|
|
167
185
|
return 0.0;
|
168
186
|
}
|
169
187
|
|
188
|
+
float SMCGetFanSpeed(int fanNum)
|
189
|
+
{
|
190
|
+
SMCVal_t val;
|
191
|
+
kern_return_t result;
|
192
|
+
|
193
|
+
UInt32Char_t key;
|
194
|
+
sprintf(key, SMC_KEY_FAN_SPEED, fanNum);
|
195
|
+
result = SMCReadKey(key, &val);
|
196
|
+
return _strtof(val.bytes, val.dataSize, 2);
|
197
|
+
}
|
198
|
+
|
199
|
+
int SMCGetFanNumber(char *key)
|
200
|
+
{
|
201
|
+
SMCVal_t val;
|
202
|
+
kern_return_t result;
|
203
|
+
|
204
|
+
result = SMCReadKey(key, &val);
|
205
|
+
return _strtoul((char *)val.bytes, val.dataSize, 10);
|
206
|
+
}
|
207
|
+
|
170
208
|
// int main(int argc, char *argv[])
|
171
209
|
// {
|
172
210
|
// SMCOpen();
|
173
|
-
// printf("%0.1f°C\n", SMCGetTemperature(SMC_KEY_CPU_TEMP));
|
211
|
+
// //printf("%0.1f°C\n", SMCGetTemperature(SMC_KEY_CPU_TEMP));
|
212
|
+
// //printf("%0.1f\n", SMCGetFanSpeed(0));
|
213
|
+
// //printf("%0.1f\n", SMCGetFanSpeed(3));
|
214
|
+
// //printf("%i\n", SMCGetFanNumber(SMC_KEY_FAN_NUM));
|
174
215
|
// SMCClose();
|
175
216
|
//
|
176
217
|
// return 0;
|
177
218
|
// }
|
178
219
|
|
220
|
+
//
|
221
|
+
// RUBY MODULE
|
222
|
+
//
|
179
223
|
VALUE CPU_STATS = Qnil;
|
224
|
+
VALUE FAN_STATS = Qnil;
|
180
225
|
void Init_osx_stats() {
|
181
226
|
CPU_STATS = rb_define_module("CPU_STATS");
|
182
227
|
rb_define_method(CPU_STATS, "get_cpu_temp", method_get_cpu_temp, 0);
|
228
|
+
|
229
|
+
FAN_STATS = rb_define_module("FAN_STATS");
|
230
|
+
rb_define_method(FAN_STATS, "get_fan_number", method_get_fan_number, 0);
|
231
|
+
rb_define_method(FAN_STATS, "get_fan_speed", method_get_fan_speed, 1);
|
183
232
|
}
|
184
233
|
|
185
234
|
VALUE method_get_cpu_temp(VALUE self) {
|
@@ -189,3 +238,20 @@ VALUE method_get_cpu_temp(VALUE self) {
|
|
189
238
|
|
190
239
|
return rb_float_new(temp);
|
191
240
|
}
|
241
|
+
|
242
|
+
VALUE method_get_fan_number(VALUE self) {
|
243
|
+
SMCOpen();
|
244
|
+
int num = SMCGetFanNumber(SMC_KEY_FAN_NUM);
|
245
|
+
SMCClose();
|
246
|
+
|
247
|
+
return INT2NUM(num);
|
248
|
+
}
|
249
|
+
|
250
|
+
VALUE method_get_fan_speed(VALUE self, VALUE num) {
|
251
|
+
uint fanNum = NUM2UINT(num);
|
252
|
+
SMCOpen();
|
253
|
+
float speed = SMCGetFanSpeed(fanNum);
|
254
|
+
SMCClose();
|
255
|
+
|
256
|
+
return rb_float_new(speed);
|
257
|
+
}
|
data/ext/osx_stats/smc.h
CHANGED
@@ -41,6 +41,8 @@
|
|
41
41
|
|
42
42
|
// key values
|
43
43
|
#define SMC_KEY_CPU_TEMP "TC0P"
|
44
|
+
#define SMC_KEY_FAN_SPEED "F%dAc"
|
45
|
+
#define SMC_KEY_FAN_NUM "FNum"
|
44
46
|
|
45
47
|
|
46
48
|
typedef struct {
|
@@ -90,8 +92,12 @@ typedef struct {
|
|
90
92
|
|
91
93
|
|
92
94
|
// prototypes
|
95
|
+
float SMCGetFanSpeed(int fanNum);
|
96
|
+
int SMCGetFanNumber(char *key);
|
97
|
+
double SMCGetTemperature(char *key);
|
98
|
+
|
99
|
+
// Ruby modules
|
93
100
|
void Init_osx_stats();
|
94
101
|
VALUE method_get_cpu_temp(VALUE self);
|
95
|
-
|
96
|
-
|
97
|
-
int SMCGetFanRpm(char *key);
|
102
|
+
VALUE method_get_fan_speed(VALUE self, VALUE num);
|
103
|
+
VALUE method_get_fan_number(VALUE self);
|
data/lib/iStats.rb
CHANGED
data/lib/iStats/command.rb
CHANGED
@@ -19,6 +19,8 @@ module IStats
|
|
19
19
|
all
|
20
20
|
when 'cpu'
|
21
21
|
Cpu.delegate stat
|
22
|
+
when 'fan'
|
23
|
+
Fan.delegate stat
|
22
24
|
else
|
23
25
|
help("Unknown category: #{category}")
|
24
26
|
end
|
@@ -26,7 +28,10 @@ module IStats
|
|
26
28
|
|
27
29
|
def all
|
28
30
|
# Exec all
|
31
|
+
puts "--- CPU Stats ---\n"
|
29
32
|
Cpu.all
|
33
|
+
puts "\n--- Fan Stats ---\n"
|
34
|
+
Fan.all
|
30
35
|
end
|
31
36
|
|
32
37
|
# Public: Parse extra options
|
@@ -68,6 +73,8 @@ module IStats
|
|
68
73
|
istats all Print all stats
|
69
74
|
istats cpu Print all CPU stats
|
70
75
|
istats cpu [temp | temperature] Print CPU temperature
|
76
|
+
istats fan Print all fan stats
|
77
|
+
istats fan [speed] Print fan speed
|
71
78
|
|
72
79
|
for more help see: https://github.com/Chris911/iStats
|
73
80
|
".gsub(/^ {8}/, '') # strip the first eight spaces of every line
|
data/lib/iStats/fan.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
module IStats
|
2
|
+
# Fan Stats
|
3
|
+
# Extend FAN_STATS C module (ext/osx_stats/smc.c)
|
4
|
+
class Fan
|
5
|
+
extend FAN_STATS
|
6
|
+
class << self
|
7
|
+
include IStats::Color
|
8
|
+
|
9
|
+
def delegate(stat)
|
10
|
+
case stat
|
11
|
+
when 'all'
|
12
|
+
all
|
13
|
+
when 'number', 'num'
|
14
|
+
print_fan_number
|
15
|
+
when 'speed'
|
16
|
+
fans_speed
|
17
|
+
else
|
18
|
+
Command.help "Unknown stat for Fan: #{stat}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def all
|
23
|
+
print_fan_number
|
24
|
+
fans_speed
|
25
|
+
end
|
26
|
+
|
27
|
+
def fan_number
|
28
|
+
# C method
|
29
|
+
get_fan_number
|
30
|
+
end
|
31
|
+
|
32
|
+
def print_fan_number
|
33
|
+
puts "Total fans on system: #{fan_number}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def fans_speed
|
37
|
+
fanNum = fan_number
|
38
|
+
(0..(fanNum-1)).each do |n|
|
39
|
+
s = get_fan_speed(n)
|
40
|
+
print_fan_speed(n, s)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def print_fan_speed(fanNum, speed)
|
45
|
+
message = "Fan #{fanNum} speed: #{speed} RPM "
|
46
|
+
list = [0, 30, 55, 80, 100, 130]
|
47
|
+
sparkline = Sparkr.sparkline(list) do |tick, count, index|
|
48
|
+
if index.between?(0, 5) and speed > 5500
|
49
|
+
flash_red(tick)
|
50
|
+
elsif index.between?(0, 1)
|
51
|
+
green(tick)
|
52
|
+
elsif index.between?(2, 3) and speed > 2500
|
53
|
+
light_yellow(tick)
|
54
|
+
elsif index == 4 and speed > 3500
|
55
|
+
yellow(tick)
|
56
|
+
elsif index == 5 and speed > 4500
|
57
|
+
red(tick)
|
58
|
+
else
|
59
|
+
tick
|
60
|
+
end
|
61
|
+
end
|
62
|
+
puts message + sparkline
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/iStats/version.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iStats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Chris911
|
@@ -14,65 +13,57 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: sparkr
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: bundler
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '1.3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '1.3'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake-compiler
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
description: Stats for your mac
|
@@ -84,7 +75,7 @@ extensions:
|
|
84
75
|
- ext/osx_stats/extconf.rb
|
85
76
|
extra_rdoc_files: []
|
86
77
|
files:
|
87
|
-
- .gitignore
|
78
|
+
- ".gitignore"
|
88
79
|
- Gemfile
|
89
80
|
- Gemfile.lock
|
90
81
|
- LICENSE
|
@@ -99,32 +90,32 @@ files:
|
|
99
90
|
- lib/iStats/color.rb
|
100
91
|
- lib/iStats/command.rb
|
101
92
|
- lib/iStats/cpu.rb
|
93
|
+
- lib/iStats/fan.rb
|
102
94
|
- lib/iStats/symbols.rb
|
103
95
|
- lib/iStats/version.rb
|
104
96
|
homepage: https://github.com/Chris911/iStats
|
105
97
|
licenses:
|
106
98
|
- MIT
|
99
|
+
metadata: {}
|
107
100
|
post_install_message:
|
108
101
|
rdoc_options: []
|
109
102
|
require_paths:
|
110
103
|
- lib
|
111
104
|
- ext
|
112
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
106
|
requirements:
|
115
|
-
- -
|
107
|
+
- - ">="
|
116
108
|
- !ruby/object:Gem::Version
|
117
109
|
version: '0'
|
118
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
111
|
requirements:
|
121
|
-
- -
|
112
|
+
- - ">="
|
122
113
|
- !ruby/object:Gem::Version
|
123
114
|
version: '0'
|
124
115
|
requirements: []
|
125
116
|
rubyforge_project:
|
126
|
-
rubygems_version:
|
117
|
+
rubygems_version: 2.2.2
|
127
118
|
signing_key:
|
128
|
-
specification_version:
|
119
|
+
specification_version: 4
|
129
120
|
summary: Stats for your mac
|
130
121
|
test_files: []
|