Skip to content

Instantly share code, notes, and snippets.

@kennyz
Last active December 25, 2021 12:41
Show Gist options
  • Select an option

  • Save kennyz/4748807 to your computer and use it in GitHub Desktop.

Select an option

Save kennyz/4748807 to your computer and use it in GitHub Desktop.
kongwu pi tips

在Pi上增加负载和CPU温度的监控

send_data.sh 的代码如下:

cd /home/pi/bin/cosm/
sed 's/\([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\) \([0-9]*\.[0-9][0-9]\)\(.*\)/{"datastreams":[ {"id":"5min","current_value":"\1"},{"id":"10min","current_value":"\2"},{"id":"15min","current_value":"\3"} ]}/' /proc/loadavg > cosm-load.json
curl --request PUT --data-binary @cosm-load.json --header "X-ApiKey: -APIKEY" http://api.cosm.com/v2/feeds/95397?timezone=+8

VAL=`cat /sys/class/thermal/thermal_zone0/temp`
STR=`awk 'BEGIN{printf "{\"datastreams\":[ {\"id\":\"temp\",\"current_value\":\"%.1f\"} ] } ",'$VAL'/1000}'`
echo $STR > cosm_temp.json
curl --request PUT --data-binary @cosm_temp.json --header "X-ApiKey: -APIKEY" http://api.cosm.com/v2/feeds/95397?timezone=+8

更换了一个更加快速的源:

pi的源列表: http://www.raspbian.org/RaspbianMirrors

测试了之后发现这个源在国内更新最快

http://mirror.devunt.kr/raspbian/raspbian/

更换源:

sudo vi /etc/apt/sources.list

更换为以下代码: deb http://mirror.devunt.kr/raspbian/raspbian/ wheezy main contrib non-free rpi

解决磁盘速度问题

外接磁盘绝对不能使用NTFS格式分区!速度非常慢

安装测试磁盘速度的软件: sudo apt-get install hdparm

测试本地card的读写速度:

hdparm -Tt /dev/mmcblk0

pi@raspberrypi ~/downloads $ sudo hdparm -Tt /dev/mmcblk0

/dev/mmcblk0:
 Timing cached reads: 210 MB in 2.02 seconds = 104.21 MB/sec
 Timing buffered disk reads: 54 MB in 3.09 seconds = 17.45 MB/sec
pi@raspberrypi ~/downloads $ dd count=50 bs=1M if=/dev/zero of=~/test.img
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 1.55218 s, 33.8 MB/s

测试外接硬盘的读写速度:

hdparm -Tt /dev/sda1

pi@raspberrypi ~/downloads $ sudo hdparm -Tt /dev/sda1

/dev/sda1:
 Timing cached reads: 316 MB in 2.01 seconds = 157.46 MB/sec
 Timing buffered disk reads: 62 MB in 3.03 seconds = 20.48 MB/sec

pi@raspberrypi ~/downloads $ dd count=50 bs=1M if=/dev/zero of=/media/usbdisk/test.img

50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 13.5962 s, 3.9 MB/s

将external disk 格式化成ext4

sudo mount -t ext4 /dev/sda1 /media/usbdisk

pi@raspberrypi / $ sudo dd count=50 bs=1M if=/dev/zero of=/media/usbdisk/test.img

50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 1.15549 s, 45.4 MB/s

bingo!!

Copy link

ghost commented Jun 19, 2017

过了这么些年,该改一改了。
比如外接盘用ntfs慢,那是因为仓库的ntfs-3g是旧版的(貌似是2014版).。以下源码安装2016版的ntfs-3g能达到的速度(外接盘是个非常垃圾的赠品u盘,而且旧版ntfs-3g只能几百Kb):

> sudo hdparm -Tt /dev/sda4
/dev/sda4:
 Timing cached reads:   502 MB in  2.00 seconds = 250.63 MB/sec
 Timing buffered disk reads:  46 MB in  3.12 seconds =  14.75 MB/sec

> ntfs-3g --help
ntfs-3g 2016.2.22 integrated FUSE 27 - Third Generation NTFS Driver
                Configuration type 1, XATTRS are on, POSIX ACLS are off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment