Skip to content

Commit

Permalink
Merge branch 'linuxkerneltravel:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nanshuaibo authored Dec 18, 2023
2 parents 013caa8 + 03bdace commit e76f052
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
/eBPF_Supermarket/Network_Subsystem/net_watcher @helight @LinkinPF @chenamy2017
/eBPF_Supermarket/CPU_Subsystem/cpu_watcher @helight @LinkinPF @chenamy2017
/eBPF_Supermarket/CPU_Subsystem/eBPF_proc_image @helight @LinkinPF @chenamy2017 @zhangzihengya
/eBPF_Supermarket/Stack_Analyser @helight @LinkinPF @chenamy2017
/eBPF_Supermarket/Stack_Analyser @helight @LinkinPF @chenamy2017 @GorilaMond
/eBPF_Supermarket/kvm_watcher @helight @LinkinPF @chenamy2017
30 changes: 30 additions & 0 deletions eBPF_Supermarket/Stack_Analyser/libbpf/client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cpprest/http_client.h>
#include <cpprest/json.h>

using namespace web;
using namespace web::http;
using namespace web::http::client;

int main() {
utility::string_t url = U("http://0.0.0.0:8080/data"); // 替换为你的API URL

http_client client(url);

json::value postData;
postData[U("key")] = json::value::string(U("value")); // 替换为你要发送的数据

http_request request(methods::POST);
request.headers().set_content_type(U("application/json"));
request.set_body(postData);

client.request(request).then([](http_response response) {
if (response.status_code() == status_codes::OK) {
// 处理成功响应
// response.extract_json() 可以用于处理响应的JSON数据
} else {
// 处理错误响应
}
}).wait();

return 0;
}
86 changes: 86 additions & 0 deletions eBPF_Supermarket/Stack_Analyser/libbpf/pyroscope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 1.21

## server

```shell
git clone https://github.com/grafana/pyroscope.git
cd pyroscope
wget https://cdn.cypress.io/desktop/12.11.0/linux-x64/cypress.zip
unzip cypress.zip
tar -zcvf cypress.tar.gz cypress
yarn add cypress.tar.gz
make build
./pyroscope # server

./profilecli canary-exporter # run test agent in other shell
# port for the HTTP(S) server used for data ingestion and web UI
# address of the pyroscope server
# default http://localhost:4040

```

## agent

构建

```shell
git clone https://github.com/grafana/agent.git
make agent-flow
cd build
```

将以下配置保存到 config.river

```r
pyroscope.ebpf "instance" {
forward_to = [pyroscope.write.endpoint.receiver]
targets_only = false
default_target = {"service_name" = "ebpf_profile"}
}

pyroscope.write "endpoint" {
endpoint {
url = "http://localhost:4040"
}
}
```

运行

```shell
sudo ./grafana-agent-flow run config.river
/<path>/<to>/<pyroscope>/pyroscope
# port for the HTTP(S) server used for data ingestion and web UI
# address of the pyroscope server
# default http://localhost:4040
```

# 0.36

```shell
sudo ./pyroscope server
sudo ./pyroscope ebpf
# port for the HTTP(S) server used for data ingestion and web UI
# address of the pyroscope server
# default http://localhost:4040
```

# yarn install package from local folder

如果您想在本地文件夹中安装 yarn 包,您可以使用以下命令:

首先,需要将本地文件夹打包成 tar 压缩包。您可以使用以下命令:

```shell
tar -zcvf package_name.tar.gz /path/to/local/folder
```

然后,您可以使用以下命令在项目根目录中安装本地 tar 包:

```shell
yarn add file:/path/to/package_name.tar.gz
```

这将解压 tar 包并将其安装到项目的 node_modules 文件夹中。

请注意,安装本地 tar 包不是 yarn 的推荐方法,因此在生产环境中使用时请谨慎。
42 changes: 42 additions & 0 deletions eBPF_Supermarket/Stack_Analyser/libbpf/server.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <cpprest/http_listener.h>
#include <cpprest/json.h>

using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;

void handle_post(http_request request) {
request.extract_json().then([&request](json::value body) {
// 处理收到的JSON数据
// body 变量包含从客户端发送过来的JSON数据
std::cout << body << std::endl;
// 返回成功响应
request.reply(status_codes::OK);
}).wait();
}

int main() {
http_listener listener("http://0.0.0.0:8080/data"); // 替换为你想要监听的URL
listener.support(methods::POST, handle_post);

try {
listener.open().then([]() {
// 服务器启动成功
}).wait();

std::cout << "Server running..." << std::endl;

// 阻塞直到用户按下任意键退出程序
std::cout << "Press Enter to exit..." << std::endl;
std::string line;
std::getline(std::cin, line);

listener.close().then([]() {
// 服务器关闭成功
}).wait();
} catch (std::exception const & e) {
std::wcout << e.what() << std::endl;
}

return 0;
}

0 comments on commit e76f052

Please sign in to comment.