1 /*
2  * Copyright 2008-2019 by Emeric Vernat
3  *
4  *     This file is part of Java Melody.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.bull.javamelody;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import org.springframework.boot.context.properties.ConfigurationProperties;
24
25 /**
26  * Configuration properties for JavaMelody. <br/>
27  * This class is used for binding the configuration values in "application.yml" or "application.properties".
28  *
29  * @author Georg Wittberger
30  * @since 1.64.0
31  */

32 @ConfigurationProperties(prefix = JavaMelodyConfigurationProperties.PREFIX)
33 public class JavaMelodyConfigurationProperties {
34     /**
35      * Prefix of properties names.
36      */

37     public static final String PREFIX = "javamelody";
38
39     /**
40      * If JavaMelody should be enabled within the application.
41      */

42     private boolean enabled = true;
43     /**
44      * Comma-separated list of data source names which should be excluded from monitoring.
45      */

46     private String excludedDatasources;
47     /**
48      * If monitoring based on @RestController, @Controller, @Service, @Async, @Scheduled, @MonitoredWithSpring,
49      *  @FeignClient or on RestTemplate, MongoDatabaseFactory or ElasticsearchOperations should be enabled.
50      */

51     private boolean springMonitoringEnabled = true;
52     /**
53      * If /monitoring should be enabled for reports in the management http port instead of on the application http port.
54      */

55     private boolean managementEndpointMonitoringEnabled;
56     /**
57      * Map of initialization parameters to be passed to the JavaMelody monitoring filter.
58      * The available parameters are listed here: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
59      */

60     private Map<String, String> initParameters = new HashMap<>();
61
62     /**
63      * Returns if JavaMelody should be enabled within the application.
64      *
65      * @return <code>true</code> if JavaMelody should be enabled, otherwise <code>false</code>. Default: <code>true</code>
66      */

67     public boolean isEnabled() {
68         return enabled;
69     }
70
71     /**
72      * Sets whether JavaMelody should be enabled within the application.
73      *
74      * @param enabled <code>true</code> if JavaMelody should be enabled, otherwise <code>false</code>.
75      */

76     public void setEnabled(boolean enabled) {
77         this.enabled = enabled;
78     }
79
80     /**
81      * Returns a comma-separated list of data source names which should be excluded from monitoring.
82      *
83      * @return Data source names to exclude from monitoring.
84      */

85     public String getExcludedDatasources() {
86         return excludedDatasources;
87     }
88
89     /**
90      * Sets a comma-separated list of data source names which should be excluded from monitoring.
91      *
92      * @param excludedDatasources Data source names to exclude from monitoring.
93      */

94     public void setExcludedDatasources(String excludedDatasources) {
95         this.excludedDatasources = excludedDatasources;
96     }
97
98     /**
99      * If monitoring based on @RestController, @Controller, @Service, @Async, @Scheduled, @MonitoredWithSpring,
100      *  @FeignClient or on RestTemplate, MongoDatabaseFactory or ElasticsearchOperations should be enabled.
101      * @return true or false
102      */

103     public boolean isSpringMonitoringEnabled() {
104         return springMonitoringEnabled;
105     }
106
107     /**
108      * If monitoring based on @RestController, @Controller, @Service, @Async, @Scheduled, @MonitoredWithSpring,
109      *  @FeignClient or on RestTemplate, MongoDatabaseFactory or ElasticsearchOperations should be enabled.
110      * @param springMonitoringEnabled true or false
111      */

112     public void setSpringMonitoringEnabled(boolean springMonitoringEnabled) {
113         this.springMonitoringEnabled = springMonitoringEnabled;
114     }
115
116     /**
117      * Returns if /monitoring should be enabled for reports in the management http port instead of on the application http port.
118      * @return true or false
119      */

120     public boolean isManagementEndpointMonitoringEnabled() {
121         return managementEndpointMonitoringEnabled;
122     }
123
124     /**
125      * Sets whether /monitoring should be enabled for reports in the management http port instead of on the application http port.
126      * @param managementEndpointEnabled true or false
127      */

128     public void setManagementEndpointMonitoringEnabled(boolean managementEndpointEnabled) {
129         this.managementEndpointMonitoringEnabled = managementEndpointEnabled;
130     }
131
132     /**
133      * Returns a map of initialization parameters to be passed to the JavaMelody monitoring filter.
134      * The available parameters are listed here: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
135      *
136      * @return Initialization parameters for the JavaMelody monitoring filter.
137      */

138     public Map<String, String> getInitParameters() {
139         return initParameters;
140     }
141
142     /**
143      * Sets a map of initialization parameters to be passed to the JavaMelody monitoring filter.
144      * The available parameters are listed here: https://github.com/javamelody/javamelody/wiki/UserGuide#6-optional-parameters
145      *
146      * @param initParameters Initialization parameters for the JavaMelody monitoring filter.
147      */

148     public void setInitParameters(Map<String, String> initParameters) {
149         this.initParameters = initParameters;
150     }
151
152     /** {@inheritDoc} */
153     @Override
154     public String toString() {
155         return "JavaMelodyConfigurationProperties [enabled=" + enabled + ", excludedDatasources="
156                 + excludedDatasources + ", initParameters=" + initParameters + "]";
157     }
158 }
159