Ver código fonte

Merge branch 'dashboard' of github.com:flashmob/go-guerrilla into dashboard

flashmob 8 anos atrás
pai
commit
b44b3bf14d

+ 2 - 2
Makefile

@@ -24,7 +24,7 @@ dependencies:
 	$(GO_VARS) $(GO) list -f='{{ join .Deps "\n" }}' $(ROOT)/cmd/guerrillad | grep -v $(ROOT) | tr '\n' ' ' | $(GO_VARS) xargs $(GO) install -v
 	cd dashboard/js && npm install && cd ../..
 
-dashboard: dashboard/*
+dashboard: dashboard/*.go */*/*/*.js */*/*/*/*.js
 	cd dashboard/js && npm run build && cd ../..
 	statik -src=dashboard/js/build -dest=dashboard
 
@@ -44,4 +44,4 @@ testrace: *.go */*.go */*/*.go
 	$(GO_VARS) $(GO) test -v ./tests -race
 	$(GO_VARS) $(GO) test -v ./cmd/guerrillad -race
 	$(GO_VARS) $(GO) test -v ./response -race
-	$(GO_VARS) $(GO) test -v ./backends -race
+	$(GO_VARS) $(GO) test -v ./backends -race

+ 4 - 3
backends/gateway.go

@@ -7,11 +7,12 @@ import (
 	"sync"
 	"time"
 
+	"runtime/debug"
+	"strings"
+
 	"github.com/flashmob/go-guerrilla/log"
 	"github.com/flashmob/go-guerrilla/mail"
 	"github.com/flashmob/go-guerrilla/response"
-	"runtime/debug"
-	"strings"
 )
 
 var ErrProcessorNotFound error
@@ -146,7 +147,7 @@ func (gw *BackendGateway) Process(e *mail.Envelope) Result {
 		return NewResult(response.Canned.SuccessMessageQueued + status.queuedID)
 
 	case <-time.After(gw.saveTimeout()):
-		Log().Error("Backend has timed out while saving eamil")
+		Log().Error("Backend has timed out while saving email")
 		return NewResult(response.Canned.FailBackendTimeout)
 	}
 }

+ 2 - 1
dashboard/dashboard.go

@@ -6,12 +6,13 @@ import (
 	"net/http"
 	"time"
 
+	"sync"
+
 	log "github.com/Sirupsen/logrus"
 	_ "github.com/flashmob/go-guerrilla/dashboard/statik"
 	"github.com/gorilla/mux"
 	"github.com/gorilla/websocket"
 	"github.com/rakyll/statik/fs"
-	"sync"
 )
 
 var (

+ 4 - 1
dashboard/datastore.go

@@ -121,7 +121,6 @@ func (ds *dataStore) rankingManager() {
 		case <-stopRankingManager:
 			return
 		}
-
 	}
 }
 
@@ -132,6 +131,8 @@ func (ds *dataStore) aggregateRankings() ranking {
 	topHelo := make(map[string]int, len(ds.topHelo[0]))
 	topIP := make(map[string]int, len(ds.topIP[0]))
 
+	ds.lock.Lock()
+	// Aggregate buffers
 	for i := 0; i < nRankingBuffers; i++ {
 		for domain, count := range ds.topDomain[i] {
 			topDomain[domain] += count
@@ -143,6 +144,7 @@ func (ds *dataStore) aggregateRankings() ranking {
 			topIP[ip] += count
 		}
 	}
+	ds.lock.Unlock()
 
 	return ranking{
 		TopDomain: topDomain,
@@ -302,6 +304,7 @@ func (h logHook) Fire(e *log.Entry) error {
 			ip:     ip,
 		}
 	case "disconnect":
+		log.Infof("disconnect in dashboard, nclients: %d", store.nClients)
 		store.lock.Lock()
 		store.nClients--
 		store.lock.Unlock()

+ 1 - 0
dashboard/js/src/components/App.js

@@ -47,6 +47,7 @@ class App extends Component {
 		ws.onclose = event => console.log(event);
 		ws.onmessage = event => {
 			const message = JSON.parse(event.data);
+			console.log(message);
 			props.dispatch(message);
 		};
 

+ 0 - 3
dashboard/js/src/reducer.js

@@ -41,9 +41,6 @@ const reducer = (state = initialState, {type, payload}) => {
 				.push(...payload.ram))
 			.setIn(['nClients', 'data'], state.getIn(['nClients', 'data'])
 				.push(...payload.nClients))
-			.set('topDomain', Immutable.fromJS(payload.topDomain))
-			.set('topHelo', Immutable.fromJS(payload.topHelo))
-			.set('topIP', Immutable.fromJS(payload.topIP));
 		if (newState.getIn(['ram', 'data']).count() > state.get('maxPoints')) {
 			newState = newState
 				.setIn(['ram', 'data'], state.getIn(['ram', 'data'])

+ 0 - 3
dashboard/js/src/util.js

@@ -9,7 +9,6 @@ export const createActionTypes = list => {
 };
 
 export const formatBytes = (bytes, decimals) => {
-	console.log(bytes);
 	if (bytes < 1000) return `${bytes} B`;
 	const k = 1000;
 	const dm = decimals || 3;
@@ -21,7 +20,6 @@ export const formatBytes = (bytes, decimals) => {
 };
 
 export const formatNumber = (num, decimals) => {
-	console.log(num);
 	if (num < 1000) return `${num}`;
 	const k = 1000;
 	const dm = decimals || 3;
@@ -29,6 +27,5 @@ export const formatNumber = (num, decimals) => {
 	const i = Math.floor(Math.log(num) / Math.log(k));
 
 	if (i < 0) return '';
-	console.log(parseFloat((num / Math.pow(k, i)).toFixed(dm)));
 	return `${parseFloat((num / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
 }