Skip to content

Commit 1b807ba

Browse files
author
Heran Yang
committed
Metric return node name
1 parent 4095a27 commit 1b807ba

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

fileserver/metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func publishMetrics() error {
140140
MetricType: "gauge",
141141
ComponentName: ComponentName,
142142
MetricHelp: "The number of currently running http requests.",
143+
NodeName: option.NodeName,
143144
}
144145

145146
data, err := json.Marshal(msg)

fileserver/option/option.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ var (
7979
// seahub
8080
SeahubURL string
8181
JWTPrivateKey string
82+
83+
// metric
84+
NodeName string
8285
)
8386

8487
type DBOption struct {
@@ -159,6 +162,11 @@ func LoadFileServerOptions(centralDir string) {
159162
if GroupTableName == "" {
160163
GroupTableName = "Group"
161164
}
165+
166+
NodeName = os.Getenv("NODE_NAME")
167+
if NodeName == "" {
168+
NodeName = "default"
169+
}
162170
}
163171

164172
func parseFileServerSection(section *ini.Section) {

server/metric-mgr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ publish_in_flight_request (SeafMetricManager *mgr)
9999
json_object_set_new (obj, "metric_type", json_string("gauge"));
100100
json_object_set_new (obj, "component_name", json_string(COMPONENT_NAME));
101101
json_object_set_new (obj, "metric_help", json_string("The number of currently running http requests."));
102+
json_object_set_new (obj, "node_name", json_string(seaf->node_name));
102103

103104
msg = json_dumps (obj, JSON_COMPACT);
104105

server/seafile-session.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ load_config (SeafileSession *session, const char *config_file_path)
117117
const char *private_key = NULL;
118118
const char *site_root = NULL;
119119
const char *log_to_stdout = NULL;
120+
const char *node_name = NULL;
120121

121122
config = g_key_file_new ();
122123
if (!g_key_file_load_from_file (config, config_file_path,
@@ -144,6 +145,7 @@ load_config (SeafileSession *session, const char *config_file_path)
144145
log_to_stdout = g_getenv("SEAFILE_LOG_TO_STDOUT");
145146
notif_server = g_getenv("INNER_NOTIFICATION_SERVER_URL");
146147
enable_notif_server = g_getenv("ENABLE_NOTIFICATION_SERVER");
148+
node_name = g_getenv("NODE_NAME");
147149

148150
if (!private_key) {
149151
seaf_warning ("Failed to read JWT_PRIVATE_KEY.\n");
@@ -166,6 +168,11 @@ load_config (SeafileSession *session, const char *config_file_path)
166168
session->log_to_stdout = TRUE;
167169
}
168170

171+
if (!node_name || g_strcmp0 (node_name, "") == 0) {
172+
node_name = "default";
173+
}
174+
session->node_name = g_strdup (node_name);
175+
169176
out:
170177
if (ret < 0) {
171178
if (config)

server/seafile-session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct _SeafileSession {
100100

101101
// For metric
102102
SeafMetricManager *metric_mgr;
103+
char *node_name;
103104

104105
ObjCache *obj_cache;
105106

0 commit comments

Comments
 (0)