func NewEruApp(container *docker.Container, extend map[string]interface{}) *EruApp { name, entrypoint, ident := utils.GetAppInfo(container.Name) if name == "" { logs.Info("Container name invaild", container.Name) return nil } logs.Debug("Eru App", name, entrypoint, ident) transfer, _ := g.Transfers.Get(container.ID, 0) client := falcon.CreateFalconClient( transfer, time.Duration(g.Config.Metrics.Timeout)*time.Millisecond, ) step := time.Duration(g.Config.Metrics.Step) * time.Second extend["hostname"] = g.Config.HostName extend["cid"] = container.ID[:12] extend["ident"] = ident tag := []string{} for k, v := range extend { tag = append(tag, fmt.Sprintf("%s=%v", k, v)) } endpoint := fmt.Sprintf("%s-%s", name, entrypoint) meta := defines.Meta{container.ID, container.State.Pid, name, entrypoint, ident, extend} metric := metric.CreateMetric(step, client, strings.Join(tag, ","), endpoint) eruApp := &EruApp{meta, metric} return eruApp }
func main() { var dockerAddr string var transferAddr string var certDir string flag.BoolVar(&logs.Mode, "DEBUG", false, "enable debug") flag.StringVar(&dockerAddr, "d", "tcp://192.168.99.100:2376", "docker daemon addr") flag.StringVar(&transferAddr, "t", "10.200.8.37:8433", "transfer addr") flag.StringVar(&certDir, "c", "/root/.docker", "cert files dir") flag.Parse() if flag.NArg() < 1 { fmt.Println("need at least one container id") return } cert := fmt.Sprintf("%s/cert.pem", certDir) key := fmt.Sprintf("%s/key.pem", certDir) ca := fmt.Sprintf("%s/ca.pem", certDir) dockerclient, err := docker.NewTLSClient(dockerAddr, cert, key, ca) if err != nil { fmt.Println(err) return } metric.SetGlobalSetting(dockerclient, 2, 3, "vnbe", "eth0") client := falcon.CreateFalconClient(transferAddr, 5*time.Millisecond) for i := 0; i < flag.NArg(); i++ { if c, err := dockerclient.InspectContainer(flag.Arg(i)); err != nil { fmt.Println(flag.Arg(i), err) continue } else { go start_watcher(client, c.ID, c.State.Pid) } } for { } }