001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.actuate.autoconfigure.metrics;
018
019import java.util.LinkedHashMap;
020import java.util.Map;
021
022import org.springframework.boot.context.properties.ConfigurationProperties;
023
024/**
025 * {@link ConfigurationProperties} for configuring Micrometer-based metrics.
026 *
027 * @author Jon Schneider
028 * @author Alexander Abramov
029 * @since 2.0.0
030 */
031@ConfigurationProperties("management.metrics")
032public class MetricsProperties {
033
034        /**
035         * Whether auto-configured MeterRegistry implementations should be bound to the global
036         * static registry on Metrics. For testing, set this to 'false' to maximize test
037         * independence.
038         */
039        private boolean useGlobalRegistry = true;
040
041        /**
042         * Whether meter IDs starting-with the specified name should be enabled. The longest
043         * match wins, the key `all` can also be used to configure all meters.
044         */
045        private final Map<String, Boolean> enable = new LinkedHashMap<>();
046
047        /**
048         * Common tags that are applied to every meter.
049         */
050        private final Map<String, String> tags = new LinkedHashMap<>();
051
052        private final Web web = new Web();
053
054        private final Distribution distribution = new Distribution();
055
056        public boolean isUseGlobalRegistry() {
057                return this.useGlobalRegistry;
058        }
059
060        public void setUseGlobalRegistry(boolean useGlobalRegistry) {
061                this.useGlobalRegistry = useGlobalRegistry;
062        }
063
064        public Map<String, Boolean> getEnable() {
065                return this.enable;
066        }
067
068        public Map<String, String> getTags() {
069                return this.tags;
070        }
071
072        public Web getWeb() {
073                return this.web;
074        }
075
076        public Distribution getDistribution() {
077                return this.distribution;
078        }
079
080        public static class Web {
081
082                private final Client client = new Client();
083
084                private final Server server = new Server();
085
086                public Client getClient() {
087                        return this.client;
088                }
089
090                public Server getServer() {
091                        return this.server;
092                }
093
094                public static class Client {
095
096                        /**
097                         * Name of the metric for sent requests.
098                         */
099                        private String requestsMetricName = "http.client.requests";
100
101                        /**
102                         * Maximum number of unique URI tag values allowed. After the max number of
103                         * tag values is reached, metrics with additional tag values are denied by
104                         * filter.
105                         */
106                        private int maxUriTags = 100;
107
108                        public String getRequestsMetricName() {
109                                return this.requestsMetricName;
110                        }
111
112                        public void setRequestsMetricName(String requestsMetricName) {
113                                this.requestsMetricName = requestsMetricName;
114                        }
115
116                        public int getMaxUriTags() {
117                                return this.maxUriTags;
118                        }
119
120                        public void setMaxUriTags(int maxUriTags) {
121                                this.maxUriTags = maxUriTags;
122                        }
123
124                }
125
126                public static class Server {
127
128                        /**
129                         * Whether requests handled by Spring MVC, WebFlux or Jersey should be
130                         * automatically timed. If the number of time series emitted grows too large
131                         * on account of request mapping timings, disable this and use 'Timed' on a
132                         * per request mapping basis as needed.
133                         */
134                        private boolean autoTimeRequests = true;
135
136                        /**
137                         * Name of the metric for received requests.
138                         */
139                        private String requestsMetricName = "http.server.requests";
140
141                        /**
142                         * Maximum number of unique URI tag values allowed. After the max number of
143                         * tag values is reached, metrics with additional tag values are denied by
144                         * filter.
145                         */
146                        private int maxUriTags = 100;
147
148                        public boolean isAutoTimeRequests() {
149                                return this.autoTimeRequests;
150                        }
151
152                        public void setAutoTimeRequests(boolean autoTimeRequests) {
153                                this.autoTimeRequests = autoTimeRequests;
154                        }
155
156                        public String getRequestsMetricName() {
157                                return this.requestsMetricName;
158                        }
159
160                        public void setRequestsMetricName(String requestsMetricName) {
161                                this.requestsMetricName = requestsMetricName;
162                        }
163
164                        public int getMaxUriTags() {
165                                return this.maxUriTags;
166                        }
167
168                        public void setMaxUriTags(int maxUriTags) {
169                                this.maxUriTags = maxUriTags;
170                        }
171
172                }
173
174        }
175
176        public static class Distribution {
177
178                /**
179                 * Whether meter IDs starting with the specified name should publish percentile
180                 * histograms. For monitoring systems that support aggregable percentile
181                 * calculation based on a histogram, this can be set to true. For other systems,
182                 * this has no effect. The longest match wins, the key `all` can also be used to
183                 * configure all meters.
184                 */
185                private final Map<String, Boolean> percentilesHistogram = new LinkedHashMap<>();
186
187                /**
188                 * Specific computed non-aggregable percentiles to ship to the backend for meter
189                 * IDs starting-with the specified name. The longest match wins, the key `all` can
190                 * also be used to configure all meters.
191                 */
192                private final Map<String, double[]> percentiles = new LinkedHashMap<>();
193
194                /**
195                 * Specific SLA boundaries for meter IDs starting-with the specified name. The
196                 * longest match wins. Counters will be published for each specified boundary.
197                 * Values can be specified as a long or as a Duration value (for timer meters,
198                 * defaulting to ms if no unit specified).
199                 */
200                private final Map<String, ServiceLevelAgreementBoundary[]> sla = new LinkedHashMap<>();
201
202                /**
203                 * Minimum value that meter IDs starting-with the specified name are expected to
204                 * observe. The longest match wins. Values can be specified as a long or as a
205                 * Duration value (for timer meters, defaulting to ms if no unit specified).
206                 */
207                private final Map<String, String> minimumExpectedValue = new LinkedHashMap<>();
208
209                /**
210                 * Maximum value that meter IDs starting-with the specified name are expected to
211                 * observe. The longest match wins. Values can be specified as a long or as a
212                 * Duration value (for timer meters, defaulting to ms if no unit specified).
213                 */
214                private final Map<String, String> maximumExpectedValue = new LinkedHashMap<>();
215
216                public Map<String, Boolean> getPercentilesHistogram() {
217                        return this.percentilesHistogram;
218                }
219
220                public Map<String, double[]> getPercentiles() {
221                        return this.percentiles;
222                }
223
224                public Map<String, ServiceLevelAgreementBoundary[]> getSla() {
225                        return this.sla;
226                }
227
228                public Map<String, String> getMinimumExpectedValue() {
229                        return this.minimumExpectedValue;
230                }
231
232                public Map<String, String> getMaximumExpectedValue() {
233                        return this.maximumExpectedValue;
234                }
235
236        }
237
238}