saussact / openhab

Automatically exported from code.google.com/p/openhab
0 stars 0 forks source link

'System' binding / built in items #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
There should be a binding and probably a set of build in items which carry 
relevant system information to be shown to the users. Relevant information 
could be:

* Uptime
* last reload time of item-, sitemap-, rules-file
* list of aktive bindings
* ??

Original issue reported on code.google.com by teichsta on 20 Mar 2011 at 10:10

GoogleCodeExporter commented 9 years ago
I think that for bus bindings like KNX it would be worth to be able to see the 
current bus connection state - if it is active or not. Probably there should be 
individual item for every binding, so that you can select which binding's 
statuses you want to see in the sitemap.

Original comment by belovic...@gmail.com on 11 Apr 2012 at 10:15

GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 20 Apr 2012 at 8:00

GoogleCodeExporter commented 9 years ago
I see a work has been started. Are these going to be exposed in the REST API?

Original comment by mishoboss on 20 Apr 2012 at 2:50

GoogleCodeExporter commented 9 years ago
Any news on this?

Original comment by belovic...@gmail.com on 9 Jul 2012 at 5:42

GoogleCodeExporter commented 9 years ago
no, not so far, sorry!

Original comment by teichsta on 13 Jul 2012 at 9:45

GoogleCodeExporter commented 9 years ago
this might by useful in that context: 
http://stackoverflow.com/questions/47177/how-to-monitor-the-computers-cpu-memory
-and-disk-usage-in-java

Original comment by teichsta on 7 Jan 2013 at 10:56

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by teichsta on 21 May 2013 at 9:23

GoogleCodeExporter commented 9 years ago
I'm volunteer to provide the system binding. 

I made some testing and I have prototype which can provide system information 
like
- cpu, memory and disk usage.
- uptime
- last reload time of item-, sitemap-, rules-files
- list of bindings/bundles

Usages are probably best to provided by the items, so that we can use 
persistence service to provide cpu and memory usage history?

How about the last reload time of the files and list of bindings, etc? Should 
there be just rest interface to provide data or should that data be available 
by the items (String item which contains e.g. list of bindings or file reload 
times)?  

Any ideas are welcome.

Original comment by pauli.an...@gmail.com on 16 Jul 2013 at 4:23

GoogleCodeExporter commented 9 years ago
As it is supposed to be a binding, all information should imho indeed be bound 
to items.

Original comment by kai.openhab on 16 Jul 2013 at 7:19

GoogleCodeExporter commented 9 years ago
Maybe I was not clear enough. I wondered that should system binding only 
provide cpu, memory and disk usages, uptime, etc. And then expand the io.rest 
bundle to provide bundle/binding and file information, because item probably is 
not very usable to provide list data. 

Original comment by pauli.an...@gmail.com on 16 Jul 2013 at 7:43

GoogleCodeExporter commented 9 years ago
No, I wouldn't touch the rest api for this use case. Doing a comma separated 
list in a string item should be good enough. Anyhow I am not so sure if the 
list of bindings is that much of an interest - I would leave this out. CPU, 
memory, disk, uptime are the things I would really see in here.

Original comment by kai.openhab on 16 Jul 2013 at 7:47

GoogleCodeExporter commented 9 years ago
OK. Have anyone real use case for list of bundles/bindings and state? Some kind 
of web maintenance interface to see and stop/start/restart bundles, see logs, 
etc?

Original comment by pauli.an...@gmail.com on 17 Jul 2013 at 6:07

GoogleCodeExporter commented 9 years ago
If you ask me - DEFINITIVELY YES!!!
I would LOVE to see that Designer UI could connect remotely to openHAB runtime 
and administrate it beautifully. I would like to have real time access to 
console logs. I would like to enable/disable/install/remove/update bindings 
from UI. I would like to have real time bus events monitor in a nice and user 
friendly UI. And a lot more wishes for the Designer (UI with dropdown options 
for setting rules).

Original comment by mishoboss on 17 Jul 2013 at 9:01

GoogleCodeExporter commented 9 years ago
BTW, this is something I've prepared a year ago - http://m-design.bg/openhab/
Would love to see Designer evolving in this direction!

Original comment by mishoboss on 17 Jul 2013 at 9:05

GoogleCodeExporter commented 9 years ago
First alpha versions of System binding for testing purposes. Binding provides 
only system and process information.

Any feedback is welcome. Binding is developed with OS X environment, but 
binding use SIGAR API to get system/process information, so it should work on 
Linux and Windows environment as well. 

Quick help:

Copy native librarie(s) to openhab lib folder and binding to addon folder.

Binding Configuration (openhab.cfg):

system:granularity=1000
system:units=M

Where units: B=Bytes, K=kB, M=MB, T=TB

Items configuration:

system="<direction><commandType>:<refreshPeriod>(<target>)

Examples:

Number loadAverage1min { system="<LoadAverage1Min:5000" }
Number loadAverage5min { system="<LoadAverage5Min:5000" }
Number loadAverage15min { system="<LoadAverage15Min:5000" }

Number cpuCompined { system="<CpuCombined:5000" }
Number cpuUser { system="<CpuUser:5000" }
Number cpuSystem { system="<CpuSystem:5000" }
Number cpuNice { system="<CpuNice:5000" }
Number cpuWait { system="<CpuWait:5000" }

Number uptime { system="<Uptime:5000" }
String uptimeFormatted { system="<UptimeFormatted:5000" }

Number MemFree { system="<MemFree:5000" }
Number MemFreePercent { system="<MemFreePercent:5000" }
Number MemUsed { system="<MemUsed:5000" }
Number MemUsedPercent { system="<MemUsedPercent:5000" }
Number MemActualFree { system="<MemActualFree:5000" }
Number MemActualUsed { system="<MemActualUsed:5000" }
Number MemTotal { system="<MemTotal:5000" }

Number SwapFree { system="<SwapFree:5000" }
Number SwapTotal { system="<SwapTotal:5000" }
Number SwapUsed { system="<SwapUsed:5000" }
Number SwapPageIn { system="<SwapPageIn:5000" }
Number SwapPageOut { system="<SwapPageOut:5000" }

Number NetTxBytes { system="<NetTxBytes:5000:en1" }
Number NetRxBytes { system="<NetRxBytes:5000:en1" }

target=net interface (check ifconfig, ipconfig or openhab debug "21:56:12.930 
DEBUG o.o.b.s.internal.SystemBinding[:479] - valid net interfaces: [lo0, en0, 
en1, p2p0, vboxnet0]

Number DiskReads { system="<DiskReads:5000:disk0s2" }
Number DiskWrites { system="<DiskWrites:5000:disk0s2" }
Number DiskReadBytes { system="<DiskReadBytes:5000:disk0s2" }
Number DiskWriteBytes { system="<DiskWriteBytes:5000:disk0s2" }

target=disk (check iostat or openhab debug "21:56:12.931 DEBUG 
o.o.b.s.internal.SystemBinding[:493] - valid disk names: [/dev/disk0s2]")

Number DirUsage { system="<DirUsage:5000:/Users/pali" }
Number DirFiles { system="<DirFiles:5000:/Users/pali" }

target=directory path (note: if folder contains lot of files scan can take a 
while!)

Number OpenhabRealMem { system="<ProcessRealMem:5000:$$" }
Number OpenhabVirtualMem { system="<ProcessVirtualMem:5000:$$" }
Number OpenhabCpuPercent { system="<ProcessCpuPercent:5000:$$" }
Number OpenhabCpuSystem { system="<ProcessCpuSystem:5000:$$" }
Number OpenhabCpuUser { system="<ProcessCpuUser:5000:$$" }
Number OpenhabCpuTotal { system="<ProcessCpuTotal:5000:$$" }
Number OpenhabUptime { system="<ProcessUptime:5000:$$" }
String OpenhabUptimeFormatted { system="<ProcessUptimeFormatted:5000:$$" }

Number EclipseRealMem1 { system="<ProcessCpuPercent:10000:eclipse" }
Number EclipseRealMem2 { system="<ProcessCpuPercent:10000:*eclipse" }
Number EclipseRealMem3 { system="<ProcessCpuPercent:10000:eclipse*" }
Number EclipseRealMem4 { system="<ProcessCpuPercent:10000:=eclipse" }
Number EclipseRealMem5 { 
system="<ProcessCpuPercent:10000:#State.Name.eq=eclipse" }

target=process name ($$=current)

Original comment by pauli.an...@gmail.com on 21 Jul 2013 at 7:08

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by kai.openhab on 7 Aug 2013 at 7:19

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Pauli, thank you very much for this contribution!

Please find below some review comments:

# general
* i am a bit ambivalent if the name "system" is a slightly too general. But 
admittedly i don't have the inspiring idea. ".systeminfo" ?

# SystemBindingProvider
* L59 could you briefly explain which "command" is meant here
* L81 could you briefly explain what is meant with target here

# SystemBinding
* getData() - with your JavaScript Transformation Rule in mind i would opt for 
returning the raw data rather than doing initial calculations here
* L78 shouldn't the unit be configurable for each value individually? There 
should be a reasonable default though.
* L422,429 please remove unused methods
* L467-494 please move code to dedicated method like "initializeSystemMonitor" 
or similar

# SystemGenericBindingProvider
* L81 since all values a readonly the prefix '<' could be eliminated completely

# lib
* sigar.jar - please rename and add current version of the jar

# binding.xml
* please remove property event.topics

# openhab_default.cfg
* please add section for system binding

# Wiki-Page
* please add wikipage
* please make all possible values available on the wiki page.
* i added labels to make values visible. Some units could be refined though

Number loadAverage1min  "Load avg. 1min [%.1f]" (System) { 
system="<LoadAverage1Min:5000" }
Number loadAverage5min  "Load avg. 5min [%.1f]" (System) { 
system="<LoadAverage5Min:5000" }
Number loadAverage15min "Load avg. 15min [%.1f]"    (System) { 
system="<LoadAverage15Min:5000" }

Number cpuCompined  "CPU combined [%.1f]"   (System) { system="<CpuCombined:5000" }
Number cpuUser  "CPU user [%.1f]"   (System) { system="<CpuUser:5000" }
Number cpuSystem    "CPU system [%.1f]" (System) { system="<CpuSystem:5000" }
Number cpuNice  "CPU nice [%.1f]"   (System) { system="<CpuNice:5000" }
Number cpuWait "CPU wait [%.1f]"    (System) { system="<CpuWait:5000" }

Number uptime   "Uptime [%.1f]" (System) { system="<Uptime:5000" }
String uptimeFormatted  "Update formatted [%s]" (System) { 
system="<UptimeFormatted:5000" }

Number MemFree "Mem free [%.1f]"    (System) { system="<MemFree:5000" }
Number MemFreePercent   "Mem free [%.1f%%]" (System) { 
system="<MemFreePercent:5000" }
Number MemUsed  "Mem used [%.1f]"   (System) { system="<MemUsed:5000" }
Number MemUsedPercent   "Mem used [%.1f%%]" (System) { 
system="<MemUsedPercent:5000" }
Number MemActualFree    "Mem actual free [%.1f]"    (System) { 
system="<MemActualFree:5000" }
Number MemActualUsed    "Mem actual used [%.1f]"    (System) { 
system="<MemActualUsed:5000" }
Number MemTotal "Mem total [%.1f]"  (System) { system="<MemTotal:5000" }

Number SwapFree "Swap free [%.1f]"  (System) { system="<SwapFree:5000" }
Number SwapTotal    "Swap total [%.1f]" (System) { system="<SwapTotal:5000" }
Number SwapUsed "Swap used [%.1f]"  (System) { system="<SwapUsed:5000" }
Number SwapPageIn   "Swap pagein [%.1f]"    (System) { system="<SwapPageIn:5000" }
Number SwapPageOut  "Swap pageout [%.1f]"   (System) { system="<SwapPageOut:5000" }

Number NetTxBytes   "Next tx bytes [%.1f]"  (System) { 
system="<NetTxBytes:5000:en1" }
Number NetRxBytes   "Next rx bytes [%.1f]"  (System) { 
system="<NetRxBytes:5000:en1" }

Number DiskReads    "Disk reads [%.1f]" (System) { 
system="<DiskReads:5000:/dev/disk1" }
Number DiskWrites   "Disk writes [%.1f]"    (System) { 
system="<DiskWrites:5000:/dev/disk1" }
Number DiskReadBytes    "Disk read bytes [%.1f]"    (System) { 
system="<DiskReadBytes:5000:/dev/disk1" }
Number DiskWriteBytes   "Disk write bytes [%.1f]"   (System) { 
system="<DiskWriteBytes:5000:/dev/disk1" }

Number DirUsage "Dir usage [%.1f]"  (System) { 
system="<DirUsage:5000:/Users/thomasee" }
Number DirFiles "Dir files [%.1f]"  (System) { 
system="<DirFiles:5000:/Users/thomasee" }

Number OpenhabRealMem   "Real mem [%.1f]"   (System) { 
system="<ProcessRealMem:5000:$$" }
Number OpenhabVirtualMem    "Virtual mem [%.1f]"    (System) { 
system="<ProcessVirtualMem:5000:$$" }
Number OpenhabCpuPercent    "Cpu percent [%.1f%%]"  (System) { 
system="<ProcessCpuPercent:5000:$$" }
Number OpenhabCpuSystem "CPU system [%.1f]" (System) { 
system="<ProcessCpuSystem:5000:$$" }
Number OpenhabCpuUser   "CPU user [%.1f]"   (System) { 
system="<ProcessCpuUser:5000:$$" }
Number OpenhabCpuTotal  "CPU total [%.1f]"  (System) { 
system="<ProcessCpuTotal:5000:$$" }
Number OpenhabUptime    "Uptime [%d]"   (System) { system="<ProcessUptime:5000:$$" }
String OpenhabUptimeFormatted   "Uptime form. [%s]" (System) { 
system="<ProcessUptimeFormatted:5000:$$" }

Number EclipseRealMem1  "Real mem1 [%.1f]"  (System) { 
system="<ProcessCpuPercent:10000:eclipse" }
Number EclipseRealMem2  "Real mem2 [%.1f]"  (System) { 
system="<ProcessCpuPercent:10000:*eclipse" }
Number EclipseRealMem3  "Real mem3 [%.1f]"  (System)  { 
system="<ProcessCpuPercent:10000:eclipse*" }
Number EclipseRealMem4  "Real mem4 [%.1f]"  (System) { 
system="<ProcessCpuPercent:10000:=eclipse" }
Number EclipseRealMem5  "Real mem5 [%.1f]"  (System) { 
system="<ProcessCpuPercent:10000:#State.Name.eq=eclipse" }

Original comment by teichsta on 26 Aug 2013 at 10:08

GoogleCodeExporter commented 9 years ago
# SystemBindingProvider
* L59 could you briefly explain which "command" is meant here
* L81 could you briefly explain what is meant with target here
Done

# SystemBinding
* getData() - with your JavaScript Transformation Rule in mind i would opt for 
returning the raw data rather than doing initial calculations here
Well, JavaScript Transformation Rules are not yet committed to main repo. So 
maybe one day :)

* L78 shouldn't the unit be configurable for each value individually? There 
should be a reasonable default though.
Maybe this can be handled someday with java script as well. Binding could 
provide generic unit configuration, which can be override with script.

* L422,429 please remove unused methods
* L467-494 please move code to dedicated method like "initializeSystemMonitor" 
or similar
Done

# SystemGenericBindingProvider
* L81 since all values a readonly the prefix '<' could be eliminated completely
Maybe someday binding supports also out binding features, so imho, it's more 
future proof.

# lib
* sigar.jar - please rename and add current version of the jar
Done

# binding.xml
* please remove property event.topics
Done

# openhab_default.cfg
* please add section for system binding
Done

# Wiki-Page
* please add wikipage
* please make all possible values available on the wiki page.
* i added labels to make values visible. Some units could be refined though
I will do

How Sigar native libs will be distributed? 

Original comment by pauli.an...@gmail.com on 27 Aug 2013 at 6:48

GoogleCodeExporter commented 9 years ago
> Maybe someday binding supports also out binding features, so imho, it's more 
future proof.

ok, but i'd prefer implementing features when they are really needed. 
Experience shows that implementing things that could be relevant in the future 
only rises the complexity and often won't come to reality. With the Epson 
binding (Connection types) i was with you but this is another discussion here 
is think.

What do you think?

Original comment by teichsta on 27 Aug 2013 at 7:37

GoogleCodeExporter commented 9 years ago
When I extended the exec binding to support in binding, there was no direction 
flag on the current format, so now exec binding support two different kind of 
formats, which is not very nice or maintainable either. 

But anyway, I can remove direction flag, no problem :)

Imho all bindings should use similar binding configuration format as possible. 
There probably should be some kind of guide line about the format, so that not 
every developer invent own style.

Original comment by pauli.an...@gmail.com on 28 Aug 2013 at 2:11

GoogleCodeExporter commented 9 years ago
> When I extended the exec binding to support in binding, there was no 
direction flag on the current format, so 
> now exec binding support two different kind of formats, which is not very 
nice or maintainable either. 

ok, got your point! But that is always the matter when systems evolve. However, 
for the sake of simplicity, i would opt for removing the flag.

> But anyway, I can remove direction flag, no problem :)

Thanks!

> Imho all bindings should use similar binding configuration format as 
possible. There probably 
> should be some kind of guide line about the format, so that not every 
developer invent own style.

Agreed, it would be nice if the binding developers would follow some kind of 
best practices. We could add an appropriate hint to the HowToBuildABinding 
Wikipage.

What do you think?

Original comment by teichsta on 28 Aug 2013 at 2:24

GoogleCodeExporter commented 9 years ago
# SystemGenericBindingProvider
* L81 since all values a readonly the prefix '<' could be eliminated completely
Done

Also improved exception handling when binding configuration format mismatch.

Original comment by pauli.an...@gmail.com on 28 Aug 2013 at 2:57

GoogleCodeExporter commented 9 years ago
I merged the binding into the default repo (see 
http://code.google.com/p/openhab/source/detail?r=87325aff7ce62a4c7f50686e4b6ff34
e09de15b8). After speaking to Kai i renamed it to 'systeminfo' because 'system' 
seems to be a bit to generic. Furthermore i added a template for the Wiki-Page 
(see http://code.google.com/p/openhab/wiki/SysteminfoBinding).

I'll leave this issue open until the Wiki-Page is ready.

> How Sigar native libs will be distributed? 

Good question. Ideally it unpacks the appropriate lib into the root folder 
independently. The nrseriallib must have the same problem. For now we could 
explain and link from the Wiki-Page. What do you think?

Thanks, Pali for this contribution :-)

Original comment by teichsta on 29 Aug 2013 at 7:51

GoogleCodeExporter commented 9 years ago
Wiki page added. 

>Ideally it unpacks the appropriate lib into the root folder independently. The 
nrseriallib must have the same problem. For now we could explain and link from 
the Wiki-Page.

nrjavaserial-3.8.8.jar seems to contains native libs inside and automatically 
deploy them at runtime, but sigar don't. So do you mean that native libs are 
not distributed by openhab, but user need to download and manually add to lib 
folder?

Original comment by pauli.an...@gmail.com on 31 Aug 2013 at 8:25

GoogleCodeExporter commented 9 years ago
> nrjavaserial-3.8.8.jar seems to contains native libs inside and automatically 
deploy them at runtime, but sigar 
> don't. So do you mean that native libs are not distributed by openhab, but 
user need to download and manually 
> add to lib folder?

no, i meant we could possibly learn from nrjavaserial how they manage to deploy 
their native libs. But for now a link on the wiki-page should be good enough. 
Will you add this link?

Original comment by teichsta on 31 Aug 2013 at 9:41