Example #1
0
func main() {
	flag.Parse()

	common.Info("initializing metric http endpoint")
	connector, err := common.BuildRabbitMQConnector(*rabbitHost, *rabbitPort, *rabbitUser, *rabbitPassword, *rabbitExchange)
	if err != nil {
		log.Fatalln("error", err)
	}

	bindTo := fmt.Sprintf(":%d", *serverPort)

	common.Info("binding to:", bindTo)

	service := metricsService{connector: connector}

	gin.SetMode(gin.ReleaseMode)
	r := gin.New()
	r.Use(gin.Recovery())
	r.POST("/metrics", service.createMetric)
	r.GET("/debug/vars", expvar.Handler())

	if err := r.Run(bindTo); err != nil {
		log.Fatalln(err)
	}
}
Example #2
0
func main() {
	flag.Parse()
	common.DebugLevel = *debugMode
	common.Info("disctinct name Worker")
	common.Info(`collects daily occurrences of distinct events in Redis. 
				Metrics that are older than 30 days are merged into a monthly bucket, 
				then cleared.`)

	common.Info("connecting to Redis...")

	r, err := OpenRedis(*redisHost, *redisPort)
	if err != nil {
		log.Fatalln("Cannot dial redis", err)
	}
	defer r.Close()
	common.Info("Connected")
	common.Info("connecting to RabbitMQ...")

	connector, err := common.BuildRabbitMQConnector(*rabbitHost, *rabbitPort, *rabbitUser, *rabbitPassword, *rabbitExchange)
	if err != nil {
		log.Fatalln("cannot connect to rabbitmq", err)
	}
	defer connector.Close()
	common.Info("connected")
	common.Info("Starting worker proccesor")

	connector.Handle("distinct-name", func(b []byte) bool {
		d := common.MustUnmarshallFromJSON(b)
		if _, err = r.processMetric(d); err != nil {
			log.Println("error inserting in redis", err)
			return false //requeue
		}
		return true
	})

	if err != nil {
		log.Fatalln("error connecting to Rabbit", err)
	}
	common.Info("Starting a metrics http server")

	bindTo := fmt.Sprintf(":%v", *metricsPort)
	go http.ListenAndServe(bindTo, nil)

	common.Info("Starting old buckets ticker")
	for range time.Tick(time.Minute) {
		if _, err = r.processBuckets(); err != nil {
			log.Println("error proccesing buckets:", err)
		}
	}
}
Example #3
0
func main() {
	flag.Parse()
	common.DebugLevel = *debugMode
	common.Info("AccountName Worker")
	common.Info(`collects all the account names that sent metrics, with their 
				first occurrence datetime (UTC) into PostgreSQL.`)
	common.Info("connecting to PostgreSQL...")

	db, err := openDB(*postgreSQLHost, *postgreSQLPort, *postgreSQLUser, *postgreSQLPassword, *postgreSQLDB)
	if err != nil {
		log.Fatalln("cannot open connection to DB:", err)
	}
	defer db.Close()

	common.Info("Connected")

	if err := db.createTable(); err != nil {
		log.Fatalln("table:", err)
	}

	common.Info("connecting to RabbitMQ...")
	c, err := common.BuildRabbitMQConnector(*rabbitHost, *rabbitPort, *rabbitUser, *rabbitPassword, *rabbitExchange)
	if err != nil {
		log.Fatalln("cannot connect to rabbitmq", err)
	}
	common.Info("connected")
	defer c.Close()

	common.Info("Starting worker proccesor")
	err = c.Handle("account-name", func(b []byte) bool {
		d := common.MustUnmarshallFromJSON(b)
		if err := db.insertEntry(d.Username, d.Time); err != nil {
			log.Println("error inserting in pgsql", err)
			return false //requeue
		}
		return true
	})
	if err != nil {
		log.Fatalln("error connecting to Rabbit", err)
	}

	common.Info("Starting a metrics http server")

	bindTo := fmt.Sprintf(":%v", *metricsPort)
	http.ListenAndServe(bindTo, nil)
}
Example #4
0
func main() {
	flag.Parse()
	common.DebugLevel = *debugMode
	common.Info("AccountName Worker")
	common.Info("collects all items that occurred in the last hour into MongoDB")
	common.Info("connecting to Mongo...")

	m, err := OpenMongo(*mongoDBHost, *mongoDBPort)
	if err != nil {
		log.Fatalln("Error on Mongo:", err)
	}
	defer m.Close()
	common.Info("Connected")
	common.Info("connecting to RabbitMQ...")

	connector, err := common.BuildRabbitMQConnector(*rabbitHost, *rabbitPort, *rabbitUser, *rabbitPassword, *rabbitExchange)
	if err != nil {
		log.Fatalln("cannot connect to rabbitmq", err)
	}
	defer connector.Close()

	common.Info("connected")
	common.Info("Starting worker proccesor")

	err = connector.Handle("hourly-log", func(b []byte) bool {
		d := common.MustUnmarshallFromJSON(b)
		if err = m.InsertMetric(d); err != nil {
			log.Println("error inserting in mongo", err)
			return false //requeue
		}
		return true
	})

	if err != nil {
		log.Fatalln("error connecting to Rabbit", err)
	}

	common.Info("Starting a metrics http server")

	bindTo := fmt.Sprintf(":%v", *metricsPort)
	http.ListenAndServe(bindTo, nil)
}