Skip to content

Commit f86a148

Browse files
committed
documentation and demo
1 parent d73aff2 commit f86a148

File tree

3 files changed

+36
-53
lines changed

3 files changed

+36
-53
lines changed

README.md

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,28 @@ Basic implementation of proxy client may be found at https://github.com/GoMetric
6262

6363
```bash
6464
statsd-http-proxy \
65-
--verbose \
66-
--http-host=127.0.0.1 \
67-
--http-port=8080 \
68-
--statsd-host=127.0.0.1 \
69-
--statsd-port=8125 \
70-
--jwt-secret=somesecret \
71-
--metric-prefix=prefix.subprefix
65+
--verbose \
66+
--http-host=127.0.0.1 \
67+
--http-port=8080 \
68+
--statsd-host=127.0.0.1 \
69+
--statsd-port=8125 \
70+
--jwt-secret=somesecret \
71+
--metric-prefix=prefix.subprefix
7272
```
7373

7474
* Run server (HTTPS):
7575

7676
```bash
7777
statsd-http-proxy \
78-
--verbose \
79-
--http-host=127.0.0.1 \
80-
--http-port=433 \
81-
--tls-cert=cert.pem \
82-
--tls-key=key.pem \
83-
--statsd-host=127.0.0.1 \
84-
--statsd-port=8125 \
85-
--jwt-secret=somesecret \
86-
--metric-prefix=prefix.subprefix
78+
--verbose \
79+
--http-host=127.0.0.1 \
80+
--http-port=433 \
81+
--tls-cert=cert.pem \
82+
--tls-key=key.pem \
83+
--statsd-host=127.0.0.1 \
84+
--statsd-port=8125 \
85+
--jwt-secret=somesecret \
86+
--metric-prefix=prefix.subprefix
8787
```
8888

8989
Print server version and exit:
@@ -109,32 +109,15 @@ Command line arguments:
109109

110110
Sample code to send metric in browser with JWT token in header:
111111

112-
* HTTP:
113-
114112
```javascript
115113
$.ajax({
116114
url: 'http://127.0.0.1:8080/count/some.key.name',
117115
method: 'POST',
118116
headers: {
119-
'X-JWT-Token' => 'some-jwt-token'
120-
},
121-
data: {
122-
value: 100500
123-
}
124-
});
125-
```
126-
127-
* HTTPS (if self-signed certificate is used it has to be accepted!):
128-
129-
```javascript
130-
$.ajax({
131-
url: 'https://127.0.0.1:433/count/some.key.name',
132-
method: 'POST',
133-
headers: {
134-
'X-JWT-Token' => 'some-jwt-token'
117+
'X-JWT-Token': 'some-jwt-token'
135118
},
136119
data: {
137-
value: 100500
120+
value: 100500
138121
}
139122
});
140123
```
@@ -145,7 +128,7 @@ Authentication is optional. It based on passing JWT token to server, encrypted w
145128
command line argument. If secret not configured in `jwt-secret`, then requests to server accepted without authentication.
146129
Token sends to server in `X-JWT-Token` header or in `token` query parameter.
147130

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

150133
## Rest resources
151134

demo/index.html

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010

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

1415
<p>Communication protocol:</p>
1516
<div>
16-
<input type="radio" id="protocol" class="protocolRadio"
17-
name="protocol" value="http" checked>
18-
<label for="protocol">HTTP (8080)</label>
19-
<input type="radio" id="protocol" class="protocolRadio"
20-
name="protocol" value="https">
21-
<label for="protocol">HTTPS (433)</label>
17+
<label>
18+
<input type="radio" name="protocol" value="http" checked>
19+
HTTP (8080)
20+
</label>
21+
</div>
22+
<div>
23+
<label>
24+
<input type="radio" name="protocol" value="https">
25+
HTTPS (4433)
26+
</label>
2227
</div>
2328

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

5560
// send some metric
5661
setInterval(function() {
62+
var protocol = $('[name=protocol]:checked').val();
5763
var headers = {};
58-
var protocol = $('.protocolRadio:checked').val();
59-
var port = '8080' // http
60-
61-
if (protocol == 'https') {
62-
port = '433'
63-
}
64-
64+
var port = protocol === 'https' ? 4433 : 8080;
65+
6566
var url = protocol + '://' + statsdHttpProxyHost + ':' + port + '/' + metricType + '/' + metricName;
6667
var data = {};
6768

demo/statsdHttpsProxy.sh

100644100755
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# This server start listening connections by HTTPS and pass it to StatsD by UDP
44

55
if [ ! -f "key.pem" -o ! -f "cert.pem" ]; then
6-
echo "Https credentials do not exist. Generating new self-signed certificate and key with a default subject"
7-
6+
echo "Generating new self-signed certificate and key with a default subject"
87
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"
98
fi
109

@@ -13,7 +12,7 @@ CURRENT_DIR=$(dirname $(readlink -f $0))
1312
$CURRENT_DIR/../bin/statsd-http-proxy \
1413
--verbose \
1514
--http-host=127.0.0.1 \
16-
--http-port=433 \
15+
--http-port=4433 \
1716
--tls-cert=cert.pem \
1817
--tls-key=key.pem \
1918
--statsd-host=127.0.0.1 \

0 commit comments

Comments
 (0)