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.export.prometheus;
018
019import java.time.Duration;
020import java.util.HashMap;
021import java.util.Map;
022
023import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation;
024import org.springframework.boot.context.properties.ConfigurationProperties;
025
026/**
027 * {@link ConfigurationProperties} for configuring metrics export to Prometheus.
028 *
029 * @author Jon Schneider
030 * @author Stephane Nicoll
031 * @since 2.0.0
032 */
033@ConfigurationProperties(prefix = "management.metrics.export.prometheus")
034public class PrometheusProperties {
035
036        /**
037         * Whether to enable publishing descriptions as part of the scrape payload to
038         * Prometheus. Turn this off to minimize the amount of data sent on each scrape.
039         */
040        private boolean descriptions = true;
041
042        /**
043         * Configuration options for using Prometheus Pushgateway, allowing metrics to be
044         * pushed when they cannot be scraped.
045         */
046        private final Pushgateway pushgateway = new Pushgateway();
047
048        /**
049         * Step size (i.e. reporting frequency) to use.
050         */
051        private Duration step = Duration.ofMinutes(1);
052
053        public boolean isDescriptions() {
054                return this.descriptions;
055        }
056
057        public void setDescriptions(boolean descriptions) {
058                this.descriptions = descriptions;
059        }
060
061        public Duration getStep() {
062                return this.step;
063        }
064
065        public void setStep(Duration step) {
066                this.step = step;
067        }
068
069        public Pushgateway getPushgateway() {
070                return this.pushgateway;
071        }
072
073        /**
074         * Configuration options for push-based interaction with Prometheus.
075         */
076        public static class Pushgateway {
077
078                /**
079                 * Enable publishing via a Prometheus Pushgateway.
080                 */
081                private Boolean enabled = false;
082
083                /**
084                 * Base URL for the Pushgateway.
085                 */
086                private String baseUrl = "localhost:9091";
087
088                /**
089                 * Frequency with which to push metrics.
090                 */
091                private Duration pushRate = Duration.ofMinutes(1);
092
093                /**
094                 * Job identifier for this application instance.
095                 */
096                private String job;
097
098                /**
099                 * Grouping key for the pushed metrics.
100                 */
101                private Map<String, String> groupingKey = new HashMap<>();
102
103                /**
104                 * Operation that should be performed on shutdown.
105                 */
106                private ShutdownOperation shutdownOperation = ShutdownOperation.NONE;
107
108                public Boolean getEnabled() {
109                        return this.enabled;
110                }
111
112                public void setEnabled(Boolean enabled) {
113                        this.enabled = enabled;
114                }
115
116                public String getBaseUrl() {
117                        return this.baseUrl;
118                }
119
120                public void setBaseUrl(String baseUrl) {
121                        this.baseUrl = baseUrl;
122                }
123
124                public Duration getPushRate() {
125                        return this.pushRate;
126                }
127
128                public void setPushRate(Duration pushRate) {
129                        this.pushRate = pushRate;
130                }
131
132                public String getJob() {
133                        return this.job;
134                }
135
136                public void setJob(String job) {
137                        this.job = job;
138                }
139
140                public Map<String, String> getGroupingKey() {
141                        return this.groupingKey;
142                }
143
144                public void setGroupingKey(Map<String, String> groupingKey) {
145                        this.groupingKey = groupingKey;
146                }
147
148                public ShutdownOperation getShutdownOperation() {
149                        return this.shutdownOperation;
150                }
151
152                public void setShutdownOperation(ShutdownOperation shutdownOperation) {
153                        this.shutdownOperation = shutdownOperation;
154                }
155
156        }
157
158}