I think I know how to connect LEDs to GPIO but I want to illuminate them when there is read / write operation to sdcard or other mass storage connected to Pi/ Is it possible ? I am doing little project and this feature would be very nice if implemented :)
2 Answers
Have a look at /proc/diskstats
. It shows a lot of details per partition. Monitor for changes and light up an LED connected to the GPIO. You could even whip up a script and monitor multiple individual partitions. You could use separate LEDs for reads, writes, and activity down to the sector level. Basically, you can monitor any storage device on the Pi. In short, it's magical.
Here's what the fields mean (from leftmost):
What: /proc/diskstats
Date: February 2008
Contact: Jerome Marchand <[email protected]>
Description:
The /proc/diskstats file displays the I/O statistics
of block devices. Each line contains the following 14
fields:
1 - major number
2 - minor mumber
3 - device name
4 - reads completed successfully
5 - reads merged
6 - sectors read
7 - time spent reading (ms)
8 - writes completed
9 - writes merged
10 - sectors written
11 - time spent writing (ms)
12 - I/Os currently in progress
13 - time spent doing I/Os (ms)
14 - weighted time spent doing I/Os (ms)
For more details refer to Documentation/iostats.txt
Here's a sample output of it (leftmost is column/field 1):
cat /proc/diskstats Fri Feb 12 11:42:52 2016
1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
1 1 ram1 0 0 0 0 0 0 0 0 0 0 0
1 2 ram2 0 0 0 0 0 0 0 0 0 0 0
1 3 ram3 0 0 0 0 0 0 0 0 0 0 0
1 4 ram4 0 0 0 0 0 0 0 0 0 0 0
1 5 ram5 0 0 0 0 0 0 0 0 0 0 0
1 6 ram6 0 0 0 0 0 0 0 0 0 0 0
1 7 ram7 0 0 0 0 0 0 0 0 0 0 0
1 8 ram8 0 0 0 0 0 0 0 0 0 0 0
1 9 ram9 0 0 0 0 0 0 0 0 0 0 0
1 10 ram10 0 0 0 0 0 0 0 0 0 0 0
1 11 ram11 0 0 0 0 0 0 0 0 0 0 0
1 12 ram12 0 0 0 0 0 0 0 0 0 0 0
1 13 ram13 0 0 0 0 0 0 0 0 0 0 0
1 14 ram14 0 0 0 0 0 0 0 0 0 0 0
1 15 ram15 0 0 0 0 0 0 0 0 0 0 0
7 0 loop0 0 0 0 0 0 0 0 0 0 0 0
7 1 loop1 0 0 0 0 0 0 0 0 0 0 0
7 2 loop2 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
7 4 loop4 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
7 6 loop6 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
179 0 mmcblk0 527505 88918 29249795 8576080 1132401 1077981 72635057 165882110 0 8239300 174477770
179 1 mmcblk0p1 79 29 1801 350 1 0 1 10 0 310 350
179 2 mmcblk0p2 527337 88889 29246402 8575440 1132400 1077981 72635056 165882100 0 8239160 174741170
8 0 sda 110 0 1784 160 0 0 0 0 0 110 160
8 1 sda1 104 0 1736 140 0 0 0 0 0 90 140
For example, you could monitor column 4 so that every time it changes, you'll light up an LED to indicate a read operation just happened.
I'll leave it to your imagination to come up with something out of this.
-
Great help - now I have something to start with. Thanks a lot :)– zebikCommented Feb 13, 2016 at 10:46
-
One more thing. Would you know how to extract data from /proc/diskstats say the one that shows write completes etc in python ? It's probably very easy but I can't get my head round it :)– zebikCommented Feb 13, 2016 at 19:01
-
@zebik My idea is to slice it up into an array and compare it with a second array containing previous results, but I'm not sure if that's the most efficient way. If you'll do that, you'll need a bit of basic math skills. I'm sure people on StackOverflow will know more.– AlohaCommented Feb 13, 2016 at 23:31
You can use an arbitrary GPIO to replace the activity LED. However that only shows MMC activity.
See /boot/overlays/README for act_led_gpio and act_led_trigger.
-
-
MMC (I think it stands for Multi Media Card) is the SD card. You can set the LED to indicated other activity but I don't think general disk I/O is a choice.– joanCommented Feb 12, 2016 at 11:05