diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..b639f68ef81e47f5d1ca0c3e13497b3d586b058e
Binary files /dev/null and b/.DS_Store differ
diff --git a/.gitignore b/.gitignore
index cab19059ca54dc1e96fa511dc0e71aecdb6998a5..40a844cf97c51e9911797ce9870e063f2b71d5ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,7 @@
*.o.cmd
*.ko
*.ko.cmd
-
+*.idea
Module.symvers
modules.builtin
modules.order
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000000000000000000000000000000000000..53624c9e1f9ab0331fd10b32c26747519ace5794
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..35eb1ddfbbc029bcab630581847471d7f238ec53
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/source/.DS_Store b/source/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..fe62bc3d37d7e43ee3c765a76137456f136a5618
Binary files /dev/null and b/source/.DS_Store differ
diff --git a/source/lib/internal/ebpf/coolbpf b/source/lib/internal/ebpf/coolbpf
index ae774b805b2185fcbfafb71457ad1e37065466ff..d0fabf821d2d8eb9d27da8eefd4797dc181cc92b 160000
--- a/source/lib/internal/ebpf/coolbpf
+++ b/source/lib/internal/ebpf/coolbpf
@@ -1 +1 @@
-Subproject commit ae774b805b2185fcbfafb71457ad1e37065466ff
+Subproject commit d0fabf821d2d8eb9d27da8eefd4797dc181cc92b
diff --git a/source/tools/.DS_Store b/source/tools/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..12272494a9145ab77e6821d51a35aa9e656937e1
Binary files /dev/null and b/source/tools/.DS_Store differ
diff --git a/source/tools/monitor/.DS_Store b/source/tools/monitor/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..54403a1caa441bc5047ab36847f73aef327fef34
Binary files /dev/null and b/source/tools/monitor/.DS_Store differ
diff --git a/source/tools/monitor/unity/beaver/guide/metrics.md b/source/tools/monitor/unity/beaver/guide/metrics.md
index 2a84de2e195bf81422273d17b47285bf76f9ab9e..f8984bef0f903ce571b8713c024d1c702caf63d6 100644
--- a/source/tools/monitor/unity/beaver/guide/metrics.md
+++ b/source/tools/monitor/unity/beaver/guide/metrics.md
@@ -6,28 +6,128 @@
-------------
-### uptime 表
+### cpu\_total 表
+
+* 对应export 指标 sysak\_proc\_cpu\_total
+* 属性标签: mode
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | ---: | :---- | :---- | :--- |
-| uptime | 秒 | 从系统启动到现在的时间 | | collector/proc\_uptime.lua |
-| idletime | 秒 | 系统总空闲的时间 | | collector/proc\_uptime.lua |
-| stamp | 秒 | 系统时间戳 | unix 时间 | collector/proc\_uptime.lua |
+| softirq | % | 软中断百分比 | | collector/proc\_stat.lua |
+| user | % | 用户态占用率百分比 | | collector/proc\_stat.lua |
+| guestnice | % | guestnice百分比 | | collector/proc\_stat.lua |
+| guest | % |guest百分比 | | collector/proc\_stat.lua |
+| steal | % |steal百分比 | | collector/proc\_stat.lua |
+| hardirq | % | 硬中断百分比 | | collector/proc\_stat.lua |
+| nice | % | nice百分比 | | collector/proc\_stat.lua |
+| idle | % | idle百分比 | | collector/proc\_stat.lua |
+| sys | % | sys百分比 | | collector/proc\_stat.lua |
+| iowait | % | iowait百分比 | | collector/proc\_stat.lua |
+
+### cpus 表
+
+* 对应export 指标 sysak\_proc\_cpus
+* 属性标签: mode
-### uname 表
-每小时获取一次
+| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
+| :--- | ---: | :---- | :---- | :--- |
+| cpu_name | | CPU 名称 | | collector/proc\_stat.lua |
+| softirq | % | 软中断百分比 | | collector/proc\_stat.lua |
+| user | % | 用户态占用率百分比 | | collector/proc\_stat.lua |
+| guestnice | % | guestnice百分比 | | collector/proc\_stat.lua |
+| guest | % |guest百分比 | | collector/proc\_stat.lua |
+| steal | % |steal百分比 | | collector/proc\_stat.lua |
+| hardirq | % | 硬中断百分比 | | collector/proc\_stat.lua |
+| nice | % | nice百分比 | | collector/proc\_stat.lua |
+| idle | % | idle百分比 | | collector/proc\_stat.lua |
+| sys | % | sys百分比 | | collector/proc\_stat.lua |
+| iowait | % | iowait百分比 | | collector/proc\_stat.lua |
+
+
+### cpus 表
+
+* 对应export 指标 sysak\_proc\_cpus
+* 属性标签: mode
+
+
+| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
+| :--- | ---: | :---- | :---- | :--- |
+| cpu_name | | CPU 名称 | | collector/proc\_stat.lua |
+| softirq | % | 软中断百分比 | | collector/proc\_stat.lua |
+| user | % | 用户态占用率百分比 | | collector/proc\_stat.lua |
+| guestnice | % | guestnice百分比 | | collector/proc\_stat.lua |
+| guest | % |guest百分比 | | collector/proc\_stat.lua |
+| steal | % |steal百分比 | | collector/proc\_stat.lua |
+| hardirq | % | 硬中断百分比 | | collector/proc\_stat.lua |
+| nice | % | nice百分比 | | collector/proc\_stat.lua |
+| idle | % | idle百分比 | | collector/proc\_stat.lua |
+| sys | % | sys百分比 | | collector/proc\_stat.lua |
+| iowait | % | iowait百分比 | | collector/proc\_stat.lua |
+
+
+### stat\_counters表
+
+* 对应export 指标 sysak\_proc\_stat\_counters
+* 属性标签: counter
+
+| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
+| :--- | ---: | :---- | :---- | :--- |
+| procs_blocked | | D状态任务数量 | | collector/proc\_stat.lua |
+| processes_forks | | fork 任务数量 | | collector/proc\_stat.lua |
+| btime | | 启动时间 | | collector/proc\_stat.lua |
+| procs_running | | 并行任务数量 | | collector/proc\_stat.lua |
+| ctxt | | 上下文切换次数 | | collector/proc\_stat.lua |
+
+
+### proc\_loadavg 表
+
+* 对应 export 指标: sysak\_proc\_loadavg
+* 属性标签:value
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
|:---------| ---: | :---- | :---- | :--- |
-| nodename | - | uname -r | | collector/proc\_uptime.lua |
-| version | - | uname -r | | collector/proc\_uptime.lua |
-| release | - | uname -r | | collector/proc\_uptime.lua |
-| machine | - | uname -r | | collector/proc\_uptime.lua |
-| sysname | - | uname -r | | collector/proc\_uptime.lua |
+| runq | - | rq队列长度 | | collector/proc\_load.lua |
+| load1 | - | load1 | | collector/proc\_load.lua |
+| load5 | - | load5 | | collector/proc\_load.lua |
+| load10 | - | load10 | | collector/proc\_load.lua |
+| plit | - | plit | | collector/proc\_load.lua |
+
+
+### proc\_loadavg 表
+
+* 对应 export 指标: sysak\_proc\_loadavg
+* 属性标签:value
+
+| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
+|:---------| ---: | :---- | :---- | :--- |
+| runq | - | rq队列长度 | | collector/proc\_load.lua |
+| load1 | - | load1 | | collector/proc\_load.lua |
+| load5 | - | load5 | | collector/proc\_load.lua |
+| load10 | - | load10 | | collector/proc\_load.lua |
+| plit | - | plit | | collector/proc\_load.lua |
+
+
+### meminfo 表
+
+* 对应 export 指标: sysak\_proc\_meminfo
+* 属性标签:value
+
+指标说明参考[/proc/meminfo内存文件详解](https://zhuanlan.zhihu.com/p/145524701)
+
+### vmstat 表
+
+* 对应 export 指标: sysak\_proc\_vmstate
+* 属性标签:value
+
+指标说明参考[/proc/vmstat输出含义](https://blog.csdn.net/kaka__55/article/details/125236633)
### cgroups 表
+* 对应 export 指标: sysak\_cgroups
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| type | - | subsys类型 | | collector/proc\_cgroups.lua |
@@ -46,6 +146,9 @@
### interrupts 表
+* 对应 export 指标: sysak\_interrupts
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| cpu | - | CPU ID | | collector/proc\_interrupts.lua |
@@ -53,6 +156,9 @@
### mounts 表
+* 对应 export 指标: sysak\_fs\_stat
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| fs | - | sysfs | | collector/proc\_mounts.lua |
@@ -67,6 +173,9 @@
### softirqs 表
+* 对应 export 指标: sysak\_softirqs
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| cpu | - | CPU ID | | collector/proc\_softirqs.lua |
@@ -82,7 +191,10 @@
| RCU | 次 | RCU软中断触发次数 | | collector/proc\_softirqs.lua |
### self_statm 表
-统计监控进程的statm信息
+
+* 统计监控进程的statm信息
+* 对应 export 指标: sysak\_self\_statm
+* 属性标签:value
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
@@ -100,13 +212,18 @@
### arp
+* 对应 export 指标: sysak\_arp
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | ---: | :---- | :---- | :--- |
| count | 个 | 网卡名 | 网卡上对应arp表数量 | collector/proc\_arp.lua |
### networks
-这是网卡流量统计信息,已做差值处理
+* 这是网卡流量统计信息,已做差值处理
+* 对应 export 指标: sysak\_proc\_networks
+* 属性标签:value
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | ---: | :---- | :---- | :--- |
@@ -129,7 +246,9 @@
### pkt_status
-这里统计所有包状态,详细可以通过 pkt_logs 获取
+* 对应 export 指标: sysak\_proc\_pkt\_status
+* 属性标签:counter
+* 这里统计所有包状态,详细可以通过 pkt\_logs 获取
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | ---: | :---- | :---- | :--- |
@@ -143,6 +262,9 @@
### sock_stat
+* 对应 export 指标: sysak\_sock\_stat
+* 属性标签:value
+
统计所有包状态。[参考连接](https://developer.aliyun.com/article/484451)
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
@@ -163,7 +285,8 @@
### softnets
-This parser parses the stats from network devices. These stats includes events per cpu\(in row\), number of packets processed i.e packet_process \(first column\), number of packet drops packet\_drops \(second column\), time squeeze eg net\_rx\_action performed time_squeeze\(third column\), cpu collision eg collision occur while obtaining device lock while transmitting cpu\_collision packets \(eighth column\), received_rps number of times cpu woken up received\_rps \(ninth column\), number of times reached flow limit count flow\_limit\_count \(tenth column\), backlog status \(eleventh column\), core id \(twelfth column\).
+* 对应 export 指标: sysak\_softnets
+* 属性标签:value
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | ---: | :---- | :---- | :--- |
@@ -176,6 +299,9 @@ This parser parses the stats from network devices. These stats includes events p
### cgroups 表
+* 对应 export 指标: sysak\_cgroups
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| type | - | subsys类型 | | collector/proc\_cgroups.lua |
@@ -192,56 +318,6 @@ This parser parses the stats from network devices. These stats includes events p
| perf\_event | 个 | perf_event cgroup数量 | | collector/proc\_cgroups.lua |
| memory | 个 | memory cgroup数量 | | collector/proc\_cgroups.lua |
-### interrupts 表
-
-| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
-| :--- | --- | :---- | :---- | :--- |
-| cpu | - | CPU ID | | collector/proc\_interrupts.lua |
-| 中断名称 | 次 | 中断触发次数 | | collector/proc\_interrupts.lua |
-
-### mounts 表
-
-| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
-| :--- | --- | :---- | :---- | :--- |
-| fs | - | sysfs | | collector/proc\_mounts.lua |
-| mount | - | 挂载目录 | | collector/proc\_mounts.lua |
-| f\_bsize | - | Filesystem block size | | collector/proc\_mounts.lua |
-| f\_blocks | - | Size of fs in f_frsize units | | collector/proc\_mounts.lua |
-| f\_bfree | - | Number of free blocks | | collector/proc\_mounts.lua |
-| f\_bavail | - | Number of free blocks for unprivileged users | | collector/proc\_mounts.lua |
-| f\_files | - | Number of inodes | | collector/proc\_mounts.lua |
-| f\_ffree | - | Number of free inodes | | collector/proc\_mounts.lua |
-| f\_favail | - | Number of free inodes for unprivileged users | | collector/proc\_mounts.lua |
-
-### softirqs 表
-
-| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
-| :--- | --- | :---- | :---- | :--- |
-| cpu | - | CPU ID | | collector/proc\_softirqs.lua |
-| HI | 次 | HI软中断触发次数 | | collector/proc\_softirqs.lua |
-| TIMER | 次 | TIMER软中断触发次数 | | collector/proc\_softirqs.lua |
-| NET\_TX | 次 | NET\_TX软中断触发次数 | | collector/proc\_softirqs.lua |
-| NET\_RX | 次 | NET\_RX软中断触发次数 | | collector/proc\_softirqs.lua |
-| BLOCK | 次 | BLOCK软中断触发次数 | | collector/proc\_softirqs.lua |
-| IRQ_POLL | 次 | IRQ\_POLL软中断触发次数 | | collector/proc\_softirqs.lua |
-| TASKLET | 次 | TASKLET软中断触发次数 | | collector/proc\_softirqs.lua |
-| SCHED | 次 | SCHED软中断触发次数 | | collector/proc\_softirqs.lua |
-| HRTIMER | 次 | HRTIMER软中断触发次数 | | collector/proc\_softirqs.lua |
-| RCU | 次 | RCU软中断触发次数 | | collector/proc\_softirqs.lua |
-
-### self_statm 表
-统计监控进程的statm信息
-
-| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
-| :--- | --- | :---- | :---- | :--- |
-| size | - | total program size | | collector/proc\_statm.lua |
-| resident | - | resident set size | | collector/proc\_statm.lua |
-| shared | - | number of resident shared pages | | collector/proc\_statm.lua |
-| text | - | text (code) | | collector/proc\_statm.lua |
-| lib | - | library | | collector/proc\_statm.lua |
-| data | - | data + stack | | collector/proc\_statm.lua |
-| dt | - | dirty pages | | collector/proc\_statm.lua |
-
## IO指标
@@ -275,12 +351,20 @@ This parser parses the stats from network devices. These stats includes events p
-----------
### cg_cpu_stat 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| nr_throttled | - | total throttled number | | collector/container/cg\_cpu\_stat.lua |
| throttled_time | ms | total throttled time | | collector/container/cg\_cpu\_stat.lua |
### cg_proc_stat 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| user | % | usr cpu util | | collector/container/cg\_cpuacct\_proc\_stat.lua |
@@ -302,11 +386,19 @@ This parser parses the stats from network devices. These stats includes events p
| nr_uninterruptible | - | number of deep sleep tasks | | collector/container/cg\_cpuacct\_proc\_stat.lua |
### cg_memfail_cnt 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| fail_cnt | - | number of mem fail counts | | collector/container/cg\_memory\_fail\_cnt.lua |
### cg_memdrcm_latency 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
This table show the hist of the latency of direct memory reclamation
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
@@ -318,6 +410,10 @@ This table show the hist of the latency of direct memory reclamation
| memDrcm_lat_1000ms | - | times more than 1s | | collector/container/cg\_memory\_drcm\_latency.lua |
### cg_memmcmp_latency 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
This table show the hist of the latency of direct memory compaction
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
@@ -329,6 +425,10 @@ This table show the hist of the latency of direct memory compaction
| memDcmp_lat_1000ms | - | times more than 1s | | collector/container/cg\_memory\_dcmp\_latency.lua |
### pmu_events 表
+
+* 对应 export 指标: sysak\_
+* 属性标签:value
+
| 指标名 | 单位 | 标签说明 | 备注 | 源码路径 |
| :--- | --- | :---- | :---- | :--- |
| cpu_cycles | - | cycles | | collector/plugin/pmu_events/pmu\_events.c |
diff --git a/source/tools/monitor/unity/beaver/guide/outLine.md b/source/tools/monitor/unity/beaver/guide/outLine.md
index 22a77dcd9ed46f9fdd6cebba7f18815a4dd367f4..d1788e81a59a0ddf18f1454bf11aec293fb0b627 100644
--- a/source/tools/monitor/unity/beaver/guide/outLine.md
+++ b/source/tools/monitor/unity/beaver/guide/outLine.md
@@ -1,9 +1,11 @@
# 外部数据写入支持
-unity-mon可以作为一个独立的TSDB 数据库进行使用,支持[行协议](https://jasper-zhang1.gitbooks.io/influxdb/content/Write_protocols/line_protocol.html)写入数据,并按需完成对外数据吐出。
+unity-mon可以作为一个独立的TSDB 数据库进行使用,支持[行协议](https://jasper-zhang1.gitbooks.io/influxdb/content/Write_protocols/line_protocol.html)写入数据,并按需完成对外数据吐出,如exporter等接口。
## 行协议格式支持情况
unity-mon 当前除了不支持时间戳,支持行协议其它所有的数据类型,包含数值和日志。写行数据时,有以下注意事项:
+* 指标写入周期需要与大循环刷新周期保持一致,参考 yaml/config/freq 参数配置;
+
* 不要将同一表名和同一索引,但数值不同的数据放在同一批次写入操作中,会发生时序数据覆盖,如;
```
@@ -18,7 +20,7 @@ talbe_a,index=table_a value1=1,value2=2
talbe_a,index=table_b value1=3,value2=4
```
-不要出现同一张表,但是写入的索引和数值不的情况,如:
+* 不要出现同一张表,但是写入的索引和数值不的情况,如:
```
talbe_a,index=table_a value1=1
@@ -34,7 +36,7 @@ unity-mon 同时支持管道和http post 两种方式进行写入,两者差别
| --- | --- | --- |
| 适用范围 | 内部 | 内部 + 外部 |
| 写入效率 | 高 | 低 |
-| 最大写入数据长度 | 64K | 2M |
+| 最大单次写入数据长度 | 64K | 2M |
使用者可以结合自己的实际情况进行推送
diff --git a/source/tools/monitor/unity/beaver/localBeaver.lua b/source/tools/monitor/unity/beaver/localBeaver.lua
index 22d679e88f44942c0f7071341771cc4ae2d6f4c7..d0c2c5dea9dbafc1eeed5e4c0f23384d562090cc 100644
--- a/source/tools/monitor/unity/beaver/localBeaver.lua
+++ b/source/tools/monitor/unity/beaver/localBeaver.lua
@@ -23,12 +23,17 @@ end
function CLocalBeaver:_init_(frame, fYaml)
local port, ip, backlog, unix_socket = setupServer(fYaml)
+ self:_installFFI()
if not unix_socket then
self._bfd = self:_install_fd(port, ip, backlog)
else
self._bfd = self:_install_fd_unisock(backlog, unix_socket)
end
- self._efd = self:_installFFI()
+ --self._efd = self:_installFFI()
+
+ local efd = self._cffi.init(self._bfd)
+ assert(efd > 0)
+ self._efd = efd
self._cos = {}
self._last = os.time()
@@ -85,18 +90,16 @@ function CLocalBeaver:_installFFI()
self._ffi = ffi.ffi
self._cffi = ffi.cffi
- local efd = self._cffi.init(self._bfd)
- assert(efd > 0)
- return efd
end
-local function localBind(fd, tPort)
+local function localBind(cffi, fd, tPort)
local try = 0
local res, err, errno
-- can reuse for time wait socket.
- res, err, errno = socket.setsockopt(fd, socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);
- if not res then
+ --res, err, errno = socket.setsockopt(fd, socket.SOL_SOCKET, socket.SO_REUSEADDR, 1);
+ res = cffi.setsockopt_AP(fd)
+ if res<0 then
system:posixError("set sock opt failed.");
end
@@ -120,7 +123,7 @@ function CLocalBeaver:_install_fd_unisock(backlog,unix_socket)
fd, err, errno = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
if fd then -- for socket
local tPort = {family=socket.AF_UNIX, path=unix_socket}
- local r, msg = pcall(localBind, fd, tPort)
+ local r, msg = pcall(localBind, self._cffi, fd, tPort)
if r then
res, err, errno = socket.listen(fd, backlog)
if res then -- for listen
@@ -130,7 +133,7 @@ function CLocalBeaver:_install_fd_unisock(backlog,unix_socket)
system:posixError("socket listen failed", err, errno)
end
else
- print(msg)
+ print("call localBind failed, report: " .. msg)
unistd.close(fd)
os.exit(1)
end
@@ -144,7 +147,7 @@ function CLocalBeaver:_install_fd(port, ip, backlog)
fd, err, errno = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
if fd then -- for socket
local tPort = {family=socket.AF_INET, addr=ip, port=port}
- local r, msg = pcall(localBind, fd, tPort)
+ local r, msg = pcall(localBind, self._cffi, fd, tPort)
if r then
res, err, errno = socket.listen(fd, backlog)
if res then -- for listen
@@ -154,7 +157,7 @@ function CLocalBeaver:_install_fd(port, ip, backlog)
system:posixError("socket listen failed", err, errno)
end
else
- print(msg)
+ print("call localBind failed, report: " .. msg)
unistd.close(fd)
os.exit(1)
end
diff --git a/source/tools/monitor/unity/beaver/native/beavercffi.lua b/source/tools/monitor/unity/beaver/native/beavercffi.lua
index a3d00f11323f881ea57719cd822494ba9eb2b92e..9aa9cef9289cba53c4b7cc66be400eca94f88051 100644
--- a/source/tools/monitor/unity/beaver/native/beavercffi.lua
+++ b/source/tools/monitor/unity/beaver/native/beavercffi.lua
@@ -24,6 +24,7 @@ int add_fd(int efd, int fd);
int mod_fd(int efd, int fd, int wr);
int del_fd(int efd, int fd);
int poll_fds(int efd, int tmo, native_events_t* nes);
+int setsockopt_AP(int fd);
void deinit(int efd);
]]
diff --git a/source/tools/monitor/unity/beaver/native/local_beaver.c b/source/tools/monitor/unity/beaver/native/local_beaver.c
index 641e8837fffa6c406c80d432fb63b43c1bc4530a..634907813f204e4027c2d695bfde37047835fc9b 100644
--- a/source/tools/monitor/unity/beaver/native/local_beaver.c
+++ b/source/tools/monitor/unity/beaver/native/local_beaver.c
@@ -4,6 +4,7 @@
#include "local_beaver.h"
#include
+#include
#include
#include
#include
@@ -11,6 +12,16 @@
#include
#include
+int setsockopt_AP(int fd){
+ int opt =1;
+ int r = setsockopt(fd, SOL_SOCKET,SO_REUSEPORT,(char*)&opt,sizeof(int));
+// SO_REUSEPORT
+ if(r<0){
+ perror("set sock opt");
+ }
+ return r;
+}
+
static int socket_non_blocking(int sfd)
{
int flags, res;
diff --git a/source/tools/monitor/unity/beaver/url_api.lua b/source/tools/monitor/unity/beaver/url_api.lua
index e54fa5c3d1b8a03b69e7a6b0237edbae0e4c5f9d..47389f6b62f50270bd5694a1fdf27054caaa33cc 100644
--- a/source/tools/monitor/unity/beaver/url_api.lua
+++ b/source/tools/monitor/unity/beaver/url_api.lua
@@ -45,11 +45,11 @@ local function reqOSS(oss, uuid, stream)
end
function CurlApi:oss(tReq)
- local stat, tJson = pcall(self.getJson, self, tReq)
- if stat and tJson then
- local uuid = tJson.uuid
- local stream = tJson.stream
- if uuid and stream then
+ local uuid = tReq.header['uuid']
+ local cLen = tonumber(tReq.header['content-length'])
+ if uuid and cLen and cLen > 0 then
+ local stream = tReq.data
+ if stream then
local stat, body = pcall(reqOSS, self._oss, uuid, stream)
if stat then
return body
@@ -57,10 +57,10 @@ function CurlApi:oss(tReq)
return "bad req dns " .. body, 400
end
else
- return "need uuid and stream arg.", 400
+ return "need stream arg.", 400
end
else
- return "bad dns " .. tReq.data, 400
+ return "need uuid and content-length > 0." .. tReq.data, 400
end
end
diff --git a/source/tools/monitor/unity/beeQ/clock/ee_clock.c b/source/tools/monitor/unity/beeQ/clock/ee_clock.c
index 3ccebd204062d102d3aef1bb3bb337d505d52d19..37e5df54a59a81f07a41aa33fb71b14ae8b012e6 100644
--- a/source/tools/monitor/unity/beeQ/clock/ee_clock.c
+++ b/source/tools/monitor/unity/beeQ/clock/ee_clock.c
@@ -7,8 +7,10 @@
#include
#include
#include
+#include
#define TIME_SECOND_UNIT 100000UL // 睡眠校准时间,
+#define MICRO_UNIT (1000 * 1000UL)
static ee_clock_t clk_coef = 0;
@@ -20,24 +22,43 @@ static ee_clock_t get_cycles() {
return res;
}
+ee_clock_t get_native_us(void) {
+ ee_clock_t res = 0;
+ struct timeval tv;
+
+ if (gettimeofday(&tv, NULL) == 0) {
+ res = tv.tv_sec * MICRO_UNIT + tv.tv_usec;
+ }
+ return res;
+}
+
// 校准时钟
int calibrate_local_clock(){
ee_clock_t coef1, coef2;
- ee_clock_t t1, t2, t3;
+ ee_clock_t t1, t2;
+ ee_clock_t ts1, ts2;
ee_clock_t delta1, delta2;
+ ee_clock_t dts1, dts2;
ee_clock_t res;
t1 = get_cycles();
+ ts1 = get_native_us();
usleep(TIME_SECOND_UNIT);
t2 = get_cycles();
- usleep(TIME_SECOND_UNIT);
- t3 = get_cycles();
-
+ ts2 = get_native_us();
delta1 = t2 - t1;
- delta2 = t3 - t2;
+ dts1 = ts2 - ts1;
+
+ t1 = get_cycles();
+ ts1 = get_native_us();
+ usleep(TIME_SECOND_UNIT);
+ t2 = get_cycles();
+ ts2 = get_native_us();
+ delta2 = t2 - t1;
+ dts2 = ts2 - ts1;
- coef1 = delta1 / TIME_SECOND_UNIT;
- coef2 = delta2 / TIME_SECOND_UNIT;
+ coef1 = delta1 / dts2;
+ coef2 = delta2 / dts1;
if (coef1 <= 100 || coef2 <= 100) {
fprintf(stderr, "read clock too small.\n");
@@ -47,6 +68,7 @@ int calibrate_local_clock(){
res = 100 * coef1 / coef2;
if (res >= 110 || res <= 90) {
fprintf(stderr, "calibrate local clock failed.\n");
+ fprintf(stderr, "delta1: %ld, delta2: %ld, dts1: %ld, dts2: %ld.\n", delta1, delta2, dts1, dts2);
return -EIO;
}
diff --git a/source/tools/monitor/unity/beeQ/foxRecv.lua b/source/tools/monitor/unity/beeQ/foxRecv.lua
index 1e3c2dd62b45d75c7d5cfca275483187259279d7..fb3323dc01f12afbe3c493217b36fac819bdea05 100644
--- a/source/tools/monitor/unity/beeQ/foxRecv.lua
+++ b/source/tools/monitor/unity/beeQ/foxRecv.lua
@@ -24,6 +24,9 @@ local function setupCo(fYaml)
fcntl.fcntl(fdIn, 1031, 1024 * 1024)
fcntl.fcntl(fdOut, 1031, 1024 * 1024)
+
+ system:fdNonBlocking(fdOut)
+
lua_push_start(fdIn)
return fdIn, fdOut
end
@@ -50,11 +53,19 @@ function CfoxRecv:_del_()
end
end
-function CfoxRecv:outToFd(stream)
+local function pipeOut(fd, stream)
local len = #stream
local s = struct.pack("mtx);
if (q->stop) {
@@ -243,11 +244,14 @@ int beeQ_send(struct beeQ *q, void *msg) {
}
if (isempty(q)) {
- pthread_cond_signal(&q->cond); // need to wakeup.
+ wake = 1;
}
q->send = (q->send + 1) % q->size;
q->msgs[q->send] = msg;
pthread_mutex_unlock(&q->mtx);
+ if (wake) {
+ pthread_cond_signal(&q->cond); // need to wakeup.
+ }
return 0;
}
diff --git a/source/tools/monitor/unity/collector/btfLoader.lua b/source/tools/monitor/unity/collector/btfLoader.lua
index c9354b8339ec56c9dfbed911a43003c7e37af043..44770eaf3931caab1276c09ed9003e90c5a2726e 100644
--- a/source/tools/monitor/unity/collector/btfLoader.lua
+++ b/source/tools/monitor/unity/collector/btfLoader.lua
@@ -70,7 +70,7 @@ local function downKo(path, name, region, machine, release)
end
function CbtfLoader:_init_(root)
- local distro = utsname.uname()
+ --local distro = utsname.uname()
if distro then
local release, machine = distro.release, distro.machine
local path = '/boot/vmlinux-' .. release
diff --git a/source/tools/monitor/unity/collector/container/cg_memory_util.lua b/source/tools/monitor/unity/collector/container/cg_memory_util.lua
new file mode 100644
index 0000000000000000000000000000000000000000..54316714212fbe234af962f080fabc8d31997e4a
--- /dev/null
+++ b/source/tools/monitor/unity/collector/container/cg_memory_util.lua
@@ -0,0 +1,80 @@
+require("common.class")
+local pystring = require("common.pystring")
+local CvProc = require("collector.vproc")
+local root = "sys/fs/cgroup/memory/"
+local dfile = "/memory.stat"
+local usage = "/memory.usage_in_bytes"
+local limit = "/memory.limit_in_bytes"
+local system = require("common.system")
+
+local CgMemUtil = class("cg_memory_util", CvProc)
+
+--ls{}, (pod_name and docker_name
+function CgMemUtil:_init_(proto, pffi, mnt, path, ls)
+ CvProc._init_(self, proto, pffi, mnt, root .. path .. dfile)
+ self.ls = ls
+ self.path = mnt..root..path..dfile
+ self.limitpath = mnt..root..path..limit
+ self.usagepath = mnt..root..path..usage
+ self.limit = 0
+ self.usage = 0
+end
+
+function CgMemUtil:_getLimit_()
+ local pfile = io.open(self.limitpath, "r")
+ local line = pfile:read()
+ self.limit = tonumber(line)
+ io.close(pfile)
+end
+
+function CgMemUtil:_getUsage_()
+ local pfile = io.open(self.usagepath, "r")
+ local line = pfile:read()
+ self.usage = tonumber(line)
+ io.close(pfile)
+end
+
+function CgMemUtil:proc(elapsed, lines)
+ local c = 1
+ local k = 1
+ CvProc.proc(self)
+ self:_getLimit_()
+ self:_getUsage_()
+ local values = {}
+ for line in io.lines(self.pFile) do
+ local name
+ local cell = pystring:split(line)
+ local num = #cell
+ local val = tonumber(cell[num])
+ local metrics = {["total_cache"] = 1, ["total_rss"] = 1, ["total_shmem"]=1,["total_dirty"]=1,["total_pgpgin"]=1,["total_pgpgout"]=1,
+ ["total_inactive_anon"] =1, ["total_active_anon"]=1,["total_inactive_file"] =1, ["total_active_file"] =1,["total_pgfault"]=1}
+ --we assume that: memory.use_hierarchy is "1"
+ if metrics[cell[1]] then
+ name = string.sub(cell[1], 7)
+ values[k] = {
+ name = name,
+ value = val
+ }
+ k = k + 1
+ if ("total_cache" == cell[1]) or ("total_rss" == cell[1]) then
+ local ratio = (100.00*val) / tonumber(self.usage)
+ values[k] = {
+ name = name.."_ratio",
+ value = ratio
+ }
+ k = k + 1
+ end
+ end
+ end
+ values[k] = {
+ name = "usage",
+ value = self.usage
+ }
+ values[k+1] = {
+ name = "mem_util",
+ value = (tonumber(self.usage)*100.0)/ tonumber(self.limit)
+ }
+ self:appendLine(self:_packProto("cg_memory_util", self.ls, values))
+ self:push(lines)
+end
+return CgMemUtil
diff --git a/source/tools/monitor/unity/collector/guard/calcJiffies.lua b/source/tools/monitor/unity/collector/guard/calcJiffies.lua
index 922f345bcc7ab5c9d6ee6f6bef882741e0a2d40d..bbb914e91eae64074c0a2e71f3c9dee0993d31de 100644
--- a/source/tools/monitor/unity/collector/guard/calcJiffies.lua
+++ b/source/tools/monitor/unity/collector/guard/calcJiffies.lua
@@ -6,6 +6,7 @@
local mod = {}
local ptime = require("posix.time")
+local pstime = require("posix.sys.time")
local unistd = require("posix.unistd")
local system = require("common.system")
@@ -26,7 +27,16 @@ local function read_jiffies(path, procffi)
return res
end
-local function nproc()
+local function get_native_us()
+ local res, err, errno = pstime.gettimeofday()
+ if res then
+ return res.tv_sec * 1e6 + res.tv_usec
+ else
+ system:posixError("gettimeofday failed", err, errno)
+ end
+end
+
+local function nproc() -- get cpu numbers, exec nproc
local r, err, errno = unistd.sysconf(84)
if err then
system:posixError("sysconf failed", err, errno)
@@ -40,26 +50,30 @@ function mod.calc(mnt, procffi)
local r, err, errno
local j1 = read_jiffies(path, procffi)
+ local ns1 = get_native_us()
r, err, errno = ptime.nanosleep(t)
if err then
system:posixError("nano sleep failed", err, errno)
end
local j2 = read_jiffies(path, procffi)
+ local ns2 = get_native_us()
ptime.nanosleep(t)
if err then
system:posixError("nano sleep failed", err, errno)
end
local j3 = read_jiffies(path, procffi)
+ local ns3 = get_native_us()
+
local delta1, delta2 = j2 - j1, j3 -j2
- local comp = delta1 / delta2
+ local dts1, dts2 = ns2 - ns1, ns3 - ns2
+ local comp = (delta1 / dts1) / ( delta2 / dts2 )
if comp >= 1.1 or comp < 0.9 then
- error("calculate jiffies failed.")
+ error(string.format("calculate jiffies failed, delta1: %d, delta2: %d, dts1: %d, dts2: %d", delta1, delta2, dts1, dts2))
end
-
- return (delta1 + delta2) * 2.5 / nproc()
+ return (delta1 + delta2) * ( 1e6 / (dts1 + dts2)) / nproc()
end
return mod
diff --git a/source/tools/monitor/unity/collector/guard/guardSched.lua b/source/tools/monitor/unity/collector/guard/guardSched.lua
index e248ea1c24fa0194ae7b0d584471a38a9ec451b9..46c21d1461ddb63fb30f493952d354828ea5ee83 100644
--- a/source/tools/monitor/unity/collector/guard/guardSched.lua
+++ b/source/tools/monitor/unity/collector/guard/guardSched.lua
@@ -15,7 +15,7 @@ function CguardSched:_init_(tid, procs, names, jperiod)
self._jperiod = jperiod
self._procs = procs
self._names = names
- self._limit = 1e5*5 -- 500 ms
+ self._limit = 1e5 * 5 -- 500 ms
end
function CguardSched:proc(t, lines)
@@ -38,7 +38,7 @@ function CguardSched:proc(t, lines)
if stop - start - overTime >= self._limit then --
print(stop - start)
local j2 = self._stat:jiffies()
- if j2 - j1 >= self._limit / 1e6 * self._jperiod * 3 / 4 then -- 3/4 time used bye plugin
+ if j2 - j1 >= self._limit / 1e6 * self._jperiod * 3 / 4 then -- 3/4 time used by plugin
table.insert(toRemove, i)
end
end
diff --git a/source/tools/monitor/unity/collector/loop.lua b/source/tools/monitor/unity/collector/loop.lua
index 9156c8a5f46fd20e4e6800e123639d3d60ceb8ac..47e793ded8ae19fe1eb7a5740ca2b9d2206d828f 100644
--- a/source/tools/monitor/unity/collector/loop.lua
+++ b/source/tools/monitor/unity/collector/loop.lua
@@ -16,8 +16,8 @@ local CguardDaemon = require("collector.guard.guardDaemon")
local CguardSelfStat = require("collector.guard.guardSelfStat")
local CpostPlugin = require("collector.postPlugin.postPlugin")
local CforkRun = require("collector.execEngine.forkRun")
-local CpodFilter = require("collector.podMan.podFilter")
-
+---local CpodFilter = require("collector.podMan.podFilter")
+local CpodsAll = require("collector.podMan.podsAll")
local Cloop = class("loop")
function Cloop:_init_(que, proto_q, fYaml, tid)
@@ -51,11 +51,12 @@ function Cloop:loadLuaPlugin(res, proc_path, procffi)
c = c + 1
end
end
- --self._procs[c] = CpodsAll.new(res, self._proto, procffi, proc_path)
- --self._names[c] = "podMon"
if res.container then
- self._procs[c] = CpodFilter.new(res, self._proto, procffi, proc_path)
- self._names[c] = "podFilter"
+ ---self._procs[c] = CpodFilter.new(res, self._proto, procffi, proc_path)
+ ---self._names[c] = "podFilter"
+ self._procs[c] = CpodsAll.new(res, self._proto, procffi, proc_path)
+ self._names[c] = "podMon"
+
end
print("add " .. system:keyCount(self._procs) .. " lua plugin.")
end
diff --git a/source/tools/monitor/unity/collector/native/plugincffi.lua b/source/tools/monitor/unity/collector/native/plugincffi.lua
index 037ba320191235b2a7cdead8373e7c9cdbbffbf7..9c23c9e3e73f661c85d4869ef2f8ddee4af748ae 100644
--- a/source/tools/monitor/unity/collector/native/plugincffi.lua
+++ b/source/tools/monitor/unity/collector/native/plugincffi.lua
@@ -39,6 +39,9 @@ void deinit(void);
void free(void *p);
int setns(int fd, int nstype);
+char* scanall();
+int monitor_init(const char* proc);
+void monitor_exit();
]]
return ffi
diff --git a/source/tools/monitor/unity/collector/plugin/podmem/Makefile b/source/tools/monitor/unity/collector/plugin/podmem/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..ee676b26bc55a689222fd0bdaee798b7fb705440
--- /dev/null
+++ b/source/tools/monitor/unity/collector/plugin/podmem/Makefile
@@ -0,0 +1,21 @@
+CC := g++
+CFLAG := -g -fpic
+LDFLAG := -g -fpic -shared -static-libstdc++
+OBJS := memcg.o offset.o memread.o
+SO := libpodmem.so
+LIBS += -L ${OBJ_LIB_PATH}/lib -lcoolbpf -lelf -lz -lpthread
+LDFLAG += -Wall $(LIBS)
+
+all: $(SO) install
+
+%.o: %.cpp
+ $(CC) -c $< -o $@ $(CFLAG)
+
+$(SO): $(OBJS)
+ $(CC) -o $@ $(OBJS) $(LDFLAG)
+
+install: $(SO)
+ cp $(SO) ../../native/
+
+clean:
+ rm -f $(SO) $(OBJS)
diff --git a/source/tools/monitor/unity/collector/plugin/podmem/btfparse.h b/source/tools/monitor/unity/collector/plugin/podmem/btfparse.h
new file mode 100644
index 0000000000000000000000000000000000000000..3a586d0f0bdec166b25804215f644cd3cfef8a52
--- /dev/null
+++ b/source/tools/monitor/unity/collector/plugin/podmem/btfparse.h
@@ -0,0 +1,38 @@
+
+
+#ifndef __BTF_PARSE_H
+#define __BTF_PARSE_H
+
+
+
+/**
+ * btf_load: load btf from btf_custom_path
+ *
+ * @btf_custom_path: path of btf file
+ */
+struct btf *btf_load(char *btf_custom_path);
+typedef unsigned int uint32_t;
+
+struct member_attribute
+{
+ uint32_t size; // size of structure's member
+ uint32_t real_size; // real_size mean
+ uint32_t offset; // offset of member in strucutre
+};
+
+/**
+ * btf_find_struct_member - find struct btfid by structure's name
+ *
+ * @btf:
+ * @struct_name: name of struct
+ * @member_name: name of structure's member
+ * @return: NULL mean error, get error number from errno.
+ *
+ * Note: Remember to free pointer of struct member_attribute
+ */
+struct member_attribute *btf_find_struct_member(struct btf *btf, char *struct_name, char *member_name);
+void btf__free(struct btf *btf);
+
+
+#endif
+
diff --git a/source/tools/monitor/unity/collector/plugin/podmem/cache.h b/source/tools/monitor/unity/collector/plugin/podmem/cache.h
new file mode 100644
index 0000000000000000000000000000000000000000..8b8c14bc63d0518973648426c6771f1475f4a14f
--- /dev/null
+++ b/source/tools/monitor/unity/collector/plugin/podmem/cache.h
@@ -0,0 +1,103 @@
+/*
+ * Page scan tool
+ */
+#ifndef _PAGESCAN_UTIL_H
+#define _PAGESCAN_UTIL_H
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+extern unsigned long page_shift;
+#define MAX_ORDER 11
+#define PAGE_SIZE (1UL << page_shift)
+#define HUGE_SIZE (PAGE_SIZE * HUGE_PAGE_NR)
+#define BUFF_MAX 4096
+#define SIZE_KB (1UL << 10)
+#define SIZE_MB (1UL << 20)
+#define MAX_KCORE_ELF_HEADER_SIZE 32768
+
+
+#ifdef DEBUG
+#define LOG_DEBUG(...) fprintf(stderr, __VA_ARGS__)
+#else
+#define LOG_DEBUG(...) do { } while (0)
+#endif /* DEBUG */
+
+#define LOG_INFO(...) fprintf(stdout, __VA_ARGS__)
+#define LOG_WARN(...) fprintf(stderr, __VA_ARGS__)
+#define LOG_ERROR(...) fprintf(stderr, __VA_ARGS__)
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+extern unsigned long vmemmap_base;
+extern unsigned long page_offset_base;
+extern uint64_t g_max_phy_addr;
+extern unsigned long memstart_addr;
+#define PAGE_STRUCT_SIZE 64
+
+#ifdef __aarch64__ /*arm arch*/
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0) /*kernel 510*/
+#define VA_BITS (48)
+#define SZ_2M 0x00200000
+#define STRUCT_PAGE_MAX_SHIFT (6)
+#define VA_BITS_MIN (48)
+
+#define _PAGE_END(va) (-((unsigned long )(1) << ((va) - 1)))
+#define _PAGE_OFFSET(va) (-((unsigned long )(1) << (va)))
+#define PAGE_OFFSET (_PAGE_OFFSET(VA_BITS))
+#define VMEMMAP_SIZE ((_PAGE_END(VA_BITS_MIN) - PAGE_OFFSET) \
+ >> (page_shift - STRUCT_PAGE_MAX_SHIFT))
+#define PHYS_OFFSET (memstart_addr)
+#define VMEMMAP_START (-VMEMMAP_SIZE - SZ_2M)
+#define vmemmap (VMEMMAP_START - (memstart_addr >> page_shift)*PAGE_STRUCT_SIZE)
+
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 9)/*kernel 419*/
+#define VA_BITS (48)
+#define VA_START ((unsigned long )(0xffffffffffffffff) - \
+ ((unsigned long )(1) << VA_BITS) + 1)
+#define PAGE_OFFSET ((unsigned long )(0xffffffffffffffff) - \
+ ((unsigned long )(1) << (VA_BITS - 1)) + 1)
+#define STRUCT_PAGE_MAX_SHIFT (6)
+#define VMEMMAP_SIZE ((unsigned long )(1) << (VA_BITS - page_shift - 1 + STRUCT_PAGE_MAX_SHIFT))
+#define VMEMMAP_START (PAGE_OFFSET - VMEMMAP_SIZE)
+#define vmemmap (VMEMMAP_START - (memstart_addr >> page_shift)*PAGE_STRUCT_SIZE)
+
+#else /*others*/
+#define SZ_64K 0x00010000
+#define PAGE_OFFSET (unsigned long )(0xffffffc000000000)
+#define VMALLOC_END (PAGE_OFFSET - (unsigned long)(0x400000000) - SZ_64K)
+#define vmemmap ((struct page *)(VMALLOC_END + SZ_64K))
+
+#endif /*end to check ver, arm arch*/
+#define PFN_TO_VIRT(pfn) (((unsigned long)((pfn) - PHYS_OFFSET) | PAGE_OFFSET) + ((pfn) << page_shift))
+#define PFN_TO_PAGE(pfn) (vmemmap + (pfn) * PAGE_STRUCT_SIZE)
+#define is_kvaddr(kvaddr) (!!(kvaddr >= PAGE_OFFSET))
+#else /*x86 arch*/
+
+#define PFN_TO_VIRT(pfn) (page_offset_base + ((pfn) << page_shift))
+#define PFN_TO_PAGE(pfn) (vmemmap_base + (pfn) * PAGE_STRUCT_SIZE)
+#define is_kvaddr(kvaddr) (!!(kvaddr >= page_offset_base))
+#endif
+#define max_pfn (g_max_phy_addr>>12)
+
+struct options {
+ bool podmem;
+ bool fullscan;
+ char *cgroupfile;
+ char *cgroup;
+ unsigned int rate;
+ unsigned int top;
+};
+
+#define KPF_SIZE 8
+ssize_t kpageflags_read(void *buf, size_t count, off_t offset);
+ssize_t kpagecgroup_read(void *buf, size_t count, off_t offset);
+uintptr_t lookup_kernel_symbol(const char *symbol_name);
+ssize_t kcore_readmem(unsigned long kvaddr, void *buf, ssize_t size);
+#endif /* _PAGESCAN_UTIL_H */
diff --git a/source/tools/monitor/unity/collector/plugin/podmem/memcg.cpp b/source/tools/monitor/unity/collector/plugin/podmem/memcg.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bea1c24f824cb52f2730e2828efd4c70e4ee94d2
--- /dev/null
+++ b/source/tools/monitor/unity/collector/plugin/podmem/memcg.cpp
@@ -0,0 +1,598 @@
+#include
+#include
+#include
+#include
+#include
+#include "cache.h"
+#include "memcg.h"
+#include "btfparse.h"
+
+#include
+#include
+#include
+#include
+#include
+#include