forked from scouter-project/scouter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigure.java
More file actions
419 lines (351 loc) · 13 KB
/
Configure.java
File metadata and controls
419 lines (351 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
/*
* Copyright 2015 the original author or authors.
* @https://github.com/scouter-project/scouter
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package scouter.server;
import scouter.lang.conf.ConfigValueUtil;
import scouter.lang.value.ListValue;
import scouter.lang.value.MapValue;
import scouter.net.NetConstants;
import scouter.util.*;
import java.io.*;
import java.util.HashSet;
import java.util.Properties;
import java.util.StringTokenizer;
public class Configure extends Thread {
private static Configure instance = null;
public final static String CONF_DIR = "./conf/";
public final static synchronized Configure getInstance() {
if (instance == null) {
instance = new Configure();
instance.setDaemon(true);
instance.setName(ThreadUtil.getName(instance));
instance.start();
}
return instance;
}
//SERVER
public String server_id = SysJMX.getHostName();
//Log
public boolean log_tcp_action_enabled = false;
public boolean log_udp_multipacket = false;
public boolean log_expired_multipacket = true;
public boolean log_udp_packet = false;
public boolean log_udp_counter = false;
public boolean log_udp_xlog = false;
public boolean log_udp_profile = false;
public boolean log_udp_text = false;
public boolean log_udp_alert = false;
public boolean log_udp_object = false;
public boolean log_udp_status = false;
public boolean log_udp_stack = false;
public boolean log_udp_summary = false;
public boolean log_service_handler_list = false;
public boolean log_rotation_enabled = true;
public int log_keep_days = 31;
public boolean log_sql_parsing_fail_enabled = false;
public boolean _trace = false;
//Network
public String net_udp_listen_ip = "0.0.0.0";
public int net_udp_listen_port = NetConstants.SERVER_UDP_PORT;
public String net_tcp_listen_ip = "0.0.0.0";
public int net_tcp_listen_port = NetConstants.SERVER_TCP_PORT;
public int net_tcp_client_so_timeout_ms = 8000;
public int net_tcp_agent_so_timeout_ms = 60000;
public int net_tcp_agent_keepalive_interval_ms = 5000;
public int net_tcp_get_agent_connection_wait_ms = 1000;
public int net_udp_packet_buffer_size = 65535;
public int net_udp_so_rcvbuf_size = 1024 * 1024 * 4;
public int _net_udp_worker_thread_count = 3;
public int net_tcp_service_pool_size = 100;
//Dir
public String db_dir = "./database";
public String log_dir = "./logs";
public String plugin_dir = "./plugin";
public String client_dir = "./client";
//Object
public int object_deadtime_ms = 8000;
//Compress
public boolean compress_xlog_enabled = false;
public boolean compress_profile_enabled = false;
public int _compress_write_buffer_block_count = 3;
public int _compress_read_cache_block_count = 3;
public long _compress_read_cache_expired_ms = DateUtil.MILLIS_PER_MINUTE;
public int _compress_dailycount_header_cache_size = 3;
public int _compress_write_thread = 2;
//Auto
public boolean _auto_5m_sampling = true;
//Manager
public boolean mgr_purge_enabled = true;
public boolean mgr_purge_only_xlog_enabled = false;
public int mgr_purge_disk_usage_pct = 80;
public int mgr_purge_keep_days = 0;
public StringSet mgr_log_ignore_ids = new StringSet();
//XLog
public int xlog_queue_size = 10000;
public int xlog_realtime_lower_bound_ms = 0;
public int xlog_pasttime_lower_bound_ms = 0;
public int xlog_profile_save_lower_bound_ms = 0;
//Profile
public int profile_queue_size = 1000;
//GeoIP
public boolean geoip_enabled = true;
public String geoip_data_city_file = "./GeoLiteCity.dat";
//SQL
public boolean sql_table_parsing_enabled = true;
//TagCount
public boolean tagcnt_enabled = false;
//Visitor Hourly
public boolean visitor_hourly_count_enabled = true;
private Configure() {
reload(false);
}
/**
* @deprecated
*/
private Configure(boolean b) {
}
private long last_load_time = -1;
public Properties property = new Properties();
private boolean running = true;
public void run() {
while (running) {
reload(false);
ThreadUtil.sleep(3000);
}
}
private File propertyFile;
public File getPropertyFile() {
if (propertyFile != null) {
return propertyFile;
}
String s = System.getProperty("scouter.config", CONF_DIR + "scouter.conf");
propertyFile = new File(s.trim());
return propertyFile;
}
long last_check = 0;
public synchronized boolean reload(boolean force) {
long now = System.currentTimeMillis();
if (force == false && now < last_check + 3000)
return false;
last_check = now;
File file = getPropertyFile();
if (file.lastModified() == last_load_time) {
return false;
}
last_load_time = file.lastModified();
Properties temp = new Properties();
if (file.canRead()) {
FileInputStream in = null;
try {
in = new FileInputStream(file);
temp.load(in);
} catch (Exception e) {
e.printStackTrace();
} finally {
FileUtil.close(in);
}
}
property = ConfigValueUtil.replaceSysProp(temp);
apply();
return true;
}
public static boolean WORKABLE = true;
private void apply() {
this.xlog_queue_size = getInt("xlog_queue_size", 10000);
this.profile_queue_size = getInt("profile_queue_size", 1000);
this.log_tcp_action_enabled = getBoolean("log_tcp_action_enabled", false);
this.net_udp_listen_ip = getValue("net_udp_listen_ip", "0.0.0.0");
this.net_udp_listen_port = getInt("net_udp_listen_port", NetConstants.SERVER_UDP_PORT);
this.net_tcp_listen_ip = getValue("net_tcp_listen_ip", "0.0.0.0");
this.net_tcp_listen_port = getInt("net_tcp_listen_port", NetConstants.SERVER_TCP_PORT);
this.net_tcp_client_so_timeout_ms = getInt("net_tcp_client_so_timeout_ms", 8000);
this.net_tcp_agent_so_timeout_ms = getInt("net_tcp_agent_so_timeout_ms", 60000);
this.net_tcp_agent_keepalive_interval_ms = getInt("net_tcp_agent_keepalive_interval_ms", 5000);
this.net_tcp_get_agent_connection_wait_ms = getInt("net_tcp_get_agent_connection_wait_ms", 1000);
this.server_id = getValue("server_id", SysJMX.getHostName());
this.db_dir = getValue("db_dir", "./database");
this.log_dir = getValue("log_dir", "./logs");
this.plugin_dir = getValue("plugin_dir", "./plugin");
this.client_dir = getValue("client_dir", "./client");
this.object_deadtime_ms = getInt("object_deadtime_ms", 8000);
this.compress_xlog_enabled = getBoolean("compress_xlog_enabled", false);
this.compress_profile_enabled = getBoolean("compress_profile_enabled", false);
this._compress_write_buffer_block_count = getInt("_compress_write_buffer_block_count", 3);
this._compress_dailycount_header_cache_size = getInt("_compress_dailycount_header_cache_size", 3);
this._compress_read_cache_block_count = getInt("_compress_read_cache_block_count", 3);
this._compress_read_cache_expired_ms = getLong("_compress_read_cache_expired_ms", DateUtil.MILLIS_PER_MINUTE);
this._compress_write_thread = getInt("_compress_write_thread", 2);
this.net_udp_packet_buffer_size = getInt("net_udp_packet_buffer_size", 65535);
int default_so_rcvbuf = 1024 * 1024 * 4;
if (SystemUtil.IS_AIX || SystemUtil.IS_HP_UX) {
default_so_rcvbuf = 0;
}
this.net_udp_so_rcvbuf_size = getInt("net_udp_so_rcvbuf_size", default_so_rcvbuf);
this.log_expired_multipacket = getBoolean("log_expired_multipacket", true);
this.log_udp_multipacket = getBoolean("log_udp_multipacket", false);
this.log_udp_packet = getBoolean("log_udp_packet", false);
this.log_udp_counter = getBoolean("log_udp_counter", false);
this.log_udp_xlog = getBoolean("log_udp_xlog", false);
this.log_udp_profile = getBoolean("log_udp_profile", false);
this.log_udp_text = getBoolean("log_udp_text", false);
this.log_udp_alert = getBoolean("log_udp_alert", false);
this.log_udp_object = getBoolean("log_udp_object", false);
this.log_udp_status = getBoolean("log_udp_status", false);
this.log_udp_stack = getBoolean("log_udp_stack", false);
this.log_udp_summary = getBoolean("log_udp_summary", false);
this.log_service_handler_list = getBoolean("log_service_handler_list", false);
this.log_rotation_enabled = getBoolean("log_rotation_enabled", true);
this.log_keep_days = getInt("log_keep_days", 31);
this.log_sql_parsing_fail_enabled = getBoolean("log_sql_parsing_fail_enabled", false);
this._trace = getBoolean("_trace", false);
this._auto_5m_sampling = getBoolean("_auto_5m_sampling", true);
this.xlog_realtime_lower_bound_ms = getInt("xlog_realtime_lower_bound_ms", 0);
this.xlog_pasttime_lower_bound_ms = getInt("xlog_pasttime_lower_bound_ms", 0);
this.mgr_purge_enabled = getBoolean("mgr_purge_enabled", true);
this.mgr_purge_only_xlog_enabled = getBoolean("mgr_purge_only_xlog_enabled", false);
this.mgr_purge_disk_usage_pct = getInt("mgr_purge_disk_usage_pct", 80);
this.mgr_purge_keep_days = getInt("mgr_purge_keep_days", 0);
this._net_udp_worker_thread_count = getInt("_net_udp_worker_thread_count", 3);
this.geoip_data_city_file = getValue("geoip_data_city_file", "./GeoLiteCity.dat");
this.geoip_enabled = getBoolean("geoip_enabled", true);
this.xlog_profile_save_lower_bound_ms = getInt("xlog_profile_save_lower_bound_ms", 0);
this.sql_table_parsing_enabled = getBoolean("sql_table_parsing_enabled", true);
this.mgr_log_ignore_ids = getStringSet("mgr_log_ignore_ids", ",");
this.tagcnt_enabled = getBoolean("tagcnt_enabled", false);
this.visitor_hourly_count_enabled = getBoolean("visitor_hourly_count_enabled", true);
this.net_tcp_service_pool_size = getInt("net_tcp_service_pool_size", 100);
ConfObserver.exec();
}
private StringSet getStringSet(String key, String deli) {
StringSet set = new StringSet();
String v = getValue(key);
if (v != null) {
String[] vv = StringUtil.split(v, deli);
for (String x : vv) {
x = StringUtil.trimToEmpty(x);
if (x.length() > 0)
set.put(x);
}
}
return set;
}
public String getValue(String key) {
return StringUtil.trim(property.getProperty(key));
}
public String getValue(String key, String def) {
return StringUtil.trim(property.getProperty(key, def));
}
public int getInt(String key, int def) {
try {
String v = getValue(key);
if (v != null)
return Integer.parseInt(v);
} catch (Exception e) {
}
return def;
}
public long getLong(String key, long def) {
try {
String v = getValue(key);
if (v != null)
return Long.parseLong(v);
} catch (Exception e) {
}
return def;
}
public boolean getBoolean(String key, boolean def) {
try {
String v = getValue(key);
if (v != null)
return Boolean.parseBoolean(v);
} catch (Exception e) {
}
return def;
}
public String loadText() {
File file = getPropertyFile();
InputStream fin = null;
try {
fin = new FileInputStream(file);
byte[] buff = FileUtil.readAll(fin);
return new String(buff);
} catch (Exception e) {
} finally {
FileUtil.close(fin);
}
return null;
}
public boolean saveText(String text) {
File file = getPropertyFile();
OutputStream out = null;
try {
if (file.getParentFile().exists() == false) {
file.getParentFile().mkdirs();
}
out = new FileOutputStream(file);
out.write(text.getBytes());
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
FileUtil.close(out);
}
return false;
}
public static void main(String[] args) {
StringKeyLinkedMap<Object> defMap = ConfigValueUtil.getConfigDefault(new Configure(true));
StringEnumer enu = defMap.keys();
while (enu.hasMoreElements()) {
String key = enu.nextString();
if (ignoreSet.contains(key))
continue;
System.out.println(key + " : " + ConfigValueUtil.toValue(defMap.get(key)));
}
}
private static HashSet<String> ignoreSet = new HashSet<String>();
static {
ignoreSet.add("property");
}
public MapValue getKeyValueInfo() {
StringKeyLinkedMap<Object> defMap = ConfigValueUtil.getConfigDefault(new Configure(true));
StringKeyLinkedMap<Object> curMap = ConfigValueUtil.getConfigDefault(this);
MapValue m = new MapValue();
ListValue nameList = m.newList("key");
ListValue valueList = m.newList("value");
ListValue defList = m.newList("default");
StringEnumer enu = defMap.keys();
while (enu.hasMoreElements()) {
String key = enu.nextString();
if (ignoreSet.contains(key))
continue;
nameList.add(key);
valueList.add(ConfigValueUtil.toValue(curMap.get(key)));
defList.add(ConfigValueUtil.toValue(defMap.get(key)));
}
return m;
}
public static StringLinkedSet toOrderSet(String values, String deli) {
StringLinkedSet set = new StringLinkedSet();
StringTokenizer nizer = new StringTokenizer(values, deli);
while (nizer.hasMoreTokens()) {
String s = StringUtil.trimToEmpty(nizer.nextToken());
if (s.length() > 0) {
set.put(s);
}
}
return set;
}
}