Top > calendar - 日記

2017年 08月 の 日記

<< 2017.8 >>
[日記]
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

26
August, 2017Edit

linuxサーバのプロセス制御

CentOS上で動いているdplusの負荷変動(CPU負荷が100%に近づく)と他の影響で
dplusがハングアップ状態になることを防ぐ対策。※dplus だけでなく他にも応用可。

  1. dplusのCPU負荷状態の記録を取る
    --- /root/logdplus.sh ---
    #!/bin/bash
    
    sleep 60
    while :
    do
    DT1=`date | cut -c12-20`
    #echo "$DT1"
    top -b -d20 -n1 | grep dplus | grep -v "logdplus" > hukadt.txt
    HUKA=`head -1 hukadt.txt | cut -c41-`
    echo "$DT1 $HUKA"
    echo "$DT1 $HUKA" >> hukadt0.txt
    sleep 10
    done
  2. 記録を解析してdplusを再起動させる
    --- /root/dplreset.sh ---
    #!/bin/bash
    DPLF=`ps ax | grep dplus | grep JP1YJQ`
    if test "$DPLF" = ""; then
      /etc/init.d/dplus restart
      sleep 60
    fi
    
    while :
    do
    FUKA=`tail -1 /root/hukadt0.txt | cut -c11-13`
    #echo "$FUKA"
    FUKA=$((FUKA + 0))
    if test $FUKA -gt 20 ; then
      sleep 12
      FUKA=`tail -1 /root/hukadt0.txt | cut -c11-13`
      FUKA=$((FUKA + 0))
      if test $FUKA -gt 20 ; then
        echo "dplus is going to loop ?" >> /root/hukadt0.txt
        echo "dplus is going to loop ?"
        sleep 180
        FUKA=`tail -1 /root/hukadt0.txt | cut -c11-13`
        FUKA=$((FUKA + 0))
        if test $FUKA -gt 20 ; then
          echo "Dplus is stoping" >> /root/hukadt0.txt
          echo "Dplus is stoping" | /usr/local/bin/msend.sh
          /etc/init.d/dplus stop
          echo "waiting for 5 min" >> /root/hukadt0.txt
          echo "waiting for 5 min" | /usr/local/bin/msend.sh
          sleep 300
          echo "Dplus is starting" >> /root/hukadt0.txt
          echo "Dplus is starting" | /usr/local/bin/msend.sh
          /etc/init.d/dplus start
        else
          echo "No. Nothing to do" >> /root/hukadt0.txt
          echo "No. Nothing to do"
        fi
      fi
    fi
    sleep 13
    done
  3. 結果(hungupしなかった場合)

    # tail -f /root/hukadt0.txt
    10:59:46 0.0 0.1 18:29.19 dplus
    10:59:56 0.0 0.1 18:29.20 dplus
    11:00:07 0.0 0.1 18:29.21 dplus
    11:00:17 0.0 0.1 18:29.21 dplus
    11:00:27 7.5 0.1 18:29.25 dplus
    11:00:38 84.8 0.1 18:38.76 dplus
    11:00:49 91.7 0.1 18:48.94 dplus
    dplus is going to loop ?
    11:00:59 72.8 0.1 18:57.89 dplus
    11:01:10 89.9 0.1 19:08.13 dplus
    11:01:20 58.5 0.1 19:17.11 dplus
    11:01:31 93.6 0.1 19:27.31 dplus
    11:01:41 82.9 0.1 19:36.26 dplus
    11:01:51 67.4 0.1 19:46.33 dplus
    11:02:02 44.7 0.1 19:55.21 dplus
    11:02:12 67.4 0.1 20:05.04 dplus
    11:02:23 71.5 0.1 20:14.29 dplus
    11:02:33 0.0 0.1 20:17.93 dplus
    11:02:43 0.0 0.1 20:17.93 dplus
    11:02:54 0.0 0.1 20:17.95 dplus
    11:03:04 3.7 0.1 20:17.96 dplus
    11:03:14 0.0 0.1 20:17.97 dplus
    11:03:25 0.0 0.1 20:17.97 dplus
    11:03:35 0.0 0.1 20:17.98 dplus
    11:03:45 0.0 0.1 20:17.98 dplus
    11:03:56 0.0 0.1 20:17.98 dplus
    No. Nothing to do
    11:04:06 0.0 0.1 20:17.98 dplus
    11:04:16 0.0 0.1 20:17.99 dplus


URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

07
August, 2017Edit

tee の使い方

ログを取る時に、標準出力と同時にファイルに保存したい場合に用いる。

  1. 標準エラーを含まず、一時ファイルに保存する場合
    $ echo "test" | tee test.txt
  2. 標準エラーを含め、一時ファイルに保存する場合
    $ echo "test" 2>&1 | tee test.txt
  3. ファイルに追加保存していく場合は
    $ echo "test" 2>&1 | tee -a test.txt

エアコンの制御

USB赤外線リモコン アドバンスを購入し、室内エアコンを室内温度を見ながら制御を行い、
適温に調整できるようにした。(エアコンが常時ONではなく、ON/OFFするので、41%ほど
電気節約になるかな?)
参考:http://blue-black.ink/?p=2973

  1. Raspberry pi で夏仕様
    --- tmplog.sh ---
    #!/bin/bash
    clear
    U=1
    D=1
    while :
    do
    DT1=`date +%m-%d-%h:%M`
    DT0=`cat /sys/class/thermal/thermal_zone0/temp | cut -c1-3`
    DT0=$((DT0 + 0))
    OND=$((DT0 / 10 - 7))
    if test $OND -gt 28 -a $U -eq 1 ; then
      U=0
      D=1
      echo "$DT1: 現在 $OND ℃で暑いのでエアコンは ON 状態"  | tee  -a ./tmpkiroku.txt
      /home/pi/bin/irsend.py /home/pi/22k3.txt
      #sleep 12
      #/home/pi/bin/irsend.py /home/pi/wvl01.txt
    elif test $OND -lt 25 -a $D -eq 1 ; then
      D=0
      U=1
      echo "$DT1: 現在 $OND ℃で冷えたのでエアコンは OFF 状態"  | tee -a ./tmpkiroku.txt
      /home/pi/bin/irsend.py /home/pi/22k3.txt
    else
      echo "$DT1: 現在 $OND ℃です"
    fi
    sleep 10
    done
  2. Orange Pi で夏仕様
    ---- /usr/local/bin/tmpcool.sh -----
    #!/bin/bash
    clear
    U=1
    D=1
    while :
    do
    DT1=`date +%m-%d-%H:%M`
    DT0=`cat /sys/class/thermal/thermal_zone0/temp`
    DT0=$((DT0 + 0))
    OND=$((DT0 - 26))
    if test $OND -gt 26 -a $U -eq 1 ; then
      U=0
      D=1
      echo "$DT1: 現在 $OND ℃で暑いのでエアコンは ON 状態"  | tee -a ./tmpkiroku.txt
      /home/pi-star/bin/irsend.py /home/pi-star/22k3.txt
      sleep 12
      /home/pi-star/bin/irsend.py /home/pi-star/wvl01.txt
    elif test $OND -lt 25 -a $D -eq 1 ; then
      D=0
      U=1
      echo "$DT1: 現在 $OND ℃で冷えたのでエアコンは OFF 状態"  | tee -a ./tmpkiroku.txt
      /home/pi-star/bin/irsend.py /home/pi-star/22k3.txt
    else
      echo "$DT1: 現在 $OND ℃です"
    fi
    sleep 10
    done
     Orange Piでは、消費電流が0.5A以上必要なので、電源は1A以上のものを
     使用した方が良い。
     
  3. エアコン制御なし(温度、CPU温度の表示)
    -------- /usr/local/bin/tmplog.sh --
     
    以下赤外線データ 22k3.txt と wvl01.txt は
    *1温度22℃、風量3に設定 *2風量のみ1に設定
     


05
August, 2017Edit

Raspberry Pi soundcard認識

いつも忘れてしまうので、メモ。
kernelを4.4以上にupdateした場合は、/boot/config.txt に以下追加必須。

# jed /boot/config.txt
dtparam=audio=on を追加。

参考URL:https://forum.voidlinux.eu/t/solved-alsa-raspberry-pi-2-analog-output-issues/557/3
Sound works on the Raspberry Pi with Kernel 4.4 after adding "dtparam=audio=on" to /boot/config.txt





*1 22k3.txt
*2 wvl01.txt

    ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS