-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (35 loc) · 1.19 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"bootic_stathat/client"
"flag"
"github.com/bootic/bootic_zmq"
"log"
"time"
)
func main() {
var (
topic string
zmqAddress string
stathatAccount string
interval string
)
flag.StringVar(&topic, "topic", "", "ZMQ topic to subscribe to") // event type. ie "order", "pageview"
flag.StringVar(&zmqAddress, "zmqsocket", "tcp://127.0.0.1:6000", "ZMQ socket address to bind to")
flag.StringVar(&stathatAccount, "stathatAccount", "", "Stathat email or account key")
flag.StringVar(&interval, "interval", "60s", "Time interval to send stats on. Ie. 30s, 2m, etc")
flag.Parse()
duration, err := time.ParseDuration(interval)
if err != nil {
panic("INTERVAL cannot be parsed")
}
// Setup ZMQ subscriber +++++++++++++++++++++++++++++++
zmq, _ := booticzmq.NewZMQSubscriber(zmqAddress, topic)
log.Println("ZMQ socket started on", zmqAddress, "topic '", topic, "'")
cl, err := client.NewBufferedClient(stathatAccount, topic, duration)
if err != nil {
panic("Client could not connect")
}
log.Println("Sending", topic, "events to Stathat as", stathatAccount)
zmq.SubscribeToType(cl.Notifier, topic)
cl.Listen()
}