[1] docker stats [docker guide]

Display a live stream of container(s) resource usage statistics

실시간으로 컨테이너들이 시스템에서 사용 중인 리소스를 보여준다.

  • CPU 사용량 | Memory 사용량 & Limit | I/O | PID
docker stats {컨테이너명} {컨테이너 ID} 

 

  • CPU 사용량 | Memory 사용량 & Limit
docker stats --all --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" {컨테이너명} {컨테이너명} {컨테이너명}

[2] Runtime options with Memory, CPUs, and GPUs [docker guide]

By default, a container has no resource constraints and can use as much of a given resource as the host’s kernel scheduler allows. Docker provides ways to control how much memory, or CPU a container can use, setting runtime configuration flags of the docker run command. This section provides details on when you should set such limits and the possible implications of setting them.

Many of these features require your kernel to support Linux capabilities. To check for support, you can use the docker info command. If a capability is disabled in your kernel, you may see a warning at the end of the output like the following:

WARNING: No swap limit support

Consult your operating system’s documentation for enabling them. Learn more.

기본적으로 컨테이너에는 리소스 제한이 없으며 호스트의 커널 스케줄러가 허용하는 한 지정된 리소스를 많이 사용할 수 있습니다. Docker는 docker run command 의 런타임 플래그를 통해 컨테이너가 사용할 수있는 메모리 또는 CPU 양을 제어하는 ​​방법을 제공합니다. 이 섹션에서는 이러한 제한을 설정해야하는 시기와 설정의 의미에 대해 설명합니다.

이러한 기능 중 다수는 Linux 기능을 지원하기 위해 커널이 필요합니다. 지원 여부를 확인하기 위해 docker info명령을 사용할 수 있습니다 . 커널에서 기능이 비활성화 된 경우 다음과 같이 출력 끝에 경고가 표시 될 수 있습니다.

메모리 액세스 제한 (커널 메모리 설명도 있지만 여기선 다루지 않았습니다.)

  • -m or --moemory= 

컨테이너가 사용할 수있는 최대 메모리 양. 이 옵션을 설정하면 허용되는 최소값은 4m(4MB)입니다.

  • --memory-swap*

이 컨테이너가 디스크로 스왑 할 수있는 메모리 양입니다. 자세한 --memory-swap내용을 참조 하십시오 .

  • --memory-reservation

--memoryDocker가 호스트 시스템에서 경합 또는 메모리 부족을 감지 할 때 활성화되는 것보다 작은 소프트 한계를 지정할 수 있습니다. --memory-reservation를 사용하는 경우, 우선 순위 --memory보다 낮게 설정해야합니다. 한계이므로 컨테이너가 한계를 초과하지는 않습니다.

CPU

기본 스케줄러 구성

  • 초당 최대 CPU 50% (docker 1.13 이상)
docker run -it --cpus=".5" ubuntu /bin/bash

-cpus="1.5"하면 컨테이너는 최대 1/5의 CPU를 보장합니다. 이것은 설정 --cpu-period="100000"과 동일합니다.

  • docker 1.12 이하
docker run -it --cpu-period=100000 --cpu-quota=50000 ubuntu /bin/bash

 

  • --cpu-period CPU CFS 스케줄러 기간

--cpu-quota. 기본값은 100 마이크로 초입니다. 대부분의 사용자는 이것을 기본값에서 변경하지 않습니다.

  • --cpu-quota CPU CFS 할당량

--cpu-period컨테이너  제한 시간 (마이크로 초) 은 제한 전에 제한됩니다.

반응형

Virtualize Selenium ( 셀레니움 가상화 )

오늘 포스트는 도커, 파이썬을 활용해서 셀레니움을 가상화할 수 있도록 지원해주는 오픈소스 툴에 대한 정리입니다.


docker option 설명 [인용]

-p, --publish=[]: 호스트에 연결된 컨테이너의 특정 포트를 외부에 노출합니다. 보통 웹 서버의 포트를 노출할 때 주로 사용합니다.

  • <호스트 포트>:<컨테이너 포트> 예) -p 80:80
  • <IP 주소>:<호스트 포트>:<컨테이너 포트> 호스트에 네트워크 인터페이스가 여러 개이거나 IP 주소가 여러 개 일 때 사용합니다. 예) -p 192.168.0.10:80:80
  • <IP 주소>::<컨테이너 포트> 호스트 포트를 설정하지 않으면 호스트의 포트 번호가 무작위로 설정됩니다. 예) -p 192.168.0.10::80
  • <컨테이너 포트> 컨테이너 포트만 설정하면 호스트의 포트 번호가 무작위로 설정됩니다. 예) -p 80

[1] firefox-headless-selenium-python

https://github.com/juusechec/docker-firefox-headless-selenium-python

 

juusechec/docker-firefox-headless-selenium-python

Docker container with python and selenium with firefox - juusechec/docker-firefox-headless-selenium-python

github.com

Dockerfile

FROM ubuntu:17.10
ENV LC_ALL C
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true

MAINTAINER Jorge Useche <juusechec@gmail.com>
USER root
# Install dependencies
RUN apt-get -qqy update
RUN apt-get -qqy --no-install-recommends install \
  wget \
  firefox \
  x11vnc \
  xvfb \
  xfonts-100dpi \
  xfonts-75dpi \
  xfonts-scalable \
  xfonts-cyrillic \
  openjdk-8-jre-headless \
  python3-pip \
  curl \
  && rm -rf /var/lib/apt/lists/* /var/cache/apt/*
RUN pip3 install selenium
# Create user for use selenium-server-standalone
RUN useradd -d /home/seleuser -m seleuser
RUN mkdir -p /home/seleuser/chrome
RUN chown -R seleuser /home/seleuser
RUN chgrp -R seleuser /home/seleuser

RUN wget https://selenium-release.storage.googleapis.com/3.6/selenium-server-standalone-3.6.0.jar \
  && mv selenium-server-standalone-*.jar /home/seleuser/selenium-server-standalone.jar
RUN wget https://github.com/mozilla/geckodriver/releases/download/v0.19.0/geckodriver-v0.19.0-linux64.tar.gz -O /tmp/geckodriver.tar.gz \
  && tar -xzf /tmp/geckodriver.tar.gz -C /usr/bin && rm -rf /tmp/geckodriver.tar.gz

# Run at begin
ADD ./scripts/ /home/root/scripts
EXPOSE 4444 5999
CMD ["sh", "/home/root/scripts/start.sh"]

 

[2] dockselpy

https://github.com/dimmg/dockselpy

 

dimmg/dockselpy

Dockerized Selenium and Python with support for Chrome, Firefox and PhantomJS - dimmg/dockselpy

github.com

Dockerfile - dockselpy

FROM ubuntu:bionic

RUN apt-get update && apt-get install -y \
    python3 python3-pip \
    fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
    libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 \
    curl unzip wget \
    xvfb


# install geckodriver and firefox

RUN GECKODRIVER_VERSION=`curl https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+'` && \
    wget https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \
    tar -zxf geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz -C /usr/local/bin && \
    chmod +x /usr/local/bin/geckodriver && \
    rm geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz

RUN FIREFOX_SETUP=firefox-setup.tar.bz2 && \
    apt-get purge firefox && \
    wget -O $FIREFOX_SETUP "https://download.mozilla.org/?product=firefox-latest&os=linux64" && \
    tar xjf $FIREFOX_SETUP -C /opt/ && \
    ln -s /opt/firefox/firefox /usr/bin/firefox && \
    rm $FIREFOX_SETUP


# install chromedriver and google-chrome

RUN CHROMEDRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE` && \
    wget https://chromedriver.storage.googleapis.com/$CHROMEDRIVER_VERSION/chromedriver_linux64.zip && \
    unzip chromedriver_linux64.zip -d /usr/bin && \
    chmod +x /usr/bin/chromedriver && \
    rm chromedriver_linux64.zip

RUN CHROME_SETUP=google-chrome.deb && \
    wget -O $CHROME_SETUP "https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" && \
    dpkg -i $CHROME_SETUP && \
    apt-get install -y -f && \
    rm $CHROME_SETUP


# install phantomjs

RUN wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
    tar -jxf phantomjs-2.1.1-linux-x86_64.tar.bz2 && \
    cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && \
    rm phantomjs-2.1.1-linux-x86_64.tar.bz2


RUN pip3 install selenium
RUN pip3 install pyvirtualdisplay

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONUNBUFFERED=1

ENV APP_HOME /usr/src/app
WORKDIR /$APP_HOME

COPY . $APP_HOME/

CMD tail -f /dev/null
# CMD python3 example.py

Dockerfile - dockselpy for firefox

FROM ubuntu:bionic

RUN apt-get update && apt-get install -y \
    python3 python3-pip \
    fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
    libnspr4 libnss3 lsb-release xdg-utils libxss1 libdbus-glib-1-2 \
    curl unzip wget \
    xvfb


# install geckodriver and firefox

RUN GECKODRIVER_VERSION=`curl https://github.com/mozilla/geckodriver/releases/latest | grep -Po 'v[0-9]+.[0-9]+.[0-9]+'` && \
    wget https://github.com/mozilla/geckodriver/releases/download/$GECKODRIVER_VERSION/geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz && \
    tar -zxf geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz -C /usr/local/bin && \
    chmod +x /usr/local/bin/geckodriver && \
    rm geckodriver-$GECKODRIVER_VERSION-linux64.tar.gz

RUN FIREFOX_SETUP=firefox-setup.tar.bz2 && \
    apt-get purge firefox && \
    wget -O $FIREFOX_SETUP "https://download.mozilla.org/?product=firefox-latest&os=linux64" && \
    tar xjf $FIREFOX_SETUP -C /opt/ && \
    ln -s /opt/firefox/firefox /usr/bin/firefox && \
    rm $FIREFOX_SETUP

RUN pip3 install selenium
RUN pip3 install pyvirtualdisplay

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONUNBUFFERED=1

ENV APP_HOME /usr/src/app
WORKDIR /$APP_HOME

COPY . $APP_HOME/

CMD tail -f /dev/null
# CMD python3 example.py (실행하고자 하는 python 파일명)
반응형

[1] Helpers - Bulk API 

특정 사항이나  raw API를 요약하는 간단한 Helpers functions 컬렉션입니다.

특정 형식에 대한 요구 사항 및 다른 사항으로 인해 직접 사용하는 경우 번거로울 수 있으므로 Bulk API에는 여러 가지 Helpers가 있습니다.

모든 Bulk Helpers는 Elasticsearch 클래스의 인스턴스와 반복 가능한 작업을 수용합니다 (반복 가능하거나 생성자가 될 수 있음). 대량의 데이터 세트를 메모리에 로드하지 않고도 인덱싱 할 수 있습니다.

[2] 사용 예제

import json
import os
from elasticsearch import Elasticsearch
from elasticsearch import helpers

ES_HOST = '127.0.0.1'  # set es url or host
ES = Elasticsearch(hosts=ES_HOST, port=9200)
n = 10

##############################
# Bulk api 사용법
# bulk api를 활용해서 불안정한 search api 대신,
# 다량의 데이터를 한번에 전송하기 위해 작성된 예제 코드입니다.
# 코드는 아래와 같은 방식으로 구현되었습니다.
# ==========================================
# 먼저, resultList로 부터 json 포맷으로 저장된 결과들을 list형인 result_dict에 저장합니다.
# 여기서, resultDict에 있는 데이터들이 n개 이상일 경우, 엘라스틱서치에 전송됩니다.
# n개를 넘지않을 경우에는 추가 데이터를 받아오거나,
# 코드가 종료되는 시점에서 나머지 데이터를 전송하는 방향으로 처리하시면 됩니다.
# ==========================================
##############################
def collector():
  resultList = [{"target":apple, "taste":"good"}, {"target":banana, "taste": "bad"}]
  resultDict = []
  
  for data in resultList:
  	result = {"_index": ES_index, "_source": data}
  	resultDict.append(result)
    
    if len(resultDict) > n:
      helpers.bulk(ES, resultDict)
      resultDict = []
      
  helpers.bulk(ES, resultDict)

[3] 참고 자료

Python Helpers 모듈, https://elasticsearch-py.readthedocs.io/en/master/helpers.html

 

Helpers — Elasticsearch 7.5.1 documentation

Lets say we have an iterable of data. Lets say a list of words called mywords and we want to index those words into individual documents where the structure of the document is like {"word": " "} . The parallel_bulk() api is a wrapper around the bulk() api

elasticsearch-py.readthedocs.io

 

반응형

elasticsearch의 인덱스에 대한 change 여부를 체크하는 방법에 대한 포스트입니다.

1. 시퀀스 번호를 활용한 추적

시퀀스 번호 체크 방법

http://{ip}:9200/_search?seq_no_primary_term=true

Today this can be solved client side by storing the last sequence number and then polling the shard level stats for the current sequence number; if it is higher, there must have been a change. Closing.

마지막 시퀀스 번호를 저장 한 다음 현재 시퀀스 번호의 샤드 레벨 통계를 폴링하여 클라이언트 측에서 해결할 수 있습니다.

https://github.com/elastic/elasticsearch/issues/13830

Determine if the index has been modified · Issue #13830 · elastic/elasticsearch

Today, it is difficult to determine if any index has been updated (e.g., in mostly read only scenarios where the answer becomes more interesting). If you have a simple, outside cache, then it would...

github.com

2. 스택 모니터링의 indices stats 정보, index stats API  히스토리컬 데이터 확인

http://{ip}:9200/_stats

 

http://{ip}:9200/{index}/_stats

https://www.elastic.co/guide/en/kibana/7.5/elasticsearch-metrics.html#indices-overview-page

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html

반응형

1. docker 가이드

https://subicura.com/2017/01/19/docker-guide-for-beginners-1.html

https://www.slideshare.net/pyrasis/docker-fordummies-44424016

 

1.1. docker for mini OS

https://blog.ubuntu.com/2018/07/09/minimal-ubuntu-released

 

Minimal Ubuntu, on public clouds and Docker Hub | Ubuntu

Today we are delighted to introduce the new Minimal Ubuntu, optimized for automated use at scale, with a tiny package set and minimal security cross-section. Speed, performance and stability are primary concerns for cloud developers and ops. “The small foo

ubuntu.com

 

1.2. docker redis

https://jistol.github.io/docker/2017/09/01/docker-redis/

 

Docker Redis 사용하기

 

jistol.github.io

 

1.3. docker - let's set redis on docker

http://yongho1037.tistory.com/699

 

Docker 활용기(4) - redis 구성해보기

Custom config 파일 적용하기 redis 이미지를 구동하면 설정이 기본값으로 적용되기 때문에 직접 설정한 redis.conf 파일을 적용하려면 docker run 명령 수행시에 -v 옵션을 통해 container 내의 /usr/local/etc/r..

yongho1037.tistory.com

 

1.4. docker blog

http://yongho1037.tistory.com/category/Programming/Docker?page=2

 

'Programming/Docker' 카테고리의 글 목록 (2 Page)

 

yongho1037.tistory.com

 

1.5. docker elasticsearch

http://brownbears.tistory.com/66

 

Elasticsearch 설치 및 사용법

Elastic Search 설치 $ docker pull elasticsearch # 이미지 다운로드 $ docker run -d -p 9200:9200 --name elastic elasticsearch # 기본세팅으로 바로 실행 $ docker run -d -p 9200:9200 --name elastic elast..

brownbears.tistory.com

 

1.6. docker save the change thing

https://code.i-harness.com/ko/q/1b402e1

불러오는 중입니다...

 

1.7. set the password in redis

http://dejavuqa.tistory.com/154

 

redis 암호 설정과 외부 접속 허용 설정

redis-server를 기본으로 설정했다면 로컬 접속만 허용되게 됩니다. 외부 서버에서는 접속이 되지 않습니다. 외부에서 접속하기 위한 설정과 암호를 설정해 봅시다. 먼저 암호설정입니다. redis.conf를 엽니다. $..

dejavuqa.tistory.com

 

2. docker 명령어 모음

docker + command

docker search < image name >

docker pull < image name > : < tag >

docker images

docker run < option > < image name > < file >

docker ps

docker start < container name > / restart

docker attach < container name >

docker exec < container name >

docker stop < container name >

docker rm < container name >

docker rmi < image name > : < tag >

docker build < option > < Dockerfile path >

 

2.1. 한 라인으로 모든 컨테이너 삭제

only one line command for delete all container

docker stop $(docker ps -a -q)

docker rm $(docker ps -a -q)

 

 

반응형

이번 포스트는 Elasticsearch를 공부하면서 참고한 자료들을 단순히 주제별로 정리한 포스트입니다.

 

1. ELK 스택

Elasticsearch + Logstash + Kibana 스택 구축 가이드

Digital Ocean - [how to install]

 

2. elasticsearch-dump [엘라스틱서치-덤프]

엘라스틱 서치에 있는 파일들을 json 포맷이나 csv 포맷으로 저장하는 파이썬 모듈 

2.1. Copy

2.2. Backup

 

3.4. merge

curl -XPOST 'localhost:9200/kimchy,elasticsearch/_forcemerge?pretty'

Best way, using reindex API

POST _reindex
{
  "conflicts": "proceed",
  "source": {
  "index": ["twitter", "blog"],
  "type": ["tweet", "post"]
  },
  "dest": {
  "index": "all_together"
  }
}

 

3.5. mapping

PUT post
{
  "mappings":{
    "nulled":{
      "properties":{
        "user":{
        "type":"text"
        },
        "title":{
        "type":"text"
        },
        "detail":{
        "type":"text"
        },
        "url":{
        "type":"text"
        },
        "datetime":{
        "type":"date","format":"YYYY-MM-dd HH:mm"
        }
     }
   }
}



반응형

+ Recent posts