-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liangqi1
committed
Jul 11, 2022
1 parent
95f5652
commit a94419d
Showing
38 changed files
with
1,142 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# pmon2 开发 | ||
|
||
## 环境构建 | ||
|
||
```shell | ||
# 运行init_dev.sh 初始化开发配置文件 | ||
sh init_dev.sh | ||
``` | ||
`init_dev.sh` 会负责生成项目的开发配置文件,以及相关目录、环境变量等。 | ||
|
||
## 测试开发 | ||
|
||
```shell | ||
sudo PMON2_CONF=config/config-dev.yml ./bin/pmond | ||
sudo PMON2_CONF=config/config-dev.yml ./bin/pmon2 exec bin/test | ||
``` | ||
|
||
因为 `pmon2` 启动进程使用的是fork/exec,所以需要sudo或root级别权限。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
package conf | ||
|
||
import "os" | ||
|
||
// current app version | ||
const Version = "1.9.0" | ||
var Version = "1.10.0" | ||
|
||
func GetDefaultConf() string{ | ||
conf := os.Getenv("PMON2_CONF") | ||
if len(conf) == 0 { | ||
conf = "/etc/pmon2/config/config.yml" | ||
} | ||
return conf | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,15 @@ | ||
package conf | ||
|
||
import ( | ||
"os" | ||
"path" | ||
) | ||
|
||
type Tpl struct { | ||
AppDir string | ||
Data string `yaml:"data"` | ||
Logs string `yaml:"logs"` | ||
Sock string `yaml:"sock"` | ||
Bin string `yaml:"bin"` | ||
Conf string | ||
} | ||
|
||
func (c *Tpl) GetSockFile() string { | ||
if len(c.Sock) <= 0 { | ||
panic("run sock file is empty") | ||
} | ||
|
||
sockDir := path.Dir(c.Sock) | ||
_, err := os.Stat(sockDir) | ||
if os.IsNotExist(err) { | ||
err = os.MkdirAll(sockDir, 0755) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
// if sock file exist, try to clear | ||
_, err = os.Stat(c.Sock) | ||
if !os.IsNotExist(err) { | ||
err = os.Remove(c.Sock) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
return c.Sock | ||
Data string `yaml:"data"` | ||
Logs string `yaml:"logs"` | ||
Conf string | ||
} | ||
|
||
func (c *Tpl) GetDataDir() string { | ||
if path.IsAbs(c.Data) { | ||
return c.Data | ||
} | ||
|
||
return c.AppDir + "/" + c.Data | ||
return c.Data | ||
} | ||
|
||
func (c *Tpl) GetLogsDir() string { | ||
if path.IsAbs(c.Logs) { | ||
return c.Logs | ||
} | ||
|
||
return c.AppDir + "/" + c.Logs | ||
return c.Logs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package proc | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
|
||
"github.com/mdlayher/netlink/nlenc" | ||
"golang.org/x/net/bpf" | ||
) | ||
|
||
func loadBPF(filters []EventType) ([]bpf.RawInstruction, error) { | ||
|
||
fmt.Printf("Filter List: %#v\n", filters) | ||
var totals uint32 | ||
for _, toFilter := range filters { | ||
totals = totals | uint32(toFilter) | ||
} | ||
|
||
inst, err := bpf.Assemble([]bpf.Instruction{ | ||
bpf.LoadAbsolute{Off: (16 + 20), Size: 4}, | ||
bpf.JumpIf{Cond: bpf.JumpBitsNotSet, Val: swap(totals), SkipTrue: 1}, | ||
bpf.RetConstant{Val: 4096}, | ||
bpf.RetConstant{Val: 0}, | ||
}) | ||
|
||
return inst, err | ||
} | ||
|
||
//if needed, change the endian-ness before we file the bitmask off to bpf | ||
func swap(val uint32) uint32 { | ||
|
||
if nlenc.NativeEndian() == binary.LittleEndian { | ||
return (val << 24) | | ||
((val << 8) & 0x00ff0000) | | ||
((val >> 8) & 0x0000ff00) | | ||
((val >> 24) & 0x000000ff) | ||
} | ||
|
||
return val | ||
|
||
} |
Oops, something went wrong.