diff --git a/.gitignore b/.gitignore index f077465..9ecfe15 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ src # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 .glide/ + +# keys +*.pem diff --git a/README.md b/README.md index 2066c82..165395f 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Basic implementation of proxy client may be found at https://github.com/GoMetric ## Usage -Run server: +* Run server (HTTP): ```bash statsd-http-proxy \ @@ -71,6 +71,21 @@ statsd-http-proxy \ --metric-prefix=prefix.subprefix ``` +* Run server (HTTPS): + +```bash +statsd-http-proxy \ + --verbose \ + --http-host=127.0.0.1 \ + --http-port=433 \ + --tls-cert=cert.pem \ + --tls-key=key.pem \ + --statsd-host=127.0.0.1 \ + --statsd-port=8125 \ + --jwt-secret=somesecret \ + --metric-prefix=prefix.subprefix +``` + Print server version and exit: ```bash @@ -79,19 +94,23 @@ statsd-http-proxy --version Command line arguments: -| Parameter | Description | Default value | -|-----------------|--------------------------------------|--------------------------------------------------------------------------------| -| verbose | Print debug info to stderr | Optional. Default false | -| http-host | Host of HTTP server | Optional. Default 127.0.0.1. To accept connections on any interface, set to "" | -| http-port | Port of HTTP server | Optional. Default 80 | -| statsd-host | Host of StatsD instance | Optional. Default 127.0.0.1 | -| statsd-port | Port of StatsD instance | Optional. Default 8125 | -| jwt-secret | JWT token secret | Optional. If not set, server accepts all connections | -| metric-prefix | Prefix, added to any metric name | Optional. If not set, do not add prefix | -| version | Print version of server and exit | Optional | +| Parameter | Description | Default value | +|-----------------|--------------------------------------|-----------------------------------------------------------------------------------| +| verbose | Print debug info to stderr | Optional. Default false | +| http-host | Host of HTTP server | Optional. Default 127.0.0.1. To accept connections on any interface, set to "" | +| http-port | Port of HTTP server | Optional. Default 80 | +| tls-cert | TLS certificate for the HTTPS | Optional. Default "" to use HTTP. If both tls-cert and tls-key set, HTTPS is used | +| tls-key | TLS private key for the HTTPS | Optional. Default "" to use HTTP. If both tls-cert and tls-key set, HTTPS is used | +| statsd-host | Host of StatsD instance | Optional. Default 127.0.0.1 | +| statsd-port | Port of StatsD instance | Optional. Default 8125 | +| jwt-secret | JWT token secret | Optional. If not set, server accepts all connections | +| metric-prefix | Prefix, added to any metric name | Optional. If not set, do not add prefix | +| version | Print version of server and exit | Optional | Sample code to send metric in browser with JWT token in header: +* HTTP: + ```javascript $.ajax({ url: 'http://127.0.0.1:8080/count/some.key.name', @@ -105,6 +124,21 @@ $.ajax({ }); ``` +* HTTPS (if self-signed certificate is used it has to be accepted!): + +```javascript +$.ajax({ + url: 'https://127.0.0.1:433/count/some.key.name', + method: 'POST', + headers: { + 'X-JWT-Token' => 'some-jwt-token' + }, + data: { + value: 100500 + } +}); +``` + ## Authentication Authentication is optional. It based on passing JWT token to server, encrypted with secret, specified in `jwt-secret` @@ -178,7 +212,7 @@ value=1 | Parameter | Description | Default value | |------------|--------------------------------------|------------------------------------| -| value | Integer value | Optional. Default 1 | +| value | Integer value | Optional. Default 1 | ## Response @@ -188,7 +222,7 @@ Other HTTP status codes: | CODE | Description | |------------------|-----------------------------------------| -| 400 Bad Request | Invalid parameters specified | +| 400 Bad Request | Invalid parameters specified | | 401 Unauthorized | Token not sent | | 403 Forbidden | Token invalid/expired | | 404 Not found | Invalid url requested | diff --git a/demo/index.html b/demo/index.html index 2cfcf20..659eb88 100644 --- a/demo/index.html +++ b/demo/index.html @@ -6,9 +6,22 @@ -You are running demo of StatsD HTTP Proxy. Please, start statsdHttpProxy.sh for handling HTTP requests and -statsdStub.sh for monitoring proxied metrics. +

You are running demo of StatsD HTTP(s) Proxy.

+

Please start statsdHttpProxy.sh for handling HTTP requests or statsdHttpsProxy.sh for handling HTTPS requests.

+

Please start statsdStub.sh for monitoring proxied metrics.

+ +

Communication protocol:

+
+ + + + +
+ +

Options: