8
8
"os/signal"
9
9
"strconv"
10
10
"strings"
11
+ "sync"
11
12
"time"
12
13
13
14
"bufio"
@@ -33,16 +34,23 @@ type (
33
34
httpHost string
34
35
httpPort string
35
36
}
37
+ comutex struct {
38
+ mu sync.Mutex
39
+ compiling bool
40
+ }
36
41
)
37
42
38
43
// Setting up flags
39
44
var (
40
- confdir = flag .String ("c" , "conf.sample" , "configuration directory" )
41
- all = flag .Bool ("a" , true , "run all parsers when set. Set by default" )
42
- specific = flag .String ("o" , "" , "run only a specific parser [sshd]" )
43
- redisD4 redis.Conn
44
- redisParsers * redis.Pool
45
- parsers = [1 ]string {"sshd" }
45
+ confdir = flag .String ("c" , "conf.sample" , "configuration directory" )
46
+ all = flag .Bool ("a" , true , "run all parsers when set. Set by default" )
47
+ specific = flag .String ("o" , "" , "run only a specific parser [sshd]" )
48
+ redisD4 redis.Conn
49
+ redisParsers * redis.Pool
50
+ parsers = [1 ]string {"sshd" }
51
+ compilationTrigger = 10
52
+ wg sync.WaitGroup
53
+ compiling comutex
46
54
)
47
55
48
56
func main () {
@@ -135,6 +143,9 @@ func main() {
135
143
// Create a connection Pool
136
144
redisParsers = newPool (rp .redisHost + ":" + rp .redisPort , rp .redisDBCount )
137
145
146
+ // Line counter to trigger HTML compilation
147
+ nblines := 0
148
+
138
149
var torun = []logparser.Parser {}
139
150
// Init parser depending on the parser flags:
140
151
if * all {
@@ -185,12 +196,32 @@ func main() {
185
196
log .Fatal (err )
186
197
}
187
198
}
188
-
199
+ nblines ++
200
+ if nblines > compilationTrigger {
201
+ nblines = 0
202
+ // Non-blocking
203
+ if ! compiling .compiling {
204
+ go compile ()
205
+ }
206
+ }
189
207
}
190
208
209
+ wg .Wait ()
191
210
log .Println ("Exit" )
192
211
}
193
212
213
+ func compile () {
214
+ compiling .mu .Lock ()
215
+ compiling .compiling = true
216
+ wg .Add (1 )
217
+ log .Println ("I should probably be writing" )
218
+ time .Sleep (500 * time .Millisecond )
219
+ log .Println ("Writing" )
220
+ compiling .compiling = false
221
+ compiling .mu .Unlock ()
222
+ wg .Done ()
223
+ }
224
+
194
225
func newPool (addr string , maxconn int ) * redis.Pool {
195
226
return & redis.Pool {
196
227
MaxActive : maxconn ,
0 commit comments