chg: [sshd] HTML compiler logic
parent
75a917b6b8
commit
ebb2911277
33
main.go
33
main.go
|
@ -8,6 +8,7 @@ import (
|
|||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"bufio"
|
||||
|
@ -33,6 +34,10 @@ type (
|
|||
httpHost string
|
||||
httpPort string
|
||||
}
|
||||
comutex struct {
|
||||
mu sync.Mutex
|
||||
compiling bool
|
||||
}
|
||||
)
|
||||
|
||||
// Setting up flags
|
||||
|
@ -43,6 +48,9 @@ var (
|
|||
redisD4 redis.Conn
|
||||
redisParsers *redis.Pool
|
||||
parsers = [1]string{"sshd"}
|
||||
compilationTrigger = 10
|
||||
wg sync.WaitGroup
|
||||
compiling comutex
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -135,6 +143,9 @@ func main() {
|
|||
// Create a connection Pool
|
||||
redisParsers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)
|
||||
|
||||
// Line counter to trigger HTML compilation
|
||||
nblines := 0
|
||||
|
||||
var torun = []logparser.Parser{}
|
||||
// Init parser depending on the parser flags:
|
||||
if *all {
|
||||
|
@ -185,12 +196,32 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
nblines++
|
||||
if nblines > compilationTrigger {
|
||||
nblines = 0
|
||||
// Non-blocking
|
||||
if !compiling.compiling {
|
||||
go compile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
log.Println("Exit")
|
||||
}
|
||||
|
||||
func compile() {
|
||||
compiling.mu.Lock()
|
||||
compiling.compiling = true
|
||||
wg.Add(1)
|
||||
log.Println("I should probably be writing")
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
log.Println("Writing")
|
||||
compiling.compiling = false
|
||||
compiling.mu.Unlock()
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
func newPool(addr string, maxconn int) *redis.Pool {
|
||||
return &redis.Pool{
|
||||
MaxActive: maxconn,
|
||||
|
|
Loading…
Reference in New Issue