只收集指定的网卡数据,用于过滤机器上的虚拟网卡,支持正则

This commit is contained in:
shuhai
2022-01-31 13:29:47 +08:00
parent 870d7565d1
commit f6767725c9
2 changed files with 15 additions and 2 deletions

View File

@@ -9,8 +9,17 @@
```toml
[Summary]
SampleRate = 1
NetAdapter = '@en\d+@'
```
```toml
[Summary]
SampleRate = 1
NetAdapter = "eth"
```
- SampleRate 采样率,单位秒,即每一秒采样一次
- NetAdapter 只收集指定的网卡数据,用于过滤机器上的虚拟网卡,支持正则
## 数据结构

View File

@@ -158,6 +158,10 @@ func (s *ServerSummary) collect() {
s.HardDisk.Usage = d.UsedPercent
s.NetWork = make([]NetWorkInfo, len(nv))
for i, n := range nv {
if !isNetAdapter(n.Name) {
continue
}
s.NetWork[i].Name = n.Name
s.NetWork[i].Receive = n.BytesRecv
s.NetWork[i].Sent = n.BytesSent
@@ -178,9 +182,9 @@ func isNetAdapter(name string) bool {
}
//正则用@作正则修饰符
if !strings.Contains(name, "@") {
if !strings.Contains(config.NetAdapter, "@") {
return strings.Contains(name, config.NetAdapter)
}
return gregex.IsMatchString(config.NetAdapter, name)
return gregex.IsMatchString(strings.Trim(config.NetAdapter, "@"), name)
}