Blog

  • Telegraf install

    curl --silent --location -O https://repos.influxdata.com/influxdata-archive.key 
    echo "943666881a1b8d9b849b74caebf02d3465d6beb716510d86a39f6c8e8dac7515  influxdata-archive.key" | sha256sum -c - && cat influxdata-archive.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/influxdata-archive.gpg > /dev/null 
    echo 'deb [signed-by=/etc/apt/trusted.gpg.d/influxdata-archive.gpg] https://repos.influxdata.com/debian stable main' | sudo tee /etc/apt/sources.list.d/influxdata.list
    sudo apt-get update && sudo apt-get install telegraf

  • influx CLI 작성중

    회사에서 사용하는 influxDB의 접속 ID/PW를 까먹었다. 그래서 ID와 PW를 확인 또는 PW 초기화를 해보고자 한다.

    홈페이지에서 내용을 조회하면 View Users 항목이 있다. influx CLI를 이용하면 할 수 있다고 한다.

    influx CLI는다음 과정을 거쳐서 설치할 수 있다.

    wget https://download.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-linux-amd64.tar.gz
    
    tar xvzf path/to/influxdb2-client-2.7.5-linux-amd64.tar.gz
    
    sudo cp influxdb2-client-2.7.5-linux-amd64/influx /usr/local/bin/

    https://docs.influxdata.com/influxdb/v2/admin/users/recover-credentials

  • Telegraf

    InfluxDB와 같은 회사 제품으로 추정되는 Telegraf를 설치했다.

    sudo apt install telegraf

    InfluxDB에서 시스템 별로 구분하기 위하여 tag을 지정해 준다. [agent]에서 hostname부분을 설정해 주면 시스템 상의 hostname이 아닌 이 이름으로 저장이 돈다.

    [agent]
    hostname = "server"

    저장할 DB를 다음과 같이 설정해 준다.

    [[outputs.influxdb_v2]]
    urls = ["http://sweet.home:8086"]
    token = ""
    organization = ""
    bucket = ""

    난 단순한 네트웍 I/O를 확인하는 것이 필요했다. 그래서 다음을 추가해 주었다.

    [[inputs.net]]
    interfaces = ["eno*", "enp0s[0-1]", "lo"]
    ignore_protocol_stats = false
  • pseudo API

    집 서버는 데비안으로 운영된다. 오랜 기간동안 재부팅을 하지 않아도 잘 동작한다. 그런데 너무 안하면 설정이 꼬이는 경우가 생긴 적이 있다. 그래서 주기적으로 재부팅을 한다. 재부팅 할 때 마다 beep이 난다. 소리를 끄는 것 보다 집에 사람이 없을 때 재부팅을 하는 쪽으로 시도해 보기로 했다.

    외출할 때 항상 휴대폰을 들고 나간다. 우리 집은 스마트폰을 항상 WIFI가 켜져 있다. 공유기에서 충분한 거리가 멀어지면 연결이 끊어지고 DHCP 에 이것이 반영된다. 미크로틱 DHCP 서버가 특정 MAC에 대하여 어떤 상태인지를 알기 위한 명령어는 다음과 같다.

    /ip dhcp-server lease print where mac-address=98:C8:54:21:19:A6

    결과는 다음과 같다.

    이 대로 처리를 해도 된다. 그런데 자신이 없으므로 다음과 같이 as-value라는 명령어를 넣어주면 결과를 묶어서 볼 수 있다. 그런데 이렇게만 하면 결과가 보이지 않는다. 그래서 앞에 명령어를 더 입력한다.

    :put [/ip dhcp-server lease print as-value where mac-address=98:C8:54:21:19:A6]

    결과는 다음과 같다.

    .id=*d3;address=192.168.88.165;comment=SY;last-seen=4h35m36s;mac-address=98:C8:54:21:19:A6;server=dhcp1;status=waiting

    DHCP 서버가 특정 MAC에 IP를 할당하면 status에 bound가 그렇지 않으면 waiting 으로 출력된다. 위에서 보면 알 수 있듯이 status가 가장 마지막 항목으로 출력된다. 그래서 글자를 나눈 다음 뒤에서 첫 번째 것을 선택하여 판단 기준으로 삼는다.

    import subprocess
    
    command = 'sshpass -p 820958 ssh -p 2222 admin@router.lan ":put [/ip dhcp-server lease print as-value where mac-address=9C:25:95:19:7B:D7]"'
    result = subprocess.check_output(command, shell=True, text=True)
    result = result.strip()
    result = result.split('status=')[-1]