반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[python] elasticsearch 리소스 확인 본문

Python

[python] elasticsearch 리소스 확인

닉의네임 2022. 11. 17. 10:41
반응형

    # data = client.cat.shards('hyper-item')
    data = client.nodes.stats()
        print(data)

# es.cat.indices(h='index', s='index').split()
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
import numpy as np
import matplotlib.pyplot as plt
import pprint as ppr
import json
import time
import threading


def nodes_stats():
    data = client.nodes.stats()
    return [data['nodes']['sZyeNvOxTAGDXfPMxA_l4g']['os']['mem']['used_percent'], data['nodes']['sZyeNvOxTAGDXfPMxA_l4g']['jvm']['mem']['heap_used_percent']]

if __name__ == '__main__':

    client = Elasticsearch(hosts='localhost', port='9200', http_auth=('elastic', 'dlengus'))
    SIZE = 5
    used_percents=[]
    heap_used_percents=[]

    for i in range(SIZE):
        used_percent, heap_used_percent =  nodes_stats()
        used_percents.append(used_percent)
        heap_used_percents.append(heap_used_percent)

    t= range(0, SIZE)
    y1= used_percents
    y2= heap_used_percents

    plt.rcParams['font.family'] = 'AppleGothic'

    fig, ax = plt.subplots()
    ax.set_title('used_percent VS heap_used_percent')
    line1, = ax.plot(t, y1, lw=2, label='used_percent')
    line2, = ax.plot(t, y2, lw=2, label='heap_used_percent')
    leg = ax.legend(fancybox=True, shadow=True)

    ax.set_ylabel('query 속도(ms)')
    ax.set_xlabel('조회수(회)')

    lines = [line1, line2]
    lined = {}  # Will map legend lines to original lines.
    for legline, origline in zip(leg.get_lines(), lines):
        legline.set_picker(True)  # Enable picking on the legend line.
        lined[legline] = origline


    def on_pick(event):
        legline = event.artist
        origline = lined[legline]
        visible = not origline.get_visible()
        origline.set_visible(visible)
        legline.set_alpha(1.0 if visible else 0.2)
        fig.canvas.draw()

    fig.canvas.mpl_connect('pick_event', on_pick)
    plt.show()



반응형

'Python' 카테고리의 다른 글

[python] .csv파일 읽어서 sql 문 만들기  (0) 2023.04.11
[python] byte convert size format  (0) 2022.11.17
[python] replace( )  (0) 2022.10.09
[python] float check  (2) 2022.10.06
[python] random number  (0) 2022.07.03
Comments