Skip to content

Commit 08f210e

Browse files
authored
[systeminfo] Add CPU frequency channels (openhab#16012)
Signed-off-by: Mark Herwege <[email protected]>
1 parent afa65f2 commit 08f210e

File tree

11 files changed

+148
-24
lines changed

11 files changed

+148
-24
lines changed

bundles/org.openhab.binding.systeminfo/README.md

+16-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
The system information binding provides operating system and hardware information including:
44

55
- Operating system name, version and manufacturer;
6-
- CPU average load for last 1, 5, 15 minutes, name, description, number of physical and logical cores, running threads number, system uptime;
6+
- CPU average load for last 1, 5, 15 minutes, name, description, number of physical and logical cores, running threads number, system uptime, max frequency and frequency by logical core;
77
- Free, total and available memory;
88
- Free, total and available swap memory;
99
- Hard drive name, model and serial number;
@@ -76,9 +76,9 @@ In the list below, you can find, how are channel group and channels id`s related
7676
- **group** `battery` (deviceIndex)
7777
- **channel** `name, remainingCapacity, remainingTime`
7878
- **group** `cpu`
79-
- **channel** `name, description, load, load1, load5, load15, uptime, threads`
79+
- **channel** `name, description, maxfreq, freq `(deviceIndex)`, load, load1, load5, load15, uptime, threads`
8080
- **group** `sensors`
81-
- **channel** `cpuTemp, cpuVoltage, fanSpeed`
81+
- **channel** `cpuTemp, cpuVoltage, fanSpeed `(deviceIndex)
8282
- **group** `network` (deviceIndex)
8383
- **channel** `ip, mac, networkDisplayName, networkName, packetsSent, packetsReceived, dataSent, dataReceived`
8484
- **group** `currentProcess`
@@ -92,7 +92,7 @@ The groups marked with "(deviceIndex)" may have device index attached to the Cha
9292
- deviceIndex ::= number >= 0
9393
- (e.g. _storage1#available_)
9494

95-
The `fanSpeed` channel in the `sensors` group may have a device index attached to the Channel.
95+
The channels marked with "(deviceIndex)" may have a device index attached to the Channel.
9696

9797
- channel ::= channel_group & # channel_id & (deviceIndex)
9898
- deviceIndex ::= number >= 0
@@ -119,6 +119,8 @@ The binding introduces the following channels:
119119
| load5 | Load for the last 5 minutes | Number | Medium | True |
120120
| load15 | Load for the last 15 minutes | Number | Medium | True |
121121
| threads | Number of threads currently running or for the process | Number | Medium | True |
122+
| maxfreq | CPU maximum frequency | Number:Frequency | Low | True |
123+
| freq | Logical processor frequency | Number:Frequency | High | True |
122124
| path | The full path of the process | String | Low | False |
123125
| uptime | System uptime (time after start) in minutes | Number:Time | Medium | True |
124126
| name | Name of the device or process | String | Low | False |
@@ -172,16 +174,17 @@ Parameter PID has a default value 0 - this is the PID of the System Idle process
172174
## Known issues and workarounds
173175

174176
- Temperature readings are not well supported on standard Windows systems, run [OpenHardwareMonitor.exe](https://openhardwaremonitor.org) for the binding to get more reliable readings.
177+
- CPU frequency readings are not available on some OS versions.
175178

176179
## Reporting issues
177180

178181
As already mentioned this binding depends heavily on the [OSHI](https://github.com/oshi/oshi) API to provide the operating system and hardware information.
179182

180183
Take a look at the console for an ERROR log message.
181184

182-
If you find an issue with a support for a specific hardware or software architecture please take a look at the [OSHI issues](https://github.com/oshi/oshi/issues).
185+
If you find an issue with support for a specific hardware or software architecture please take a look at the [OSHI issues](https://github.com/oshi/oshi/issues).
183186
Your problem might have be already reported and solved!
184-
Feel free to open a new issue there with the log message and the and information about your software or hardware configuration.
187+
Feel free to open a new issue there with the log message and the information about your software or hardware configuration.
185188

186189
For a general problem with the binding report the issue directly to openHAB.
187190

@@ -209,6 +212,8 @@ Number Network_PacketsReceived "Packets received" <returnpipe> { chann
209212
/* CPU information*/
210213
String CPU_Name "Name" <none> { channel="systeminfo:computer:work:cpu#name" }
211214
String CPU_Description "Description" <none> { channel="systeminfo:computer:work:cpu#description" }
215+
Number:Frequency CPU_MaxFreq "CPU Max Frequency" <none> { channel="systeminfo:computer:work:cpu#maxfreq" }
216+
Number:Frequency CPU_Freq "CPU Frequency" <none> { channel="systeminfo:computer:work:cpu#freq" }
212217
Number:Dimensionless CPU_Load "CPU Load" <none> { channel="systeminfo:computer:work:cpu#load" }
213218
Number CPU_Load1 "Load (1 min)" <none> { channel="systeminfo:computer:work:cpu#load1" }
214219
Number CPU_Load5 "Load (5 min)" <none> { channel="systeminfo:computer:work:cpu#load5" }
@@ -232,7 +237,7 @@ Number:Dimensionless Storage_Available_Percent "Available (%)" <none> { chann
232237
Number:Dimensionless Storage_Used_Percent "Used (%)" <none> { channel="systeminfo:computer:work:storage#usedPercent" }
233238

234239
/* Memory information*/
235-
Number Memory_Available "Available" <none> { channel="systeminfo:computer:work:memory#available" }
240+
Number:DataAmount Memory_Available "Available" <none> { channel="systeminfo:computer:work:memory#available" }
236241
Number:DataAmount Memory_Used "Used" <none> { channel="systeminfo:computer:work:memory#used" }
237242
Number:DataAmount Memory_Total "Total" <none> { channel="systeminfo:computer:work:memory#total" }
238243
Number:Dimensionless Memory_Available_Percent "Available (%)" <none> { channel="systeminfo:computer:work:memory#availablePercent" }
@@ -260,14 +265,14 @@ Number Sensor_FanSpeed "Fan speed" <fan> { chann
260265

261266
/* Current process information*/
262267
Number:Dimensionless Current_process_load "Load" <none> { channel="systeminfo:computer:work:currentProcess#load" }
263-
Number:Dimensionless Current_process_used "Used" <none> { channel="systeminfo:computer:work:currentProcess#used" }
268+
Number:DataAmount Current_process_used "Used" <none> { channel="systeminfo:computer:work:currentProcess#used" }
264269
String Current_process_name "Name" <none> { channel="systeminfo:computer:work:currentProcess#name" }
265270
Number Current_process_threads "Threads" <none> { channel="systeminfo:computer:work:currentProcess#threads" }
266271
String Current_process_path "Path" <none> { channel="systeminfo:computer:work:currentProcess#path" }
267272

268273
/* Process information*/
269274
Number:Dimensionless Process_load "Load" <none> { channel="systeminfo:computer:work:process#load" }
270-
Number:Dimensionless Process_used "Used" <none> { channel="systeminfo:computer:work:process#used" }
275+
Number:DataAmount Process_used "Used" <none> { channel="systeminfo:computer:work:process#used" }
271276
String Process_name "Name" <none> { channel="systeminfo:computer:work:process#name" }
272277
Number Process_threads "Threads" <none> { channel="systeminfo:computer:work:process#threads" }
273278
String Process_path "Path" <none> { channel="systeminfo:computer:work:process#path" }
@@ -290,6 +295,8 @@ sitemap systeminfo label="Systeminfo" {
290295
Frame label="CPU Information" {
291296
Default item=CPU_Name
292297
Default item=CPU_Description
298+
Default item=CPU_MaxFreq
299+
Default item=CPU_Freq
293300
Default item=CPU_Load1
294301
Default item=CPU_Load5
295302
Default item=CPU_Load15

bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SysteminfoBindingConstants.java

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
*
2222
* @author Svilen Valkanov - Initial contribution
2323
* @author Mark Herwege - Add dynamic creation of extra channels
24+
* @author Mark Herwege - Processor frequency channels
2425
*/
2526
@NonNullByDefault
2627
public class SysteminfoBindingConstants {
@@ -278,6 +279,16 @@ public class SysteminfoBindingConstants {
278279
*/
279280
public static final String CHANNEL_CPU_DESCRIPTION = "cpu#description";
280281

282+
/**
283+
* Maximum frequency of the CPU
284+
*/
285+
public static final String CHANNEL_CPU_MAXFREQ = "cpu#maxfreq";
286+
287+
/**
288+
* Frequency of the CPU
289+
*/
290+
public static final String CHANNEL_CPU_FREQ = "cpu#freq";
291+
281292
/**
282293
* Average recent CPU load
283294
*/

bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/SysteminfoThingTypeProvider.java

+5
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,15 @@ public List<ChannelGroupDefinition> getChannelGroupDefinitions(ThingTypeUID type
230230
ChannelBuilder builder = ChannelBuilder.create(channelUID).withType(channelTypeUID)
231231
.withConfiguration(baseChannel.getConfiguration());
232232
builder.withLabel(channelType.getLabel() + " " + index);
233+
builder.withDefaultTags(channelType.getTags());
233234
String description = channelType.getDescription();
234235
if (description != null) {
235236
builder.withDescription(description);
236237
}
238+
String itemType = channelType.getItemType();
239+
if (itemType != null) {
240+
builder.withAcceptedItemType(itemType);
241+
}
237242
return builder.build();
238243
}
239244

bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/handler/SysteminfoHandler.java

+8
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
* @author Lyubomir Papzov - Separate the creation of the systeminfo object and its initialization
6464
* @author Wouter Born - Add null annotations
6565
* @author Mark Herwege - Add dynamic creation of extra channels
66+
* @author Mark Herwege - Processor frequency channels
6667
*/
6768
@NonNullByDefault
6869
public class SysteminfoHandler extends BaseThingHandler {
@@ -258,6 +259,7 @@ private boolean addDynamicChannels() {
258259

259260
List<Channel> newChannels = new ArrayList<>();
260261
newChannels.addAll(createChannels(thingUID, CHANNEL_SENSORS_FAN_SPEED, systeminfo.getFanCount()));
262+
newChannels.addAll(createChannels(thingUID, CHANNEL_CPU_FREQ, systeminfo.getCpuLogicalCores().intValue()));
261263
if (!newChannels.isEmpty()) {
262264
logger.debug("Creating additional channels");
263265
newChannels.addAll(0, thing.getChannels());
@@ -482,6 +484,12 @@ private State getInfoForChannel(ChannelUID channelUID) {
482484
case CHANNEL_SENSORS_FAN_SPEED:
483485
state = systeminfo.getSensorsFanSpeed(deviceIndex);
484486
break;
487+
case CHANNEL_CPU_MAXFREQ:
488+
state = systeminfo.getCpuMaxFreq();
489+
break;
490+
case CHANNEL_CPU_FREQ:
491+
state = systeminfo.getCpuFreq(deviceIndex);
492+
break;
485493
case CHANNEL_CPU_LOAD:
486494
PercentType cpuLoad = cpuLoadCache.getValue();
487495
state = (cpuLoad != null) ? new QuantityType<>(cpuLoad, Units.PERCENT) : null;

bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/OSHISysteminfo.java

+14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020

2121
import javax.measure.quantity.ElectricPotential;
22+
import javax.measure.quantity.Frequency;
2223
import javax.measure.quantity.Temperature;
2324
import javax.measure.quantity.Time;
2425

@@ -62,6 +63,7 @@
6263
* @author Wouter Born - Update to OSHI 4.0.0 and add null annotations
6364
* @author Mark Herwege - Add dynamic creation of extra channels
6465
* @author Mark Herwege - Use units of measure
66+
* @author Mark Herwege - Processor frequency channels
6567
*
6668
* @see <a href="https://github.com/oshi/oshi">OSHI GitHub repository</a>
6769
*/
@@ -197,6 +199,18 @@ public DecimalType getCpuPhysicalCores() {
197199
return new DecimalType(physicalProcessorCount);
198200
}
199201

202+
@Override
203+
public @Nullable QuantityType<Frequency> getCpuMaxFreq() {
204+
long maxFreq = cpu.getMaxFreq();
205+
return maxFreq >= 0 ? new QuantityType<>(maxFreq, Units.HERTZ) : null;
206+
}
207+
208+
@Override
209+
public @Nullable QuantityType<Frequency> getCpuFreq(int logicalProcessorIndex) {
210+
long freq = cpu.getCurrentFreq()[logicalProcessorIndex];
211+
return freq >= 0 ? new QuantityType<>(freq, Units.HERTZ) : null;
212+
}
213+
200214
@Override
201215
public QuantityType<DataAmount> getMemoryTotal() {
202216
long totalMemory = memory.getTotal();

bundles/org.openhab.binding.systeminfo/src/main/java/org/openhab/binding/systeminfo/internal/model/SysteminfoInterface.java

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package org.openhab.binding.systeminfo.internal.model;
1414

1515
import javax.measure.quantity.ElectricPotential;
16+
import javax.measure.quantity.Frequency;
1617
import javax.measure.quantity.Temperature;
1718
import javax.measure.quantity.Time;
1819

@@ -31,6 +32,7 @@
3132
* @author Wouter Born - Add null annotations
3233
* @author Mark Herwege - Add dynamic creation of extra channels
3334
* @author Mark Herwege - Use units of measure
35+
* @author Mark Herwege - Processor frequency channels
3436
*/
3537
@NonNullByDefault
3638
public interface SysteminfoInterface {
@@ -80,6 +82,18 @@ public interface SysteminfoInterface {
8082
*/
8183
DecimalType getCpuPhysicalCores();
8284

85+
/**
86+
* Get the maximum CPU frequency of the processor.
87+
*/
88+
@Nullable
89+
QuantityType<Frequency> getCpuMaxFreq();
90+
91+
/**
92+
* Get the current CPU frequency of a logical processor.
93+
*/
94+
@Nullable
95+
QuantityType<Frequency> getCpuFreq(int logicalProcessorIndex);
96+
8397
/**
8498
* Returns the system cpu load.
8599
*

bundles/org.openhab.binding.systeminfo/src/main/resources/OH-INF/thing/channels.xml

+18
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@
107107
<channels>
108108
<channel id="name" typeId="name"/>
109109
<channel id="description" typeId="description"/>
110+
<channel id="maxfreq" typeId="maxfreq"/>
111+
<channel id="freq" typeId="freq"/>
110112
<channel id="load" typeId="load"/>
111113
<channel id="load1" typeId="loadAverage"/>
112114
<channel id="load5" typeId="loadAverage"/>
@@ -308,6 +310,22 @@
308310
<config-description-ref uri="channel-type:systeminfo:mediumpriority"/>
309311
</channel-type>
310312

313+
<channel-type id="maxfreq" advanced="true">
314+
<item-type>Number:Frequency</item-type>
315+
<label>Maximum Frequency</label>
316+
<description>CPU maximum frequency</description>
317+
<state readOnly="true" pattern="%.0f MHz"/>
318+
<config-description-ref uri="channel-type:systeminfo:lowpriority"/>
319+
</channel-type>
320+
321+
<channel-type id="freq" advanced="true">
322+
<item-type>Number:Frequency</item-type>
323+
<label>Current Frequency</label>
324+
<description>Logical processor frequency</description>
325+
<state readOnly="true" pattern="%.0f MHz"/>
326+
<config-description-ref uri="channel-type:systeminfo:highpriority"/>
327+
</channel-type>
328+
311329
<channel-type id="load">
312330
<item-type>Number:Dimensionless</item-type>
313331
<label>Load</label>

bundles/org.openhab.binding.systeminfo/src/main/resources/OH-INF/thing/computer.xml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
</channel-groups>
2727

2828
<properties>
29+
<property name="thingTypeVersion">1</property>
30+
2931
<property name="CPU Logical Cores">Not available</property>
3032
<property name="CPU Physical Cores">Not available</property>
3133
<property name="OS Manufacturer">Not available</property>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<update:update-descriptions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
4+
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">
5+
6+
<thing-type uid="systeminfo:computer">
7+
<instruction-set targetVersion="1">
8+
<add-channel id="maxfreq" groupIds="cpu">
9+
<type>systeminfo:maxfreq</type>
10+
</add-channel>
11+
<add-channel id="freq" groupIds="cpu">
12+
<type>systeminfo:freq</type>
13+
</add-channel>
14+
</instruction-set>
15+
</thing-type>
16+
17+
</update:update-descriptions>

itests/org.openhab.binding.systeminfo.tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<dependency>
3434
<groupId>com.github.oshi</groupId>
3535
<artifactId>oshi-core</artifactId>
36-
<version>6.2.2</version>
36+
<version>6.4.8</version>
3737
<exclusions>
3838
<exclusion>
3939
<groupId>org.slf4j</groupId>

0 commit comments

Comments
 (0)