Make forwarder and collector compatible with py35
Change-Id: Ia269ec000caec80cea2ca201012f65520efb046d
This commit is contained in:
parent
3712e124a6
commit
7b150fa352
|
@ -12,4 +12,4 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from check import AgentCheck # noqa
|
||||
from monasca_agent.collector.checks.check import AgentCheck # noqa
|
||||
|
|
|
@ -220,7 +220,7 @@ class Collector(util.Dimensions):
|
|||
# Sort by the last collection time so the checks that take the
|
||||
# least amount of time are run first so they are more likely to
|
||||
# complete within the check_frequency
|
||||
sorted_checks = sorted(self.collection_times.itervalues(),
|
||||
sorted_checks = sorted(self.collection_times.values(),
|
||||
key=lambda x: x['last_collect_time'])
|
||||
for entry in sorted_checks:
|
||||
check = entry['check']
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
import collections
|
||||
from concurrent import futures
|
||||
import Queue
|
||||
from queue import Queue
|
||||
import threading
|
||||
|
||||
import eventlet
|
||||
|
@ -60,7 +60,7 @@ class ServicesCheck(monasca_agent.collector.checks.AgentCheck):
|
|||
# A dictionary to keep track of service statuses
|
||||
self.statuses = {}
|
||||
self.notified = {}
|
||||
self.resultsq = Queue.Queue()
|
||||
self.resultsq = Queue()
|
||||
self.nb_failures = 0
|
||||
self.pool = None
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ import sys
|
|||
import time
|
||||
|
||||
# Custom modules
|
||||
import checks.collector
|
||||
import checks.services_checks as status_checks
|
||||
import jmxfetch
|
||||
from monasca_agent.collector.checks.collector import Collector
|
||||
import monasca_agent.collector.checks.services_checks as status_checks
|
||||
from monasca_agent.collector import jmxfetch
|
||||
import monasca_agent.common.config as cfg
|
||||
import monasca_agent.common.daemon
|
||||
import monasca_agent.common.emitter
|
||||
|
@ -103,7 +103,7 @@ class CollectorDaemon(monasca_agent.common.daemon.Daemon):
|
|||
# Load the checks_d checks
|
||||
checksd = util.load_check_directory()
|
||||
|
||||
self.collector = checks.collector.Collector(
|
||||
self.collector = Collector(
|
||||
config, monasca_agent.common.emitter.http_emitter, checksd)
|
||||
|
||||
check_frequency = int(config['check_freq'])
|
||||
|
|
|
@ -13,7 +13,11 @@
|
|||
|
||||
from hashlib import md5
|
||||
import json
|
||||
import urllib2
|
||||
from six.moves.urllib.error import HTTPError
|
||||
from six.moves.urllib.request import build_opener
|
||||
from six.moves.urllib.request import ProxyHandler
|
||||
from six.moves.urllib.request import Request
|
||||
from six import PY3
|
||||
|
||||
|
||||
def post_headers(payload):
|
||||
|
@ -37,15 +41,17 @@ def http_emitter(message, log, url):
|
|||
partial_payload.append(measurement)
|
||||
|
||||
payload = json.dumps(partial_payload)
|
||||
if PY3:
|
||||
payload = payload.encode('utf-8')
|
||||
url = "%s/intake" % url
|
||||
headers = post_headers(payload)
|
||||
|
||||
try:
|
||||
# Make sure no proxy is autodetected for this localhost connection
|
||||
proxy_handler = urllib2.ProxyHandler({})
|
||||
proxy_handler = ProxyHandler({})
|
||||
# Should this be installed as the default opener and reused?
|
||||
opener = urllib2.build_opener(proxy_handler)
|
||||
request = urllib2.Request(url, payload, headers)
|
||||
opener = build_opener(proxy_handler)
|
||||
request = Request(url, payload, headers)
|
||||
response = None
|
||||
try:
|
||||
response = opener.open(request)
|
||||
|
@ -57,7 +63,7 @@ def http_emitter(message, log, url):
|
|||
finally:
|
||||
if response:
|
||||
response.close()
|
||||
except urllib2.HTTPError as e:
|
||||
except HTTPError as e:
|
||||
if e.code == 202:
|
||||
log.debug("http payload accepted")
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue