Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
added a Node.js timeseries api example
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgangB33r committed Nov 9, 2015
1 parent 6ff671c commit 9cd24cd
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 0 deletions.
26 changes: 26 additions & 0 deletions LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2008-2015, Dynatrace LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the dynaTraceRuxit software nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

26 changes: 26 additions & 0 deletions timeseries-examples/Node.js/LICENSE.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 2008-2015, Dynatrace LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the dynaTraceRuxit software nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.

24 changes: 24 additions & 0 deletions timeseries-examples/Node.js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Overview

This Ruxit timeseries data export API example demonstrate the export of CPU timeseries for a given host and how to
chart the resulting data points by using Google charts.
Mind that a Node.js service wrapper is used to cope with the Browsers security restriction to only load resources
from the same origin. The service wrapper also hides the secret API token for accessing the Ruxit tenant data instead
of exposing it within the JavaScript.

### Ruxit data export API documentation

The full API documentation can be found here:
https://ruxit.com/help/api-documentation/v1/timeseries

####`API key`
The API key for your Ruxit tenant. You can generate a key by following these steps

1. go to your Ruxit environment: https://{tenant}.live.ruxit.com
2. Click the burger menu in the right upper corner and select **Integration**
3. You will see the "API" section;
4. Enter a description label and click on **Generate**
5. copy it and use it in your data export API examples

##License
This module is provided under BSD-3-Clause license. Please check out the details in the LICENSE.txt
41 changes: 41 additions & 0 deletions timeseries-examples/Node.js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Local Node.js service that wraps Ruxit Data Export API calls for local JavaScript/Browser usage.
//
var express = require('express');
var app = express();
var https = require('https');

app.use(express.static('public'));

var YOUR_API_TOKEN = "j2pnF2JGR9mhF1ABFna1_";
var YOUR_HOST = "HOST-A3C4D3D278C161FA";

//
// Read the CPU of a given host and return the JSON result
//
app.get('/cpu', function (req, res) {
var options = {
host: 'kyp91462.live.ruxit.com',
path: '/api/v1/timeseries/?Api-Token=' + YOUR_API_TOKEN + '&relativeTime=hour&entity=' + YOUR_HOST + '&aggregationType=AVG&timeseriesId=com.ruxit.builtin:host.cpu.user'
};

callback = function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});

// all data was received, send the result as JSON
response.on('end', function () {
res.send(str);
});
}

https.request(options, callback).end();
});

var server = app.listen(8080, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
43 changes: 43 additions & 0 deletions timeseries-examples/Node.js/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://www.google.com/jsapi?autoload={
'modules':[{
'name':'visualization',
'version':'1',
'packages':['corechart']
}]
}">
</script>
<script type="text/javascript">
var array = [];

$.get( "/cpu", function( data ) {
// set header titles
array.push(['time', 'CPU usage']);
var result = JSON.parse( data );
array = array.concat(result.result.dataPoints["HOST-A3C4D3D278C161FA"]);
// and draw the data
drawChart();
});

function drawChart() {
var data = google.visualization.arrayToDataTable(array);

var options = {
title: 'CPU usage',
curveType: 'function',
legend: { position: 'bottom' }
};

var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>

0 comments on commit 9cd24cd

Please sign in to comment.