百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程字典 > 正文

聊聊springboot的http.server.requests

toyiye 2024-09-16 06:12 3 浏览 0 评论

本文主要研究一下springboot的http.server.requests

http.server.requests

org/springframework/boot/actuate/autoconfigure/metrics/MetricsProperties.java

        public static class Server {

            private final ServerRequest request = new ServerRequest();

            /**
             * Maximum number of unique URI tag values allowed. After the max number of
             * tag values is reached, metrics with additional tag values are denied by
             * filter.
             */
            private int maxUriTags = 100;

            public ServerRequest getRequest() {
                return this.request;
            }

            public int getMaxUriTags() {
                return this.maxUriTags;
            }

            public void setMaxUriTags(int maxUriTags) {
                this.maxUriTags = maxUriTags;
            }

            public static class ServerRequest {

                /**
                 * Name of the metric for received requests.
                 */
                private String metricName = "http.server.requests";

                /**
                 * Whether the trailing slash should be ignored when recording metrics.
                 */
                private boolean ignoreTrailingSlash = true;

                //......
            }   
        }    

MetricsProperties.Server.ServerRequest定义了http.server.requests这个metrics名

WebMvcMetricsAutoConfiguration

org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.java

@Configuration(proxyBeanMethods = false)
@AutoConfigureAfter({ MetricsAutoConfiguration.class, CompositeMeterRegistryAutoConfiguration.class,
        SimpleMetricsExportAutoConfiguration.class })
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET)
@ConditionalOnClass(DispatcherServlet.class)
@ConditionalOnBean(MeterRegistry.class)
@EnableConfigurationProperties(MetricsProperties.class)
public class WebMvcMetricsAutoConfiguration {

    private final MetricsProperties properties;

    public WebMvcMetricsAutoConfiguration(MetricsProperties properties) {
        this.properties = properties;
    }

    @Bean
    @ConditionalOnMissingBean(WebMvcTagsProvider.class)
    public DefaultWebMvcTagsProvider webMvcTagsProvider(ObjectProvider<WebMvcTagsContributor> contributors) {
        return new DefaultWebMvcTagsProvider(this.properties.getWeb().getServer().getRequest().isIgnoreTrailingSlash(),
                contributors.orderedStream().collect(Collectors.toList()));
    }

    @Bean
    public FilterRegistrationBean<WebMvcMetricsFilter> webMvcMetricsFilter(MeterRegistry registry,
            WebMvcTagsProvider tagsProvider) {
        ServerRequest request = this.properties.getWeb().getServer().getRequest();
        WebMvcMetricsFilter filter = new WebMvcMetricsFilter(registry, tagsProvider, request.getMetricName(),
                request.getAutotime());
        FilterRegistrationBean<WebMvcMetricsFilter> registration = new FilterRegistrationBean<>(filter);
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ASYNC);
        return registration;
    }

    @Bean
    @Order(0)
    public MeterFilter metricsHttpServerUriTagFilter() {
        String metricName = this.properties.getWeb().getServer().getRequest().getMetricName();
        MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(
                () -> String.format("Reached the maximum number of URI tags for '%s'.", metricName));
        return MeterFilter.maximumAllowableTags(metricName, "uri", this.properties.getWeb().getServer().getMaxUriTags(),
                filter);
    }

    @Bean
    public MetricsWebMvcConfigurer metricsWebMvcConfigurer(MeterRegistry meterRegistry,
            WebMvcTagsProvider tagsProvider) {
        return new MetricsWebMvcConfigurer(meterRegistry, tagsProvider);
    }
}    

WebMvcMetricsAutoConfiguration定义了webMvcTagsProvider,可以接收WebMvcTagsContributor对tag进行定制,还注册了WebMvcMetricsFilter、MeterFilter、metricsWebMvcConfigurer

DefaultWebMvcTagsProvider

org/springframework/boot/actuate/metrics/web/servlet/DefaultWebMvcTagsProvider.java

public class DefaultWebMvcTagsProvider implements WebMvcTagsProvider {

    private final boolean ignoreTrailingSlash;

    private final List<WebMvcTagsContributor> contributors;

    public DefaultWebMvcTagsProvider() {
        this(false);
    }

    /**
     * Creates a new {@link DefaultWebMvcTagsProvider} that will provide tags from the
     * given {@code contributors} in addition to its own.
     * @param contributors the contributors that will provide additional tags
     * @since 2.3.0
     */
    public DefaultWebMvcTagsProvider(List<WebMvcTagsContributor> contributors) {
        this(false, contributors);
    }

    public DefaultWebMvcTagsProvider(boolean ignoreTrailingSlash) {
        this(ignoreTrailingSlash, Collections.emptyList());
    }

    /**
     * Creates a new {@link DefaultWebMvcTagsProvider} that will provide tags from the
     * given {@code contributors} in addition to its own.
     * @param ignoreTrailingSlash whether trailing slashes should be ignored when
     * determining the {@code uri} tag.
     * @param contributors the contributors that will provide additional tags
     * @since 2.3.0
     */
    public DefaultWebMvcTagsProvider(boolean ignoreTrailingSlash, List<WebMvcTagsContributor> contributors) {
        this.ignoreTrailingSlash = ignoreTrailingSlash;
        this.contributors = contributors;
    }

    @Override
    public Iterable<Tag> getTags(HttpServletRequest request, HttpServletResponse response, Object handler,
            Throwable exception) {
        Tags tags = Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, response, this.ignoreTrailingSlash),
                WebMvcTags.exception(exception), WebMvcTags.status(response), WebMvcTags.outcome(response));
        for (WebMvcTagsContributor contributor : this.contributors) {
            tags = tags.and(contributor.getTags(request, response, handler, exception));
        }
        return tags;
    }

    @Override
    public Iterable<Tag> getLongRequestTags(HttpServletRequest request, Object handler) {
        Tags tags = Tags.of(WebMvcTags.method(request), WebMvcTags.uri(request, null, this.ignoreTrailingSlash));
        for (WebMvcTagsContributor contributor : this.contributors) {
            tags = tags.and(contributor.getLongRequestTags(request, handler));
        }
        return tags;
    }

}

DefaultWebMvcTagsProvider实现了WebMvcTagsProvider接口,其构造器可以接收WebMvcTagsContributor,对tag进行定制;默认的tag为WebMvcTags.method(method)、WebMvcTags.uri(uri)、WebMvcTags.exception(exception)、WebMvcTags.status(status)、WebMvcTags.outcome(outcome)

WebMvcMetricsFilter

org/springframework/boot/actuate/metrics/web/servlet/WebMvcMetricsFilter.java

public class WebMvcMetricsFilter extends OncePerRequestFilter {

    private final MeterRegistry registry;

    private final WebMvcTagsProvider tagsProvider;

    private final String metricName;

    private final AutoTimer autoTimer;

    /**
     * Create a new {@link WebMvcMetricsFilter} instance.
     * @param registry the meter registry
     * @param tagsProvider the tags provider
     * @param metricName the metric name
     * @param autoTimer the auto-timers to apply or {@code null} to disable auto-timing
     * @since 2.2.0
     */
    public WebMvcMetricsFilter(MeterRegistry registry, WebMvcTagsProvider tagsProvider, String metricName,
            AutoTimer autoTimer) {
        this.registry = registry;
        this.tagsProvider = tagsProvider;
        this.metricName = metricName;
        this.autoTimer = autoTimer;
    }

    @Override
    protected boolean shouldNotFilterAsyncDispatch() {
        return false;
    }

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
        TimingContext timingContext = TimingContext.get(request);
        if (timingContext == null) {
            timingContext = startAndAttachTimingContext(request);
        }
        try {
            filterChain.doFilter(request, response);
            if (!request.isAsyncStarted()) {
                // Only record when async processing has finished or never been started.
                // If async was started by something further down the chain we wait
                // until the second filter invocation (but we'll be using the
                // TimingContext that was attached to the first)
                Throwable exception = (Throwable) request.getAttribute(DispatcherServlet.EXCEPTION_ATTRIBUTE);
                record(timingContext, request, response, exception);
            }
        }
        catch (NestedServletException ex) {
            response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            record(timingContext, request, response, ex.getCause());
            throw ex;
        }
        catch (ServletException | IOException | RuntimeException ex) {
            record(timingContext, request, response, ex);
            throw ex;
        }
    }

    //......
}    

WebMvcMetricsFilter继承了OncePerRequestFilter,其doFilterInternal方法通过TimingContext来维护timerSample,然后在filterChain.doFilter(request, response)之后进行record

record

    private void record(TimingContext timingContext, HttpServletRequest request, HttpServletResponse response,
            Throwable exception) {
        Object handler = getHandler(request);
        Set<Timed> annotations = getTimedAnnotations(handler);
        Timer.Sample timerSample = timingContext.getTimerSample();
        if (annotations.isEmpty()) {
            if (this.autoTimer.isEnabled()) {
                Builder builder = this.autoTimer.builder(this.metricName);
                timerSample.stop(getTimer(builder, handler, request, response, exception));
            }
        }
        else {
            for (Timed annotation : annotations) {
                Builder builder = Timer.builder(annotation, this.metricName);
                timerSample.stop(getTimer(builder, handler, request, response, exception));
            }
        }
    }

    private Timer getTimer(Builder builder, Object handler, HttpServletRequest request, HttpServletResponse response,
            Throwable exception) {
        return builder.tags(this.tagsProvider.getTags(request, response, handler, exception)).register(this.registry);
    }    

record方法主要执行timerSample.stop(getTimer(builder, handler, request, response, exception))

timerSample

micrometer-core-1.5.9.jar!/io/micrometer/core/instrument/Timer.class

    public static class Sample {
        private Tags tags = Tags.empty();
        private final long startTime;
        private final Clock clock;

        Sample(Clock clock) {
            this.clock = clock;
            this.startTime = clock.monotonicTime();
        }

        public long stop(Timer timer) {
            long durationNs = this.clock.monotonicTime() - this.startTime;
            timer.record(durationNs, TimeUnit.NANOSECONDS);
            return durationNs;
        }

        @Incubating(
            since = "1.4.0"
        )
        public long stop(MeterRegistry registry, Builder timerBuilder) {
            return this.stop(timerBuilder.tags((Iterable)this.tags).register(registry));
        }

        @Incubating(
            since = "1.4.0"
        )
        public Sample tags(String... tags) {
            return this.tags((Iterable)Tags.of(tags));
        }

        @Incubating(
            since = "1.4.0"
        )
        public Sample tags(Iterable<Tag> tags) {
            this.tags = this.tags.and(tags);
            return this;
        }
    }

Timer.Sample的stop方法主要执行timer.record(durationNs, TimeUnit.NANOSECONDS)

PrometheusTimer

io/micrometer/prometheus/PrometheusTimer.java

public class PrometheusTimer extends AbstractTimer {
    private static final CountAtBucket[] EMPTY_HISTOGRAM = new CountAtBucket[0];

    private final LongAdder count = new LongAdder();
    private final LongAdder totalTime = new LongAdder();
    private final TimeWindowMax max;

    private final HistogramFlavor histogramFlavor;

    @Nullable
    private final Histogram histogram;

    PrometheusTimer(Id id, Clock clock, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector, HistogramFlavor histogramFlavor) {
        super(id, clock,
                DistributionStatisticConfig.builder()
                        .percentilesHistogram(false)
                        .serviceLevelObjectives()
                        .build()
                        .merge(distributionStatisticConfig),
                pauseDetector, TimeUnit.SECONDS, false);

        this.histogramFlavor = histogramFlavor;
        this.max = new TimeWindowMax(clock, distributionStatisticConfig);

        if (distributionStatisticConfig.isPublishingHistogram()) {
            switch (histogramFlavor) {
                case Prometheus:
                    histogram = new TimeWindowFixedBoundaryHistogram(clock, DistributionStatisticConfig.builder()
                            .expiry(Duration.ofDays(1825)) // effectively never roll over
                            .bufferLength(1)
                            .build()
                            .merge(distributionStatisticConfig), true);
                    break;
                case VictoriaMetrics:
                    histogram = new FixedBoundaryVictoriaMetricsHistogram();
                    break;
                default:
                    histogram = null;
                    break;
            }
        } else {
            histogram = null;
        }
    }

    @Override
    protected void recordNonNegative(long amount, TimeUnit unit) {
        count.increment();
        long nanoAmount = TimeUnit.NANOSECONDS.convert(amount, unit);
        totalTime.add(nanoAmount);
        max.record(nanoAmount, TimeUnit.NANOSECONDS);

        if (histogram != null)
            histogram.recordLong(TimeUnit.NANOSECONDS.convert(amount, unit));
    }

    @Override
    public long count() {
        return count.longValue();
    }

    @Override
    public double totalTime(TimeUnit unit) {
        return TimeUtils.nanosToUnit(totalTime.doubleValue(), unit);
    }

    @Override
    public double max(TimeUnit unit) {
        return max.poll(unit);
    }

    public HistogramFlavor histogramFlavor() {
        return histogramFlavor;
    }

    /**
     * For Prometheus we cannot use the histogram counts from HistogramSnapshot, as it is based on a
     * rolling histogram. Prometheus requires a histogram that accumulates values over the lifetime of the app.
     *
     * @return Cumulative histogram buckets.
     */
    public CountAtBucket[] histogramCounts() {
        return histogram == null ? EMPTY_HISTOGRAM : histogram.takeSnapshot(0, 0, 0).histogramCounts();
    }

    @Override
    public HistogramSnapshot takeSnapshot() {
        HistogramSnapshot snapshot = super.takeSnapshot();

        if (histogram == null) {
            return snapshot;
        }

        return new HistogramSnapshot(snapshot.count(),
                snapshot.total(),
                snapshot.max(),
                snapshot.percentileValues(),
                histogramCounts(),
                snapshot::outputSummary);
    }
}

PrometheusTimer继承了AbstractTimer,默认histogram为null

PrometheusMeterRegistry

io/micrometer/prometheus/PrometheusMeterRegistry.java

    protected io.micrometer.core.instrument.Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionStatisticConfig, PauseDetector pauseDetector) {
        PrometheusTimer timer = new PrometheusTimer(id, clock, distributionStatisticConfig, pauseDetector, prometheusConfig.histogramFlavor());
        applyToCollector(id, (collector) ->
                addDistributionStatisticSamples(distributionStatisticConfig, collector, timer, tagValues(id), false));
        return timer;
    }

PrometheusMeterRegistry的newTimer创建的是PrometheusTimer,同时applyToCollector调用了addDistributionStatisticSamples

addDistributionStatisticSamples

    private void addDistributionStatisticSamples(DistributionStatisticConfig distributionStatisticConfig, MicrometerCollector collector,
                                                 HistogramSupport histogramSupport, List<String> tagValues, boolean forLongTaskTimer) {
        collector.add(tagValues, (conventionName, tagKeys) -> {
            Stream.Builder<Collector.MetricFamilySamples.Sample> samples = Stream.builder();

            HistogramSnapshot histogramSnapshot = histogramSupport.takeSnapshot();
            ValueAtPercentile[] percentileValues = histogramSnapshot.percentileValues();
            CountAtBucket[] histogramCounts = histogramSnapshot.histogramCounts();
            double count = histogramSnapshot.count();

            if (percentileValues.length > 0) {
                List<String> quantileKeys = new LinkedList<>(tagKeys);
                quantileKeys.add("quantile");

                // satisfies https://prometheus.io/docs/concepts/metric_types/#summary
                for (ValueAtPercentile v : percentileValues) {
                    List<String> quantileValues = new LinkedList<>(tagValues);
                    quantileValues.add(Collector.doubleToGoString(v.percentile()));
                    samples.add(new Collector.MetricFamilySamples.Sample(
                            conventionName, quantileKeys, quantileValues, v.value(TimeUnit.SECONDS)));
                }
            }

            Collector.Type type = distributionStatisticConfig.isPublishingHistogram() ? Collector.Type.HISTOGRAM : Collector.Type.SUMMARY;
            if (histogramCounts.length > 0) {
                // Prometheus doesn't balk at a metric being BOTH a histogram and a summary
                type = Collector.Type.HISTOGRAM;

                List<String> histogramKeys = new LinkedList<>(tagKeys);

                String sampleName = conventionName + "_bucket";
                switch (prometheusConfig.histogramFlavor()) {
                    case Prometheus:
                        histogramKeys.add("le");

                        // satisfies https://prometheus.io/docs/concepts/metric_types/#histogram
                        for (CountAtBucket c : histogramCounts) {
                            final List<String> histogramValues = new LinkedList<>(tagValues);
                            histogramValues.add(Collector.doubleToGoString(c.bucket(TimeUnit.SECONDS)));
                            samples.add(new Collector.MetricFamilySamples.Sample(
                                    sampleName, histogramKeys, histogramValues, c.count()));
                        }

                        // the +Inf bucket should always equal `count`
                        final List<String> histogramValues = new LinkedList<>(tagValues);
                        histogramValues.add("+Inf");
                        samples.add(new Collector.MetricFamilySamples.Sample(
                                sampleName, histogramKeys, histogramValues, count));
                        break;
                    case VictoriaMetrics:
                        histogramKeys.add("vmrange");

                        for (CountAtBucket c : histogramCounts) {
                            final List<String> histogramValuesVM = new LinkedList<>(tagValues);
                            histogramValuesVM.add(FixedBoundaryVictoriaMetricsHistogram.getRangeTagValue(c.bucket()));
                            samples.add(new Collector.MetricFamilySamples.Sample(
                                    sampleName, histogramKeys, histogramValuesVM, c.count()));
                        }
                        break;
                    default:
                        break;
                }

            }

            samples.add(new Collector.MetricFamilySamples.Sample(
                    conventionName + (forLongTaskTimer ? "_active_count" : "_count"), tagKeys, tagValues, count));

            samples.add(new Collector.MetricFamilySamples.Sample(
                    conventionName + (forLongTaskTimer ? "_duration_sum" : "_sum"), tagKeys, tagValues, histogramSnapshot.total(TimeUnit.SECONDS)));

            return Stream.of(new MicrometerCollector.Family(type, conventionName, samples.build()),
                    new MicrometerCollector.Family(Collector.Type.GAUGE, conventionName + "_max", Stream.of(
                            new Collector.MetricFamilySamples.Sample(conventionName + "_max", tagKeys, tagValues,
                                    histogramSnapshot.max(getBaseTimeUnit())))));
        });
    }

addDistributionStatisticSamples会判断isPublishingHistogram,是则发布HISTOGRAM,否则发布SUMMARY(默认为否),之后给samples添加_count及_sum的sample,最后额外添加一个_max的gauge

示例

示例1

Timer timer = meterRegistry.timer("abc", "a", "b");
timer.record(Duration.of(100, ChronoUnit.SECONDS));

最后产生的metrics如下

# HELP abc_seconds_max  
# TYPE abc_seconds_max gauge
abc_seconds_max{a="b",} 0.0
# HELP abc_seconds  
# TYPE abc_seconds summary
abc_seconds_count{a="b",} 1.0
abc_seconds_sum{a="b",} 100.0

示例2

http.server.requests的prometheus指标

# HELP http_server_requests_seconds_max
# TYPE http_server_requests_seconds_max gauge
http_server_requests_seconds_max{}
# TYPE http_server_requests_seconds summary
http_server_requests_seconds_count{}
http_server_requests_seconds_sum{}

grafana展示

HTTP Server Requests Count

            {
              "expr": "http_server_requests_seconds_count{instance=\"$instance\", application=\"$application\"}",
              "format": "time_series",
              "interval": "",
              "intervalFactor": 1,
              "legendFormat": "{{method}} [{{status}}] - {{uri}}",
              "refId": "A"
            }

HTTP Server Requests Sum

            {
              "expr": "http_server_requests_seconds_sum{instance=\"$instance\", application=\"$application\"}",
              "format": "time_series",
              "interval": "",
              "intervalFactor": 1,
              "legendFormat": "{{method}} [{{status}}] - {{uri}}",
              "refId": "A"
            }

HTTP Server Requests Max

            {
              "expr": "http_server_requests_seconds_max{instance=\"$instance\", application=\"$application\"}",
              "format": "time_series",
              "interval": "",
              "intervalFactor": 1,
              "legendFormat": "{{method}} [{{status}}] - {{uri}}",
              "refId": "A"
            }

Total Requests

        {
          "expr": "sum(increase(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\"}[150s]))",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "",
          "refId": "A"
        }

Request Count

        {
          "expr": "irate(http_server_requests_seconds_count{instance=\"$instance\", application=\"$application\", uri!~\".*actuator.*\"}[5m])",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "{{method}} [{{status}}] - {{uri}} -{{reqPath}}",
          "refId": "A"
        }

Failed Requests

        {
          "expr": "sum(increase(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\", uri=~\"$uri\", status!=\"200\"}[$__interval]))",
          "format": "time_series",
          "intervalFactor": 1,
          "refId": "A"
        }

Req / sec

        {
          "expr": "sum(irate(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\"}[1m]))",
          "format": "time_series",
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "",
          "refId": "A"
        }

Requests per second

        {
          "expr": "rate(http_server_requests_seconds_count{application=\"$application\", instance=\"$instance\"}[1m])",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "{{method}}-{{status}}-{{uri}}",
          "refId": "A"
        }

Top 10 Most Used API endpoints

        {
          "expr": "topk(10, sum by(uri, method) (rate(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\"}[1m])))",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "",
          "refId": "A"
        }

Error Rate

        {
          "expr": "sum(increase(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\", uri=~\"$uri\", status!=\"200\"}[$__interval])) / sum(increase(http_server_requests_seconds_count{application=\"$application\", instance=~\"$instance\", uri=~\"$uri\"}[$__interval])) * 100",
          "format": "time_series",
          "intervalFactor": 1,
          "refId": "A"
        }

Mean response time

        {
          "expr": "rate(http_server_requests_seconds_sum{application=\"$application\", instance=\"$instance\"}[1m])/rate(http_server_requests_seconds_count{application=\"$application\", instance=\"$instance\"}[1m])",
          "format": "time_series",
          "instant": false,
          "intervalFactor": 1,
          "legendFormat": "{{method}}-{{status}}-{{uri}}",
          "refId": "A"
        }

Response Time

        {
          "expr": "irate(http_server_requests_seconds_sum{instance=\"$instance\", application=\"$application\", exception=\"None\", uri!~\".*actuator.*\"}[5m]) / irate(http_server_requests_seconds_count{instance=\"$instance\", application=\"$application\", exception=\"None\", uri!~\".*actuator.*\"}[5m])",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "{{method}} [{{status}}] - {{uri}}",
          "refId": "A"
        }

Response time of 50%, 75%, 90%, 95% of requests

        {
          "expr": "histogram_quantile(0.95, sum(rate(http_server_requests_seconds_bucket{application=\"$application\", instance=\"$instance\"}[1m])) by (le))",
          "format": "time_series",
          "instant": false,
          "interval": "",
          "intervalFactor": 1,
          "legendFormat": "95%",
          "refId": "A"
        },
        {
          "expr": "histogram_quantile(0.9, sum(rate(http_server_requests_seconds_bucket{application=\"$application\", instance=\"$instance\"}[1m])) by (le))",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "90%",
          "refId": "B"
        },
        {
          "expr": "histogram_quantile(0.75, sum(rate(http_server_requests_seconds_bucket{application=\"$application\", instance=\"$instance\"}[1m])) by (le))",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "75%",
          "refId": "C"
        },
        {
          "expr": "histogram_quantile(0.5, sum(rate(http_server_requests_seconds_bucket{application=\"$application\", instance=\"$instance\"}[1m])) by (le))",
          "format": "time_series",
          "intervalFactor": 1,
          "legendFormat": "50%",
          "refId": "D"
        }

小结

springboot的WebMvcMetricsAutoConfiguration给mvc提供了http.server.requests指标,类型为timer,当输出到prometheus的时候,默认是没有开启Histogram,输出的是一个_max的gauge,以及summary类型(_count及_sum)。

相关推荐

为何越来越多的编程语言使用JSON(为什么编程)

JSON是JavascriptObjectNotation的缩写,意思是Javascript对象表示法,是一种易于人类阅读和对编程友好的文本数据传递方法,是JavaScript语言规范定义的一个子...

何时在数据库中使用 JSON(数据库用json格式存储)

在本文中,您将了解何时应考虑将JSON数据类型添加到表中以及何时应避免使用它们。每天?分享?最新?软件?开发?,Devops,敏捷?,测试?以及?项目?管理?最新?,最热门?的?文章?,每天?花?...

MySQL 从零开始:05 数据类型(mysql数据类型有哪些,并举例)

前面的讲解中已经接触到了表的创建,表的创建是对字段的声明,比如:上述语句声明了字段的名称、类型、所占空间、默认值和是否可以为空等信息。其中的int、varchar、char和decimal都...

JSON对象花样进阶(json格式对象)

一、引言在现代Web开发中,JSON(JavaScriptObjectNotation)已经成为数据交换的标准格式。无论是从前端向后端发送数据,还是从后端接收数据,JSON都是不可或缺的一部分。...

深入理解 JSON 和 Form-data(json和formdata提交区别)

在讨论现代网络开发与API设计的语境下,理解客户端和服务器间如何有效且可靠地交换数据变得尤为关键。这里,特别值得关注的是两种主流数据格式:...

JSON 语法(json 语法 priority)

JSON语法是JavaScript语法的子集。JSON语法规则JSON语法是JavaScript对象表示法语法的子集。数据在名称/值对中数据由逗号分隔花括号保存对象方括号保存数组JS...

JSON语法详解(json的语法规则)

JSON语法规则JSON语法是JavaScript对象表示法语法的子集。数据在名称/值对中数据由逗号分隔大括号保存对象中括号保存数组注意:json的key是字符串,且必须是双引号,不能是单引号...

MySQL JSON数据类型操作(mysql的json)

概述mysql自5.7.8版本开始,就支持了json结构的数据存储和查询,这表明了mysql也在不断的学习和增加nosql数据库的有点。但mysql毕竟是关系型数据库,在处理json这种非结构化的数据...

JSON的数据模式(json数据格式示例)

像XML模式一样,JSON数据格式也有Schema,这是一个基于JSON格式的规范。JSON模式也以JSON格式编写。它用于验证JSON数据。JSON模式示例以下代码显示了基本的JSON模式。{"...

前端学习——JSON格式详解(后端json格式)

JSON(JavaScriptObjectNotation)是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。它基于JavaScriptProgrammingLa...

什么是 JSON:详解 JSON 及其优势(什么叫json)

现在程序员还有谁不知道JSON吗?无论对于前端还是后端,JSON都是一种常见的数据格式。那么JSON到底是什么呢?JSON的定义...

PostgreSQL JSON 类型:处理结构化数据

PostgreSQL提供JSON类型,以存储结构化数据。JSON是一种开放的数据格式,可用于存储各种类型的值。什么是JSON类型?JSON类型表示JSON(JavaScriptO...

JavaScript:JSON、三种包装类(javascript 包)

JOSN:我们希望可以将一个对象在不同的语言中进行传递,以达到通信的目的,最佳方式就是将一个对象转换为字符串的形式JSON(JavaScriptObjectNotation)-JS的对象表示法...

Python数据分析 只要1分钟 教你玩转JSON 全程干货

Json简介:Json,全名JavaScriptObjectNotation,JSON(JavaScriptObjectNotation(记号、标记))是一种轻量级的数据交换格式。它基于J...

比较一下JSON与XML两种数据格式?(json和xml哪个好)

JSON(JavaScriptObjectNotation)和XML(eXtensibleMarkupLanguage)是在日常开发中比较常用的两种数据格式,它们主要的作用就是用来进行数据的传...

取消回复欢迎 发表评论:

请填写验证码