|
@@ -3,6 +3,7 @@ package containers
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "github.com/coroot/coroot-node-agent/kube"
|
|
|
. "github.com/coroot/coroot-node-agent/utils"
|
|
. "github.com/coroot/coroot-node-agent/utils"
|
|
|
"github.com/coroot/coroot-node-agent/utils/enums"
|
|
"github.com/coroot/coroot-node-agent/utils/enums"
|
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
@@ -199,7 +200,7 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
|
|
|
runtimeApps := make(map[uint32]AppStatusInfo)
|
|
runtimeApps := make(map[uint32]AppStatusInfo)
|
|
|
for pid, c := range r.containersByPid {
|
|
for pid, c := range r.containersByPid {
|
|
|
if c != nil {
|
|
if c != nil {
|
|
|
- if !common.IsOpenFilter() {
|
|
|
|
|
|
|
+ if c != nil && !common.IsOpenFilter() {
|
|
|
verifyAttachConditions := c.verifyAttachConditions(r, pid)
|
|
verifyAttachConditions := c.verifyAttachConditions(r, pid)
|
|
|
if verifyAttachConditions {
|
|
if verifyAttachConditions {
|
|
|
err = c.RegisterAppInfo(r, pid)
|
|
err = c.RegisterAppInfo(r, pid)
|
|
@@ -284,6 +285,7 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
|
|
|
}
|
|
}
|
|
|
if ok := prometheus.WrapRegistererWith(setLabels(string(id),
|
|
if ok := prometheus.WrapRegistererWith(setLabels(string(id),
|
|
|
c.K8sContainer.ns,
|
|
c.K8sContainer.ns,
|
|
|
|
|
+ c.K8sContainer.workload,
|
|
|
c.K8sContainer.podName,
|
|
c.K8sContainer.podName,
|
|
|
c.K8sContainer.containerName,
|
|
c.K8sContainer.containerName,
|
|
|
c.K8sContainer.pid), r.reg).Unregister(c); !ok {
|
|
c.K8sContainer.pid), r.reg).Unregister(c); !ok {
|
|
@@ -408,10 +410,12 @@ func (r *Registry) handleEvents(ch <-chan ebpftracer.Event) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
case ebpftracer.EventTypeL7Request:
|
|
case ebpftracer.EventTypeL7Request:
|
|
|
|
|
+
|
|
|
//fmt.Println("e.L7Request Payload:", string(e.L7Request.Payload))
|
|
//fmt.Println("e.L7Request Payload:", string(e.L7Request.Payload))
|
|
|
if e.L7Request == nil {
|
|
if e.L7Request == nil {
|
|
|
continue
|
|
continue
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
if c := r.containersByPid[e.Pid]; c != nil {
|
|
if c := r.containersByPid[e.Pid]; c != nil {
|
|
|
//fmt.Println("EventTypeL7Request", e.Pid, c.checkL7AttachReady())
|
|
//fmt.Println("EventTypeL7Request", e.Pid, c.checkL7AttachReady())
|
|
|
//a, _ := json.Marshal(e.L7Request)
|
|
//a, _ := json.Marshal(e.L7Request)
|
|
@@ -522,6 +526,7 @@ func (r *Registry) getOrCreateContainer(pid uint32) *Container {
|
|
|
setK8sTag(c, extensionTag, pid)
|
|
setK8sTag(c, extensionTag, pid)
|
|
|
if err := prometheus.WrapRegistererWith(setLabels(string(id),
|
|
if err := prometheus.WrapRegistererWith(setLabels(string(id),
|
|
|
extensionTag[Namespace],
|
|
extensionTag[Namespace],
|
|
|
|
|
+ extensionTag[Workload],
|
|
|
extensionTag[PodName],
|
|
extensionTag[PodName],
|
|
|
extensionTag[ProcessName],
|
|
extensionTag[ProcessName],
|
|
|
fmt.Sprintf("%d", pid)), r.reg).Register(c); err != nil {
|
|
fmt.Sprintf("%d", pid)), r.reg).Register(c); err != nil {
|
|
@@ -537,7 +542,8 @@ func (r *Registry) getOrCreateContainer(pid uint32) *Container {
|
|
|
func calcId(cg *cgroup.Cgroup, md *ContainerMetadata, pid uint32) (ContainerID, map[string]string) {
|
|
func calcId(cg *cgroup.Cgroup, md *ContainerMetadata, pid uint32) (ContainerID, map[string]string) {
|
|
|
// 卡一下防止概率性获取为bash
|
|
// 卡一下防止概率性获取为bash
|
|
|
time.Sleep(1 * time.Millisecond)
|
|
time.Sleep(1 * time.Millisecond)
|
|
|
- extensionTag := map[string]string{Namespace: "", Workload: "", PodName: "", ProcessName: ""}
|
|
|
|
|
|
|
+ procName := proc.GetProcName(pid)
|
|
|
|
|
+ extensionTag := map[string]string{Namespace: "", Workload: "", PodName: "", ProcessName: procName}
|
|
|
if cg.ContainerType == cgroup.ContainerTypeSystemdService {
|
|
if cg.ContainerType == cgroup.ContainerTypeSystemdService {
|
|
|
if strings.HasPrefix(cg.ContainerId, "/system.slice/crio-conmon-") {
|
|
if strings.HasPrefix(cg.ContainerId, "/system.slice/crio-conmon-") {
|
|
|
return "", extensionTag
|
|
return "", extensionTag
|
|
@@ -545,8 +551,7 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata, pid uint32) (ContainerID,
|
|
|
return ContainerID(cg.ContainerId), extensionTag
|
|
return ContainerID(cg.ContainerId), extensionTag
|
|
|
}
|
|
}
|
|
|
if cg.ContainerType == cgroup.ContainerTypeStandaloneProcess {
|
|
if cg.ContainerType == cgroup.ContainerTypeStandaloneProcess {
|
|
|
- procName := proc.GetProcName(pid)
|
|
|
|
|
- extensionTag[ProcessName] = procName
|
|
|
|
|
|
|
+ //extensionTag[ProcessName] = procName
|
|
|
return ContainerID(fmt.Sprintf("/%s/%s/%d", "standalone", procName, pid)), extensionTag
|
|
return ContainerID(fmt.Sprintf("/%s/%s/%d", "standalone", procName, pid)), extensionTag
|
|
|
}
|
|
}
|
|
|
switch cg.ContainerType {
|
|
switch cg.ContainerType {
|
|
@@ -568,9 +573,11 @@ func calcId(cg *cgroup.Cgroup, md *ContainerMetadata, pid uint32) (ContainerID,
|
|
|
return "", extensionTag
|
|
return "", extensionTag
|
|
|
}
|
|
}
|
|
|
extensionTag[Namespace] = namespace
|
|
extensionTag[Namespace] = namespace
|
|
|
- extensionTag[Workload] = ""
|
|
|
|
|
|
|
+ if *flags.RunInContainer {
|
|
|
|
|
+ extensionTag[Workload], _ = kube.GetWorkload(namespace, pod)
|
|
|
|
|
+ }
|
|
|
extensionTag[PodName] = pod
|
|
extensionTag[PodName] = pod
|
|
|
- extensionTag[ProcessName] = name
|
|
|
|
|
|
|
+ //extensionTag[ProcessName] = name
|
|
|
return ContainerID(fmt.Sprintf("/k8s/%s/%s/%s", namespace, pod, name)), extensionTag
|
|
return ContainerID(fmt.Sprintf("/k8s/%s/%s/%s", namespace, pod, name)), extensionTag
|
|
|
}
|
|
}
|
|
|
if taskNameParts := strings.SplitN(md.labels["com.docker.swarm.task.name"], ".", 3); len(taskNameParts) == 3 {
|
|
if taskNameParts := strings.SplitN(md.labels["com.docker.swarm.task.name"], ".", 3); len(taskNameParts) == 3 {
|