commit b28b03b78eb1ad341aba9dff15292706c5dedbc4 Author: Andrew Tomaka Date: Sat Jan 5 14:10:01 2013 -0500 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3405235 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config/*.coffee +node_modules/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ce36e6 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +#DBMonitor + +Use your web browser to monitor table inserts + +##Description + +Monitor inserts to a specific table of a datbase based on a MySQL timestamp +column. + +##Dependencies + +* nodejs +* npm +* Static web server + +##Install + +``` +$ git clone git://github.com/atomaka/dbmonitor.git +$ cd dbmonitor +$ npm install +$ cp config/application.coffee.sample application.coffee +$ cp config/database.coffee.sample database.coffee +``` + +* Edit settings in application.coffee and database.coffee as necessary +* Setup your web server to serve the public directory + +##Usage + +Go to URL setup in your static web server! + +##License + +The MIT License + +Copyright (c) 2012 Andrew Tomaka + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/config/application.coffee.sample b/config/application.coffee.sample new file mode 100644 index 0000000..6b900e9 --- /dev/null +++ b/config/application.coffee.sample @@ -0,0 +1,10 @@ +application_config = { + port: 5120 + updateTime: 10 + table: 'print_jobs' + columns: ['print_host','user_print', '(pages_end - pages_start) AS pages', 'queue_name'] + timestamp_column: 'rec_time' + where: "queue_name IN('wellsaop1','wellsaop2')" +} + +module.exports = application_config \ No newline at end of file diff --git a/config/database.coffee.sample b/config/database.coffee.sample new file mode 100644 index 0000000..7215781 --- /dev/null +++ b/config/database.coffee.sample @@ -0,0 +1,9 @@ +database_config = { + host: 'localhost' + port: 3306 + database: 'database' + username: 'username' + password: 'password' +} + +module.exports = database_config \ No newline at end of file diff --git a/dbmonitor.coffee b/dbmonitor.coffee new file mode 100644 index 0000000..494e864 --- /dev/null +++ b/dbmonitor.coffee @@ -0,0 +1,32 @@ +database = require './config/database.coffee' +application = require './config/application.coffee' + +moment = require 'moment' +io = require('socket.io').listen(application.port) + +sockets = [] +io.set('log level', 1); + +db = require('mysql-native').createTCPClient(database.host, database.port) +db.auth database.database, database.username, database.password +db.auto_prepare = true + +checkDate = moment().add('minutes', -5) + +getDatabaseUpdates = () -> + query = "SELECT " + application.timestamp_column + "," + application.columns.join(',') + " FROM " + application.table + " WHERE " + application.where + " AND " + application.timestamp_column + " > '" + checkDate.format('YYYY-MM-DD HH:mm:ss') + "'" + db.query(query).addListener 'row', (job) -> + jobDate = moment(job.rec_time, 'YYYY-MM-DD HH:mm:ss') + checkDate = jobDate if jobDate > checkDate + updateClient job + +updateClient = (job) -> + for client in sockets + client.emit 'update', job + +io.sockets.on 'connection', (socket) -> + sockets.push socket + +setInterval () -> + getDatabaseUpdates() +, 1000 * application.updateTime diff --git a/package.json b/package.json new file mode 100644 index 0000000..ad24cbe --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "dbmonitor", + "description": "Use your web browser to monitor table inserts", + "version": "1.0.0", + "private": true, + "dependencies": { + "mysql-native": "0.4.x", + "socket.io": "0.9.x", + "moment": "1.7.x" + } +} \ No newline at end of file diff --git a/public/css/style.css b/public/css/style.css new file mode 100644 index 0000000..1d5e45b --- /dev/null +++ b/public/css/style.css @@ -0,0 +1,50 @@ +.down { + width: 794px; + margin-left: auto; + margin-right: auto; + background-color: #f2cac2; + padding: 3px; +} + +#container { + width: 800px; + margin-left: auto; + margin-right: auto; +} + +#empty { + display: none; +} + +table { + border-collapse:collapse; + border-bottom: 1px solid black; +} + +table, th, td { + border-left: 1px solid black; + border-right: 1px solid black; +} + +th { + border-top: 1px solid black; + border-bottom: 1px solid black; + text-align: left; + background-color: #ccc; +} + +th, td { + padding: 3px; +} + +tr:nth-child(odd) { + background-color: #eee; +} + +tr:nth-child(even) { + background-color: #fff; +} + +.text-center { + text-align: center; +} \ No newline at end of file diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..6c93305 --- /dev/null +++ b/public/index.html @@ -0,0 +1,67 @@ + + + + + DBMonitor + + + + + + + + + + + + + +
Not connected to the server. Retrying...
+
Waiting to receive data from the server.
+ + + +
+ + \ No newline at end of file diff --git a/public/templates/views.html b/public/templates/views.html new file mode 100644 index 0000000..197ec15 --- /dev/null +++ b/public/templates/views.html @@ -0,0 +1,15 @@ + + +