Skip to content

Commit

Permalink
support prometheus metric
Browse files Browse the repository at this point in the history
Signed-off-by: zwmagic <[email protected]>
  • Loading branch information
zwmagic committed Aug 30, 2024
1 parent d81f072 commit b881d73
Show file tree
Hide file tree
Showing 27 changed files with 1,729 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ agent.service.dynamic.config.enable=true
agent.service.httpserver.enable=false
# xDS service switch
agent.service.xds.service.enable=false
# Metric service switch
agent.service.metric.enable=false
#============================= Event configuration =============================#
# Event switch
event.enable=false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class ServiceConfig implements BaseConfig {
@ConfigFieldKey("xds.service.enable")
private boolean xdsServiceEnable = false;

@ConfigFieldKey("metric.enable")
private boolean metricEnable = false;

public boolean isHeartBeatEnable() {
return heartBeatEnable;
}
Expand Down Expand Up @@ -105,6 +108,14 @@ public void setXdsServiceEnable(boolean xdsServiceEnable) {
this.xdsServiceEnable = xdsServiceEnable;
}

public boolean isMetricEnable() {
return metricEnable;
}

public void setMetricEnable(boolean metricEnable) {

Check warning on line 115 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议1.2 布尔变量名或方法以is开头(has have does do did will should can may must could等疑问助动词也可以,Android允许m作为疑问助动词前缀) Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/ServiceConfig.java:115:0: warning: 编程规范-建议1.2 布尔变量名或方法以is开头(has have does do did will should can may must could等疑问助动词也可以,Android允许m作为疑问助动词前缀) (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
this.metricEnable = metricEnable;
}

/**
* Check whether the service of the given class name is enabled.
*
Expand Down Expand Up @@ -133,6 +144,9 @@ public boolean checkServiceEnable(String serviceName) {
if (ServiceManager.XDS_CORE_SERVICE_IMPL.equals(serviceName)) {
return isXdsServiceEnable();
}
if (ServiceManager.METRIC_SERVICE_IMPL.equals(serviceName)) {
return isMetricEnable();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ public class ServiceManager {
public static final String XDS_CORE_SERVICE_IMPL =
"io.sermant.implement.service.xds.XdsCoreServiceImpl";

/**
* Metric Service Discover
*/
public static final String METRIC_SERVICE_IMPL =
"io.sermant.implement.service.metrics.MeterMetricServiceImpl";

/**
* logger
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*

Check failure on line 1 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Counter.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 请检查版权声明中其实年份与@SInCE中年份是否一致 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/Counter.java:1:0: error: 请检查版权声明中其实年份与@SInCE中年份是否一致 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck)
* Copyright 2017 VMware, Inc.
*
* Licensed 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
*
* https://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.
*/

/*
* Based on io/micrometer/core/instrument/Counter.java
* from the Micrometer project.
*/

package io.sermant.core.service.metric.api;

/**
* metric Counter interface
*
* @author zwmagic
* @since 2024-08-16
*/
public interface Counter {
/**
* Update the counter by one.
*/
default void increment() {
increment(1.0);
}

/**
* Update the counter by {@code amount}.
*
* @param amount Amount to add to the counter.
*/
void increment(double amount);

/**
* get the counter value
*
* @return The cumulative count since this counter was created.
*/
double count();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*

Check failure on line 1 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 请检查版权声明中其实年份与@SInCE中年份是否一致 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:1:0: error: 请检查版权声明中其实年份与@SInCE中年份是否一致 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck)
* Copyright 2017 VMware, Inc.
*
* Licensed 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
*
* https://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.
*/

/*
* Based on io/micrometer/core/instrument/distribution/DistributionStatisticConfig.java
* from the Micrometer project.
*/

package io.sermant.core.service.metric.api;

import java.time.Duration;

/**
* DistributionStatisticConfig
*
* @author zwmagic
* @since 2024-08-17
*/
public class DistributionStatisticConfig {
private static final Integer EXPIRY_MINUTE = 2;

/**
* Defines a static final constant named DEFAULT, which represents a distribution statistic configuration. This
* configuration controls and describes various aspects of data distribution statistics, such as the publication of
* percentile histograms, the precision of percentiles, and the expected value range. These configurations are
* useful for monitoring and analyzing data distributions, particularly in system performance monitoring and log
* analysis.
*/
public static final DistributionStatisticConfig DEFAULT =
new DistributionStatisticConfig().publishPercentileHistogram(false)
.percentilePrecision(1).minimumExpectedValue(1.0).maximumExpectedValue(Double.POSITIVE_INFINITY)
.distributionStatisticExpiry(Duration.ofMinutes(EXPIRY_MINUTE))
.distributionStatisticBufferLength(3);

private Boolean percentileHistogram;

private double[] percentiles;

private Integer percentilePrecision;

private Double minimumExpectedValue;

private Double maximumExpectedValue;

private Duration expiry;

private Integer bufferLength;

Check warning on line 60 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:60:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)

/**
* Gets the percentile histogram flag.
*
* @return the percentile histogram flag
*/
public Boolean getPercentileHistogram() {

Check warning on line 67 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:67:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return percentileHistogram;
}

/**
* Gets the array of percentiles.
*
* @return the array of percentiles
*/
public double[] getPercentiles() {
return percentiles;
}

/**
* Gets the precision for percentiles.
*
* @return the precision for percentiles
*/
public Integer getPercentilePrecision() {

Check warning on line 85 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:85:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return percentilePrecision;
}

/**
* Gets the minimum expected value.
*
* @return the minimum expected value
*/
public Double getMinimumExpectedValue() {

Check warning on line 94 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:94:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return minimumExpectedValue;
}

/**
* Gets the maximum expected value.
*
* @return the maximum expected value
*/
public Double getMaximumExpectedValue() {

Check warning on line 103 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:103:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return maximumExpectedValue;
}

/**
* Gets the expiry duration.
*
* @return the expiry duration
*/
public Duration getExpiry() {
return expiry;
}

/**
* Gets the length of the buffer.
*
* @return the length of the buffer
*/
public Integer getBufferLength() {

Check warning on line 121 in sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java

View workflow job for this annotation

GitHub Actions / Checkstyle

[Checkstyle Check] reported by reviewdog 🐶 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 Raw Output: /home/runner/work/Sermant/Sermant/./sermant-agentcore/sermant-agentcore-core/src/main/java/io/sermant/core/service/metric/api/DistributionStatisticConfig.java:121:0: warning: 编程规范-建议4.2: 基本类型优于包装类型,注意合理使用包装类型 (com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck)
return bufferLength;
}

/**
* Produces an additional time series for each requested percentile. This percentile is computed locally, and so
* can't be aggregated with percentiles computed across other dimensions (e.g. in a different instance). Use
* {@link #publishPercentileHistogram()} to publish a histogram that can be used to generate aggregable percentile
* approximations.
*
* @param percentilesValue Percentiles to compute and publish. The 95th percentile should be expressed as
* {@code 0.95}.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig publishPercentiles(double[] percentilesValue) {
this.percentiles = percentilesValue;
return this;
}

/**
* Adds histogram buckets used to generate aggregable percentile approximations in monitoring systems that have
* query facilities to do so (e.g. Prometheus' {@code histogram_quantile}, Atlas' {@code :percentiles}).
*
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig publishPercentileHistogram() {
return publishPercentileHistogram(true);
}

/**
* Adds histogram buckets used to generate aggregable percentile approximations in monitoring systems that have
* query facilities to do so (e.g. Prometheus' {@code histogram_quantile}, Atlas' {@code :percentiles}).
*
* @param enabled Determines whether percentile histograms should be published.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig publishPercentileHistogram(Boolean enabled) {
this.percentileHistogram = enabled;
return this;
}

/**
* Determines the number of digits of precision to maintain on the dynamic range histogram used to compute
* percentile approximations. The higher the degrees of precision, the more accurate the approximation is at the
* cost of more memory.
*
* @param digitsOfPrecision The digits of precision to maintain for percentile approximations.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig percentilePrecision(Integer digitsOfPrecision) {
this.percentilePrecision = digitsOfPrecision;
return this;
}

/**
* Sets the minimum value that this distribution summary is expected to observe. Sets a lower bound on histogram
* buckets that are shipped to monitoring systems that support aggregable percentile approximations.
*
* @param min The minimum value that this distribution summary is expected to observe.
* @return This builder.
*/
public DistributionStatisticConfig minimumExpectedValue(Double min) {
this.minimumExpectedValue = min;
return this;
}

/**
* Sets the maximum value that this distribution summary is expected to observe. Sets an upper bound on histogram
* buckets that are shipped to monitoring systems that support aggregable percentile approximations.
*
* @param max The maximum value that this distribution summary is expected to observe.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig maximumExpectedValue(Double max) {
this.maximumExpectedValue = max;
return this;
}

/**
* Statistics emanating from a distribution summary like max, percentiles, and histogram counts decay over time to
* give greater weight to recent samples (exception: histogram counts are cumulative for those systems that expect
* cumulative histogram buckets). Samples are accumulated to such statistics in ring buffers which rotate after this
* expiry, with a buffer length of {@link #distributionStatisticBufferLength(Integer)}.
*
* @param expiryDuration The amount of time samples are accumulated to a histogram before it is reset and rotated.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig distributionStatisticExpiry(Duration expiryDuration) {
this.expiry = expiryDuration;
return this;
}

/**
* Statistics emanating from a distribution summary like max, percentiles, and histogram counts decay over time to
* give greater weight to recent samples (exception: histogram counts are cumulative for those systems that expect
* cumulative histogram buckets). Samples are accumulated to such statistics in ring buffers which rotate after
* {@link #distributionStatisticExpiry(Duration)}, with this buffer length.
*
* @param bufferLengthValue The number of histograms to keep in the ring buffer.
* @return DistributionStatisticConfig
*/
public DistributionStatisticConfig distributionStatisticBufferLength(Integer bufferLengthValue) {
this.bufferLength = bufferLengthValue;
return this;
}
}
Loading

0 comments on commit b881d73

Please sign in to comment.