Skip to content

Commit

Permalink
Merge branch 'master' into improve-add-flink-on-yarn-monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsun28 authored Jun 16, 2024
2 parents 1cc86c8 + b7217b5 commit b1a0071
Show file tree
Hide file tree
Showing 76 changed files with 4,413 additions and 737 deletions.
27 changes: 27 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,33 @@
"contributions": [
"doc"
]
},
{
"login": "yykaue",
"name": "Limbo",
"avatar_url": "https://avatars.githubusercontent.com/u/22905143?v=4",
"profile": "https://github.com/yykaue",
"contributions": [
"code"
]
},
{
"login": "irenhongyan",
"name": "哈哈哈哈哈哈哈哈哈",
"avatar_url": "https://avatars.githubusercontent.com/u/53438321?v=4",
"profile": "https://github.com/irenhongyan",
"contributions": [
"code"
]
},
{
"login": "ileonli",
"name": "Leon Li",
"avatar_url": "https://avatars.githubusercontent.com/u/45332412?v=4",
"profile": "https://github.com/ileonli",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ Thanks to these wonderful people, welcome to join us:
<td align="center" valign="top" width="14.28%"><a href="https://www.yitianyigexiangfa.com/"><img src="https://avatars.githubusercontent.com/u/3973419?v=4?s=100" width="100px;" alt="Bill Lau"/><br /><sub><b>Bill Lau</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=JavaProgrammerLB" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lw-yang"><img src="https://avatars.githubusercontent.com/u/23456873?v=4?s=100" width="100px;" alt="lwyang"/><br /><sub><b>lwyang</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=lw-yang" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/xfl12345"><img src="https://avatars.githubusercontent.com/u/17960863?v=4?s=100" width="100px;" alt="xfl12345"/><br /><sub><b>xfl12345</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=xfl12345" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yykaue"><img src="https://avatars.githubusercontent.com/u/22905143?v=4?s=100" width="100px;" alt="Limbo"/><br /><sub><b>Limbo</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=yykaue" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/irenhongyan"><img src="https://avatars.githubusercontent.com/u/53438321?v=4?s=100" width="100px;" alt="哈哈哈哈哈哈哈哈哈"/><br /><sub><b>哈哈哈哈哈哈哈哈哈</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=irenhongyan" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ileonli"><img src="https://avatars.githubusercontent.com/u/45332412?v=4?s=100" width="100px;" alt="Leon Li"/><br /><sub><b>Leon Li</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=ileonli" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
5 changes: 5 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ Thanks these wonderful people, welcome to join us:
<td align="center" valign="top" width="14.28%"><a href="https://www.yitianyigexiangfa.com/"><img src="https://avatars.githubusercontent.com/u/3973419?v=4?s=100" width="100px;" alt="Bill Lau"/><br /><sub><b>Bill Lau</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=JavaProgrammerLB" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/lw-yang"><img src="https://avatars.githubusercontent.com/u/23456873?v=4?s=100" width="100px;" alt="lwyang"/><br /><sub><b>lwyang</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=lw-yang" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/xfl12345"><img src="https://avatars.githubusercontent.com/u/17960863?v=4?s=100" width="100px;" alt="xfl12345"/><br /><sub><b>xfl12345</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=xfl12345" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/yykaue"><img src="https://avatars.githubusercontent.com/u/22905143?v=4?s=100" width="100px;" alt="Limbo"/><br /><sub><b>Limbo</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=yykaue" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/irenhongyan"><img src="https://avatars.githubusercontent.com/u/53438321?v=4?s=100" width="100px;" alt="哈哈哈哈哈哈哈哈哈"/><br /><sub><b>哈哈哈哈哈哈哈哈哈</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=irenhongyan" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ileonli"><img src="https://avatars.githubusercontent.com/u/45332412?v=4?s=100" width="100px;" alt="Leon Li"/><br /><sub><b>Leon Li</b></sub></a><br /><a href="https://github.com/apache/hertzbeat/commits?author=ileonli" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private DnsResolveResult dig(DnsProtocol dns) throws IOException {
responseTimeStopWatch.start();

Name name = Name.fromString(dns.getAddress(), Name.root);
Message query = Message.newQuery(Record.newRecord(name, Type.ANY, DClass.ANY));
Message query = Message.newQuery(Record.newRecord(name, Type.ANY, DClass.value(dns.getQueryClass())));
Resolver res = new SimpleResolver(dns.getDnsServerIP());
res.setTimeout(Duration.of(Long.parseLong(dns.getTimeout()), ChronoUnit.MILLIS));
res.setTCP(Boolean.parseBoolean(dns.getTcp()));
Expand Down Expand Up @@ -195,7 +195,7 @@ private Map<String, String> getHeaderInfo(Message message, Long responseTime) {

private List<String> getSectionInfo(Message message, int section) {
List<RRset> currentSetList = message.getSectionRRsets(section);

if (CollectionUtils.isEmpty(currentSetList)) {
return Lists.newArrayList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void collect(CollectRep.MetricsData.Builder builder,
// Option 1: Parse using InputStream, but this requires significant code changes;
// Option 2: Manually trigger garbage collection, similar to how it's done in Dubbo for large inputs.
String resp = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (StringUtils.hasText(resp)) {
if (!StringUtils.hasText(resp)) {
log.info("http response entity is empty, status: {}.", statusCode);
}
Long responseTime = System.currentTimeMillis() - startTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.collector.collect.imap;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.net.imap.IMAPClient;
import org.apache.commons.net.imap.IMAPSClient;
import org.apache.hertzbeat.collector.collect.AbstractCollect;
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
import org.apache.hertzbeat.collector.util.CollectUtil;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.job.Metrics;
import org.apache.hertzbeat.common.entity.job.protocol.ImapProtocol;
import org.apache.hertzbeat.common.entity.message.CollectRep;
import org.apache.hertzbeat.common.util.CommonUtil;
import org.springframework.util.Assert;

/**
* imap collect
*/
@Slf4j
public class ImapCollectImpl extends AbstractCollect {

private static final String UTF_7_X = "X-MODIFIED-UTF-7";
private static final String STATUS = "STATUS";
private static final String STATUS_COMMAND = "(MESSAGES RECENT UNSEEN)";
private static final String MESSAGES = "MESSAGES";
private static final String RECENT = "RECENT";
private static final String UNSEEN = "UNSEEN";
private static final String RESPONSETIME = "responseTime";
private static final String totalMessageCount = "TotalMessageCount";
private static final String recentMessageCount = "RecentMessageCount";
private static final String unseenMessageCount = "UnseenMessageCount";

@Override
public void preCheck(Metrics metrics) throws IllegalArgumentException {
ImapProtocol imapProtocol = metrics.getImap();
Assert.notNull(metrics, "IMAP collect must has Imap params");
Assert.notNull(metrics.getImap(), "IMAP collect must has Imap params");
Assert.hasText(imapProtocol.getHost(), "IMAP host is required");
Assert.hasText(imapProtocol.getPort(), "IMAP port is required");
Assert.hasText(imapProtocol.getEmail(), "IMAP email is required");
Assert.hasText(imapProtocol.getAuthorize(), "IMAP authorize code is required");
Assert.hasText(imapProtocol.getFolderName(), "IMAP folder name is required");
}

@Override
public void collect(CollectRep.MetricsData.Builder builder, long monitorId, String app, Metrics metrics) {
long startTime = System.currentTimeMillis();
ImapProtocol imapProtocol = metrics.getImap();
IMAPClient imapClient = null;
boolean ssl = Boolean.parseBoolean(imapProtocol.getSsl());

try {
imapClient = createImapClient(imapProtocol, ssl);
// if Connected, then collect metrics
if (imapClient.isConnected()) {
long responseTime = System.currentTimeMillis() - startTime;
String folderName = imapProtocol.getFolderName();
collectImapMetrics(builder, imapClient, metrics.getAliasFields(), folderName, responseTime);
} else {
builder.setCode(CollectRep.Code.UN_CONNECTABLE);
builder.setMsg("Peer connect failed,Timeout " + imapProtocol.getTimeout() + "ms");
}
} catch (Exception e) {
String errorMsg = CommonUtil.getMessageFromThrowable(e);
log.error(errorMsg);
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg(errorMsg);
} finally {
if (imapClient != null) {
try {
imapClient.logout();
imapClient.disconnect();
} catch (IOException e) {
String errorMsg = CommonUtil.getMessageFromThrowable(e);
log.error(errorMsg);
builder.setCode(CollectRep.Code.FAIL);
builder.setMsg(errorMsg);
}
}
}
}

@Override
public String supportProtocol() {
return DispatchConstants.PROTOCOL_IMAP;
}

private IMAPClient createImapClient(ImapProtocol imapProtocol, boolean ssl) throws Exception {
IMAPClient imapClient = null;
// determine whether to use SSL-encrypted connections
imapClient = new IMAPSClient(true);
if (!ssl) {
imapClient = new IMAPClient();
}
// set timeout
int timeout = Integer.parseInt(imapProtocol.getTimeout());
if (timeout > 0) {
imapClient.setConnectTimeout(timeout);
}
//set Charset
imapClient.setCharset(StandardCharsets.US_ASCII);
// connect to the IMAP server
String host = imapProtocol.getHost();
int port = Integer.parseInt(imapProtocol.getPort());
imapClient.connect(host, port);
// validate credentials
String email = imapProtocol.getEmail();
String authorize = imapProtocol.getAuthorize();
boolean isAuthenticated = imapClient.login(email, authorize);
if (!isAuthenticated) {
throw new Exception("IMAP client authentication failed");
}
return imapClient;

}

private void collectImapMetrics(CollectRep.MetricsData.Builder builder, IMAPClient imapClient, List<String> aliasFields,
String folderName, long responseTime) throws Exception {
Map<String, String> resultsMap = new HashMap<>();
resultsMap.put(RESPONSETIME, String.valueOf(responseTime));
imapClient.sendCommand(STATUS + " \"" + CollectUtil.stringEncodeUtf7String(folderName, UTF_7_X) + "\" " + STATUS_COMMAND);
String[] response = imapClient.getReplyString().split("\\s+|\\(|\\)");
for (int i = 0; i < response.length; i++) {
switch (response[i]) {
case MESSAGES:
resultsMap.put(folderName + totalMessageCount, response[i + 1]);
break;
case RECENT:
resultsMap.put(folderName + recentMessageCount, response[i + 1]);
break;
case UNSEEN:
resultsMap.put(folderName + unseenMessageCount, response[i + 1]);
break;
default:
break;
}
}

CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
for (String field : aliasFields) {
String fieldValue = resultsMap.get(field);
valueRowBuilder.addColumns(Objects.requireNonNullElse(fieldValue, CommonConstants.NULL_VALUE));
}
builder.addValues(valueRowBuilder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.hertzbeat.collector.collect.common.cache.ConnectionCommonCache;
import org.apache.hertzbeat.collector.collect.common.cache.MongodbConnect;
import org.apache.hertzbeat.collector.dispatch.DispatchConstants;
import org.apache.hertzbeat.common.constants.CollectorConstants;
import org.apache.hertzbeat.common.constants.CommonConstants;
import org.apache.hertzbeat.common.entity.job.Metrics;
import org.apache.hertzbeat.common.entity.job.protocol.MongodbProtocol;
Expand Down Expand Up @@ -188,11 +189,20 @@ private MongoClient getClient(Metrics metrics, CacheIdentifier identifier) {
if (mongoClient != null) {
return mongoClient;
}
// If the multiplexing fails, create a new connection to connect to mongodb
// Passwords may contain special characters and need to be encoded using JS-like encodeURIComponent, which uses java URLEncoder
String url = String.format("mongodb://%s:%s@%s:%s/%s?authSource=%s", mongodbProtocol.getUsername(),
URLEncoder.encode(mongodbProtocol.getPassword(), StandardCharsets.UTF_8), mongodbProtocol.getHost(), mongodbProtocol.getPort(),
mongodbProtocol.getDatabase(), mongodbProtocol.getAuthenticationDatabase());

String url = null;
if (CollectorConstants.MONGO_DB_ATLAS_MODEL.equals(mongodbProtocol.getModel())){
url = String.format("mongodb+srv://%s:%s@%s/%s?authSource=%s", mongodbProtocol.getUsername(),
URLEncoder.encode(mongodbProtocol.getPassword(), StandardCharsets.UTF_8), mongodbProtocol.getHost(),
mongodbProtocol.getDatabase(), mongodbProtocol.getAuthenticationDatabase());
} else {
// If the multiplexing fails, create a new connection to connect to mongodb
// Passwords may contain special characters and need to be encoded using JS-like encodeURIComponent, which uses java URLEncoder
url = String.format("mongodb://%s:%s@%s:%s/%s?authSource=%s", mongodbProtocol.getUsername(),
URLEncoder.encode(mongodbProtocol.getPassword(), StandardCharsets.UTF_8), mongodbProtocol.getHost(), mongodbProtocol.getPort(),
mongodbProtocol.getDatabase(), mongodbProtocol.getAuthenticationDatabase());
}

// Use the Mongo Client Settings builder to configure timeouts and other configurations
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(new ConnectionString(url))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.hertzbeat.collector.dispatch;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* Collector info configuration Properties
*/
@Component
@ConfigurationProperties(prefix = CollectorInfoProperties.INFO_PREFIX)
public class CollectorInfoProperties {
protected static final String INFO_PREFIX = "collector.info";

private String version;
private String ip;

public String getVersion() {
return version;
}

public void setVersion(String version) {
this.version = version;
}

public String getIp() {
return ip;
}

public void setIp(String ip) {
this.ip = ip;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public interface DispatchConstants {
* protocol redfish
*/
String PROTOCOL_REDFISH = "redfish";
/**
* protocol imap
*/
String PROTOCOL_IMAP = "imap";

// Protocol type related - end

Expand Down
Loading

0 comments on commit b1a0071

Please sign in to comment.