mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-11 03:36:37 +08:00
变更流量计费方法
This commit is contained in:
Binary file not shown.
Binary file not shown.
+1
-1
@@ -119,7 +119,7 @@ func main() {
|
||||
log := xlogger.NewLogger()
|
||||
logger.SetDefault(log)
|
||||
|
||||
wsReporter := socket.StartWebSocketReporterWithConfig(config.Addr, config.Secret, "1.0.7")
|
||||
wsReporter := socket.StartWebSocketReporterWithConfig(config.Addr, config.Secret, "1.1.0")
|
||||
defer wsReporter.Stop()
|
||||
|
||||
service.SetHTTPReportURL(config.Addr, config.Secret)
|
||||
|
||||
@@ -369,19 +369,10 @@ func (s *defaultService) observeStats(ctx context.Context) {
|
||||
},
|
||||
}
|
||||
if outputBytes > 0 || inputBytes > 0 {
|
||||
reportItems := []TrafficReportItem{
|
||||
{
|
||||
N: s.name,
|
||||
T: "cc",
|
||||
U: int64(outputBytes),
|
||||
D: int64(inputBytes),
|
||||
},
|
||||
{
|
||||
N: s.name,
|
||||
T: "conn",
|
||||
U: int64(inputBytes),
|
||||
D: int64(outputBytes),
|
||||
},
|
||||
reportItems := TrafficReportItem{
|
||||
N: s.name,
|
||||
U: int64(outputBytes),
|
||||
D: int64(inputBytes),
|
||||
}
|
||||
success, err := sendTrafficReport(ctx, reportItems)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,6 @@ var httpAESCrypto *crypto.AESCrypto // 新增:HTTP上报加密器
|
||||
// TrafficReportItem 流量报告项(压缩格式)
|
||||
type TrafficReportItem struct {
|
||||
N string `json:"n"` // 服务名(name缩写)
|
||||
T string `json:"t"` // 连接类型:conn, cc(type缩写)
|
||||
U int64 `json:"u"` // 上行流量(up缩写)
|
||||
D int64 `json:"d"` // 下行流量(down缩写)
|
||||
}
|
||||
@@ -30,7 +29,7 @@ type TrafficReportItem struct {
|
||||
func SetHTTPReportURL(addr string, secret string) {
|
||||
httpReportURL = "http://" + addr + "/flow/upload?secret=" + secret
|
||||
configReportURL = "http://" + addr + "/flow/config?secret=" + secret
|
||||
|
||||
|
||||
// 创建 AES 加密器
|
||||
var err error
|
||||
httpAESCrypto, err = crypto.NewAESCrypto(secret)
|
||||
@@ -43,7 +42,7 @@ func SetHTTPReportURL(addr string, secret string) {
|
||||
}
|
||||
|
||||
// sendTrafficReport 发送流量报告到HTTP接口
|
||||
func sendTrafficReport(ctx context.Context, reportItems []TrafficReportItem) (bool, error) {
|
||||
func sendTrafficReport(ctx context.Context, reportItems TrafficReportItem) (bool, error) {
|
||||
jsonData, err := json.Marshal(reportItems)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("序列化报告数据失败: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user