more G-Labs products

Author Topic: CPU Load Sensor  (Read 9937 times)

November 22, 2015, 04:06:19 PM
Reply #15

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

I've made something similar in C# integrated in a HG program but don't find a way to get the memory usage with mono. But it works for cpu usage
If someone want to improve this program I attach it.

Bye

November 22, 2015, 07:18:31 PM
Reply #16

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Nice, thanks for sharing!

November 22, 2015, 07:19:43 PM
Reply #17

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
Thank's DavZero, I will test.

Cheers Dani

I have made some tests but need to stay in the front of the screen. And the 2 nde RAM Avalaible value is what ? I got only 3.26 MB.
What I need is to see the memory evolution of the system in time, during several days. 

Cheers Dani
« Last Edit: November 22, 2015, 07:51:55 PM by dani »

November 23, 2015, 08:27:06 PM
Reply #18

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Yes, you should stay logged to see the message because it'a a test program and I only set a notification instead of create a widget for display the result but if needed you can create a virtual sensor and put all the value needed on the sensor widget. Please find attach a new version which do this.

But as I say in my other post, it does NOT works for the memory usage, because I haven't find the correct performance counter for get this value with mono. I'm not sure it exist

So actually, it works only for the CPU usage

November 23, 2015, 09:21:50 PM
Reply #19

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
I've just made a little improvement to get the memory usage of the HG process.

If you need total memory instead of HG process memory, use :

   double memoryUsage = 0.0;
    System.Diagnostics.Process[] proc = System.Diagnostics.Process.GetProcesses();
    for (int i = 0 ; i < proc.Length ; i++)
    {   
      memoryUsage += proc.WorkingSet64/1024/1024;
    }
    Program.RaiseEvent(systemSensor, "Sensor.System.Memory", (memoryUsage).ToString(), "update Memory usage");


Tell me if something else is needed.

Bye
« Last Edit: November 23, 2015, 09:35:39 PM by DavZero »

November 24, 2015, 09:49:35 PM
Reply #20

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi (again),

I've made a new modification. The program now extract CPU usage in %, RAM usage in % and Disk Usage in %.

If you want to modify the refresh time, just change this line :
var checkTimer = new System.Timers.Timer(10000);

put the time value in ms.

For the disk it's the total of all the disk, may be it's not what all the user want ?

Bye
« Last Edit: November 24, 2015, 11:48:55 PM by DavZero »

November 28, 2015, 01:36:31 PM
Reply #21

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

I've updated the program in order to avoid notification flood :
 - Check if values need to be update instead of update it each loop
 - Use the new "Program.RaiseEvent("Program.UIRefresh",...)


In order to use this version, you must be in HG 1.1 499 or a newer version.

Bye

November 28, 2015, 08:21:19 PM
Reply #22

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
This version seems to work pretty well.

One question though...  What CPU and memory loads are people seeing reported?  I was seeing 18% cpu and 42% memory for a couple hours unchanged.  After forcing a page refresh, it displayed 29% cpu.  This seems WAY higher than I expected so I monitored the top command and I'm seeing typically 7-8% with spikes up to 25% cpu or so.  I do have a few programs that I've written so I suppose one/some of them are not ideal with resources.

November 29, 2015, 01:05:55 PM
Reply #23

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
My batch report reel values because it's base on free and ps of linux.
I don't know about values report by C# Mono.

November 29, 2015, 04:11:26 PM
Reply #24

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Oups,
you're rigth, the widget doesn't update itself.
I think it's cause by the new raise event "Program.RaiseEvent("Program.UiRefresh","Data updated","")", I probably don't uderstand corectly how it works.
I join a version with the "old style" parameter update but all updated value generate a notification.

For the value :
CPU ==> It's the average value on the loop time (in %). So if you the the loop time every second, it should be like the task manager value, if you set the loop time every 60 secondes (as it is by default), it should be different from the task manager.
Memory ==> It's the actual physical memory use at the time the loop was executed (in %). It's the addition of the physical memory used by all process divide by the total physical memory
Disk ==> It's the actual Disk usage (in %). It's the addition of disk usage of all "fixed" disk on the computer divide by the total size of all "fixed" disk.
« Last Edit: November 29, 2015, 04:29:40 PM by DavZero »

November 29, 2015, 07:56:32 PM
Reply #25

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi DavZero,

since you're using a virtual module, you've to address the refresh event on that module rather than on the program module.

Code: [Select]
Program.RaiseEvent(yourVirtualModule, "Program.UiRefresh","Data updated","");

g.

November 29, 2015, 08:43:17 PM
Reply #26

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi Gene,

I've made the modification but the widget doesn't refresh itself, I must reload the page or change the page and go again to the page that display this widget in order to see the value updated.

This is an extract of the log file :
Code: [Select]
2015-11-29 20:33:26.9178 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:31.9175 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:36.9175 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:37.3154 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [CLOSED AFTER 0 seconds]
2015-11-29 20:33:37.3154 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [OPEN]
2015-11-29 20:33:41.9185 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:46.9175 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:47.3194 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [CLOSED AFTER 0 seconds]
2015-11-29 20:33:47.3189 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [OPEN]
2015-11-29 20:33:51.9176 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:54.3640 Info HomeAutomation.PhilipsHue 1 - Meter.Watts 0.0
2015-11-29 20:33:54.3831 Info HomeAutomation.PhilipsHue 2 - Meter.Watts 0.0
2015-11-29 20:33:54.3943 Info HomeAutomation.PhilipsHue 3 - Meter.Watts 0.0
2015-11-29 20:33:56.9175 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:33:58.3242 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [CLOSED AFTER 0 seconds]
2015-11-29 20:33:58.3242 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [OPEN]
2015-11-29 20:34:01.9183 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:34:06.9177 Info HomeAutomation.SystemChecker 1 Virtual Module Program.UiRefresh Data Updated
2015-11-29 20:34:09.3224 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [CLOSED AFTER 0 seconds]
2015-11-29 20:34:09.3224 Info WebServiceGateway 192.168.0.1 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interfaces.List/ [OPEN]
We can see that the refresh event appear every 5 secondes and it's what I ask but the widget never update if I stay on the page which display it.

I update value like that :
Code: [Select]
var UpdateParamterValue = new Func<ModuleHelper,string,string,bool> ((module,param,val) => {
  if (module.Parameter(param).Value != val)
  {
    //Program.Notify("SystemChecker", param + " : " + module.Parameter(param).Value + "->" + val);
    module.Parameter(param).Value = val;
    //Program.RaiseEvent(module, param, val, "Update " + param);
    return true;
  }
  return false; 
});

...
...
...
//Check for update only if needed
    var needUpdate = UpdateParamterValue(systemSensor,"Sensor.System.Disk",newDiskVal);
    needUpdate |= UpdateParamterValue(systemSensor,"Sensor.System.CPU",newCPUVal);
    needUpdate |= UpdateParamterValue(systemSensor,"Sensor.System.Memory",newMemoryVal);

    if (needUpdate)
      Program.RaiseEvent(systemSensor,"Program.UiRefresh", "Data Updated", "");
...
...
...

Thanks
« Last Edit: November 29, 2015, 08:46:11 PM by DavZero »

November 29, 2015, 09:19:44 PM
Reply #27

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi DavZero,

the raise event instruction is correct, though there's another thing to consider: the sensor widget only take into account events such as Sensor.*, Status.Level and few others. So it simply ignore the UiRefresh event.
What you can do is using another widget like the "homegenie/generic/status" or write your own widget that perhaps will also have some nice charts.

Cheers,
g.

November 29, 2015, 11:23:05 PM
Reply #28

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Ok I will sop this discution on this thread and continu in the dedicated thread in order to leave this one for CPU monitoring :
http://www.homegenie.it/forum/index.php?topic=1232.0

I will post as as I can a new program with a dedicated widget.

Thanks

December 05, 2015, 02:04:57 PM
Reply #29

DavZero

  • **
  • Information
  • Jr. Member
  • Posts: 48
Hi,

Please find attach a new release of the systemChecker program which use the last capability of HomeGenie in order to don't display popup on each update.

I've made to a new widget in order to add the "%" symbole after each value. I don't really like made widget (I'm a neewbie with html and javascript and I'm really not an artist ^^)

I've add too a parameter to the SystemChecker program in order to define the resfresh time (60 seconde by default)

I will now try to understand how to add these values in the statistic graph. I think that value parameter should be like Sensor.* but I'm not sure

Bye
« Last Edit: December 05, 2015, 09:11:32 PM by DavZero »