mirror of
https://github.com/dromara/hertzbeat.git
synced 2026-09-17 09:40:58 +00:00
fix the collect code checkstyle (#1593)
Co-authored-by: Logic <zqr10159@dromara.org>
This commit is contained in:
committed by
GitHub
co-authored by
Logic
parent
411eb58f3a
commit
e82f1ed9a2
Vendored
+1
@@ -25,6 +25,7 @@ public class MongodbConnect implements CacheCloseable {
|
||||
log.error("[connection common cache] close mongodb connect error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public MongoClient getMongoClient() {
|
||||
return mongoClient;
|
||||
}
|
||||
|
||||
+3
-1
@@ -87,7 +87,7 @@ public class CommonHttpClient {
|
||||
/**
|
||||
* ssl supported version
|
||||
*/
|
||||
private static final String[] SUPPORTED_SSL = {"TLSv1","TLSv1.1","TLSv1.2","SSLv3"};
|
||||
private static final String[] SUPPORTED_SSL = {"TLSv1", "TLSv1.1", "TLSv1.2", "SSLv3"};
|
||||
|
||||
static {
|
||||
try {
|
||||
@@ -95,6 +95,7 @@ public class CommonHttpClient {
|
||||
X509TrustManager x509TrustManager = new X509TrustManager() {
|
||||
@Override
|
||||
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) { }
|
||||
|
||||
@Override
|
||||
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
|
||||
// check server ssl certificate expired
|
||||
@@ -108,6 +109,7 @@ public class CommonHttpClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public X509Certificate[] getAcceptedIssuers() { return null; }
|
||||
};
|
||||
|
||||
-2
@@ -7,10 +7,8 @@ import org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier;
|
||||
import org.apache.sshd.common.NamedFactory;
|
||||
import org.apache.sshd.common.PropertyResolverUtils;
|
||||
import org.apache.sshd.common.kex.BuiltinDHFactories;
|
||||
import org.apache.sshd.common.signature.BuiltinSignatures;
|
||||
import org.apache.sshd.core.CoreModuleProperties;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* common ssh pool client
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect {
|
||||
}
|
||||
|
||||
|
||||
private Statement getConnection(String username, String password, String url,Integer timeout) throws Exception {
|
||||
private Statement getConnection(String username, String password, String url, Integer timeout) throws Exception {
|
||||
CacheIdentifier identifier = CacheIdentifier.builder()
|
||||
.ip(url)
|
||||
.username(username).password(password).build();
|
||||
|
||||
+9
-9
@@ -84,7 +84,7 @@ public class DnsCollectImpl extends AbstractCollect {
|
||||
return;
|
||||
}
|
||||
|
||||
DNSResolveResult dnsResolveResult;
|
||||
DnsResolveResult dnsResolveResult;
|
||||
try {
|
||||
// run dig command
|
||||
dnsResolveResult = dig(metrics.getDns());
|
||||
@@ -132,7 +132,7 @@ public class DnsCollectImpl extends AbstractCollect {
|
||||
/**
|
||||
* run dig command
|
||||
*/
|
||||
private DNSResolveResult dig(DnsProtocol dns) throws IOException {
|
||||
private DnsResolveResult dig(DnsProtocol dns) throws IOException {
|
||||
StopWatch responseTimeStopWatch = new StopWatch("responseTime");
|
||||
responseTimeStopWatch.start();
|
||||
|
||||
@@ -148,8 +148,8 @@ public class DnsCollectImpl extends AbstractCollect {
|
||||
return resolve(response, responseTimeStopWatch.getLastTaskTimeMillis());
|
||||
}
|
||||
|
||||
private DNSResolveResult resolve(Message message, Long responseTime) {
|
||||
return DNSResolveResult.builder()
|
||||
private DnsResolveResult resolve(Message message, Long responseTime) {
|
||||
return DnsResolveResult.builder()
|
||||
.headerInfo(getHeaderInfo(message, responseTime))
|
||||
.questionList(getSectionInfo(message, Section.QUESTION))
|
||||
.answerList(getSectionInfo(message, Section.ANSWER))
|
||||
@@ -173,13 +173,13 @@ public class DnsCollectImpl extends AbstractCollect {
|
||||
}
|
||||
|
||||
private List<String> getSectionInfo(Message message, int section) {
|
||||
List<RRset> currentRRsetList = message.getSectionRRsets(section);
|
||||
if (currentRRsetList == null || currentRRsetList.size() <= 0) {
|
||||
List<RRset> currentSetList = message.getSectionRRsets(section);
|
||||
if (currentSetList == null || currentSetList.size() <= 0) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
List<String> infoList = Lists.newArrayListWithCapacity(currentRRsetList.size());
|
||||
currentRRsetList.forEach(res -> infoList.add(res.toString()));
|
||||
List<String> infoList = Lists.newArrayListWithCapacity(currentSetList.size());
|
||||
currentSetList.forEach(res -> infoList.add(res.toString()));
|
||||
|
||||
return infoList;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ public class DnsCollectImpl extends AbstractCollect {
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
private static class DNSResolveResult {
|
||||
private static class DnsResolveResult {
|
||||
private Map<String, String> headerInfo;
|
||||
/** example: www.google.com. 140 IN A 192.133.77.133 **/
|
||||
private List<String> questionList;
|
||||
|
||||
+3
-3
@@ -96,14 +96,14 @@ public class FtpCollectImpl extends AbstractCollect {
|
||||
private void login(FTPClient ftpClient, FtpProtocol ftpProtocol) {
|
||||
try {
|
||||
// username: not empty, password: not empty
|
||||
if(StringUtils.hasText(ftpProtocol.getUsername()) && StringUtils.hasText(ftpProtocol.getPassword())) {
|
||||
if(!ftpClient.login(ftpProtocol.getUsername(), ftpProtocol.getPassword())) {
|
||||
if (StringUtils.hasText(ftpProtocol.getUsername()) && StringUtils.hasText(ftpProtocol.getPassword())) {
|
||||
if (!ftpClient.login(ftpProtocol.getUsername(), ftpProtocol.getPassword())) {
|
||||
throw new IllegalArgumentException("The username or password may be wrong.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// anonymous access
|
||||
if(!ftpClient.login(ANONYMOUS, PASSWORD)) {
|
||||
if (!ftpClient.login(ANONYMOUS, PASSWORD)) {
|
||||
throw new IllegalArgumentException("The server may not allow anonymous access, we need to username and password.");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ public class SslCertificateCollectImpl extends AbstractCollect {
|
||||
} else {
|
||||
uri = "https://" + httpProtocol.getHost() + ":" + httpProtocol.getPort();
|
||||
}
|
||||
urlConnection = (HttpsURLConnection)new URL(uri).openConnection();
|
||||
urlConnection = (HttpsURLConnection) new URL(uri).openConnection();
|
||||
urlConnection.connect();
|
||||
Certificate[] certificates = urlConnection.getServerCertificates();
|
||||
if (certificates == null || certificates.length == 0) {
|
||||
|
||||
+10
-10
@@ -28,27 +28,27 @@ public abstract class AbstractPrometheusParse {
|
||||
/**
|
||||
* prom响应类型校验:string、matrix、vector、scalar
|
||||
* todo:string、scalar类型响应未实现
|
||||
* @param responseStr
|
||||
* @return
|
||||
* @param responseStr 返回字符串
|
||||
* @return return
|
||||
*/
|
||||
abstract Boolean checkType(String responseStr);
|
||||
|
||||
/**
|
||||
* 解析prom接口响应数据
|
||||
* @param resp
|
||||
* @param aliasFields
|
||||
* @param http
|
||||
* @param builder
|
||||
* @param resp 返回数据
|
||||
* @param aliasFields alias fields
|
||||
* @param http httpProtocol
|
||||
* @param builder builder
|
||||
*/
|
||||
abstract void parse(String resp, List<String> aliasFields, HttpProtocol http,
|
||||
CollectRep.MetricsData.Builder builder);
|
||||
|
||||
/**
|
||||
* 处理prom接口响应数据
|
||||
* @param resp
|
||||
* @param aliasFields
|
||||
* @param http
|
||||
* @param builder
|
||||
* @param resp resp
|
||||
* @param aliasFields alias fields
|
||||
* @param http http
|
||||
* @param builder builder
|
||||
*/
|
||||
public void handle(String resp, List<String> aliasFields, HttpProtocol http,
|
||||
CollectRep.MetricsData.Builder builder) {
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ import java.util.List;
|
||||
public class PrometheusLastParser extends AbstractPrometheusParse {
|
||||
@Override
|
||||
public Boolean checkType(String responseStr) {
|
||||
log.error("prometheus response data:{} ,no adaptive parser",responseStr);
|
||||
return true;
|
||||
log.error("prometheus response data:{} ,no adaptive parser", responseStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ public class PrometheusMatrixParser extends AbstractPrometheusParse {
|
||||
public Boolean checkType(String responseStr) {
|
||||
try {
|
||||
PromVectorOrMatrix promVectorOrMatrix = JsonUtil.fromJson(responseStr, PromVectorOrMatrix.class);
|
||||
if(promVectorOrMatrix != null && promVectorOrMatrix.getData() != null) {
|
||||
if (promVectorOrMatrix != null && promVectorOrMatrix.getData() != null) {
|
||||
return DispatchConstants.PARSE_PROM_QL_MATRIX.equals(promVectorOrMatrix.getData().getResultType());
|
||||
}
|
||||
return false;
|
||||
|
||||
+1
@@ -16,6 +16,7 @@ public class PrometheusParseCreater implements InitializingBean {
|
||||
private static void create() {
|
||||
PROMETHEUSPARSE.setInstance(new PrometheusMatrixParser().setInstance(new PrometheusLastParser()));
|
||||
}
|
||||
|
||||
public static AbstractPrometheusParse getPrometheusParse(){
|
||||
return PROMETHEUSPARSE;
|
||||
}
|
||||
|
||||
+96
@@ -36,6 +36,9 @@ public class MetricFamily {
|
||||
*/
|
||||
private List<Metric> metricList;
|
||||
|
||||
/**
|
||||
* Metric
|
||||
*/
|
||||
@Data
|
||||
public static class Metric {
|
||||
|
||||
@@ -44,66 +47,135 @@ public class MetricFamily {
|
||||
*/
|
||||
private List<Label> labelPair;
|
||||
|
||||
/**
|
||||
* info
|
||||
*/
|
||||
private Info info;
|
||||
|
||||
/**
|
||||
* gauge
|
||||
*/
|
||||
private Gauge gauge;
|
||||
|
||||
/**
|
||||
* counter
|
||||
*/
|
||||
private Counter counter;
|
||||
|
||||
/**
|
||||
* summary
|
||||
*/
|
||||
private Summary summary;
|
||||
|
||||
/**
|
||||
* untyped
|
||||
*/
|
||||
private Untyped untyped;
|
||||
|
||||
/**
|
||||
* histogram
|
||||
*/
|
||||
private Histogram histogram;
|
||||
|
||||
/**
|
||||
* timestampMs
|
||||
*/
|
||||
private Long timestampMs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Label
|
||||
*/
|
||||
@Data
|
||||
public static class Label {
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private String value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Info
|
||||
*/
|
||||
@Data
|
||||
public static class Info {
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Counter
|
||||
*/
|
||||
@Data
|
||||
public static class Counter {
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
|
||||
// Exemplar
|
||||
}
|
||||
|
||||
/**
|
||||
* Gauge
|
||||
*/
|
||||
@Data
|
||||
public static class Gauge {
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
}
|
||||
|
||||
/**
|
||||
* untyped
|
||||
*/
|
||||
@Data
|
||||
public static class Untyped {
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary
|
||||
*/
|
||||
@Data
|
||||
public static class Summary {
|
||||
|
||||
/**
|
||||
* count
|
||||
*/
|
||||
private long count;
|
||||
|
||||
/**
|
||||
* sum
|
||||
*/
|
||||
private double sum;
|
||||
|
||||
/**
|
||||
* quantileList
|
||||
*/
|
||||
private List<Quantile> quantileList = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Quantile
|
||||
*/
|
||||
@Data
|
||||
public static class Quantile {
|
||||
/**
|
||||
@@ -111,24 +183,48 @@ public class MetricFamily {
|
||||
*/
|
||||
private double xLabel;
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Histogram
|
||||
*/
|
||||
@Data
|
||||
public static class Histogram {
|
||||
|
||||
/**
|
||||
* count
|
||||
*/
|
||||
private long count;
|
||||
|
||||
/**
|
||||
* sum
|
||||
*/
|
||||
private double sum;
|
||||
|
||||
/**
|
||||
* bucketList
|
||||
*/
|
||||
private List<Bucket> bucketList = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Bucket
|
||||
*/
|
||||
@Data
|
||||
public static class Bucket {
|
||||
|
||||
/**
|
||||
* cumulativeCount
|
||||
*/
|
||||
private long cumulativeCount;
|
||||
|
||||
/**
|
||||
* upperBound
|
||||
*/
|
||||
private double upperBound;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -118,7 +118,7 @@ public class JmxCollectImpl extends AbstractCollect {
|
||||
} else if (value instanceof String[]) {
|
||||
String[] values = (String[]) value;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int index = 0; index < values.length; index ++) {
|
||||
for (int index = 0; index < values.length; index++) {
|
||||
builder.append(values[index]);
|
||||
if (index < values.length - 1) {
|
||||
builder.append(",");
|
||||
|
||||
+3
-3
@@ -60,8 +60,8 @@ public class MemcachedCollectImpl extends AbstractCollect {
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
// 发送统计命令
|
||||
Map<String, String> resultMap = new HashMap<>(128);
|
||||
parseCMDResponse(resultMap, in, out, STATS);
|
||||
parseCMDResponse(resultMap, in, out, STATS_SETTINGS);
|
||||
parseCmdResponse(resultMap, in, out, STATS);
|
||||
parseCmdResponse(resultMap, in, out, STATS_SETTINGS);
|
||||
parseSizesOutput(resultMap, in, out);
|
||||
|
||||
resultMap.put(CollectorConstants.RESPONSE_TIME, Long.toString(responseTime));
|
||||
@@ -107,7 +107,7 @@ public class MemcachedCollectImpl extends AbstractCollect {
|
||||
}
|
||||
}
|
||||
|
||||
private static void parseCMDResponse(Map<String, String> statsMap,
|
||||
private static void parseCmdResponse(Map<String, String> statsMap,
|
||||
BufferedReader in,
|
||||
PrintWriter out,
|
||||
String cmd) throws IOException {
|
||||
|
||||
+9
@@ -29,6 +29,9 @@ public class RocketmqCollectData {
|
||||
*/
|
||||
private List<Map<String, List<TopicQueueInfo>>> topicInfoList;
|
||||
|
||||
/**
|
||||
* ClusterBrokerData
|
||||
*/
|
||||
@Data
|
||||
public static class ClusterBrokerData {
|
||||
|
||||
@@ -78,6 +81,9 @@ public class RocketmqCollectData {
|
||||
private long todayConsumeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* ConsumerInfo
|
||||
*/
|
||||
@Data
|
||||
public static class ConsumerInfo {
|
||||
|
||||
@@ -112,6 +118,9 @@ public class RocketmqCollectData {
|
||||
private long diffTotal;
|
||||
}
|
||||
|
||||
/**
|
||||
* TopicQueueInfo
|
||||
*/
|
||||
@Data
|
||||
public static class TopicQueueInfo {
|
||||
|
||||
|
||||
-2
@@ -27,7 +27,6 @@ import org.dromara.hertzbeat.common.entity.job.Metrics;
|
||||
import org.dromara.hertzbeat.common.entity.job.protocol.RocketmqProtocol;
|
||||
import org.dromara.hertzbeat.common.entity.message.CollectRep;
|
||||
import org.dromara.hertzbeat.common.util.CommonUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -44,7 +43,6 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
||||
+25
-27
@@ -172,19 +172,18 @@ public class NginxCollectImpl extends AbstractCollect {
|
||||
/**
|
||||
* 解析nginx自带ngx_http_stub_status_module模块暴露信息
|
||||
*
|
||||
* @param builder
|
||||
* @param resp
|
||||
* @param metrics
|
||||
* @param responseTime
|
||||
* @param builder builder
|
||||
* @param resp resp
|
||||
* @param metrics metrics
|
||||
* @param responseTime responseTime
|
||||
*/
|
||||
private void parseNginxStatusResponse(CollectRep.MetricsData.Builder builder, String resp, Metrics metrics,
|
||||
Long responseTime) {
|
||||
/** example
|
||||
* Active connections: 2
|
||||
* server accepts handled requests
|
||||
* 4 4 2
|
||||
* Reading: 0 Writing: 1 Waiting: 1
|
||||
*/
|
||||
//example
|
||||
//Active connections: 2
|
||||
//server accepts handled requests
|
||||
//4 4 2
|
||||
//Reading: 0 Writing: 1 Waiting: 1
|
||||
List<String> aliasFields = metrics.getAliasFields();
|
||||
Map<String, Object> metricMap = regexNginxStatusMatch(resp, metrics.getAliasFields().size());
|
||||
// 返回数据
|
||||
@@ -207,26 +206,25 @@ public class NginxCollectImpl extends AbstractCollect {
|
||||
/**
|
||||
* 解析ngx_http_reqstat_module模块暴露信息
|
||||
*
|
||||
* @param builder
|
||||
* @param resp
|
||||
* @param metrics
|
||||
* @param responseTime
|
||||
* @param builder builder
|
||||
* @param resp resp
|
||||
* @param metrics metrics
|
||||
* @param responseTime responseTime
|
||||
*/
|
||||
private void parseReqStatusResponse(CollectRep.MetricsData.Builder builder, String resp, Metrics metrics,
|
||||
Long responseTime) {
|
||||
/** example
|
||||
* zone_name key max_active max_bw traffic requests active bandwidth
|
||||
* imgstore_appid 43 27 6M 63G 374063 0 0
|
||||
* imgstore_appid 53 329 87M 2058G 7870529 50 25M
|
||||
* server_addr 10.128.1.17 2 8968 24M 1849 0 0
|
||||
* server_addr 127.0.0.1 1 6M 5G 912 1 0
|
||||
* server_addr 180.96.x.1 3358 934M 27550G 141277391 891 356M
|
||||
* server_addr 180.96.x.2 78 45M 220G 400704 0 0
|
||||
* server_addr 180.96.x.3 242 58M 646G 2990547 42 7M
|
||||
* server_name d.123.sogou.com 478 115M 2850G 30218726 115 39M
|
||||
* server_name dl.pinyin.sogou.com 913 312M 8930G 35345453 225 97M
|
||||
* server_name download.ie.sogou.com 964 275M 7462G 7979817 297 135M
|
||||
*/
|
||||
//example
|
||||
//zone_name key max_active max_bw traffic requests active bandwidth
|
||||
//imgstore_appid 43 27 6M 63G 374063 0 0
|
||||
//imgstore_appid 53 329 87M 2058G 7870529 50 25M
|
||||
//server_addr 10.128.1.17 2 8968 24M 1849 0 0
|
||||
//server_addr 127.0.0.1 1 6M 5G 912 1 0
|
||||
//server_addr 180.96.x.1 3358 934M 27550G 141277391 891 356M
|
||||
//server_addr 180.96.x.2 78 45M 220G 400704 0 0
|
||||
//server_addr 180.96.x.3 242 58M 646G 2990547 42 7M
|
||||
//server_name d.123.sogou.com 478 115M 2850G 30218726 115 39M
|
||||
//server_name dl.pinyin.sogou.com 913 312M 8930G 35345453 225 97M
|
||||
//server_name download.ie.sogou.com 964 275M 7462G 7979817 297 135M
|
||||
List<ReqSatusResponse> reqSatusResponses = regexReqStatusMatch(resp);
|
||||
List<String> aliasFields = metrics.getAliasFields();
|
||||
|
||||
|
||||
+2
-2
@@ -59,7 +59,7 @@ public class NtpCollectImpl extends AbstractCollect {
|
||||
timeInfo.computeDetails();
|
||||
|
||||
// 获取ntp服务器信息
|
||||
Map<String, String> resultMap = getNTPInfo(timeInfo);
|
||||
Map<String, String> resultMap = getNtpInfo(timeInfo);
|
||||
resultMap.put(CollectorConstants.RESPONSE_TIME, Long.toString(responseTime));
|
||||
|
||||
List<String> aliasFields = metrics.getAliasFields();
|
||||
@@ -101,7 +101,7 @@ public class NtpCollectImpl extends AbstractCollect {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getNTPInfo(TimeInfo timeInfo) {
|
||||
private Map<String, String> getNtpInfo(TimeInfo timeInfo) {
|
||||
Map<String, String> valueMap = new HashMap<>(16);
|
||||
|
||||
TimeStamp timeStamp = timeInfo.getMessage().getTransmitTimeStamp();
|
||||
|
||||
+14
-14
@@ -94,8 +94,8 @@ public class Pop3CollectImpl extends AbstractCollect {
|
||||
|
||||
/**
|
||||
* 校验参数
|
||||
* @param metrics
|
||||
* @throws Exception
|
||||
* @param metrics metrics
|
||||
* @throws Exception exception
|
||||
*/
|
||||
private void validateParams(Metrics metrics) throws Exception {
|
||||
Pop3Protocol pop3Protocol = metrics.getPop3();
|
||||
@@ -106,10 +106,10 @@ public class Pop3CollectImpl extends AbstractCollect {
|
||||
|
||||
/**
|
||||
* 创建POP3连接【支持SSL加密】
|
||||
* @param pop3Protocol
|
||||
* @param ssl
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @param pop3Protocol pop3 Protocol
|
||||
* @param ssl ssl
|
||||
* @return return
|
||||
* @throws IOException IO Exception
|
||||
*/
|
||||
private POP3Client createPOP3Client(Pop3Protocol pop3Protocol, boolean ssl) throws Exception {
|
||||
POP3Client pop3Client = null;
|
||||
@@ -141,14 +141,14 @@ public class Pop3CollectImpl extends AbstractCollect {
|
||||
|
||||
/**
|
||||
* 获取Pop3指标信息
|
||||
* @param builder
|
||||
* @param pop3Client
|
||||
* @param aliasFields
|
||||
* @param responseTime
|
||||
* @param builder builder
|
||||
* @param pop3Client pop3 client
|
||||
* @param aliasFields alias Fields
|
||||
* @param responseTime response Time
|
||||
*/
|
||||
private void obtainPop3Metrics(CollectRep.MetricsData.Builder builder, POP3Client pop3Client,
|
||||
List<String> aliasFields, long responseTime) throws IOException {
|
||||
Map<String,Object> pop3Metrics = parsePop3Metrics(pop3Client, aliasFields);
|
||||
Map<String, Object> pop3Metrics = parsePop3Metrics(pop3Client, aliasFields);
|
||||
|
||||
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
|
||||
for (String alias : aliasFields) {
|
||||
@@ -166,15 +166,15 @@ public class Pop3CollectImpl extends AbstractCollect {
|
||||
builder.addValues(valueRowBuilder);
|
||||
}
|
||||
|
||||
private Map<String,Object> parsePop3Metrics(POP3Client pop3Client, List<String> aliasFields) throws IOException {
|
||||
Map<String,Object> pop3Metrics = new HashMap<>(aliasFields.size());
|
||||
private Map<String, Object> parsePop3Metrics(POP3Client pop3Client, List<String> aliasFields) throws IOException {
|
||||
Map<String, Object> pop3Metrics = new HashMap<>(aliasFields.size());
|
||||
POP3MessageInfo status = pop3Client.status();
|
||||
int emailCount = 0;
|
||||
double mailboxSize = 0.0;
|
||||
if (status != null) {
|
||||
emailCount = status.number;
|
||||
// byte -> kb
|
||||
mailboxSize = (double)status.size / 1024.0;
|
||||
mailboxSize = (double) status.size / 1024.0;
|
||||
pop3Metrics.put(EMAIL_COUNT, emailCount);
|
||||
pop3Metrics.put(MAILBOX_SIZE, mailboxSize);
|
||||
}
|
||||
|
||||
+22
-1
@@ -23,21 +23,42 @@ public class MetricFamily {
|
||||
*/
|
||||
private List<Metric> metricList;
|
||||
|
||||
/**
|
||||
* Metric
|
||||
*/
|
||||
@Data
|
||||
public static class Metric {
|
||||
|
||||
|
||||
/**
|
||||
* labels
|
||||
*/
|
||||
private List<Label> labels;
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private double value;
|
||||
|
||||
/**
|
||||
* timestamp
|
||||
*/
|
||||
private long timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Label
|
||||
*/
|
||||
@Data
|
||||
public static class Label {
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* value
|
||||
*/
|
||||
private String value;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ public class RedisCommonCollectImpl extends AbstractCollect {
|
||||
private Map<String, String> getSingleRedisInfo(Metrics metrics) {
|
||||
StatefulRedisConnection<String, String> connection = getSingleConnection(metrics.getRedis());
|
||||
String info = connection.sync().info(metrics.getName());
|
||||
Map<String, String> valueMap = parseInfo(info ,metrics);
|
||||
Map<String, String> valueMap = parseInfo(info, metrics);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("[RedisSingleCollectImpl] fetch redis info");
|
||||
valueMap.forEach((k, v) -> log.debug("{} : {}", k, v));
|
||||
|
||||
+7
-3
@@ -92,12 +92,12 @@ public class SnmpCollectImpl extends AbstractCollect {
|
||||
+ "/" + snmpProtocol.getPort());
|
||||
TargetBuilder<?> targetBuilder = snmpBuilder.target(targetAddress);
|
||||
if (snmpVersion == SnmpConstants.version3) {
|
||||
TargetBuilder.PrivProtocol PrivPasswordEncryption = getPrivPasswordEncryption(snmpProtocol.getPrivPasswordEncryption());
|
||||
TargetBuilder.PrivProtocol privatePasswordEncryption = getPrivPasswordEncryption(snmpProtocol.getPrivPasswordEncryption());
|
||||
TargetBuilder.AuthProtocol authPasswordEncryption = getAuthPasswordEncryption(snmpProtocol.getAuthPasswordEncryption());
|
||||
target = targetBuilder
|
||||
.user(snmpProtocol.getUsername())
|
||||
.auth(authPasswordEncryption).authPassphrase(snmpProtocol.getAuthPassphrase())
|
||||
.priv(PrivPasswordEncryption).privPassphrase(snmpProtocol.getPrivPassphrase())
|
||||
.priv(privatePasswordEncryption).privPassphrase(snmpProtocol.getPrivPassphrase())
|
||||
.done()
|
||||
.timeout(timeout).retries(1)
|
||||
.build();
|
||||
@@ -105,7 +105,11 @@ public class SnmpCollectImpl extends AbstractCollect {
|
||||
SecurityModels.getInstance().addSecurityModel(usm);
|
||||
snmpService.getUSM().addUser(
|
||||
new OctetString(snmpProtocol.getUsername()),
|
||||
new UsmUser(new OctetString(snmpProtocol.getUsername()), AuthMD5.ID, new OctetString(snmpProtocol.getAuthPassphrase()), PrivDES.ID, new OctetString(snmpProtocol.getPrivPassphrase()))
|
||||
new UsmUser(new OctetString(snmpProtocol.getUsername()),
|
||||
AuthMD5.ID,
|
||||
new OctetString(snmpProtocol.getAuthPassphrase()),
|
||||
PrivDES.ID,
|
||||
new OctetString(snmpProtocol.getPrivPassphrase()))
|
||||
);
|
||||
} else if (snmpVersion == SnmpConstants.version1) {
|
||||
target = targetBuilder
|
||||
|
||||
+3
-3
@@ -45,9 +45,9 @@ public class WebsocketCollectImpl extends AbstractCollect {
|
||||
builder.setMsg("Websocket collect must has Websocket params");
|
||||
return;
|
||||
}
|
||||
WebsocketProtocol WebsocketProtocol = metrics.getWebsocket();
|
||||
String host = WebsocketProtocol.getHost();
|
||||
String port = WebsocketProtocol.getPort();
|
||||
WebsocketProtocol websocketProtocol = metrics.getWebsocket();
|
||||
String host = websocketProtocol.getHost();
|
||||
String port = websocketProtocol.getPort();
|
||||
Socket socket = null;
|
||||
try {
|
||||
socket = new Socket();
|
||||
|
||||
+8
-3
@@ -71,9 +71,11 @@ public class DispatchProperties {
|
||||
public void setNetty(NettyProperties netty) {
|
||||
this.netty = netty;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Netty Properties
|
||||
*/
|
||||
public static class NettyProperties {
|
||||
|
||||
/**
|
||||
@@ -166,6 +168,9 @@ public class DispatchProperties {
|
||||
this.kafka = kafka;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kafka Properties
|
||||
*/
|
||||
public static class KafkaProperties {
|
||||
/**
|
||||
* Whether the kafka data export is started
|
||||
|
||||
+3
@@ -99,6 +99,9 @@ public class CollectServer implements CommandLineRunner {
|
||||
this.remotingClient.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* CollectNettyEventListener
|
||||
*/
|
||||
public class CollectNettyEventListener implements NettyEventListener {
|
||||
|
||||
@Override
|
||||
|
||||
-1
@@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
Reference in New Issue
Block a user