Skip to content

Commit f300d39

Browse files
committed
🚧 mapper name refactoring
1 parent b8d2358 commit f300d39

File tree

3 files changed

+52
-35
lines changed

3 files changed

+52
-35
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
### configuration (스카우터 서버 설치 경로 하위의 conf/scouter.conf)
77
#### 기본 설정
88
* **ext_plugin_es_enabled** : 본 plugin 사용 여부 (default : true)
9-
* **ext_plugin_es_index** : elasticsearch index 명 (default : scouter-counter)
9+
* **ext_plugin_es_counter_index** : elasticsearch counter index 명 (default : scouter-counter)
10+
* **ext_plugin_es_xlog_index** : elasticsearch xlog index 명 (default : scouter-xlog)
11+
* **ext_plugin_ex_duration_day** : elasticsearch index 저장 기간 (default : 90)
1012

1113

1214
#### http 방식 연동 여부 설정

src/main/java/scouter/plugin/server/elasticsearch/ElasticSearchPlugin.java

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,37 @@
1313
import scouter.server.Logger;
1414
import scouter.server.core.AgentManager;
1515
import scouter.server.plugin.PluginHelper;
16-
import scouter.util.DateUtil;
17-
import scouter.util.HashUtil;
18-
import scouter.util.StringUtil;
16+
import scouter.util.*;
1917

2018
import java.util.*;
2119

2220
/**
2321
* @author Heo Yeo Song (yosong.heo@gmail.com) on 2019. 6. 13.
2422
*/
25-
public class ElasticSearchPlugin extends TimerTask {
23+
public class ElasticSearchPlugin {
2624

2725
private final HttpClient httpClient;
2826
Configure conf = Configure.getInstance();
2927

30-
private static final String ext_plugin_es_enabled = "ext_plugin_es_enabled";
31-
private static final String ext_plugin_es_index = "ext_plugin_es_index";
28+
private static final String ext_plugin_es_enabled = "ext_plugin_es_enabled";
29+
private static final String ext_plugin_es_counter_index = "ext_plugin_es_counter_index";
30+
private static final String ext_plugin_es_xlog_index = "ext_plugin_es_xlog_index";
31+
private static final String ext_plugin_ex_duration_day = "ext_plugin_ex_duration_day";
3232

33-
private static final String ext_plugin_es_https_enabled = "ext_plugin_es_https_enabled";
34-
private static final String ext_plugin_es_cluster_address = "ext_plugin_es_cluster_address";
33+
private static final String ext_plugin_es_https_enabled = "ext_plugin_es_https_enabled";
34+
private static final String ext_plugin_es_cluster_address = "ext_plugin_es_cluster_address";
3535

36-
private static final String ext_plugin_es_id = "ext_plugin_es_id";
37-
private static final String ext_plugin_es_password = "ext_plugin_es_password";
36+
private static final String ext_plugin_es_id = "ext_plugin_es_id";
37+
private static final String ext_plugin_es_password = "ext_plugin_es_password";
3838

3939

4040

41-
private static final String tagObjName = "obj";
42-
private static final String tagTimeTypeName = "timeType";
43-
private static final String tagObjType = "objType";
44-
private static final String tagObjFamily = "objFamily";
45-
46-
4741
final PluginHelper helper = PluginHelper.getInstance();
4842

4943
boolean enabled = conf.getBoolean(ext_plugin_es_enabled, true);
50-
private String esIndexName = conf.getValue(ext_plugin_es_index, "scouter-counter");
44+
private String esCouterIndexName = conf.getValue(ext_plugin_es_counter_index, "scouter-counter");
45+
private String esXlogIndexName = conf.getValue(ext_plugin_es_xlog_index, "scouter-xlog");
46+
private int esIndexDuration = conf.getInt(ext_plugin_ex_duration_day, 90);
5147
boolean esIsHttpSecure = conf.getBoolean(ext_plugin_es_https_enabled, false);
5248
String esHttpAddress = conf.getValue(ext_plugin_es_cluster_address, "127.0.0.1:9200");
5349
String esUser = conf.getValue(ext_plugin_es_id, "");
@@ -65,12 +61,28 @@ public ElasticSearchPlugin() {
6561
this.httpClient.init();
6662

6763
Timer jobScheduler = new Timer(true);
68-
jobScheduler.scheduleAtFixedRate(this, 1, 1000);
64+
65+
jobScheduler.scheduleAtFixedRate(new TimerTask() {
66+
@Override
67+
public void run() {
68+
httpClient.flush();
69+
}
70+
}, 1, DateTimeHelper.MILLIS_PER_SECOND);
71+
72+
Timer deleteScheduler = new Timer(true);
73+
deleteScheduler.scheduleAtFixedRate(new TimerTask() {
74+
@Override
75+
public void run() {
76+
httpClient.deleteIndex(Arrays.asList(esCouterIndexName,esXlogIndexName),esIndexDuration);
77+
}
78+
}, 1, DateTimeHelper.MILLIS_PER_DAY);
6979

7080
ConfObserver.put("ElasticPluginPlugin", new Runnable() {
7181
public void run() {
7282
enabled = conf.getBoolean(ext_plugin_es_enabled, true);
73-
esIndexName = conf.getValue(ext_plugin_es_index, "scouter-counter");
83+
esCouterIndexName = conf.getValue(ext_plugin_es_counter_index, "scouter-counter");
84+
esXlogIndexName = conf.getValue(ext_plugin_es_xlog_index, "scouter-xlog");
85+
esIndexDuration = conf.getInt(ext_plugin_ex_duration_day, 90);
7486
esIsHttpSecure = conf.getBoolean(ext_plugin_es_https_enabled, false);
7587
esHttpAddress = conf.getValue(ext_plugin_es_cluster_address, "127.0.0.1:9200");
7688
esUser = conf.getValue(ext_plugin_es_id, "");
@@ -85,10 +97,6 @@ public void run() {
8597
});
8698
}
8799

88-
@Override
89-
public void run() {
90-
this.httpClient.flush();
91-
}
92100

93101
@ServerPlugin(PluginConstants.PLUGIN_SERVER_COUNTER)
94102
public void counter(final PerfCounterPack pack) {
@@ -110,7 +118,7 @@ public void counter(final PerfCounterPack pack) {
110118
Map<String,Object> _source = new LinkedHashMap<>();
111119

112120
_source.put("bucket_time",new Date(pack.time));
113-
_source.put("objHash",String.valueOf(objHash));
121+
_source.put("objHash",Hexa32.toString32(objHash));
114122
_source.put("objName",objName);
115123
_source.put("objType",objType);
116124
_source.put("objFamily",objFamily);
@@ -125,13 +133,13 @@ public void counter(final PerfCounterPack pack) {
125133
continue;
126134
}
127135
String key = field.getKey();
128-
if("time".equals(key)) {
136+
if(Objects.equals("time",key) || Objects.equals("objHash",key)) {
129137
continue;
130138
}
131139
_source.put(key,value);
132140
}
133141

134-
String _indexName = String.join("-",esIndexName.toLowerCase(), DateUtil.format(System.currentTimeMillis(),"yyyy-MM-dd"));
142+
String _indexName = String.join("-",esCouterIndexName.toLowerCase(), DateUtil.format(System.currentTimeMillis(),"yyyy-MM-dd"));
135143
final int _id = HashUtil.hash(String.join("",
136144
_indexName ,
137145
String.valueOf(objHash) ,
@@ -156,20 +164,20 @@ public void xlog(final XLogPack p) {
156164
return;
157165
}
158166

159-
160167
Map<String,Object> _source = new LinkedHashMap<>();
161168

162169
_source.put("bucket_time",new Date(p.endTime - p.elapsed));
163170
_source.put("endTime",new Date(p.endTime));
164-
_source.put("raw_startTime",p.endTime - p.elapsed);
165-
_source.put("raw_endTime",p.endTime);
166-
_source.put("objHash",String.valueOf(p.objHash));
171+
_source.put("start_time_number",p.endTime - p.elapsed);
172+
_source.put("end_time_number",p.endTime);
173+
_source.put("objHash",Hexa32.toString32(p.objHash));
167174
_source.put("service",this.getString(helper.getServiceString(p.service)));
168175
_source.put("threadName",this.getString(helper.getHashMsgString(p.threadNameHash)));
169176

170-
_source.put("txid",p.txid);
171-
_source.put("caller",p.caller);
172-
_source.put("gxid",p.gxid);
177+
_source.put("txid",Hexa32.toString32(p.txid));
178+
_source.put("caller",Hexa32.toString32(p.caller));
179+
_source.put("gxid",Hexa32.toString32(p.gxid));
180+
173181
_source.put("elapsed",p.elapsed);
174182
_source.put("error",this.getString(helper.getHashMsgString(p.error)));
175183
_source.put("cpu",p.cpu);
@@ -196,7 +204,8 @@ public void xlog(final XLogPack p) {
196204
_source.put("queuingTime",p.queuingTime);
197205
_source.put("queuing2ndHostHash",this.getString(helper.getHashMsgString(p.queuingHostHash)));
198206
_source.put("queuing2ndTime",p.queuing2ndTime);
199-
String _indexName = String.join("-","scouter-xlog", DateUtil.format(System.currentTimeMillis(),"yyyy-MM-dd"));
207+
208+
String _indexName = String.join("-",esXlogIndexName, DateUtil.format(System.currentTimeMillis(),"yyyy-MM-dd"));
200209
final int _id = HashUtil.hash(String.join("",
201210
_indexName ,
202211
String.valueOf(p.txid) ,

src/main/java/scouter/plugin/server/elasticsearch/HttpClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.io.IOException;
2727
import java.util.Arrays;
28+
import java.util.List;
2829
import java.util.Map;
2930

3031

@@ -144,4 +145,9 @@ public void put(String indexName, String id, Map<String, Object> source) {
144145
public void flush() {
145146
this.bulkProcessor.flush();
146147
}
148+
149+
public void deleteIndex(List<String> strings, int esIndexDuration) {
150+
151+
152+
}
147153
}

0 commit comments

Comments
 (0)