func Init(metrics met.Backend) { sec := setting.Cfg.Section("collector_event_publisher") if !sec.Key("enabled").MustBool(false) { enabled = false return } enabled = true addr := sec.Key("nsqd_addr").MustString("localhost:4150") topic = sec.Key("topic").MustString("metrics") cfg := nsq.NewConfig() cfg.UserAgent = fmt.Sprintf("probe-ctrl") var err error globalProducer, err = nsq.NewProducer(addr, cfg) if err != nil { log.Fatal(0, "failed to initialize nsq producer.", err) } collectorEventPublisherMsgs = metrics.NewCount("collectoreventpublisher.events-published") }
func Init(metrics met.Backend, t string, addr string, enabled bool) { if !enabled { return } topic = t cfg := nsq.NewConfig() cfg.UserAgent = fmt.Sprintf("raintank-apps-server") var err error globalProducer, err = nsq.NewProducer(addr, cfg) if err != nil { log.Fatal(4, "failed to initialize nsq producer. %s", err) } err = globalProducer.Ping() if err != nil { log.Fatal(4, "can't connect to nsqd: %s", err) } metricsPublished = metrics.NewCount("metricpublisher.metrics-published") messagesPublished = metrics.NewCount("metricpublisher.messages-published") messagesSize = metrics.NewMeter("metricpublisher.message_size", 0) metricsPerMessage = metrics.NewMeter("metricpublisher.metrics_per_message", 0) publishDuration = metrics.NewTimer("metricpublisher.publish_duration", 0) }
func NewApi(adminKey string, metrics met.Backend) *macaron.Macaron { m := macaron.Classic() m.Use(macaron.Renderer()) m.Use(GetContextHandler()) m.Use(Auth(adminKey)) bind := binding.Bind m.Get("/", heartbeat) m.Group("/api/v1", func() { m.Get("/", heartbeat) m.Group("/agents", func() { m.Combo("/"). Get(bind(model.GetAgentsQuery{}), GetAgents). Post(AgentQuota(), bind(model.AgentDTO{}), AddAgent). Put(bind(model.AgentDTO{}), UpdateAgent) m.Get("/:id", GetAgentById) m.Get("/:id/metrics", GetAgentMetrics) m.Delete("/:id", DeleteAgent) }) m.Get("/metrics", bind(model.GetMetricsQuery{}), GetMetrics) m.Group("/tasks", func() { m.Combo("/"). Get(bind(model.GetTasksQuery{}), GetTasks). Post(bind(model.TaskDTO{}), TaskQuota(), AddTask). Put(bind(model.TaskDTO{}), UpdateTask) m.Get("/:id", GetTaskById) m.Delete("/:id", DeleteTask) }) m.Get("/socket/:agent/:ver", socket) }) taskCreate = metrics.NewCount("api.tasks_create") taskDelete = metrics.NewCount("api.tasks_delete") return m }