Skip to content

Commit

Permalink
documentation and demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sokil committed Jan 29, 2019
1 parent d73aff2 commit f86a148
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 53 deletions.
55 changes: 19 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,28 @@ Basic implementation of proxy client may be found at https://github.com/GoMetric

```bash
statsd-http-proxy \
--verbose \
--http-host=127.0.0.1 \
--http-port=8080 \
--statsd-host=127.0.0.1 \
--statsd-port=8125 \
--jwt-secret=somesecret \
--metric-prefix=prefix.subprefix
--verbose \
--http-host=127.0.0.1 \
--http-port=8080 \
--statsd-host=127.0.0.1 \
--statsd-port=8125 \
--jwt-secret=somesecret \
--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
--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:
Expand All @@ -109,32 +109,15 @@ Command line arguments:

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',
method: 'POST',
headers: {
'X-JWT-Token' => 'some-jwt-token'
},
data: {
value: 100500
}
});
```

* 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'
'X-JWT-Token': 'some-jwt-token'
},
data: {
value: 100500
value: 100500
}
});
```
Expand All @@ -145,7 +128,7 @@ Authentication is optional. It based on passing JWT token to server, encrypted w
command line argument. If secret not configured in `jwt-secret`, then requests to server accepted without authentication.
Token sends to server in `X-JWT-Token` header or in `token` query parameter.

We recomment to use JWT tokens to prevent flood requests, setup JWT token expiration time, and update active JWT token in browser.
We recommend to use JWT tokens to prevent flood requests, setup JWT token expiration time, and update active JWT token in browser.

## Rest resources

Expand Down
29 changes: 15 additions & 14 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@

<p>Please start <b>statsdHttpProxy.sh</b> for handling HTTP requests or <b>statsdHttpsProxy.sh</b> for handling HTTPS requests.</p>
<p>Please start <b>statsdStub.sh</b> for monitoring proxied metrics.</p>
<p>To see interation with StatsD proxy open "Network" tab on Developer tools.</p>

<p>Communication protocol:</p>
<div>
<input type="radio" id="protocol" class="protocolRadio"
name="protocol" value="http" checked>
<label for="protocol">HTTP (8080)</label>
<input type="radio" id="protocol" class="protocolRadio"
name="protocol" value="https">
<label for="protocol">HTTPS (433)</label>
<label>
<input type="radio" name="protocol" value="http" checked>
HTTP (8080)
</label>
</div>
<div>
<label>
<input type="radio" name="protocol" value="https">
HTTPS (4433)
</label>
</div>

<p>Options:</p>
Expand All @@ -39,7 +44,7 @@
(function() {
// Token is valid to 2029-02-23T21:32:22.615Z, and builds with secret: somesecret
var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIiLCJpYXQiOjE1MTk0MjE1NDIsImV4cCI6MTg2NjU3Njc0MiwiYXVkIjoiIiwic3ViIjoiIiwiR3JlZXRpbmciOiJIZWxsbywgZGVzY2VuZGFudHMifQ.n2qI2Ar9KzL3IsmlHjZAQmrf_Iz2ugnplwNIl4ELlDk';
var statsdHttpProxyHost = 'localhost';
var statsdHttpProxyHost = 'localhost';
var metricName = 'someMetricName';
var metricType = "count";
var tokenMode = "token-in-header";
Expand All @@ -54,14 +59,10 @@

// send some metric
setInterval(function() {
var protocol = $('[name=protocol]:checked').val();
var headers = {};
var protocol = $('.protocolRadio:checked').val();
var port = '8080' // http

if (protocol == 'https') {
port = '433'
}

var port = protocol === 'https' ? 4433 : 8080;

var url = protocol + '://' + statsdHttpProxyHost + ':' + port + '/' + metricType + '/' + metricName;
var data = {};

Expand Down
5 changes: 2 additions & 3 deletions demo/statsdHttpsProxy.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# This server start listening connections by HTTPS and pass it to StatsD by UDP

if [ ! -f "key.pem" -o ! -f "cert.pem" ]; then
echo "Https credentials do not exist. Generating new self-signed certificate and key with a default subject"

echo "Generating new self-signed certificate and key with a default subject"
openssl req -x509 -nodes -days 358000 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/C=PL/ST=test/L=test/O=test/OU=test/CN=test"
fi

Expand All @@ -13,7 +12,7 @@ CURRENT_DIR=$(dirname $(readlink -f $0))
$CURRENT_DIR/../bin/statsd-http-proxy \
--verbose \
--http-host=127.0.0.1 \
--http-port=433 \
--http-port=4433 \
--tls-cert=cert.pem \
--tls-key=key.pem \
--statsd-host=127.0.0.1 \
Expand Down

0 comments on commit f86a148

Please sign in to comment.