由于fluentd.conf配置的原因,目前ToFluentd不可用,以后能配置出来支持自定义格式的index到es的fluentd.conf再说
This commit is contained in:
		
							parent
							
								
									20a5d67d34
								
							
						
					
					
						commit
						8f519aa103
					
				| @ -156,17 +156,8 @@ func (cl *CandleList) ToFluentd() error { | ||||
| 		return fmt.Errorf("invalid period: %v", err) | ||||
| 	} | ||||
| 
 | ||||
| 	// 分批发送,每批最多50条 | ||||
| 	batchSize := 50 | ||||
| 	for i := 0; i < len(cl.Candles); i += batchSize { | ||||
| 		end := i + batchSize | ||||
| 		if end > len(cl.Candles) { | ||||
| 			end = len(cl.Candles) | ||||
| 		} | ||||
| 
 | ||||
| 		// 准备批量数据 | ||||
| 		var records []map[string]interface{} | ||||
| 		for _, candle := range cl.Candles[i:end] { | ||||
| 	// 逐条发送记录 | ||||
| 	for _, candle := range cl.Candles { | ||||
| 		// 验证时间戳是否为周期的整数倍 | ||||
| 		ts, err := strconv.ParseInt(candle.Timestamp, 10, 64) | ||||
| 		if err != nil { | ||||
| @ -181,7 +172,7 @@ func (cl *CandleList) ToFluentd() error { | ||||
| 		// 对于日线数据,检查是否为当天的 00:00:00 | ||||
| 		if cl.Period == "1D" { | ||||
| 			if cstTime.Hour() != 0 || cstTime.Minute() != 0 || cstTime.Second() != 0 { | ||||
| 					return fmt.Errorf("timestamp %d (%s) is not aligned with period %s", ts, cstTime.Format("2006-01-02 15:04:05"), cl.Period) | ||||
| 				return fmt.Errorf("timestamp %d (%s) is not aligned with period :%s", ts, cstTime.Format("2006-01-02 15:04:05"), cl.Period) | ||||
| 			} | ||||
| 		} else { | ||||
| 			// 对于其他周期,使用原来的对齐检查 | ||||
| @ -205,13 +196,10 @@ func (cl *CandleList) ToFluentd() error { | ||||
| 			"volumeCcy": candle.VolumeCcy, | ||||
| 		} | ||||
| 
 | ||||
| 			records = append(records, record) | ||||
| 		} | ||||
| 
 | ||||
| 		// 构造请求体 | ||||
| 		payload := map[string]interface{}{ | ||||
| 			"tag":    tag, | ||||
| 			"record": records, | ||||
| 			"record": record, | ||||
| 		} | ||||
| 
 | ||||
| 		jsonData, err := json.Marshal(payload) | ||||
| @ -281,9 +269,8 @@ func (cl *CandleList) ToFluentd() error { | ||||
| 		if resp.StatusCode != http.StatusOK { | ||||
| 			return fmt.Errorf("unexpected status code: %d, response: %s", resp.StatusCode, string(body)) | ||||
| 		} | ||||
| 		//回头把response列出来看看,是不是有报错 | ||||
| 
 | ||||
| 		fmt.Printf("Successfully sent %d records to Fluentd\n", len(records)) | ||||
| 		fmt.Printf("Successfully sent record to Fluentd: %s\n", fullURL) | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zhangkun9038@dingtalk.com
						zhangkun9038@dingtalk.com