Skip to content

Commit

Permalink
client logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thallium205 committed Jan 25, 2013
1 parent 1998346 commit 450c245
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 41 deletions.
2 changes: 1 addition & 1 deletion client/app.js
Expand Up @@ -10,7 +10,7 @@ var express = require('express')
var app = express();

app.configure(function(){
app.set('port', process.env.PORT || 80);
app.set('port', process.env.PORT || 8080);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
Expand Down
29 changes: 15 additions & 14 deletions client/package.json
@@ -1,15 +1,16 @@
{
"name": "BlockViewer",
"description": "Visualize the Bitcoin Payment Network",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "3.0.5",
"jade": "0.27.7",
"request": "2.12.0",
"mysql": "2.0.0"
}
{
"name": "BlockViewer",
"description": "Visualize the Bitcoin Payment Network",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app"
},
"dependencies": {
"express": "*",
"jade": "*",
"request": "*",
"mysql": "*",
"loggly": "*"
}
}
2 changes: 1 addition & 1 deletion client/routes/index.js
@@ -1,3 +1,3 @@
exports.index = function(req, res){
res.render('index', { title: 'Express' });
res.render('index', { title: 'Block Viewer' });
};
39 changes: 27 additions & 12 deletions client/routes/owner.js
@@ -1,25 +1,40 @@
var request = require('request');
var mysql = require('mysql');
var loggly = require('loggly')
var config = { subdomain: process.env.logsubdomain, auth: { username: process.env.loguser, password: process.env.logpass }};

console.log(JSON.stringify(config));

var client = loggly.createClient(config);
var logToken = process.env.logtoken;

var connection = mysql.createConnection({
host : '10.0.0.1',
user : 'root',
password : 'webster',
database : 'blockviewer'
host : process.env.sqlhost,
user : process.env.sqluser,
password : process.env.sqlpass,
database : process.env.sqldatabase
});
connection.connect();

exports.id = function(req, res){
console.log('Fetch gexf graph by Owner Id -> ' + req.params.id);
client.log(logToken, 'Fetch gexf graph by Owner Id -> ' + req.params.id);
if (req.params.format.toLowerCase() === 'gexf') {
connection.query('SELECT gexf FROM owner WHERE ownerId = ? LIMIT 1', [req.params.id], function(e, r) {
if (e) {
console.log(e);
client.log(logToken, e);
res.send({error: 'An error occured with the database'}, 500);
return;
}

if (r.length === 0) {
client.log(logToken, 'Result for owner return 0.');
res.send({error: 'The owner ID could not be found.'}, 500);
return;
}

if (r.length !== 1) {
console.log('Result returned something other than 1.');
res.send({error: 'Date not found.'}, 500);
client.log(logToken, 'Result returned something other than 1.');
res.send({error: 'Multiple owners were found.'}, 500);
return;
}
res.send(r.pop().gexf);
Expand All @@ -30,7 +45,7 @@ exports.id = function(req, res){
};

exports.addr = function(req, res){
console.log('Fetch gexf graph by Address -> ' + req.params.addr);
client.log(logToken, 'Fetch gexf graph by Address -> ' + req.params.addr);
if (req.params.format.toLowerCase() === 'gexf') {
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
Expand All @@ -40,7 +55,7 @@ exports.addr = function(req, res){
},
function (e, r, b) {
if (e) {
console.log(e);
client.log(logToken, e);
res.send({error: 'An error occured with the database'}, 500);
return;
}
Expand All @@ -49,12 +64,12 @@ exports.addr = function(req, res){
var ownerId = idArray.pop();
connection.query('SELECT gexf FROM owner WHERE ownerId = ? LIMIT 1', [ownerId], function(e, r) {
if (e) {
console.log(e);
client.log(logToken, e);
res.send({error: 'An error occured with the database'}, 500);
return;
}
if (r.length !== 1) {
console.log('Result returned something other than 1.');
client.log(logToken, 'Result returned something other than 1.');
res.send({error: 'An owner has been identified, but a graph has not been calculated yet. This is typically a result of owners who are too large to be graphed, or this owner has not been graphed yet.'}, 500);
return;
}
Expand Down
8 changes: 6 additions & 2 deletions client/routes/owns.js
@@ -1,7 +1,11 @@
var request = require('request');
var loggly = require('loggly')
var config = { subdomain: process.env.logsubdomain, auth: { username: process.env.loguser, password: process.env.logpass }};
var client = loggly.createClient(config);
var logToken = process.env.logtoken;

exports.id = function(req, res){
console.log('Fetch addresses by Owner Id -> ' + req.params.id);
client.log(logToken, 'Fetch addresses by Owner Id -> ' + req.params.id);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand All @@ -13,7 +17,7 @@ exports.id = function(req, res){
};

exports.addr = function(req, res){
console.log('Fetch addresses by Address -> ' + req.params.addr);
client.log(logToken, 'Fetch addresses by Address -> ' + req.params.addr);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand Down
19 changes: 12 additions & 7 deletions client/routes/time.js
@@ -1,23 +1,28 @@
var mysql = require('mysql');
var loggly = require('loggly')
var config = { subdomain: process.env.logsubdomain, auth: { username: process.env.loguser, password: process.env.logpass }};
var client = loggly.createClient(config);
var logToken = process.env.logtoken;

var connection = mysql.createConnection({
host : '10.0.0.1',
user : 'root',
password : 'webster',
database : 'blockviewer'
host : process.env.sqlhost,
user : process.env.sqluser,
password : process.env.sqlpass,
database : process.env.sqldatabase
});
connection.connect();

exports.day = function(req, res){
console.log('Fetch gexf day graph by Unix Time -> ' + req.params.day);
client.log(logToken, 'Fetch gexf day graph by Unix Time -> ' + req.params.day);
if (req.params.format.toLowerCase() === 'gexf') {
connection.query('SELECT gexf FROM day WHERE graphTime <= ? ORDER BY graphTime desc LIMIT 1', [req.params.day], function(e, r) {
if (e) {
console.log(e);
client.log(logToken, e);
res.send({error: 'An error occured with the database'}, 500);
return;
}
if (r.length !== 1) {
console.log('Result returned something other than 1.');
client.log(logToken, 'Result returned something other than 1.');
res.send({error: 'Date not found.'}, 500);
return;
}
Expand Down
12 changes: 8 additions & 4 deletions client/routes/trans.js
@@ -1,7 +1,11 @@
var request = require('request');
var loggly = require('loggly')
var config = { subdomain: process.env.logsubdomain, auth: { username: process.env.loguser, password: process.env.logpass }};
var client = loggly.createClient(config);
var logToken = process.env.logtoken;

exports.idIn = function(req, res){
console.log('Fetch incoming transactions by Owner Id -> ' + req.params.id);
client.log(logToken, 'Fetch incoming transactions by Owner Id -> ' + req.params.id);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand All @@ -13,7 +17,7 @@ exports.idIn = function(req, res){
};

exports.idOut = function(req, res){
console.log('Fetch outgoing transactions by Owner Id -> ' + req.params.id);
client.log(logToken, 'Fetch outgoing transactions by Owner Id -> ' + req.params.id);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand All @@ -25,7 +29,7 @@ exports.idOut = function(req, res){
};

exports.addrIn = function(req, res){
console.log('Fetch incoming transactions by Address -> ' + req.params.addr);
client.log(logToken, 'Fetch incoming transactions by Address -> ' + req.params.addr);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand All @@ -37,7 +41,7 @@ exports.addrIn = function(req, res){
};

exports.addrOut = function(req, res){
console.log('Fetch outgoing transactions by Address -> ' + req.params.addr);
client.log(logToken, 'Fetch outgoing transactions by Address -> ' + req.params.addr);
var r = request({ url: 'http://localhost:7474/db/data/cypher',
method: 'post',
headers: {'X-Stream': true},
Expand Down
9 changes: 9 additions & 0 deletions credentials.txt
@@ -0,0 +1,9 @@
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
export logsubdomain=blockviewer
export loguser=thallium205
export logpass=63aT8NarGoiVDepeLUrt
export logtoken=dbdd8ce4-079d-46b5-ac17-01183d831c77
export sqlhost=10.0.0.1
export sqluser=root
export sqlpass=webster
export sqldatabase=blockviewer

0 comments on commit 450c245

Please sign in to comment.