Skip to content

Commit

Permalink
update .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
snowinszu committed Sep 21, 2020
1 parent 53b018f commit 97baac8
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/.DS_Store
/cert
/log
config_dev.yaml
config_dev.yaml
cbsignal
Binary file removed cbsignal
Binary file not shown.
5 changes: 4 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

version: 1.1.0
version: 1.1.1

log:
writers: file # 输出位置,有两个可选项 —— file 和 stdout。选择 file 会将日志记录到 logger_file 指定的日志文件中,选择 stdout 会将日志输出到标准输出,当然也可以两者同时选择
Expand Down Expand Up @@ -31,6 +31,9 @@ allow_list:
block_list:
# - "localhost"

# 预估的信令最大连接数
capacity: 30000




Expand Down
46 changes: 46 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"cbsignal/client"
"cbsignal/handler"
"cbsignal/hub"
"encoding/json"
"fmt"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
Expand All @@ -28,6 +29,8 @@ var (
useAllowList = false
blockMap = make(map[string]bool) // block list of domain
useBlockList = false

capacity int64 = 30000
)

func init() {
Expand Down Expand Up @@ -82,6 +85,10 @@ func init() {
panic("Do not use allowList and blockList at the same time")
}

capacity = viper.GetInt64("capacity")
if capacity <= 0 {
panic("capacity <= 0")
}
}

//var EventsCollector *eventsCollector
Expand Down Expand Up @@ -155,6 +162,19 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
}()
}

type Resp struct {
Ret int `json:"ret"`
Data *SignalInfo `json:"data"`
}

type SignalInfo struct {
Version string `json:"version"`
CurrentConnections int64 `json:"current_connections"`
Capacity int64 `json:"capacity"`
UtilizationRate float32 `json:"utilization_rate"`
CompressionEnabled bool `json:"compression_enabled"`
}

func main() {

// Catch SIGINT signals
Expand Down Expand Up @@ -217,6 +237,32 @@ func main() {
w.Write([]byte(fmt.Sprintf("%s", viper.GetString("version"),)))

})
http.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) {
//fmt.Printf("URL: %s\n", r.URL.String())
w.Header().Set("Access-Control-Allow-Origin", "*")
currentConnections := hub.GetClientNum()
utilizationRate := float32(currentConnections)/float32(capacity)
info := SignalInfo{
Version: viper.GetString("version"),
CurrentConnections: hub.GetClientNum(),
Capacity: capacity,
UtilizationRate: utilizationRate,
CompressionEnabled: viper.GetBool("compression.enable"),
}
resp := Resp{
Ret: 0,
Data: &info,
}
b, err := json.Marshal(resp)
if err != nil {
resp, _ := json.Marshal(Resp{
Ret: -1,
Data: nil,
})
w.Write(resp)
}
w.Write(b)
})

if SignalPortTLS != "" && Exists(signalCert) && Exists(signalKey) {
go func() {
Expand Down
17 changes: 17 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"testing"
)

func TestUtilizationRate(t *testing.T) {

var a int64 = 1
var b int64 = 3000
var c float32 = float32(a)/float32(b)
t.Logf("%f", c)
}




0 comments on commit 97baac8

Please sign in to comment.