Skip to content
This repository was archived by the owner on Jan 21, 2019. It is now read-only.

Commit fe70e07

Browse files
committed
gauge shift
1 parent 40c8ea0 commit fe70e07

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,23 @@ value=1&sampleRate=1
5050
| sampleRate | Sample rate to skip metrics | Optional. Default to 1: accept all |
5151

5252
### Gauge
53+
54+
Gauge is an arbitrary value. If the gauge is not updated at the next flush, it will send the previous value.
55+
Gauge also may be set relatively to previously stored value.
56+
57+
Absolute value:
5358
```
5459
POST /gauge/{key}
5560
X-JWT-Token: {tokenString}
5661
value=1
5762
```
5863

59-
| Parameter | Description | Default value |
60-
|------------|--------------------------------------|------------------------------------|
61-
| value | Value | Optional. Default 1 |
64+
Shift of previous value:
65+
```
66+
POST /gauge/{key}
67+
X-JWT-Token: {tokenString}
68+
shift=-1
69+
```
6270

6371
### Timing
6472
```
@@ -114,7 +122,7 @@ Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz Dual Core / 8 GB RAM
114122
Siege test:
115123

116124
```
117-
$ time siege -c 255 -r 255 -b -H 'X-JWT-Token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdGF0c2QtcmVzdC1zZXJ2ZXIiLCJpYXQiOjE1MDY5NzI1ODAsImV4cCI6MTg4NTY2Mzc4MCwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3Nva2lsL3N0YXRzZC1yZXN0LXNlcnZlciIsInN1YiI6InNva2lsIn0.sOb0ccRBnN1u9IP2jhJrcNod14G5t-jMHNb_fsWov5c' "http://127.0.0.1:8080/count/a.b.c.d POST"
125+
$ time siege -c 255 -r 255 -b -H 'X-JWT-Token:eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdGF0c2QtcmVzdC1zZXJ2ZXIiLCJpYXQiOjE1MDY5NzI1ODAsImV4cCI6MTg4NTY2Mzc4MCwiYXVkIjoiaHR0cHM6Ly9naXRodWIuY29tL3Nva2lsL3N0YXRzZC1yZXN0LXNlcnZlciIsInN1YiI6InNva2lsIn0.sOb0ccRBnN1u9IP2jhJrcNod14G5t-jMHNb_fsWov5c' "http://127.0.0.1:8080/count/a.b.c.d POST value=42"
118126
** SIEGE 4.0.2
119127
** Preparing 255 concurrent users for battle.
120128
The server is now under siege...

main.go

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,35 @@ func handleGaugeRequest(w http.ResponseWriter, r *http.Request) {
211211
vars := mux.Vars(r)
212212
key := vars["key"]
213213

214-
// get delta
214+
// get gauge shift
215+
shiftPostFormValue := r.PostFormValue("shift")
216+
if shiftPostFormValue != "" {
217+
// get value
218+
value, err := strconv.Atoi(shiftPostFormValue)
219+
if err != nil {
220+
http.Error(w, "Invalid gauge shift specified", 400)
221+
}
222+
// send request
223+
statsdClient.GaugeShift(key, value)
224+
return
225+
}
226+
227+
// get gauge value
215228
var value = 1
216229
valuePostFormValue := r.PostFormValue("value")
217230
if valuePostFormValue != "" {
231+
// get value
218232
var err error
219233
value, err = strconv.Atoi(valuePostFormValue)
220234
if err != nil {
221-
http.Error(w, "Invalid delta specified", 400)
235+
http.Error(w, "Invalid gauge value specified", 400)
222236
}
223237
}
224238

225-
// send request
239+
// send gauge value request
226240
statsdClient.Gauge(key, value)
241+
242+
227243
}
228244

229245
// Handle StatsD Timing request
@@ -259,14 +275,14 @@ func handleSetRequest(w http.ResponseWriter, r *http.Request) {
259275
vars := mux.Vars(r)
260276
key := vars["key"]
261277

262-
// get delta
278+
// get set value
263279
var value = 1
264280
valuePostFormValue := r.PostFormValue("value")
265281
if valuePostFormValue != "" {
266282
var err error
267283
value, err = strconv.Atoi(valuePostFormValue)
268284
if err != nil {
269-
http.Error(w, "Invalid delta specified", 400)
285+
http.Error(w, "Invalid set value specified", 400)
270286
}
271287
}
272288

0 commit comments

Comments
 (0)