mirror of
https://github.com/newnius/YAO-agent.git
synced 2025-12-15 05:56:43 +00:00
switch report from kafka to http
This commit is contained in:
10
mock.py
10
mock.py
@@ -2,15 +2,15 @@ import os
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
from kafka import KafkaProducer
|
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from http.server import BaseHTTPRequestHandler, HTTPServer
|
||||||
from socketserver import ThreadingMixIn
|
from socketserver import ThreadingMixIn
|
||||||
from urllib import parse
|
from urllib import parse
|
||||||
|
import requests
|
||||||
|
|
||||||
NUMS = os.getenv('NUMS', 1)
|
NUMS = os.getenv('NUMS', 1)
|
||||||
|
|
||||||
ClientHost = os.getenv('ClientHost', "localhost")
|
ClientHost = os.getenv('ClientHost', "localhost")
|
||||||
KafkaBrokers = os.getenv('KafkaBrokers', 'localhost:9092').split(',')
|
ReportAddress = os.getenv('ReportAddress', "http://yao-scheduler:8080/?action=agent_report")
|
||||||
PORT = os.getenv('Port', 8000)
|
PORT = os.getenv('Port', 8000)
|
||||||
HeartbeatInterval = os.getenv('HeartbeatInterval', 5)
|
HeartbeatInterval = os.getenv('HeartbeatInterval', 5)
|
||||||
|
|
||||||
@@ -123,10 +123,14 @@ def report(ClientID):
|
|||||||
}
|
}
|
||||||
data = json.dumps(post_fields)
|
data = json.dumps(post_fields)
|
||||||
|
|
||||||
|
url = ReportAddress
|
||||||
|
params = {'data': data}
|
||||||
|
result = requests.post(url, data=params)
|
||||||
|
'''
|
||||||
producer = KafkaProducer(bootstrap_servers=KafkaBrokers)
|
producer = KafkaProducer(bootstrap_servers=KafkaBrokers)
|
||||||
future = producer.send('yao', value=data.encode(), partition=0)
|
future = producer.send('yao', value=data.encode(), partition=0)
|
||||||
result = future.get(timeout=5)
|
result = future.get(timeout=5)
|
||||||
|
'''
|
||||||
time.sleep(HeartbeatInterval)
|
time.sleep(HeartbeatInterval)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user