Skip to content

Commit

Permalink
v23 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
eddie murphy committed Oct 31, 2023
1 parent 1ab5aae commit 06ba4fe
Show file tree
Hide file tree
Showing 27 changed files with 493 additions and 256 deletions.
38 changes: 0 additions & 38 deletions .chglog/CHANGELOG.tpl.md

This file was deleted.

28 changes: 0 additions & 28 deletions .chglog/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
logs
tmp/
build.sh
siphub
sipgrep
.air.toml
.gitignore
CHANGELOG.md
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
node_modules
*.heapsnapshot
*.log
siphub
sipgrep
tmp
.DS_Store
heplify
heplify.log.*
run
.air*
.air.toml
demo
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version=$(shell cat VERSION)
image_name="wangduanduan/siphub-go:$(version)"
image_name="wangduanduan/sipgrep-go:$(version)"

DBAddr=
DBName=
Expand All @@ -23,12 +23,14 @@ fmt:
changelog:
git-chglog -o CHANGELOG.md
run:
-docker rm -f siphub-go;
-docker rm -f sipgrep-go;
docker run -d \
-p 3000:3000 \
-p 9060:9060/udp \
-e DBAddr="$(DBAddr)" \
-e DBName="$(DBName)" \
-e DBUserPasswd="$(DBUserPasswd)" \
--name siphub-go \
harbor:5000/wecloud/siphub-go:$(image_name)
--name sipgrep-go \
harbor:5000/wecloud/sipgrep-go:$(image_name)
t1:
http --verbose localhost:3000/api/v1/call BeginTime=="2023-10-31 00:00:00" EndTime=="2023-10-31 23:59:59"
85 changes: 53 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# V23 Roadmap, under developing

- siphub-go merge into siphub-ui, so there are no siphub-ui or siphub-go, just one siphub.
- sipgrep-go merge into sipgrep-ui, so there are no sipgrep-ui or sipgrep-go, just one sipgrep.
- using react + ant design as ui frame
- using golang fiber as the web server, no nodejs
- using [SequenceDiagram](https://github.com/davidje13/SequenceDiagram) to draw sip sequence dragram
Expand Down Expand Up @@ -52,9 +52,9 @@ this is the first version
![](./img/import.jpg)


# siphub 组件
- siphub-go: 负责处理hep消息,写入数据库
- siphub-ui: 负责web界面展示,数据搜索
# sipgrep 组件
- sipgrep-go: 负责处理hep消息,写入数据库
- sipgrep-ui: 负责web界面展示,数据搜索

# Golang版本

Expand All @@ -64,36 +64,36 @@ this is the first version

## mysql安装

先准备一个mysql数据库,并自行创建一个名为siphub的数据库
先准备一个mysql数据库,并自行创建一个名为sipgrep的数据库

## siphub-go
## sipgrep-go

docker 安装siphub-go
docker 安装sipgrep-go

```bash
docker run -d \
--name siphub-go \
--name sipgrep-go \
-p 3000:3000 \
-p 9060:9060/udp \
-e DBAddr="localhost" \
-e DBUserPasswd="root:password" \
-e DBName="siphub" \
-e DBName="sipgrep" \
-e LogLevel="info" \
-e HeaderUIDName="X-UID" \
wangduanduan/siphub-go:22.05.02
wangduanduan/sipgrep-go:22.05.02
```

- 3000/HTTP 端口
- GET /metrics/prometheus 提供普罗米修斯统计的监控接口
- 9060/UDP hep消息接收端口

- siphub-go环境变量说明
- sipgrep-go环境变量说明

```
// UDP监听端口
UDPListenPort int `env:"UDPListenPort" envDefault:"9060"`
// 最大UDP包的长度
MaxPackgeLength int `env:"MaxPackgeLength" envDefault:"4096"`
MaxPacketLength int `env:"MaxPacketLength" envDefault:"4096"`
// UDP读取超时秒数
MaxReadTimeoutSeconds int `env:"MaxReadTimeoutSecond" envDefault:"5"`
// 日志级别
Expand All @@ -107,15 +107,15 @@ docker 安装siphub-go
// 丢弃的方法,方法之间用英文逗号隔开
DiscardMethods string `env:"DiscardMethods" envDefault:"OPTIONS"`
// 最小的UDP包长度,比这个小的会丢弃
MinPackgeLength int `env:"MinPackgeLength" envDefault:"24"`
MinPacketLength int `env:"MinPacketLength" envDefault:"24"`
// 数据库连接数
SqlMaxOpenConn int `env:"SqlMaxOpenConn" envDefault:"24"`
// 数据库用户名和密码
DBUserPasswd string `env:"DBUserPasswd" envDefault:"root:123456"`
// 数据库地址
DBAddr string `env:"DBAddr" envDefault:"localhost"`
// 数据库名称
DBName string `env:"DBName" envDefault:"siphub"`
DBName string `env:"DBName" envDefault:"sipgrep"`
// 被叫号码从哪个地方抽取,RURI 或者 TO
CalleeFrom string `env:"CalleeFrom" envDefault:"RURI"`
Expand All @@ -125,44 +125,44 @@ docker 安装siphub-go
```


## siphub-ui
## sipgrep-ui

docker运行siphub-ui
docker运行sipgrep-ui

- dbHost="localhost" 数据库地址
- dbUser="root" 数据库用户
- dbPwd="some-password" 数据库密码
- dbName="siphub" 数据库名
- dbName="sipgrep" 数据库名
- logLevel="info" 日志级别
- dataKeepDays="2" 数据保存多少天

```bash
docker run -d \
--name siphub-ui \
--name sipgrep-ui \
-p 8080:8080 \
-e NODE_ENV="production" \
-e dbHost="localhost" \
-e dbUser="root" \
-e dbPwd="some-password" \
-e dbName="siphub" \
-e dbName="sipgrep" \
-e logLevel="info" \
-e dataKeepDays="2" \
wangduanduan/siphub-ui:22.03.03
wangduanduan/sipgrep-ui:22.03.03
```

- 8080/HTTP 端口 提供Web查询和展示界面

# 集成

## OpenSIPS集成
## OpenSIPS 2X集成
test witch OpenSIPS 2.4

```bash
# add hep listen
listen=hep_udp:your_ip:9061

loadmodule "proto_hep.so"
# replace SIP_HUB_IP_PORT with siphub‘s ip:port
# replace SIP_HUB_IP_PORT with sipgrep‘s ip:port
modparam("proto_hep", "hep_id","[hep_dst] SIP_HUB_IP_PORT;transport=udp;version=3")
loadmodule "siptrace.so"
modparam("siptrace", "trace_id","[tid]uri=hep:hep_dst")
Expand All @@ -173,16 +173,37 @@ if(!is_method("REGISTER") && !has_totag()){
}
```

## OpenSIPS 3.x

```
socket=hep_udp:127.0.0.1:9060
loadmodule "proto_hep.so"
modparam("proto_hep", "hep_id","[hid] SIPGREP_IP:SIPGREP_PORT;transport=udp;version=3")
loadmodule "tracer.so"
modparam("tracer", "trace_id","[tid]uri=hep:hid")
route {
...
if (has_totag()) {
route(r_seq_request);
} else {
trace("tid", "d", "sip");
}
...
}
```

## FreeSWITCH集成

fs version 版本要高于 1.6.8+

编辑: sofia.conf.xml

用真实的siphub ip:port替换SIP_HUB_IP_PORT
用真实的sipgrep ip:port替换SIPGREP_IP:SIPGREP_PORT

```
<param name="capture-server" value="udp:SIP_HUB_IP_PORT;hep=3;capture_id=100"/>
<param name="capture-server" value="udp:SIPGREP_IP:SIPGREP_PORT;hep=3;capture_id=100"/>
```

```shell
Expand Down Expand Up @@ -213,7 +234,7 @@ heplify是一个go语言开发的,基于网卡抓包的方式,捕获sip消

- -i 指定网卡。需要更具机器真实网卡进行修改
- -m SIP 指定抓SIP消息
- -hs 指定siphub-go的地址。需要根据siphub-go的真实地址进行修改
- -hs 指定sipgrep-go的地址。需要根据sipgrep-go的真实地址进行修改
- -p 指定生成日志文件的位置
- -dim 排除某些类型的SIP包,例如排除OPTIONS和REGISTER注册的包
- -pr 指定抓包的端口范围。
Expand All @@ -232,16 +253,16 @@ nohup ./heplify -i eno1 \
## 数据保留策略

- 所有新的数据,会插入到records表。
- 每天凌晨 00:01:00, records表会被重命名为siphub_old_day_YYYYMMDD, 然后会新建一个records表
- 基于siphub-ui的dataKeepDays环境变量,超过最大保留天数的表,会被删除历史的表
- 每天凌晨 00:01:00, records表会被重命名为sipgrep_old_day_YYYYMMDD, 然后会新建一个records表
- 基于sipgrep-ui的dataKeepDays环境变量,超过最大保留天数的表,会被删除历史的表

# siphub-go内存问题 与 mysql写入速度
# sipgrep-go内存问题 与 mysql写入速度

在生产环境,有观察到siphub-go的内存一直上涨,最终定位到原因是数据插入的比较慢。
在生产环境,有观察到sipgrep-go的内存一直上涨,最终定位到原因是数据插入的比较慢。

一般来说,siphub-go收到的每秒消息量,估计是每秒呼叫量的10-20倍。 也就是说,假如每秒呼叫量,即CPS是100,那么每秒siphub-go收到的消息量估计在1000-2000条sip消息。
一般来说,sipgrep-go收到的每秒消息量,估计是每秒呼叫量的10-20倍。 也就是说,假如每秒呼叫量,即CPS是100,那么每秒sipgrep-go收到的消息量估计在1000-2000条sip消息。

siphub-go不是每收到一条消息,就做一次数据库插入。而是累积到MaxBatchItems的数量之后,再执行插入。如果把MaxBatchItems设置为1000,那么两千条消息实际上只需要做两次插入。
sipgrep-go不是每收到一条消息,就做一次数据库插入。而是累积到MaxBatchItems的数量之后,再执行插入。如果把MaxBatchItems设置为1000,那么两千条消息实际上只需要做两次插入。

所以,你的呼叫量越大。就需要设置较大的MaxBatchItems。

Expand All @@ -256,4 +277,4 @@ mysql 数据库配置要求

# 关于处理能力

我们观察在生产环境,siphub每天的表的数据量+索引所占用的空间大概是80G左右,具体视呼叫量而定。
我们观察在生产环境,sipgrep每天的表的数据量+索引所占用的空间大概是80G左右,具体视呼叫量而定。
19 changes: 19 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// cSpell Settings
{
// Version of the setting file. Always 0.2
"version": "0.2",
// language - current active spelling language
"language": "en",
// words - list of words to be always considered correct
"words": [
"antd",
"Opensips",
"Infof",
],
// flagWords - list of words to be always considered incorrect
// This is useful for offensive words and common spelling errors.
// For example "hte" should be "the"
"flagWords": [
"hte"
]
}
8 changes: 8 additions & 0 deletions error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
2023-10-31T11:00:27.938+0800 INFO msg/msg.go:32 200 8011cmbc.poc->8011cmbc.poc
panic: runtime error: index out of range [0] with length 0

goroutine 8 [running]:
sipgrep/pkg/mysql.BatchSaveInit()
/Users/wangduanduan/github/siphub/pkg/mysql/record.go:65 +0x298
created by main.main in goroutine 1
/Users/wangduanduan/github/siphub/main.go:22 +0x7c
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module siphub
module sipgrep

go 1.16

require (
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/caarlos0/env/v6 v6.10.1
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/validator/v10 v10.15.5 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/gofiber/fiber/v2 v2.50.0
github.com/golang-module/carbon/v2 v2.2.11 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/prometheus/client_golang v1.17.0
Expand Down
Loading

0 comments on commit 06ba4fe

Please sign in to comment.