-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Display indicator data in KEY, VALUE format #12273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
69563f3
metrics default.
hujun-w-2 01500a1
check style
hujun-w-2 c1d22a1
test fail
hujun-w-2 4f79639
metrics default update
hujun-w-2 46ea1bd
qos
hujun-w-2 c4042fe
test
hujun-w-2 1598d38
default metrics reporter
hujun-w-2 2c38e28
Merge branch '3.2' into 3.2-develop
AlbumenJ 8a56e6c
Merge branch '3.2' into 3.2-develop
songxiaosheng c994e02
Merge branch '3.2' into 3.2-develop
songxiaosheng 4bab435
native image
hujun-w-2 38c3628
If no specific metrics type is configured and there is no Prometheus …
hujun-w-2 590ef05
Merge branch '3.2' into 3.2-develop
hujun-w-2 f4987eb
prometheus set
hujun-w-2 c8fc064
Merge remote-tracking branch 'hujun-github/3.2-develop' into 3.2-develop
hujun-w-2 66be2d9
MeterRegistry dependency check
hujun-w-2 503670f
errorcode check fail
hujun-w-2 51b0d0e
CHECKSTYLE
hujun-w-2 709e80f
Merge branch '3.2' into 3.2-develop
songxiaosheng 98be47c
1.null check
hujun-w-2 c73e2ed
default metricsreport register
hujun-w-2 cf5fe31
Merge branch '3.2' into 3.2-develop
songxiaosheng 06d9673
Merge branch '3.2' into 3.2-develop
songxiaosheng 65533a7
format response
hujun-w-2 43e9722
Merge remote-tracking branch 'hujun-github/3.2-develop' into 3.2-develop
hujun-w-2 f5f88e2
Merge branch '3.2' into 3.2-develop
songxiaosheng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
100 changes: 100 additions & 0 deletions
100
...metrics-default/src/main/java/org/apache/dubbo/metrics/report/DefaultMetricsReporter.java
This file contains hidden or 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,100 @@ | ||
| /* | ||
| * 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.dubbo.metrics.report; | ||
|
|
||
| import io.micrometer.core.instrument.Counter; | ||
| import io.micrometer.core.instrument.Gauge; | ||
| import io.micrometer.core.instrument.Tag; | ||
| import io.micrometer.core.instrument.Timer; | ||
| import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
|
|
||
| import org.apache.dubbo.common.URL; | ||
| import org.apache.dubbo.rpc.model.ApplicationModel; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public class DefaultMetricsReporter extends AbstractMetricsReporter { | ||
|
|
||
| SimpleMeterRegistry meterRegistry = new SimpleMeterRegistry(); | ||
|
|
||
| protected DefaultMetricsReporter(URL url, ApplicationModel applicationModel) { | ||
| super(url, applicationModel); | ||
| } | ||
|
|
||
| @Override | ||
| public String getResponse() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public String getResponseWithName(String metricsName) { | ||
| Map<String, List<Tag>> metricsTags = new HashMap<>(); | ||
| Map<String, Object> metricsValue = new HashMap<>(); | ||
| StringBuilder sb = new StringBuilder(); | ||
| meterRegistry.getMeters().stream().filter(meter -> { | ||
| if (meter == null || meter.getId() == null || meter.getId().getName() == null) { | ||
| return false; | ||
| } | ||
| if (metricsName != null) { | ||
| return meter.getId().getName().contains(metricsName); | ||
hujun-w-2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return true; | ||
| }).forEach(meter -> { | ||
| Object value = null; | ||
| if (meter instanceof Counter) { | ||
| Counter counter = (Counter) meter; | ||
| value = counter.count(); | ||
| } | ||
| if (meter instanceof Gauge) { | ||
| Gauge gauge = (Gauge) meter; | ||
| value = gauge.value(); | ||
| } | ||
| if (meter instanceof Timer) { | ||
| Timer timer = (Timer) meter; | ||
| value = timer.totalTime(TimeUnit.MILLISECONDS); | ||
| } | ||
| metricsTags.put(meter.getId().getName(), meter.getId().getTags()); | ||
| metricsValue.put(meter.getId().getName(), value); | ||
| }); | ||
| metricsValue.forEach((key, value) -> { | ||
| sb.append(key).append("{"); | ||
| List<Tag> tags = metricsTags.get(key); | ||
| if (tags != null && tags.size() > 0) { | ||
| tags.forEach(tag -> { | ||
| sb.append(tag.getKey()).append("=").append(tag.getValue()).append(","); | ||
| }); | ||
| } | ||
| sb.append("} ").append(value).append(System.lineSeparator()); | ||
| }); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doInit() { | ||
| addMeterRegistry(meterRegistry); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doDestroy() { | ||
|
|
||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
...-default/src/main/java/org/apache/dubbo/metrics/report/DefaultMetricsReporterFactory.java
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * 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.dubbo.metrics.report; | ||
|
|
||
| import org.apache.dubbo.common.URL; | ||
| import org.apache.dubbo.rpc.model.ApplicationModel; | ||
|
|
||
| public class DefaultMetricsReporterFactory extends AbstractMetricsReporterFactory { | ||
| private final ApplicationModel applicationModel; | ||
|
|
||
| public DefaultMetricsReporterFactory(ApplicationModel applicationModel) { | ||
| super(applicationModel); | ||
| this.applicationModel = applicationModel; | ||
| } | ||
|
|
||
| @Override | ||
| public MetricsReporter createMetricsReporter(URL url) { | ||
| return new DefaultMetricsReporter(url, applicationModel); | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
...ain/resources/META-INF/dubbo/internal/org.apache.dubbo.metrics.collector.MetricsCollector
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| default-collector=org.apache.dubbo.metrics.collector.DefaultMetricsCollector | ||
| aggregateMetricsCollector=org.apache.dubbo.metrics.collector.AggregateMetricsCollector | ||
| histogramMetricsCollector=org.apache.dubbo.metrics.collector.HistogramMetricsCollector |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/dubbo/internal/org.apache.dubbo.metrics.report.MetricsReporterFactory
This file contains hidden or 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 @@ | ||
| default=org.apache.dubbo.metrics.report.DefaultMetricsReporterFactory |
This file contains hidden or 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 hidden or 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
121 changes: 121 additions & 0 deletions
121
.../dubbo-qos/src/main/java/org/apache/dubbo/qos/command/impl/DefaultMetricsReporterCmd.java
This file contains hidden or 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,121 @@ | ||
| /* | ||
| * 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.dubbo.qos.command.impl; | ||
|
|
||
| import org.apache.dubbo.common.utils.JsonUtils; | ||
| import org.apache.dubbo.metrics.report.DefaultMetricsReporter; | ||
| import org.apache.dubbo.metrics.report.MetricsReporter; | ||
| import org.apache.dubbo.qos.api.BaseCommand; | ||
| import org.apache.dubbo.qos.api.Cmd; | ||
| import org.apache.dubbo.qos.api.CommandContext; | ||
| import org.apache.dubbo.rpc.model.ApplicationModel; | ||
| import org.apache.dubbo.rpc.model.FrameworkModel; | ||
|
|
||
| import java.io.CharArrayReader; | ||
| import java.io.IOException; | ||
| import java.io.LineNumberReader; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
|
|
||
| @Cmd(name = "metrics_default", summary = "display metrics information") | ||
| public class DefaultMetricsReporterCmd implements BaseCommand { | ||
|
|
||
| public FrameworkModel frameworkModel; | ||
|
|
||
| public DefaultMetricsReporterCmd(FrameworkModel frameworkModel) { | ||
| this.frameworkModel = frameworkModel; | ||
| } | ||
|
|
||
| @Override | ||
| public String execute(CommandContext commandContext, String[] args) { | ||
| List<ApplicationModel> models = frameworkModel.getApplicationModels(); | ||
| String result = "There is no application with data"; | ||
| if (notSpecifyApplication(args)) { | ||
| result = useFirst(models, result, null); | ||
| } else if (args.length == 1) { | ||
| result = specifyApplication(args[0], models, null); | ||
| } else if (args.length == 2) { | ||
| result = specifyApplication(args[0], models, args[1]); | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private boolean notSpecifyApplication(String[] args) { | ||
| return args == null || args.length == 0; | ||
| } | ||
|
|
||
| private String useFirst(List<ApplicationModel> models, String result, String metricsName) { | ||
| for (ApplicationModel model : models) { | ||
| String current = getResponseByApplication(model, metricsName); | ||
| if (current != null && getLineNumber(current) > 0) { | ||
| result = current; | ||
| break; | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private String specifyApplication(String appName, List<ApplicationModel> models, String metricsName) { | ||
| if ("application_all".equals(appName)) { | ||
| return allApplication(models); | ||
| } else { | ||
| return specifySingleApplication(appName, models, metricsName); | ||
| } | ||
| } | ||
|
|
||
| private String specifySingleApplication(String appName, List<ApplicationModel> models, String metricsName) { | ||
| Optional<ApplicationModel> modelOptional = models.stream() | ||
| .filter(applicationModel -> appName.equals(applicationModel.getApplicationName())).findFirst(); | ||
| if (modelOptional.isPresent()) { | ||
| return getResponseByApplication(modelOptional.get(), metricsName); | ||
| } else { | ||
| return "Not exist application: " + appName; | ||
| } | ||
| } | ||
|
|
||
| private String allApplication(List<ApplicationModel> models) { | ||
| Map<String, String> appResultMap = new HashMap<>(); | ||
| for (ApplicationModel model : models) { | ||
| appResultMap.put(model.getApplicationName(), getResponseByApplication(model, null)); | ||
| } | ||
| return JsonUtils.toJson(appResultMap); | ||
| } | ||
|
|
||
| private String getResponseByApplication(ApplicationModel applicationModel, String metricsName) { | ||
| String response = "DefaultMetricsReporter not init"; | ||
| MetricsReporter metricsReporter = applicationModel.getBeanFactory().getBean(DefaultMetricsReporter.class); | ||
| if (metricsReporter != null) { | ||
| metricsReporter.refreshData(); | ||
| response = metricsReporter.getResponseWithName(metricsName); | ||
| } | ||
| return response; | ||
| } | ||
|
|
||
|
|
||
| private static long getLineNumber(String content) { | ||
| LineNumberReader lnr = new LineNumberReader(new CharArrayReader(content.toCharArray())); | ||
hujun-w-2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| lnr.skip(Long.MAX_VALUE); | ||
| lnr.close(); | ||
| } catch (IOException ignore) { | ||
| } | ||
| return lnr.getLineNumber(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.