-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into release-1.6.0-rc2-doc-update
- Loading branch information
Showing
39 changed files
with
1,020 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
collector/src/main/java/org/apache/hertzbeat/collector/util/TimeExpressionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* 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.util; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
import java.time.temporal.TemporalUnit; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* time expression deal util | ||
*/ | ||
public class TimeExpressionUtil { | ||
|
||
private TimeExpressionUtil() { | ||
} | ||
|
||
|
||
/** | ||
* localDatetime formatter | ||
*/ | ||
private static final Map<String, Function<LocalDateTime, String>> FORMATTER = new LinkedHashMap<>(); | ||
/** | ||
* unit string mapping to TemporalUnit | ||
*/ | ||
private static final Map<Character, TemporalUnit> UNIT_MAP = new HashMap<>(); | ||
|
||
private static final String FORMATTER_NAMES; | ||
private static final String UNIT_NAMES; | ||
|
||
|
||
static { | ||
FORMATTER.put("now", date -> DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").format(date)); | ||
FORMATTER.put("date", date -> DateTimeFormatter.ofPattern("yyyy-MM-dd").format(date)); | ||
FORMATTER.put("timestamp10", date -> String.valueOf(date.toEpochSecond(ZoneOffset.UTC))); | ||
FORMATTER.put("timestamp", date -> String.valueOf(date.toInstant(ZoneOffset.UTC).toEpochMilli())); | ||
FORMATTER.put("time", date -> DateTimeFormatter.ofPattern("HH:mm:ss").format(date)); | ||
FORMATTER.put("year", date -> DateTimeFormatter.ofPattern("yyyy").format(date)); | ||
FORMATTER.put("month", date -> DateTimeFormatter.ofPattern("MM").format(date)); | ||
FORMATTER.put("day", date -> DateTimeFormatter.ofPattern("dd").format(date)); | ||
FORMATTER.put("hour", date -> DateTimeFormatter.ofPattern("HH").format(date)); | ||
FORMATTER.put("minute", date -> DateTimeFormatter.ofPattern("mm").format(date)); | ||
FORMATTER.put("millisecond", date -> DateTimeFormatter.ofPattern("SSS").format(date)); | ||
FORMATTER.put("second", date -> DateTimeFormatter.ofPattern("ss").format(date)); | ||
|
||
UNIT_MAP.put('y', ChronoUnit.YEARS); | ||
UNIT_MAP.put('M', ChronoUnit.MONTHS); | ||
UNIT_MAP.put('d', ChronoUnit.DAYS); | ||
UNIT_MAP.put('H', ChronoUnit.HOURS); | ||
UNIT_MAP.put('m', ChronoUnit.MINUTES); | ||
UNIT_MAP.put('s', ChronoUnit.SECONDS); | ||
UNIT_MAP.put('w', ChronoUnit.WEEKS); | ||
|
||
FORMATTER_NAMES = String.join("|", FORMATTER.keySet()); | ||
UNIT_NAMES = UNIT_MAP.keySet().stream().map(String::valueOf).collect(Collectors.joining("")); | ||
} | ||
|
||
|
||
public static String calculate(String template) { | ||
return calculate(template, LocalDateTime.now()); | ||
} | ||
|
||
public static String calculate(String template, LocalDateTime now) { | ||
if (StringUtils.isBlank(template)) { | ||
return template; | ||
} | ||
final String regex = "\\$\\{(@(" + FORMATTER_NAMES + ")(\\s*[-+]\\s*\\d+[" + UNIT_NAMES + "])*)}"; | ||
|
||
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); | ||
final Matcher matcher = pattern.matcher(template); | ||
|
||
while (matcher.find()) { | ||
String part = matcher.group(0); | ||
String expression = matcher.group(1); | ||
template = template.replace(part, calculateExpression(expression, now)); | ||
|
||
} | ||
return template; | ||
} | ||
|
||
|
||
private static String calculateExpression(String expression, LocalDateTime now) { | ||
expression = expression.replaceAll("\\s", ""); | ||
final String regex = "(@(" + FORMATTER_NAMES + "))|([-+]\\d+[" + UNIT_NAMES + "])"; | ||
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); | ||
final Matcher matcher = pattern.matcher(expression); | ||
List<String> elements = new ArrayList<>(); | ||
while (matcher.find()) { | ||
elements.add(matcher.group(0)); | ||
} | ||
LocalDateTime result = now; | ||
for (int i = 1; i < elements.size(); i++) { | ||
String element = elements.get(i); | ||
int operator = element.charAt(0) == '-' ? -1 : 1; | ||
int duration = Integer.parseInt(element.substring(1, element.length() - 1)); | ||
char unit = element.charAt(element.length() - 1); | ||
result = result.plus(operator * duration, UNIT_MAP.get(unit)); | ||
|
||
} | ||
return FORMATTER.get(elements.get(0).substring(1)).apply(result); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
collector/src/test/java/org/apache/hertzbeat/collector/util/TimeExpressionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* test for TimeExpressionUtil | ||
*/ | ||
class TimeExpressionUtilTest { | ||
|
||
|
||
LocalDateTime now = LocalDateTime.of(2022, 4, 24, 2, 40, 0); | ||
|
||
@Test | ||
void testBlankTemplate() { | ||
assertEquals("", TimeExpressionUtil.calculate("", LocalDateTime.now())); | ||
assertNull(TimeExpressionUtil.calculate(null, LocalDateTime.now())); | ||
} | ||
|
||
@Test | ||
void testErrorTemplate() { | ||
assertEquals("hello", TimeExpressionUtil.calculate("hello", LocalDateTime.now())); | ||
assertEquals("${}", TimeExpressionUtil.calculate("${}", LocalDateTime.now())); | ||
assertEquals("${@current-24m}", TimeExpressionUtil.calculate("${@current-24m}", LocalDateTime.now())); | ||
} | ||
|
||
@Test | ||
void testWithSpace() { | ||
assertEquals("2022-04-24 02:40:01", TimeExpressionUtil.calculate("${@now + 1s}", now)); | ||
} | ||
|
||
@Test | ||
void testCalculate() { | ||
assertEquals("2022-04-24 02:40:00", TimeExpressionUtil.calculate("${@now}", now)); | ||
assertEquals("2022-04-24", TimeExpressionUtil.calculate("${@date}", now)); | ||
assertEquals("02:40:00", TimeExpressionUtil.calculate("${@time}", now)); | ||
assertEquals("1650768000000", TimeExpressionUtil.calculate("${@timestamp}", now)); | ||
assertEquals("1650768000", TimeExpressionUtil.calculate("${@timestamp10}", now)); | ||
assertEquals("2022", TimeExpressionUtil.calculate("${@year}", now)); | ||
assertEquals("04", TimeExpressionUtil.calculate("${@month}", now)); | ||
assertEquals("24", TimeExpressionUtil.calculate("${@day}", now)); | ||
assertEquals("02", TimeExpressionUtil.calculate("${@hour}", now)); | ||
assertEquals("40", TimeExpressionUtil.calculate("${@minute}", now)); | ||
assertEquals("00", TimeExpressionUtil.calculate("${@second}", now)); | ||
assertEquals("000", TimeExpressionUtil.calculate("${@millisecond}", now)); | ||
|
||
assertEquals("2022-04-24 02:25:00", TimeExpressionUtil.calculate("${@now-15m}", now)); | ||
assertEquals("2022-05-01 02:40:00", TimeExpressionUtil.calculate("${@now+1w}", now)); | ||
assertEquals("2022-05-01 02:25:00", TimeExpressionUtil.calculate("${@now+1w-15m}", now)); | ||
assertEquals("2022-04-25 02:40:00", TimeExpressionUtil.calculate("${@now+1d}", now)); | ||
assertEquals("02:40:00", TimeExpressionUtil.calculate("${@time+1d}", now)); | ||
assertEquals("2023-04-24 02:40:00", TimeExpressionUtil.calculate("${@now+1y}", now)); | ||
} | ||
|
||
@Test | ||
void testComplexTemplate() { | ||
assertEquals("Three days after 2022-04-24 , is 2022-04-27", TimeExpressionUtil.calculate("Three days after ${@date} , is ${@date+3d}", now)); | ||
assertEquals("2022年04月24日 02:40:00", TimeExpressionUtil.calculate("${@year}年${@month}月${@day}日 ${@time}", now)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
id: pulsar | ||
title: Monitoring Pulsar Monitoring | ||
sidebar_label: Apache Pulsar | ||
keywords: [open-source monitoring system, open-source database monitoring, HbaseMaster monitoring] | ||
--- | ||
> Collecting and monitoring general performance metrics of Pulsar | ||
**Protocol Used: HTTP** | ||
|
||
## Configuration Parameters | ||
|
||
|
||
| Parameter Name | Description | | ||
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------- | | ||
| Target Host | The monitored endpoint's IPV4, IPV6, or domain name. Note⚠️: Do not include the protocol header (e.g., https://, http://). | | ||
| Port | The webServicePort value of Pulsar, default is 8080. | | ||
| Task Name | The name identifying this monitoring task, must be unique. | | ||
| Query Timeout | Set the connection timeout in milliseconds, default is 3000 milliseconds. | | ||
| Monitoring Interval | Interval time for periodic data collection, in seconds, minimum interval is 30 seconds. | | ||
| Binding Tags | Used for categorizing monitoring resources. | | ||
| Description/Remarks | Additional notes and descriptions for this monitoring task. Users can add more information here. | | ||
|
||
### Collected Metrics | ||
|
||
#### Metric Set: Version Information | ||
|
||
|
||
| Metric Name | Unit | Description | | ||
| ------------ | ---- | ------------------- | | ||
| Version Info | NONE | Version Information | | ||
|
||
#### Metric Set: process_start_time_seconds | ||
|
||
|
||
| Metric Name | Unit | Description | | ||
| ------------------ | ---- | ------------------ | | ||
| Process Start Time | NONE | Process Start Time | | ||
|
||
#### Metric Set: process_open_fds | ||
|
||
|
||
| Metric Name | Unit | Description | | ||
| --------------------- | ---- | ------------------------------- | | ||
| Open File Descriptors | NONE | Number of Open File Descriptors | | ||
|
||
#### Metric Set: process_max_fds | ||
|
||
|
||
| Metric Name | Unit | Description | | ||
| -------------------- | ---- | ---------------------------------- | | ||
| Max File Descriptors | NONE | Maximum Number of File Descriptors | | ||
|
||
#### Metric Set: jvm_memory_pool_allocated_bytes | ||
|
||
Number of bytes of memory allocated in a specific memory pool in the Java Virtual Machine (JVM). In Pulsar, this typically refers to the amount of memory allocated for various purposes in the JVM (such as heap memory, non-heap memory, etc.). | ||
|
||
#### Metric Set: jvm_memory_pool_used_bytes | ||
|
||
Unlike allocated_bytes, this metric shows the actual used memory, not just the allocated memory. | ||
|
||
#### Metric Set: jvm_memory_pool_committed_bytes | ||
|
||
Number of bytes of memory committed in a specific memory pool in the JVM. In the JVM, committed memory is the amount of memory guaranteed to be available for the application to use. This portion of memory is typically locked by the operating system to reduce swapping or garbage collection. | ||
|
||
#### Metric Set: jvm_memory_pool_max_bytes | ||
|
||
Maximum number of bytes of memory that can be allocated in a specific memory pool in the JVM. This is the upper limit on memory usage for that memory pool and helps in setting the memory usage cap. | ||
|
||
#### Metric Set: pulsar_broker_publish_latency | ||
|
||
Message publishing latency on the broker side. | ||
|
||
#### Metric Set: pulsar_metadata_store_ops_latency_ms | ||
|
||
Latency of metadata store operations on the broker side. |
Oops, something went wrong.