| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package containers
- import (
- "context"
- . "github.com/coroot/coroot-node-agent/utils/modelse"
- "os"
- "time"
- "github.com/jpillora/backoff"
- "github.com/cilium/ebpf/link"
- "github.com/coroot/coroot-node-agent/proc"
- "github.com/mdlayher/taskstats"
- )
- type Process struct {
- Pid uint32
- StartedAt time.Time
- NetNsId string
- ctx context.Context
- cancelFunc context.CancelFunc
- dotNetMonitor *DotNetMonitor
- uprobes []link.Link
- goTlsUprobesChecked bool
- openSslUprobesChecked bool
- jvmUprobesChecked bool
- stackUprobesChecked bool
- codeType CodeType
- cmdline string
- }
- func NewProcess(pid uint32, stats *taskstats.Stats) *Process {
- ns, err := proc.GetNetNs(pid)
- if err != nil {
- return nil
- }
- defer ns.Close()
- p := &Process{Pid: pid, StartedAt: stats.BeginTime, NetNsId: ns.UniqueId()}
- p.ctx, p.cancelFunc = context.WithCancel(context.Background())
- go p.instrument()
- return p
- }
- func (p *Process) isHostNs() bool {
- return p.NetNsId == hostNetNsId
- }
- func (p *Process) instrument() {
- b := backoff.Backoff{Factor: 2, Min: time.Second, Max: time.Minute}
- for {
- select {
- case <-p.ctx.Done():
- return
- default:
- dest, err := os.Readlink(proc.Path(p.Pid, "exe"))
- if err != nil {
- return
- }
- if dest != "/" {
- if dotNetAppName, err := dotNetApp(p.Pid); err == nil {
- if dotNetAppName != "" {
- p.dotNetMonitor = NewDotNetMonitor(p.ctx, p.Pid, dotNetAppName)
- }
- return
- }
- }
- time.Sleep(b.Duration())
- }
- }
- }
- func (p *Process) Close() {
- p.cancelFunc()
- for _, u := range p.uprobes {
- _ = u.Close()
- }
- }
- func (p *Process) DynamicClose() {
- for _, u := range p.uprobes {
- _ = u.Close()
- }
- p.goTlsUprobesChecked = false
- p.openSslUprobesChecked = false
- p.jvmUprobesChecked = false
- p.stackUprobesChecked = false
- p.uprobes = []link.Link{}
- }
- func (p *Process) GetCmdline() string {
- return p.cmdline
- }
|