Skip to content

Commit 63a029c

Browse files
committedApr 12, 2019
add flink monitor common
1 parent c9e7b04 commit 63a029c

File tree

4 files changed

+200
-1
lines changed

4 files changed

+200
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Flink 监控 common

‎flink-learning-monitor/flink-learning-monitor-common/src/main/java/com/zhisheng/common/model/Job.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,8 @@ public class Job {
4242
*/
4343
private Long lastModification;
4444

45-
45+
/**
46+
* job tasks
47+
*/
48+
private Task tasks;
4649
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,58 @@
11
package com.zhisheng.common.model;
22

33
import lombok.Data;
4+
import lombok.NoArgsConstructor;
45

56
@Data
7+
@NoArgsConstructor
68
public class Task {
9+
/**
10+
* task 总个数
11+
*/
12+
private int total;
713

14+
/**
15+
* 处于 created 状态的 task 个数
16+
*/
17+
private int created;
18+
19+
/**
20+
* 处于 scheduled 状态的 task 个数
21+
*/
22+
private int scheduled;
23+
24+
/**
25+
* 处于 deploying 状态的 task 个数
26+
*/
27+
private int deploying;
28+
29+
/**
30+
* 处于 running 状态的 task 个数
31+
*/
32+
private int running;
33+
34+
/**
35+
* 处于 finished 状态的 task 个数
36+
*/
37+
private int finished;
38+
39+
/**
40+
* 处于 canceling 状态的 task 个数
41+
*/
42+
private int canceling;
43+
44+
/**
45+
* 处于 canceled 状态的 task 个数
46+
*/
47+
private int canceled;
48+
49+
/**
50+
* 处于 failed 状态的 task 个数
51+
*/
52+
private int failed;
53+
54+
/**
55+
* 处于 reconciling 状态的 task 个数
56+
*/
57+
private int reconciling;
858
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package com.zhisheng.common.utils;
2+
3+
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
import java.net.URL;
7+
import java.util.*;
8+
import java.util.stream.Collectors;
9+
10+
public class PropertiesUtil {
11+
/**
12+
* 默认属性集合(文件在Constants中配置)
13+
*/
14+
public static Properties defaultProp = null;
15+
/**
16+
* 所有读取过的属性集合
17+
* 文件名 <-> 属性集合
18+
*/
19+
public static Map<String, Properties> allProps = new HashMap<>();
20+
21+
// 初始化默认的属性集合
22+
static {
23+
if (defaultProp == null && isExistProperties("application.properties")) {
24+
defaultProp = loadProperties("application.properties");
25+
allProps.put("application.properties", defaultProp);
26+
}
27+
}
28+
29+
/**
30+
* 读取属性文件,并将读出来的属性集合添加到【allProps】当中
31+
* 如果该属性文件之前已读取过,则直接从【allProps】获得
32+
*/
33+
public static Properties getProperties(String fileName) {
34+
if (fileName == null || "".equals(fileName)) {
35+
return defaultProp;
36+
} else {
37+
Properties prop = allProps.get(fileName);
38+
if (prop == null) {
39+
prop = loadProperties(fileName);
40+
allProps.put(fileName, prop);
41+
}
42+
43+
return prop;
44+
}
45+
}
46+
47+
/**
48+
* 解析属性文件,将文件中的所有属性都读取到【Properties】当中
49+
*/
50+
protected static Properties loadProperties(String fileName) {
51+
Properties prop = new Properties();
52+
InputStream ins = null;
53+
ins = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
54+
if (ins == null) {
55+
System.err.println("Can not find the resource!");
56+
} else {
57+
try {
58+
prop.load(ins);
59+
} catch (IOException e) {
60+
System.err.println("An error occurred when reading from the input stream, " + e.getMessage());
61+
} catch (IllegalArgumentException e) {
62+
System.err.println("The input stream contains a malformed Unicode escape sequence, " + e.getMessage());
63+
}
64+
}
65+
return prop;
66+
}
67+
68+
public static Boolean isExistProperties(String filePath) {
69+
URL resource = PropertiesUtil.class.getClassLoader().getResource(filePath);
70+
return resource != null;
71+
}
72+
73+
/**
74+
* 从指定的属性文件中获取某一属性值
75+
* 如果属性文件不存在该属性则返回 null
76+
*/
77+
public static String getProperty(String fileName, String name) {
78+
return getProperties(fileName).getProperty(name);
79+
}
80+
81+
/**
82+
* 从默认的属性文件中获取某一属性值
83+
* 如果属性文件不存在该属性则返回 null
84+
*/
85+
public static String getProperty(String name) {
86+
return getProperties(null).getProperty(name);
87+
}
88+
89+
/**
90+
* @param properties
91+
* @return
92+
*/
93+
public static Map<String, String> getPropertyMap(Properties properties) {
94+
return properties.values()
95+
.stream()
96+
.collect(Collectors.toMap(k -> k.toString(), v -> v.toString()));
97+
}
98+
99+
/**
100+
* @return
101+
*/
102+
public static Map<String, String> getPropertyMap() {
103+
Map<String, String> allPropsMap = new HashMap<>();
104+
allProps.values().forEach(props -> {
105+
final Map<String, String> mapProperties = getPropertyMap(props);
106+
allPropsMap.putAll(mapProperties);
107+
});
108+
return allPropsMap;
109+
}
110+
111+
/**
112+
* 获取所有的 key
113+
* @param fileName
114+
* @return
115+
* @throws IOException
116+
*/
117+
public static List<String> getkeys(String fileName) throws IOException {
118+
Properties prop = new Properties();
119+
//获取输入流
120+
InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName);
121+
//加载进去
122+
prop.load(in);
123+
Set keyValue = prop.keySet();
124+
List<String> list = new ArrayList<>();
125+
for (Iterator it = keyValue.iterator(); it.hasNext();)
126+
{
127+
String key = (String) it.next();
128+
list.add(key);
129+
}
130+
return list;
131+
}
132+
133+
//test
134+
public static void main(String[] args) throws IOException {
135+
List<String> keys = getkeys("application.properties");
136+
System.out.println(keys);
137+
for (String key:keys) {
138+
String value = PropertiesUtil.getProperty("application.properties", key);
139+
System.out.println(value);
140+
}
141+
loadProperties("application.properties").keySet().forEach(it -> System.out.println(it));
142+
getkeys("application.properties").forEach(it -> System.out.println(it));
143+
getProperties("application.properties").keySet().forEach(it-> System.out.println(it));
144+
}
145+
}

0 commit comments

Comments
 (0)
Please sign in to comment.