-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add browser example * add node metric example
- Loading branch information
Showing
5 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<html> | ||
<head> | ||
<script src="../build/signalflow.js" type="text/javascript"></script> | ||
<script src="http://d3js.org/d3.v3.min.js"></script> | ||
|
||
<style> | ||
body { | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
} | ||
|
||
.graph .axis { | ||
stroke-width: 1; | ||
} | ||
|
||
.graph .axis .tick line { | ||
stroke: black; | ||
} | ||
|
||
.graph .axis .tick text { | ||
fill: black; | ||
font-size: 0.7em; | ||
} | ||
|
||
.graph .axis .domain { | ||
fill: none; | ||
stroke: black; | ||
} | ||
|
||
.graph .group { | ||
fill: none; | ||
stroke: black; | ||
stroke-width: 1.5; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div class="graph"></div> | ||
<script> | ||
var limit = 10, | ||
duration = 10000, | ||
animDuration = 500, | ||
now = new Date(Date.now() - duration); | ||
|
||
var width = 500, | ||
height = 200; | ||
|
||
var groups = {}; | ||
|
||
var x = d3.time.scale() | ||
.domain([now - (limit - 2), now - duration]) | ||
.range([0, width]); | ||
|
||
var y = d3.scale.linear() | ||
.domain([0, 100]) | ||
.range([height, 0]); | ||
|
||
var line = d3.svg.line() | ||
.interpolate('basis') | ||
.x(function(d, i) { | ||
return x(now - (limit - i) * duration) | ||
}) | ||
.y(function(d) { | ||
return y(d) | ||
}); | ||
|
||
var svg = d3.select('.graph').append('svg') | ||
.attr('class', 'chart') | ||
.attr('width', width) | ||
.attr('height', height + 50); | ||
|
||
var axis = svg.append('g') | ||
.attr('class', 'x axis') | ||
.attr('transform', 'translate(0,' + height + ')') | ||
.call(x.axis = d3.svg.axis().scale(x).orient('bottom')); | ||
|
||
var paths = svg.append('g'); | ||
|
||
function addGroup (name) { | ||
var group = groups[name]; | ||
group.path = paths.append('path') | ||
.data([group.data]) | ||
.attr('class', name + ' group') | ||
.style('stroke', group.color); | ||
} | ||
|
||
function tick() { | ||
now = new Date(); | ||
|
||
// Shift domain | ||
x.domain([now - limit * duration, now - duration]); | ||
|
||
// Slide x-axis left | ||
axis.transition() | ||
.duration(animDuration) | ||
.ease('linear') | ||
.call(x.axis); | ||
|
||
// Slide paths left | ||
paths.attr('transform', null) | ||
.transition() | ||
.duration(animDuration) | ||
.ease('linear') | ||
.attr('transform', 'translate(' + x(now - limit * duration) + ')'); | ||
//.each('end', tick); | ||
|
||
for (var name in groups) { | ||
var group = groups[name]; | ||
group.data.shift() | ||
} | ||
} | ||
|
||
var token = 'ACCESS_TOKEN'; | ||
|
||
var sfxClient = signalfx.streamer.SignalFlow(token); | ||
|
||
var j1 = sfxClient.execute({ | ||
program: "data('cpu.utilization').publish()", | ||
start: Date.now() - 10*10000, | ||
resolution: 10000 | ||
}); | ||
|
||
j1.stream(function (err, data) { | ||
if(!err) { | ||
if ( data.type === signalfx.streamer.CONSTANTS.MESSAGE_TYPES.METADATA ) { | ||
data.data = d3.range(limit).map(function() { | ||
return 0; | ||
}); | ||
groups[data.tsId] = data; | ||
addGroup(data.tsId); | ||
} else if ( data.type === signalfx.streamer.CONSTANTS.MESSAGE_TYPES.DATA) { | ||
data.data.forEach(function (datapoint) { | ||
groups[datapoint.tsId].data.push(datapoint.value); | ||
groups[datapoint.tsId].path.attr('d', line); | ||
}); | ||
tick(); | ||
} | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
var signalflow = require('../'); | ||
|
||
var token = process.env['SPLUNK_ACCESS_TOKEN']; | ||
var realm = process.env['SPLUNK_REALM'] || 'us0'; | ||
|
||
var sfxClient = new signalflow.SignalFlow(token, { | ||
signalflowEndpoint: 'wss://stream.' + realm + '.signalfx.com', | ||
apiEndpoint: 'https://api.' + realm + '.signalfx.com' | ||
}); | ||
|
||
function receive() { | ||
var program = "data('cpu.utilization').publish()"; | ||
console.log('signalflow: ', program); | ||
|
||
var handle = sfxClient.execute({ | ||
program: program, | ||
start: Date.now() - 60000, | ||
stop: Date.now() + 60000, | ||
resolution: 10000, | ||
immediate: false, | ||
}); | ||
|
||
handle.stream(function (err, data) { | ||
if (err) { | ||
console.log(err); | ||
return; | ||
} | ||
|
||
if (data.type === 'data') { | ||
data.data.forEach(function (dataPoint) { | ||
console.log('value received: ', dataPoint); | ||
}); | ||
} | ||
}); | ||
} | ||
receive(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var http = require("http"), | ||
url = require("url"), | ||
path = require("path"), | ||
fs = require("fs"), | ||
port = process.argv[2] || 8888; | ||
|
||
http.createServer(function(request, response) { | ||
|
||
var uri = url.parse(request.url).pathname | ||
, filename = path.join(process.cwd(), uri); | ||
|
||
console.log(uri); | ||
if(uri !== '/example/index.html' && uri !== '/build/signalflow.js') { | ||
response.writeHead(500, {"Content-Type": "text/plain"}); | ||
response.end(); | ||
return; | ||
} | ||
fs.exists(filename, function(exists) { | ||
if(!exists) { | ||
response.writeHead(404, {"Content-Type": "text/plain"}); | ||
response.write("404 Not Found\n"); | ||
response.end(); | ||
return; | ||
} | ||
|
||
if (fs.statSync(filename).isDirectory()) filename += '/index.html'; | ||
|
||
fs.readFile(filename, "binary", function(err, file) { | ||
if(err) { | ||
response.writeHead(500, {"Content-Type": "text/plain"}); | ||
response.write(err + "\n"); | ||
response.end(); | ||
return; | ||
} | ||
|
||
response.writeHead(200); | ||
response.write(file, "binary"); | ||
response.end(); | ||
}); | ||
}); | ||
}).listen(parseInt(port, 10)); | ||
|
||
console.log("Static file server running at\n => http://localhost:" + port + "/\nCTRL + C to shutdown"); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.