Recent

Author Topic: How to catch the activity of my hard disk to pilot a virtual led?  (Read 1238 times)

MarkMLl

  • Jr. Member
  • **
  • Posts: 76
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #15 on: August 25, 2019, 07:18:17 pm »
Very true, although in some cases in theory there's an API to turn lights on/off which could conceivably have an extension to monitor activity. I spent an unpleasant amount of time investigating that sort of thing, and got absolutely nowhere.

From memory, test programs like (on unix) Bonnie++ work by counting and timing their own activity, so can be very much confused by unsupported device types (e.g. trying to use a program that expects "spinning rust" with a memory card on a Raspberry Pi).

All this is, of course, a good example of how prior experience with a simpler OS like DOS can warp ones expectations as to what is simple on a more complex one.

MarkMLl

winni

  • Full Member
  • ***
  • Posts: 190
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #16 on: August 26, 2019, 12:37:34 am »
The Linux-only-solution could be:

read every second /proc/diskstats

it looks like

-------------------snip----------------------------

 8       0 sda 212293 5961 11656469 77752 137101 102579 27372715 168612 0 221196 62400 26868 0 326665496 34709
   8       1 sda1 46 0 864 15 0 0 0 0 0 48 0 0 0 0 0
   8       2 sda2 211891 5924 11643783 77596 133424 99570 27334155 167487 0 219952 62380 26868 0 326665496 34709
   8       3 sda3 305 37 9054 128 1811 3009 38560 196 0 1720 4 0 0 0 0
   8      16 sdb 108813 0 6980648 554724 60 0 480 152 0 290232 413952 0 0 0 0
   8      17 sdb1 27668 0 3500352 120551 60 0 480 152 0 68796 87848 0 0 0 0
   8      18 sdb2 80850 0 3409752 431085 0 0 0 0 0 221096 323328 0 0 0 0
   8      19 sdb3 193 0 65680 2697 0 0 0 0 0 476 2436 0 0 0 0
  11       0 sr0 29 0 2096 2285 0 0 0 0 0 108 2224 0 0 0 0
   7       0 loop0 136 0 6565 3 0 0 0 0 0 32 0 0 0 0 0
   7       1 loop1 353 0 6563 5 0 0 0 0 0 16 0 0 0 0 0
   7       2 loop2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       3 loop3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       4 loop4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       5 loop5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       6 loop6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   7       7 loop7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   8      48 sdd 78 0 4228 432 0 0 0 0 0 112 364 0 0 0 0
   8      49 sdd1 33 0 2120 170 0 0 0 0 0 56 140 0 0 0 0
---------------------------snap ------------------------------

The values are explained in https://www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats

Pick your drive and your desired  value and display it.

But as markov said it's a hardware thing between Sata and the LED.

So instead of searching for solution for three or more OS : search for some hardware-fraggles who build you an interface between the LED and RS232/USB/Bluetooth or whatever. Should be the easiest solution.

Winni

lestroso

  • Jr. Member
  • **
  • Posts: 90
    • FaSasoftware
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #17 on: August 26, 2019, 08:16:53 pm »
Dear friends,

I thank you to everybody...I'm studing again this problem..I appriciate so much your help....Thanks a lot again!

Best regards,

Lestroso :D

RobsonD

  • New member
  • *
  • Posts: 9
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #18 on: August 28, 2019, 09:06:31 pm »
Has anyone had breakthrough with this issue?
lestroso, did you get anything?

My notebook does not have the hdd led, so I was looking to develop something similar. I use Debian 10.
For Windows there is a program that works 100% and has project source code, but does not work for Linux.

TKS

jamie

  • Hero Member
  • *****
  • Posts: 1901
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #19 on: August 28, 2019, 10:52:40 pm »
Good one, I've heard some whoppers in my time  :)

440bx

  • Hero Member
  • *****
  • Posts: 1086
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #20 on: August 28, 2019, 10:58:14 pm »
For Windows there is a program that works 100% and has project source code, but does not work for Linux.
Can you provide a link to that program ?  Thanks.
using FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

RobsonD

  • New member
  • *
  • Posts: 9
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #21 on: August 29, 2019, 12:05:00 am »
For Windows there is a program that works 100% and has project source code, but does not work for Linux.
Can you provide a link to that program ?  Thanks.

I'm sorry, it's not a project, it's a program named "Activity Indicator".


RobsonD

  • New member
  • *
  • Posts: 9
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #22 on: August 29, 2019, 09:31:13 pm »
Ok, ok, ...

Code: Pascal  [Select]
  1. // ...
  2.   AProcess := TProcess.Create(nil);
  3.   AStringList := TStringList.Create;
  4.   AProcess.CommandLine := 'pkexec cat /proc/diskstats | grep sda';
  5.   AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
  6.    AProcess.Execute;
  7.    AStringList.LoadFromStream(AProcess.Output);
  8.    Memo1.Lines.Add(AStringList.Text);
  9. // ...
  10.  

The problem is, "cat /proc/diskstats" only runs as root, so how do I run this routine in a loop?

tks

winni

  • Full Member
  • ***
  • Posts: 190
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #23 on: August 29, 2019, 11:08:55 pm »
Hi!

No, all entries  in  /proc are readable for everybody (and writable for nobody). And that is how it should be.

Which distribution you are using?

Winni

winni

  • Full Member
  • ***
  • Posts: 190
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #24 on: August 29, 2019, 11:13:42 pm »
TStringList.loadFromFile or LoadFromStream works  like a charm.

Perhapes your pipe tries to write in /proc. That is not allowed.

Winni

Cyrax

  • Hero Member
  • *****
  • Posts: 745
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #25 on: August 29, 2019, 11:15:20 pm »
Ok, ok, ...

Code: Pascal  [Select]
  1. // ...
  2.   AProcess := TProcess.Create(nil);
  3.   AStringList := TStringList.Create;
  4.   AProcess.CommandLine := 'pkexec cat /proc/diskstats | grep sda';
  5.   AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
  6.    AProcess.Execute;
  7.    AStringList.LoadFromStream(AProcess.Output);
  8.    Memo1.Lines.Add(AStringList.Text);
  9. // ...
  10.  

The problem is, "cat /proc/diskstats" only runs as root, so how do I run this routine in a loop?

tks

Just use TStringList.LoadFromFile('/proc/diskstats'); and then use TStringList methods to get desired output.

RobsonD

  • New member
  • *
  • Posts: 9
Re: How to catch the activity of my hard disk to pilot a virtual led?
« Reply #26 on: August 30, 2019, 02:02:27 pm »
It is true! I tried to do it the hard way, lol.
Now I have to do an infinite loop until the end of the program, and I will use Thread.
Thank you all for the information.