Skip to content

Commit f72b2a3

Browse files
committed
[working backup]
1 parent dcfee71 commit f72b2a3

File tree

13 files changed

+463
-0
lines changed

13 files changed

+463
-0
lines changed

pulse.sample.bizcounter/java-sample/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,35 @@
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
</properties>
1616

17+
<dependencies>
18+
<dependency>
19+
<groupId>com.squareup.retrofit2</groupId>
20+
<artifactId>retrofit</artifactId>
21+
<version>2.1.0</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>com.squareup.retrofit2</groupId>
25+
<artifactId>converter-gson</artifactId>
26+
<version>2.1.0</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.google.code.gson</groupId>
30+
<artifactId>gson</artifactId>
31+
<version>2.6.2</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.squareup.okhttp</groupId>
35+
<artifactId>okhttp</artifactId>
36+
<version>2.7.5</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.projectlombok</groupId>
40+
<artifactId>lombok</artifactId>
41+
<version>1.16.10</version>
42+
<scope>provided</scope>
43+
</dependency>
44+
</dependencies>
45+
1746
<build>
1847
<plugins>
1948
<plugin>

pulse.sample.bizcounter/java-sample/pulse.sample.bizcounter.iml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@
1111
</content>
1212
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
1313
<orderEntry type="sourceFolder" forTests="false" />
14+
<orderEntry type="library" name="Maven: com.squareup.retrofit2:retrofit:2.1.0" level="project" />
15+
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.3.0" level="project" />
16+
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.6.0" level="project" />
17+
<orderEntry type="library" name="Maven: com.squareup.retrofit2:converter-gson:2.1.0" level="project" />
18+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.6.2" level="project" />
19+
<orderEntry type="library" name="Maven: com.squareup.okhttp:okhttp:2.7.5" level="project" />
20+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.16.10" level="project" />
1421
</component>
1522
</module>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package scouterx.pulse.http;
2+
3+
import retrofit2.Retrofit;
4+
import retrofit2.converter.gson.GsonConverterFactory;
5+
import scouterx.pulse.protocol.counter.ObjectCounterBean;
6+
import scouterx.pulse.protocol.register.RegisterBean;
7+
8+
import java.util.List;
9+
import java.util.concurrent.BlockingQueue;
10+
import java.util.concurrent.LinkedBlockingDeque;
11+
12+
/**
13+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 31.
14+
*/
15+
public class HttpTrain extends Thread {
16+
static final String TYPE_REGISTER = "R";
17+
static final String TYPE_COUNTER_ARRAY = "A";
18+
static final String TYPE_COUNTER_LIST = "L";
19+
20+
class Bucket {
21+
String type;
22+
Object obj;
23+
24+
Bucket(String type, Object o) {
25+
this.type = type;
26+
this.obj = o;
27+
}
28+
}
29+
30+
static BlockingQueue<Bucket> queue = new LinkedBlockingDeque<>(100);
31+
32+
//TODO 어찌 초기화 할까??
33+
static Retrofit retrofit = new Retrofit.Builder()
34+
.baseUrl("https://api.github.com/")
35+
.addConverterFactory(GsonConverterFactory.create())
36+
.build();
37+
38+
private static HttpTrain instance = null;
39+
40+
public final static synchronized HttpTrain getInstance() {
41+
if (instance == null) {
42+
instance = new HttpTrain();
43+
instance.setDaemon(true);
44+
instance.setName(instance.getClass().getName());
45+
instance.start();
46+
}
47+
return instance;
48+
}
49+
50+
private HttpTrain() {
51+
}
52+
53+
@Override
54+
public void run() {
55+
while (true) {
56+
Object o = null;
57+
queue.stream().forEach(bucket -> {
58+
switch(bucket.type) {
59+
case TYPE_REGISTER:
60+
break;
61+
case TYPE_COUNTER_ARRAY:
62+
break;
63+
case TYPE_COUNTER_LIST:
64+
break;
65+
default:
66+
break;
67+
}
68+
});
69+
}
70+
}
71+
72+
73+
public boolean putRegisterBean(RegisterBean bean) {
74+
return queue.offer(new Bucket(TYPE_REGISTER, bean));
75+
}
76+
77+
public boolean putObjectCounterBeans(ObjectCounterBean[] beans) {
78+
return queue.offer(new Bucket(TYPE_COUNTER_ARRAY, beans));
79+
}
80+
81+
public boolean putObjectCounterBeans(List<ObjectCounterBean> beans) {
82+
return queue.offer(new Bucket(TYPE_COUNTER_LIST, beans));
83+
}
84+
85+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package scouterx.pulse.http;
2+
3+
import retrofit2.Response;
4+
import retrofit2.http.Body;
5+
import retrofit2.http.Headers;
6+
import retrofit2.http.POST;
7+
import scouterx.pulse.protocol.counter.ObjectValue;
8+
import scouterx.pulse.protocol.register.RegisterBean;
9+
10+
import java.util.List;
11+
12+
/**
13+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 31.
14+
*/
15+
public interface ScouterPulseService {
16+
@POST("/register")
17+
@Headers({"Accept: application/json", "Content-Yype: application/json"})
18+
Response register(@Body RegisterBean bean);
19+
20+
@POST("/counter")
21+
@Headers({"Accept: application/json", "Content-Yype: application/json"})
22+
Response counter(@Body ObjectValue[] objs);
23+
24+
@POST("/counter")
25+
@Headers({"Accept: application/json", "Content-Yype: application/json"})
26+
Response counter(@Body List<ObjectValue> objs);
27+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package scouterx.pulse.protocol.counter;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
9+
*/
10+
@Data
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class CounterValue {
14+
String name;
15+
Number value;
16+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package scouterx.pulse.protocol.counter;
2+
3+
import lombok.Data;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
10+
*/
11+
@Data
12+
public class ObjectCounterBean {
13+
private ObjectValue object;
14+
private List<CounterValue> counters;
15+
16+
private ObjectCounterBean(ObjectValue object, List<CounterValue> counters) {
17+
this.object = object;
18+
this.counters = counters;
19+
}
20+
21+
public static class Builder {
22+
private ObjectValue object;
23+
private List<CounterValue> counters = new ArrayList<>();
24+
25+
public Builder setObject(ObjectValue object) {
26+
this.object = object;
27+
return this;
28+
}
29+
30+
public Builder addCounterValue(CounterValue counter) {
31+
this.counters.add(counter);
32+
return this;
33+
}
34+
35+
public ObjectCounterBean build() {
36+
return new ObjectCounterBean(this.object, this.counters);
37+
}
38+
}
39+
}
40+
41+
42+
/*
43+
[
44+
{
45+
"object" : {
46+
"host" : "VM123",
47+
"name" : "my_server1",
48+
"type" : "redis",
49+
"address" : "10.10.10.10"
50+
},
51+
"counters" : [
52+
{"name" : "aof_rewrite_scheduled", "value" : 55},
53+
{"name" : "client_longest_output_list", "value" : 245},
54+
{"name" : "used_cpu_user", "value" : 4245}
55+
]
56+
},
57+
{
58+
"object" : {
59+
"host" : "VM123",
60+
"name" : "my_server2",
61+
"type" : "redis",
62+
"address" : "10.10.10.10"
63+
},
64+
"counters" : [
65+
{"name" : "aof_rewrite_scheduled", "value" : 35},
66+
{"name" : "client_longest_output_list", "value" : 65},
67+
{"name" : "used_cpu_user", "value" : 8888}
68+
]
69+
}
70+
71+
]
72+
*/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package scouterx.pulse.protocol.counter;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
9+
*/
10+
@Data
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class ObjectValue {
14+
String host;
15+
String name;
16+
String type;
17+
String address;
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package scouterx.pulse.protocol.register;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
9+
*/
10+
@Data
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class CounterDef {
14+
String name;
15+
String unit;
16+
String display;
17+
boolean total;
18+
boolean all;
19+
}
20+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package scouterx.pulse.protocol.register;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
/**
8+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
9+
*/
10+
@Data
11+
@AllArgsConstructor
12+
@NoArgsConstructor
13+
public class ObjectDef {
14+
String type;
15+
String display;
16+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package scouterx.pulse.protocol.register;
2+
3+
import lombok.Data;
4+
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* @author Gun Lee (gunlee01@gmail.com) on 2016. 7. 30.
10+
*/
11+
@Data
12+
public class RegisterBean {
13+
ObjectDef object;
14+
private List<CounterDef> counters = new ArrayList<>();
15+
16+
private RegisterBean(Builder builder) {
17+
this.object = builder.object;
18+
this.counters = builder.counters;
19+
}
20+
21+
public static class Builder {
22+
private ObjectDef object;
23+
private List<CounterDef> counters = new ArrayList<>();
24+
25+
public Builder setObjectSpec(ObjectDef objectSpec) {
26+
this.object = objectSpec;
27+
return this;
28+
}
29+
30+
public Builder addCounterSpec(CounterDef counterSpec) {
31+
this.counters.add(counterSpec);
32+
return this;
33+
}
34+
35+
public RegisterBean build() {
36+
return new RegisterBean(this);
37+
}
38+
}
39+
}
40+
41+
//{
42+
// "object" : {
43+
// "type" : "redis",
44+
// "display" : "Redis"
45+
// },
46+
// "counters" : [
47+
// {"name" : "aof_rewrite_scheduled",
48+
// "unit" : "cnt",
49+
// "display" : "AofRewriteScheduled",
50+
// "total" : true,
51+
// "all" : true
52+
// },
53+
// {"name" : "client_longest_output_list",
54+
// "unit" : "cnt",
55+
// "display" : "ClientLongOutList",
56+
// },
57+
// {"name" : "used_cpu_user",
58+
// "unit" : "cnt",
59+
// "display" : "UsedCpuUser",
60+
// "total" : false
61+
// },
62+
// ]
63+
// }
64+

0 commit comments

Comments
 (0)