node_exporter로 prometheus에 데이터 보내기

  1. 필요도구
  • Python과 prometheus_client 라이브러리
  • node_exporter의 custom 파일이 등록되는 경로

Node_export

아래의 예제는 solr cloud의 5분간 쿼리요청타임을 각 코어들의 모든 합을 구한 데이터를

node_exporter를 통해 prometheus 로 보내는 간단한 소스입니다.

solr 에서 결과는 json 타입으로 받아 데이터를 가공해 node_exporter 를 통해 보냅니다.

 

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import json
from prometheus_client import CollectorRegistry, Gauge, write_to_textfile
server_uri = "blahblah "
registry = CollectorRegistry()
g = Gauge('solr_query_5min', 'How many query on this server', registry=registry)
tmp_5min = list()
try:
r = requests.get('http://{}/solr/admin/metrics?group=all&prefix=QUERY./select.requestTimes&wt=json'.format(server_uri))
except Exception as e:
print(e)
c = json.loads(r.text)
data = dict(zip(*[iter(c['metrics'])]*2))
for k,v in data.items():
if 'core' in k:
try:
tmp_5min.append(dict(zip(*[iter(v[1])]*2))['5minRate'])
except KeyError:
continue
g.set(sum(map(lambda x:float("{0:.2f}".format(x)), tmp_5min)))
write_to_textfile('/var/tmp/node_exporter/solr_load_5m.prom', registry)
#!/usr/bin/env python #-*- coding: utf-8 -*- import json from prometheus_client import CollectorRegistry, Gauge, write_to_textfile server_uri = "blahblah " registry = CollectorRegistry() g = Gauge('solr_query_5min', 'How many query on this server', registry=registry) tmp_5min = list() try: r = requests.get('http://{}/solr/admin/metrics?group=all&prefix=QUERY./select.requestTimes&wt=json'.format(server_uri)) except Exception as e: print(e) c = json.loads(r.text) data = dict(zip(*[iter(c['metrics'])]*2)) for k,v in data.items(): if 'core' in k: try: tmp_5min.append(dict(zip(*[iter(v[1])]*2))['5minRate']) except KeyError: continue g.set(sum(map(lambda x:float("{0:.2f}".format(x)), tmp_5min))) write_to_textfile('/var/tmp/node_exporter/solr_load_5m.prom', registry)
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import json
from prometheus_client import CollectorRegistry, Gauge, write_to_textfile

server_uri = "blahblah "
registry = CollectorRegistry()
g = Gauge('solr_query_5min', 'How many query on this server', registry=registry)

tmp_5min = list()

try:
    r = requests.get('http://{}/solr/admin/metrics?group=all&prefix=QUERY./select.requestTimes&wt=json'.format(server_uri))
except Exception as e:
    print(e)

c = json.loads(r.text)
data = dict(zip(*[iter(c['metrics'])]*2))
for k,v in data.items():
    if 'core' in k:
        try:
            tmp_5min.append(dict(zip(*[iter(v[1])]*2))['5minRate'])
        except KeyError:
            continue

g.set(sum(map(lambda x:float("{0:.2f}".format(x)), tmp_5min)))
write_to_textfile('/var/tmp/node_exporter/solr_load_5m.prom', registry)
0 0 votes
Article Rating
Subscribe
Notify of
guest


이 사이트는 Akismet을 사용하여 스팸을 줄입니다. 댓글 데이터가 어떻게 처리되는지 알아보세요.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Scroll to top
0
Would love your thoughts, please comment.x
()
x