mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 02:00:43 +00:00
Replace curl with little python script
This commit is contained in:
@@ -14,3 +14,9 @@ goapp/app: goapp/app.go
|
||||
|
||||
clean:
|
||||
rm -f qotd/*.o qotd/qotd goapp/app
|
||||
|
||||
run: all
|
||||
docker-compose kill || true
|
||||
docker-compose rm -f || true
|
||||
docker-compose build
|
||||
docker-compose up -d
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
To run,
|
||||
|
||||
```
|
||||
make
|
||||
docker-compose up -d
|
||||
make run
|
||||
```
|
||||
|
||||
# "architecture"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FROM gliderlabs/alpine
|
||||
FROM python:2.7
|
||||
MAINTAINER Weaveworks Inc <help@weave.works>
|
||||
WORKDIR /home/weave
|
||||
RUN apk add --update curl
|
||||
ADD ./client /home/weave/
|
||||
RUN chmod u+x /home/weave/client
|
||||
ENTRYPOINT ["/home/weave/client"]
|
||||
ADD requirements.txt /home/weave/
|
||||
RUN pip install -r /home/weave/requirements.txt
|
||||
ADD client.py /home/weave/
|
||||
ENTRYPOINT ["python", "/home/weave/client.py"]
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
while true; do
|
||||
curl http://pyapp:5000/
|
||||
sleep 1
|
||||
done
|
||||
29
experimental/example/client/client.py
Normal file
29
experimental/example/client/client.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import requests
|
||||
import random
|
||||
import threading
|
||||
import logging
|
||||
import sys
|
||||
|
||||
pyapps = ['http://pyapp:5000/']
|
||||
concurrency = 5
|
||||
|
||||
def do_requests():
|
||||
while True:
|
||||
try:
|
||||
requests.get(random.choice(pyapps))
|
||||
except:
|
||||
logging.error("Error doing request", exc_info=sys.exc_info())
|
||||
logging.info("Did request")
|
||||
|
||||
def main():
|
||||
logging.info("Starting %d thread", concurrency)
|
||||
threads = [threading.Thread(target=do_requests) for i in range(concurrency)]
|
||||
for thread in threads:
|
||||
thread.start()
|
||||
for thread in threads:
|
||||
thread.join()
|
||||
logging.info("Exiting")
|
||||
|
||||
if __name__ == "__main__":
|
||||
logging.basicConfig()
|
||||
main()
|
||||
2
experimental/example/client/requirements.txt
Normal file
2
experimental/example/client/requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
requests
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import socket
|
||||
import requests
|
||||
import random
|
||||
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from flask import Flask
|
||||
from redis import Redis
|
||||
@@ -9,6 +11,8 @@ app = Flask(__name__)
|
||||
redis = Redis(host='redis', port=6379)
|
||||
pool = ThreadPoolExecutor(max_workers=10)
|
||||
|
||||
goapps = ['http://goapp1:8080/', 'http://goapp2:8080/']
|
||||
|
||||
def do_redis():
|
||||
redis.incr('hits')
|
||||
return redis.get('hits')
|
||||
@@ -23,7 +27,7 @@ def do_qotd():
|
||||
s.close()
|
||||
|
||||
def do_search():
|
||||
r = requests.get('http://goapp:8080/')
|
||||
r = requests.get(random.choice(goapps))
|
||||
return r.text
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user