2013-12-23 3 views
1

Collectd는 활성 연결을 찾기 위해 nginx의 HttpStubStatusModule 을 쿼리합니다. 플러그인은 here입니다 collectd의 모니터링 플러그인에 복수 nginx 추가

<Plugin "nginx"> 
    URL "https://localhost:8433/nginx_status" 
</Plugin> 

로 삼았

는 config 끝이 보인다.

나는 4 개의 Nginx 인스턴스가 동일한 물리적 호스트에서 실행되고 각각 다른 포트에서 수신 대기하는 설정이 있습니다. 어떻게 수집 Nginxes 여러 모니터를 만들 수 있습니까? 다음은 작동하지 않습니다. -

<Plugin "nginx"> 
    URL "https://localhost:8433/nginx_status" 
</Plugin> 

<Plugin "nginx"> 
    URL "https://localhost:8434/nginx_status" 
</Plugin> 

답변

-1

struct curl_slist * curl_list = NULL; 나는 collectd 파이썬 플러그인에 대한 작은 스크립트를 작성했습니다

curl_list = curl_slist_append(curl_list, header); 

    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, curl_list); 
+3

는 더 이상 특정 일 수 있습니다 여기에

는 소스 코드? – corradio

+0

이 답변을 읽은 후에는 무엇을해야할지 전혀 이해할 수 없습니다. C 코드를 작성해야합니까? 나 자신의 Collectd 플러그인을 작성해야합니까? 기존 플러그인을 변경 하시겠습니까? –

1

:

https://github.com/magazov/collectd-multinginx-python

그것은 사용하기 매우 간단합니다.

#! /usr/bin/env python 

import re 
import urllib2 
import collectd  

class Nginx(object): 
    def __init__(self): 
     self.pattern = re.compile("([A-Z][\w]*).+?(\d+)") 
     self.urls = {} 

    def do_nginx_status(self): 
     for instance, url in self.urls.items(): 
      try: 
       response = urllib2.urlopen(url) 
      except urllib2.HTTPError, e: 
       collectd.error(str(e)) 
      except urllib2.URLError, e: 
       collectd.error(str(e)) 
      else: 
       data = response.read() 
       m = self.pattern.findall(data) 
       for key, value in m: 
        metric = collectd.Values() 
        metric.plugin = 'nginx-%s' % instance 
        metric.type_instance = key.lower() 
        metric.type = 'nginx_connections' 
        metric.values = [value] 
        metric.dispatch() 

       requests = data.split('\n')[2].split()[-1] 
       collectd.debug('Requests %s' % requests) 
       metric = collectd.Values() 
       metric.plugin = 'nginx-%s' % instance 
       metric.type = 'nginx_requests' 
       metric.values = [requests] 
       metric.dispatch() 

    def config(self, obj): 
     self.urls = dict((node.key, node.values[0]) for node in obj.children) 


nginx = Nginx() 
collectd.register_config(nginx.config) 
collectd.register_read(nginx.do_nginx_status)