175 lines
5.9 KiB
Diff
175 lines
5.9 KiB
Diff
|
|
From 60f0111ea9eeb1ab4e26de2acafb26e252d679a9 Mon Sep 17 00:00:00 2001
|
||
|
|
From: wo_cow <niuqianqian@huawei.com>
|
||
|
|
Date: Mon, 9 Jan 2023 11:06:00 +0800
|
||
|
|
Subject: [PATCH] add system_uuid field to distinguish client when post to
|
||
|
|
pyroscope server
|
||
|
|
|
||
|
|
---
|
||
|
|
src/common/common.h | 1 +
|
||
|
|
src/common/util.c | 20 ++++++++++++++++
|
||
|
|
src/lib/imdb/imdb.c | 24 ++-----------------
|
||
|
|
.../ebpf.probe/src/stackprobe/flame_graph.c | 7 +++---
|
||
|
|
.../ebpf.probe/src/stackprobe/stackprobe.c | 3 +++
|
||
|
|
.../ebpf.probe/src/stackprobe/stackprobe.h | 2 ++
|
||
|
|
6 files changed, 32 insertions(+), 25 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/common/common.h b/src/common/common.h
|
||
|
|
index f5feebf..64c040a 100644
|
||
|
|
--- a/src/common/common.h
|
||
|
|
+++ b/src/common/common.h
|
||
|
|
@@ -192,5 +192,6 @@ int exec_cmd(const char *cmd, char *buf, unsigned int buf_len);
|
||
|
|
char is_exist_mod(const char *mod);
|
||
|
|
int __snprintf(char **buf, const int bufLen, int *remainLen, const char *format, ...);
|
||
|
|
char is_digit_str(const char *s);
|
||
|
|
+int get_system_uuid(char *buffer, size_t size);
|
||
|
|
|
||
|
|
#endif
|
||
|
|
diff --git a/src/common/util.c b/src/common/util.c
|
||
|
|
index e25e9ee..945da65 100644
|
||
|
|
--- a/src/common/util.c
|
||
|
|
+++ b/src/common/util.c
|
||
|
|
@@ -196,3 +196,23 @@ char is_digit_str(const char *s)
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
+int get_system_uuid(char *buffer, size_t size)
|
||
|
|
+{
|
||
|
|
+ FILE *fp = NULL;
|
||
|
|
+
|
||
|
|
+ fp = popen("dmidecode -s system-uuid | tr 'A-Z' 'a-z'", "r");
|
||
|
|
+ if (fp == NULL) {
|
||
|
|
+ return -1;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ if (fgets(buffer, (int)size, fp) == NULL) {
|
||
|
|
+ pclose(fp);
|
||
|
|
+ return -1;
|
||
|
|
+ }
|
||
|
|
+ if (strlen(buffer) > 0 && buffer[strlen(buffer) - 1] == '\n') {
|
||
|
|
+ buffer[strlen(buffer) - 1] = '\0';
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ pclose(fp);
|
||
|
|
+ return 0;
|
||
|
|
+}
|
||
|
|
\ No newline at end of file
|
||
|
|
diff --git a/src/lib/imdb/imdb.c b/src/lib/imdb/imdb.c
|
||
|
|
index 767b930..bc562c2 100644
|
||
|
|
--- a/src/lib/imdb/imdb.c
|
||
|
|
+++ b/src/lib/imdb/imdb.c
|
||
|
|
@@ -18,7 +18,7 @@
|
||
|
|
#include <string.h>
|
||
|
|
#include <time.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
-
|
||
|
|
+#include "common.h"
|
||
|
|
#include "imdb.h"
|
||
|
|
|
||
|
|
static uint32_t g_recordTimeout = 60; // default timeout: 60 seconds
|
||
|
|
@@ -250,26 +250,6 @@ void IMDB_TableDestroy(IMDB_Table *table)
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
-static int IMDB_GetSystemUuid(char *buffer, size_t size)
|
||
|
|
-{
|
||
|
|
- FILE *fp = NULL;
|
||
|
|
-
|
||
|
|
- fp = popen("dmidecode -s system-uuid | tr 'A-Z' 'a-z'", "r");
|
||
|
|
- if (fp == NULL) {
|
||
|
|
- return -1;
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- if (fgets(buffer, (int)size, fp) == NULL) {
|
||
|
|
- pclose(fp);
|
||
|
|
- return -1;
|
||
|
|
- }
|
||
|
|
- if (strlen(buffer) > 0 && buffer[strlen(buffer) - 1] == '\n') {
|
||
|
|
- buffer[strlen(buffer) - 1] = '\0';
|
||
|
|
- }
|
||
|
|
-
|
||
|
|
- pclose(fp);
|
||
|
|
- return 0;
|
||
|
|
-}
|
||
|
|
|
||
|
|
IMDB_DataBaseMgr *IMDB_DataBaseMgrCreate(uint32_t capacity)
|
||
|
|
{
|
||
|
|
@@ -282,7 +262,7 @@ IMDB_DataBaseMgr *IMDB_DataBaseMgrCreate(uint32_t capacity)
|
||
|
|
|
||
|
|
memset(mgr, 0, sizeof(IMDB_DataBaseMgr));
|
||
|
|
|
||
|
|
- ret = IMDB_GetSystemUuid(mgr->nodeInfo.systemUuid, sizeof(mgr->nodeInfo.systemUuid));
|
||
|
|
+ ret = get_system_uuid(mgr->nodeInfo.systemUuid, sizeof(mgr->nodeInfo.systemUuid));
|
||
|
|
if (ret != 0) {
|
||
|
|
ERROR("[IMDB] Can not get system uuid.\n");
|
||
|
|
free(mgr);
|
||
|
|
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
|
||
|
|
index 40c6dcb..d6d2eb2 100644
|
||
|
|
--- a/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
|
||
|
|
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/flame_graph.c
|
||
|
|
@@ -247,16 +247,17 @@ static int __build_url(char *url, struct post_server_s *post_server, int en_type
|
||
|
|
time_t now, before;
|
||
|
|
(void)time(&now);
|
||
|
|
if (post_server->last_post_ts == 0) {
|
||
|
|
- before = now - 30; // 60s
|
||
|
|
+ before = now - TMOUT_PERIOD;
|
||
|
|
} else {
|
||
|
|
before = post_server->last_post_ts + 1;
|
||
|
|
}
|
||
|
|
post_server->last_post_ts = now;
|
||
|
|
|
||
|
|
(void)snprintf(url, LINE_BUF_LEN,
|
||
|
|
- "http://%s/ingest?name=%s&from=%ld&until=%ld",
|
||
|
|
+ "http://%s/ingest?name=%s-%s&from=%ld&until=%ld",
|
||
|
|
post_server->host,
|
||
|
|
appname[en_type],
|
||
|
|
+ post_server->app_suffix,
|
||
|
|
(long)before,
|
||
|
|
(long)now);
|
||
|
|
return 0;
|
||
|
|
@@ -310,7 +311,7 @@ static void __curl_post(struct post_server_s *post_server, struct post_info_s *p
|
||
|
|
if(res != CURLE_OK) {
|
||
|
|
ERROR("[FLAMEGRAPH]: curl post to %s failed: %s\n", url, curl_easy_strerror(res));
|
||
|
|
} else {
|
||
|
|
- INFO("[FLAMEGRAPH]: curl post post to %s success\n", url, post_info->remain_size);
|
||
|
|
+ INFO("[FLAMEGRAPH]: curl post post to %s success\n", url);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (chunk.memory) {
|
||
|
|
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
|
||
|
|
index 9fa5079..207a5e8 100644
|
||
|
|
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
|
||
|
|
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.c
|
||
|
|
@@ -851,6 +851,9 @@ static struct stack_trace_s *create_stack_trace(StackprobeConfig *conf)
|
||
|
|
INFO("[STACKPROBE]: Do not post to Pyroscope Server.\n");
|
||
|
|
st->post_server.post_enable = 0;
|
||
|
|
} else {
|
||
|
|
+ if (get_system_uuid(st->post_server.app_suffix, APP_SUFFIX_LEN) != 0) {
|
||
|
|
+ st->post_server.app_suffix[0] = 0;
|
||
|
|
+ }
|
||
|
|
INFO("[STACKPROBE]: Will post to Pyroscope Server: %s.\n", conf->generalConfig->pyroscopeServer);
|
||
|
|
}
|
||
|
|
|
||
|
|
diff --git a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
|
||
|
|
index 97e5ea5..7d6bd39 100644
|
||
|
|
--- a/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
|
||
|
|
+++ b/src/probes/extends/ebpf.probe/src/stackprobe/stackprobe.h
|
||
|
|
@@ -24,6 +24,7 @@
|
||
|
|
|
||
|
|
#define STACKPROBE_CONF_PATH_DEFAULT "/opt/gala-gopher/extend_probes/stackprobe.conf"
|
||
|
|
#define BPF_FUNC_NAME_LEN 32
|
||
|
|
+#define APP_SUFFIX_LEN 64
|
||
|
|
|
||
|
|
struct stack_symbs_s {
|
||
|
|
struct addr_symb_s user_stack_symbs[PERF_MAX_STACK_DEPTH];
|
||
|
|
@@ -106,6 +107,7 @@ struct post_server_s {
|
||
|
|
char post_enable;
|
||
|
|
long timeout; // sec
|
||
|
|
char host[PATH_LEN];
|
||
|
|
+ char app_suffix[APP_SUFFIX_LEN];
|
||
|
|
time_t last_post_ts;
|
||
|
|
};
|
||
|
|
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|