feat(cwmp): get acs rtt info
This commit is contained in:
parent
fa2bffef23
commit
66ec86c0d5
|
|
@ -3,6 +3,7 @@ package bridge
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"oktopUSP/backend/services/acs/internal/config"
|
"oktopUSP/backend/services/acs/internal/config"
|
||||||
"oktopUSP/backend/services/acs/internal/server/handler"
|
"oktopUSP/backend/services/acs/internal/server/handler"
|
||||||
|
|
@ -11,6 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
|
|
@ -97,6 +99,26 @@ func (b *Bridge) StartBridge() {
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
b.sub(handler.NATS_CWMP_ADAPTER_SUBJECT_PREFIX+"rtt", func(msg *nats.Msg) {
|
||||||
|
log.Printf("Received message on rtt subject")
|
||||||
|
url := "127.0.0.1" + b.conf.Port
|
||||||
|
conn, err := net.Dial("tcp", url)
|
||||||
|
if err != nil {
|
||||||
|
respondMsg(msg.Respond, 500, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
info, err := tcpInfo(conn.(*net.TCPConn))
|
||||||
|
if err != nil {
|
||||||
|
respondMsg(msg.Respond, 500, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rtt := time.Duration(info.Rtt) * time.Microsecond
|
||||||
|
|
||||||
|
respondMsg(msg.Respond, 200, rtt/1000)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func respondMsg(respond func(data []byte) error, code int, msgData any) {
|
func respondMsg(respond func(data []byte) error, code int, msgData any) {
|
||||||
|
|
@ -112,7 +134,6 @@ func respondMsg(respond func(data []byte) error, code int, msgData any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
respond(msg)
|
respond(msg)
|
||||||
//log.Println("Responded with message: ", string(msg))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeviceFromSubject(subject string) string {
|
func getDeviceFromSubject(subject string) string {
|
||||||
|
|
@ -120,3 +141,22 @@ func getDeviceFromSubject(subject string) string {
|
||||||
device := paths[len(paths)-2]
|
device := paths[len(paths)-2]
|
||||||
return device
|
return device
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tcpInfo(conn *net.TCPConn) (*unix.TCPInfo, error) {
|
||||||
|
raw, err := conn.SyscallConn()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var info *unix.TCPInfo
|
||||||
|
ctrlErr := raw.Control(func(fd uintptr) {
|
||||||
|
info, err = unix.GetsockoptTCPInfo(int(fd), unix.IPPROTO_TCP, unix.TCP_INFO)
|
||||||
|
})
|
||||||
|
switch {
|
||||||
|
case ctrlErr != nil:
|
||||||
|
return nil, ctrlErr
|
||||||
|
case err != nil:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return info, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ type GeneralInfo struct {
|
||||||
MqttRtt string
|
MqttRtt string
|
||||||
WebsocketsRtt string
|
WebsocketsRtt string
|
||||||
StompRtt string
|
StompRtt string
|
||||||
|
AcsRtt string
|
||||||
ProductClassCount []entity.ProductClassCount
|
ProductClassCount []entity.ProductClassCount
|
||||||
StatusCount StatusCount
|
StatusCount StatusCount
|
||||||
VendorsCount []entity.VendorsCount
|
VendorsCount []entity.VendorsCount
|
||||||
|
|
@ -82,6 +83,16 @@ func (a *Api) generalInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
result.WebsocketsRtt = time.Until(now).String()
|
result.WebsocketsRtt = time.Until(now).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now = time.Now()
|
||||||
|
_, err = bridge.NatsReqWithoutHttpSet[time.Duration](
|
||||||
|
local.NATS_CWMP_ADAPTER_SUBJECT_PREFIX+"rtt",
|
||||||
|
[]byte(""),
|
||||||
|
a.nc,
|
||||||
|
)
|
||||||
|
if err == nil {
|
||||||
|
result.AcsRtt = time.Until(now).String()
|
||||||
|
}
|
||||||
|
|
||||||
now = time.Now()
|
now = time.Now()
|
||||||
_, err = bridge.NatsReqWithoutHttpSet[time.Duration](
|
_, err = bridge.NatsReqWithoutHttpSet[time.Duration](
|
||||||
local.NATS_STOMP_ADAPTER_SUBJECT_PREFIX+"rtt",
|
local.NATS_STOMP_ADAPTER_SUBJECT_PREFIX+"rtt",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user