The stock consumer (stock-con
) consumes data from the stock generator and performs various calculations on different endpoints on it.
Set it up locally (assumes npm
installed, tested with version 5.7.1
):
$ npm install express
$ npm install
Build and run in one terminal (note: make sure you've got the stock generator service running as well otherwise it won't work):
$ DOK_STOCKGEN_HOSTNAME=localhost DOK_STOCKGEN_PORT=9876 npm start
In another terminal (requires http installed, otherwise use curl
):
$ while true; do \
http localhost:9898/average/NYSE:RHT ; \
sleep 2 ; \
done
Usage:
/average/$SYMBOL
Behavior: If $SYMBOL
is a valid and known one a response like below, otherwise a 404
:
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 114
Content-Type: application/json; charset=utf-8
Date: Tue, 13 Mar 2018 17:34:01 GMT
ETag: W/"72-vkOrThRnV1hPbp7xrmGe17qHb4I"
X-Powered-By: Express
{
"current": 598.8333836078177,
"forecast": 437.20974460845946,
"moving_average": 599.5866511312555,
"symbol": "NYSE:RHT"
}
Usage:
/healthz
Behavior: A 200
response like below, listing the number of known symbols and the symbol that has been queried for most recently (ignoring unknown symbols):
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 38
Content-Type: application/json; charset=utf-8
Date: Tue, 13 Mar 2018 17:34:43 GMT
ETag: W/"26-rNuCWemdLty1c1TH7oAt5mn3q2U"
X-Powered-By: Express
{
"lastseen": "NYSE:RHT",
"numsymbols": 4
}
The stock-con
app container image is defined in Dockerfile and publicly available via quay.io/mhausenblas/stock-con:0.3.
To deploy it as an Kubernetes application, use the provided manifest like so:
$ kubectl apply -f app.yaml
$ kubectl get deploy,svc,po
If you do have an Ingress controller running, you can use the following to expose stock-con
to the public:
$ kubectl apply -f public-con.yaml
Once the Ingress resource is deployed (check with kubectl get ing
) you can access it like so (assuming the public-facing IP is 192.168.99.100
):
$ http --verify=no https://192.168.99.100/stock-con/average/NYSE:RHT
Note: the following is WIP, no need to look at it now.
Idea: install Prometheus and Grafana, instrument stock-con
with siimon/prom-client, and visualize the stocks over time.
TBD.
The Grafana app requires an Ingress controller.
$ kubectl create -f grafana-app.yaml
Note: see also the NGINX Ingress user guide for more options.