Difference between revisions of "Development/Tutorials/Sensors"

Jump to: navigation, search
m (Fixed prerequesites)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
 
Implementing KSysGuard sensors simple example.
 
Implementing KSysGuard sensors simple example.
  
Line 11: Line 12:
  
 
Step 1. Create, for example, "/home/vi/code/sensor/sensor.pl" with the following content:
 
Step 1. Create, for example, "/home/vi/code/sensor/sensor.pl" with the following content:
<code lang="perl">#!/usr/bin/perl -w   
+
<syntaxhighlight lang="perl">#!/usr/bin/perl -w   
 
$|=1;
 
$|=1;
  
Line 30: Line 31:
 
     print "ksysguardd> ";
 
     print "ksysguardd> ";
 
}
 
}
</code>
+
</syntaxhighlight>
  
 
Step 2: Launch KSysGuard, File->Connect Host->Custom Command, enter "/home/vi/code/sensor/sensor.pl" in the Command field, OK.
 
Step 2: Launch KSysGuard, File->Connect Host->Custom Command, enter "/home/vi/code/sensor/sensor.pl" in the Command field, OK.
Line 77: Line 78:
  
 
Example of session:
 
Example of session:
<code>
+
<syntaxhighlight lang="text">
 
ksysguardd 1.2.0
 
ksysguardd 1.2.0
 
ksysguardd> random
 
ksysguardd> random
Line 108: Line 109:
 
83
 
83
 
ksysguardd>  
 
ksysguardd>  
</code>
+
</syntaxhighlight>

Latest revision as of 17:26, 15 July 2012

Implementing KSysGuard sensors simple example.

Prerequisities: KDE, Perl.

Imagine you have a program that monitors some value important for you. You want the value to be plotted or displayed in the KDE systray.

The most straightforward way is to add it to KSysGuard as a sensor.

Contents

[edit] Example

Step 1. Create, for example, "/home/vi/code/sensor/sensor.pl" with the following content:

#!/usr/bin/perl -w  
$|=1;
 
print "ksysguardd 1.2.0\n";
print "ksysguardd> ";
 
while(<>){
    if(/monitors/){
	print "random\tinteger\n";
    }
    if(/random/){
	if(/\?/){
	    print "Random Value\t0\t100\n";
	}else{
	    print int(rand()*100),"\n";
	}
    }
    print "ksysguardd> ";
}

Step 2: Launch KSysGuard, File->Connect Host->Custom Command, enter "/home/vi/code/sensor/sensor.pl" in the Command field, OK.

Step 3: Open "127.0.0.1", find "random Integer Value", drag it to some sheet.

You will see your sensor (random value from 0 to 100 in this case).

[edit] Systray

If you want to see the plot is your systray, follow this:

Step 1: Add "KSysGuard applet to the desktop".

Step 2: In there's no spare displays, choose "Configure System Guard" in the context menu of the applet and increase "Number of displays".

Step 3: Launch KSysGuard, follow previous example to get access to your sensor.

Step 4: Drag and drop from "random Integer Value" to the free display in the systray.

Step 5: "Signal plotter", then you will be asked again to provide the data source. Choose "Custom Command" with the same script.

[Step 6: Open properties and remove grids and lines to clean up the plot]

[edit] Protocol

The ksysguardd protocol: 1. Server sends version line ("ksysguardd 1.2.0") ended with newline. 2. Server sends "ksysguardd> " with spacebar and without newline. Available commands:

  monitors -- List available sensors
  <sensor name> -- Get the value of some sensor
  <sensor name>? -- Get the metadata of the sensor

"monitor" command: For each sensor, send the sensor name TAB the sensor type (integer) NEWLINE. Then go back to the prompt "ksysguardd> ".

get command: For integer sensors, server should send one integer value and NEWLINE.

info command: Server should send the Display Name of the sensor TAB minimum value TAB maximum value TAB units NEWLINE. Looks like this command or some part of it is optional.

[edit] Example session

Example of session:

ksysguardd 1.2.0
ksysguardd> random
96
ksysguardd> random
46
ksysguardd> monitors
random.integer
ksysguardd> random
11
ksysguardd> random?
Random Value.0.100
ksysguardd> random
47
ksysguardd> random
54
ksysguardd> random
5
ksysguardd> random
37
ksysguardd> random
41
ksysguardd> random
58
ksysguardd> random
36
ksysguardd> random
69
ksysguardd> random
83
ksysguardd>

This page was last modified on 15 July 2012, at 17:26. This page has been accessed 8,994 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal