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
| func main(){ client := http.Client{ Transport: &http.Transport{ Dial: (&net.Dialer{ Timeout: 2*time.Second, Deadline: time.Now().Add(2*time.Second), }).Dial, }, } for { url_test := "http://10.186.225.124:80/monitor_test.cgi" tm := time.Now().Unix() var dimension = DimensionStu{ Appid: "hello", Product: "hello", Uuid: "hello", } var valData = rand.Float64()*100 var batch = []BatchStu{{Unit: "mib", Name: "cpu", Value: valData}} var oneData = []Data{{Timestamp: tm, Namespace: "qce/monitor_test", Dimension: dimension, Freq: 60, Batch: batch}} jsonStr, err := json.Marshal(oneData) if err != nil { panic(err) } req, err := http.NewRequest("POST", url_test, bytes.NewBuffer(jsonStr)) if err != nil { panic(err) } req.Header.Set("Content-Type", "applicate/json")
resp, err := client.Do(req) if err != nil { panic(err) } defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) fmt.Println(string(body)) time.Sleep(1*time.Second) } }
|