Skip to content

Commit a6c4bed

Browse files
committed
statsd deployrisk backend
1 parent 4510131 commit a6c4bed

8 files changed

Lines changed: 141 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ dist
2121
.sass-cache
2222
fuge/env/system.env
2323
system.env
24-
services
24+
*~

bin/start-dev.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# docker run -d -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" -e "xpack.security.enabled=false" docker.elastic.co/elasticsearch/elasticsearch:5.2.2
2+
node ../../nodezoo-web/srv/web-dev.js &
3+
node ../../nodezoo-info/srv/info-dev.js &
4+
node ../../nodezoo-npm/srv/npm-dev.js &
5+
node ../../nodezoo-search/srv/search-dev.js &
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM hopsoft/graphite-statsd
2+
3+
COPY config.js /opt/statsd/
4+
COPY deployrisk.js /opt/statsd/backends/
5+
6+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
build :
2+
docker build -t nodezoo-graphite-statsd .
3+
4+
run :
5+
docker run -d --restart=always -p 8100:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 nodezoo-graphite-statsd
6+
7+
clean :
8+
rm -f *~
9+
10+
.PHONY : build clean
11+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"graphiteHost": "127.0.0.1",
3+
"graphitePort": 2003,
4+
"port": 8125,
5+
"flushInterval": 1000,
6+
"backends": ["./backends/graphite", "./backends/deployrisk"],
7+
"deployrisk": {
8+
"inputs": [
9+
{
10+
"name": "foo",
11+
"max": 100,
12+
"weight": 0.2
13+
},
14+
{
15+
"name": "bar",
16+
"max": 1000,
17+
"weight": 0.2
18+
},
19+
{
20+
"name": "zed",
21+
"min": 400,
22+
"max": 1000,
23+
"mod": "invert",
24+
"weight": 0.6
25+
}
26+
]
27+
}
28+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var dgram = require('dgram')
2+
3+
4+
function DeployRiskBackend(startupTime, config, emitter){
5+
var self = this
6+
7+
this.client = dgram.createSocket('udp4')
8+
9+
this.score = 0
10+
11+
this.config = config.deployrisk || {}
12+
13+
this.config.port = this.config.port || 8125
14+
this.config.host = this.config.host || '127.0.0.1'
15+
16+
this.inputs = this.config.inputs || []
17+
18+
this.inputs.forEach(function (input) {
19+
var mod = input.mod
20+
var max = input.max
21+
22+
mod =
23+
null == mod ? function (x) {return x}
24+
: 'invert' === mod ? function (x, input) {return input.min + input.max - x}
25+
: mod
26+
27+
input.mod = mod
28+
29+
input.min = input.min || 0
30+
})
31+
32+
emitter.on('flush', function(timestamp, metrics) {
33+
self.flush(timestamp, metrics)
34+
})
35+
36+
emitter.on('status', function(callback) {
37+
self.status(callback)
38+
})
39+
}
40+
41+
42+
DeployRiskBackend.prototype.flush = function(timestamp, metrics) {
43+
44+
var table = []
45+
46+
this.inputs.forEach(function (input) {
47+
var name = 'deployrisk.'+input.name
48+
var min = input.min
49+
var max = input.max
50+
var mod = input.mod
51+
var weight = input.weight
52+
53+
var v = metrics.gauges[name]
54+
55+
if (null != v) {
56+
v = mod(v, input)
57+
table.push( weight * Math.max(0, (Math.min(1, (v-min) / (max-min)))) )
58+
}
59+
})
60+
61+
this.score = Math.round( 100 * table.reduce(function(ac, v) {return ac+v}, 0) )
62+
63+
var data = new Buffer('deployrisk.score:'+this.score+'|g')
64+
this.client.send(data, 0, data.length, this.config.port, this.config.host,
65+
function(err) { if (err) console.log(err) })
66+
}
67+
68+
69+
DeployRiskBackend.prototype.status = function(write) {
70+
write(null, 'deployrisk', 'score', this.score)
71+
}
72+
73+
exports.init = function(startupTime, config, events) {
74+
var instance = new DeployRiskBackend(startupTime, config, events)
75+
return true
76+
}

notes.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
git clone --branch v0.8.0 https://github.com/etsy/statsd.git v0.8.0
3+
4+
5+
# https://github.com/hopsoft/docker-graphite-statsd
6+
docker run -d --restart=always -p 8100:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 hopsoft/graphite-statsd
7+
8+
docker run -d --restart=always -p 8100:80 -p 2003-2004:2003-2004 -p 2023-2024:2023-2024 -p 8125:8125/udp -p 8126:8126 nodezoo-graphite-statsd
9+
10+

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"description": "A fuge config for NodeZoo",
55
"license": "MIT",
66
"dependencies": {
7+
"artillery": "^1.5.2",
78
"nodezoo-base": "7.0.x",
9+
"nodezoo-coveralls": "3.x.x",
10+
"nodezoo-dequeue": "1.0.x",
811
"nodezoo-github": "6.3.x",
912
"nodezoo-info": "6.0.x",
1013
"nodezoo-npm": "7.1.x",
1114
"nodezoo-search": "6.1.x",
1215
"nodezoo-travis": "7.1.x",
13-
"nodezoo-web": "6.1.x",
1416
"nodezoo-updater": "1.0.x",
15-
"nodezoo-dequeue": "1.0.x",
16-
"nodezoo-coveralls": "3.x.x"
17+
"nodezoo-web": "6.1.x"
1718
},
1819
"scripts": {
1920
"test": "echo \"Error: no test specified\" && exit 0"

0 commit comments

Comments
 (0)