将数据从Golang推送到OpenTSTB

将数据从Golang推送到OpenTSTB,go,lang,Go,Lang,我已将最后一个小时的数据存储到文件中。因此,我必须将以前的数据上传到openTSTB 因此,守则如下: go func() { file, err := os.Open("/var/lib/agent/agent.db") if err != nil { fmt.Println(err, "Err") } scanner := bufio.NewScanner(file) for sca

我已将最后一个小时的数据存储到文件中。因此,我必须将以前的数据上传到openTSTB

因此,守则如下:

go func() {
        file, err := os.Open("/var/lib/agent/agent.db")

        if err != nil {
            fmt.Println(err, "Err")
        }

        scanner := bufio.NewScanner(file)

        for scanner.Scan() {
            arr := []byte(scanner.Text())
            url := "http://192.168.2.40:4242/api/put"
            req, err := http.NewRequest("POST", url, bytes.NewBuffer(arr))
            req.Header.Set("Content-Type", "")
            client := &http.Client{}
            resp, err := client.Do(req)
            if err != nil {
                panic(err)
            }
            defer resp.Body.Close()

        }
    }()
// Regular run
go func() {
    timeStamp, _ := strconv.ParseInt(strconv.FormatInt(time.Now().UnixNano()/1e9, 10), 10, 64)
    err := opentsdb.Put(
        MetricName,
        4,
        timeStamp,
        opentsdb.Tag{"host", hostname},
    )
}()
上面的代码将最后一个小时的数据推送到openTSTB

当前数据也使用另一个GoRoutine推送到openTSTB

代码如下:

go func() {
        file, err := os.Open("/var/lib/agent/agent.db")

        if err != nil {
            fmt.Println(err, "Err")
        }

        scanner := bufio.NewScanner(file)

        for scanner.Scan() {
            arr := []byte(scanner.Text())
            url := "http://192.168.2.40:4242/api/put"
            req, err := http.NewRequest("POST", url, bytes.NewBuffer(arr))
            req.Header.Set("Content-Type", "")
            client := &http.Client{}
            resp, err := client.Do(req)
            if err != nil {
                panic(err)
            }
            defer resp.Body.Close()

        }
    }()
// Regular run
go func() {
    timeStamp, _ := strconv.ParseInt(strconv.FormatInt(time.Now().UnixNano()/1e9, 10), 10, 64)
    err := opentsdb.Put(
        MetricName,
        4,
        timeStamp,
        opentsdb.Tag{"host", hostname},
    )
}()
问题是,如果最后一条记录是4,我以前的记录已上载旧数据[Ex:4+4]

如果我运行单个GoRoutine,它工作正常。如果我使用旧的和当前的数据,结果是错误的

如何解决这个问题?非常感谢您的帮助。提前谢谢