xref: /OpenGrok/opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/StatsdConfig.java (revision 5d9f3aa0ca3da3a714233f987fa732f62c0965f6)
10d7ace53SVladimir Kotal /*
20d7ace53SVladimir Kotal  * CDDL HEADER START
30d7ace53SVladimir Kotal  *
40d7ace53SVladimir Kotal  * The contents of this file are subject to the terms of the
50d7ace53SVladimir Kotal  * Common Development and Distribution License (the "License").
60d7ace53SVladimir Kotal  * You may not use this file except in compliance with the License.
70d7ace53SVladimir Kotal  *
80d7ace53SVladimir Kotal  * See LICENSE.txt included in this distribution for the specific
90d7ace53SVladimir Kotal  * language governing permissions and limitations under the License.
100d7ace53SVladimir Kotal  *
110d7ace53SVladimir Kotal  * When distributing Covered Code, include this CDDL HEADER in each
120d7ace53SVladimir Kotal  * file and include the License file at LICENSE.txt.
130d7ace53SVladimir Kotal  * If applicable, add the following below this CDDL HEADER, with the
140d7ace53SVladimir Kotal  * fields enclosed by brackets "[]" replaced with your own identifying
150d7ace53SVladimir Kotal  * information: Portions Copyright [yyyy] [name of copyright owner]
160d7ace53SVladimir Kotal  *
170d7ace53SVladimir Kotal  * CDDL HEADER END
180d7ace53SVladimir Kotal  */
190d7ace53SVladimir Kotal 
200d7ace53SVladimir Kotal /*
21*5d9f3aa0SAdam Hornáček  * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
220d7ace53SVladimir Kotal  */
230d7ace53SVladimir Kotal package org.opengrok.indexer.configuration;
240d7ace53SVladimir Kotal 
250d7ace53SVladimir Kotal import io.micrometer.statsd.StatsdFlavor;
260d7ace53SVladimir Kotal 
270d7ace53SVladimir Kotal /**
280d7ace53SVladimir Kotal  * Configuration for Statsd metrics emitted by the Indexer via {@link org.opengrok.indexer.util.Statistics}.
290d7ace53SVladimir Kotal  */
300d7ace53SVladimir Kotal public class StatsdConfig {
310d7ace53SVladimir Kotal     private int port;
320d7ace53SVladimir Kotal     private String host;
330d7ace53SVladimir Kotal     private boolean enabled;
340d7ace53SVladimir Kotal     private StatsdFlavor flavor;
350d7ace53SVladimir Kotal 
getHost()360d7ace53SVladimir Kotal     public String getHost() {
370d7ace53SVladimir Kotal         return host;
380d7ace53SVladimir Kotal     }
390d7ace53SVladimir Kotal 
setHost(String host)400d7ace53SVladimir Kotal     public void setHost(String host) {
410d7ace53SVladimir Kotal         this.host = host;
420d7ace53SVladimir Kotal     }
430d7ace53SVladimir Kotal 
getPort()440d7ace53SVladimir Kotal     public int getPort() {
450d7ace53SVladimir Kotal         return port;
460d7ace53SVladimir Kotal     }
470d7ace53SVladimir Kotal 
setPort(int port)480d7ace53SVladimir Kotal     public void setPort(int port) {
490d7ace53SVladimir Kotal         this.port = port;
500d7ace53SVladimir Kotal     }
510d7ace53SVladimir Kotal 
getFlavor()520d7ace53SVladimir Kotal     public StatsdFlavor getFlavor() {
530d7ace53SVladimir Kotal         return flavor;
540d7ace53SVladimir Kotal     }
550d7ace53SVladimir Kotal 
setFlavor(StatsdFlavor flavor)560d7ace53SVladimir Kotal     public void setFlavor(StatsdFlavor flavor) {
570d7ace53SVladimir Kotal         this.flavor = flavor;
580d7ace53SVladimir Kotal     }
590d7ace53SVladimir Kotal 
isEnabled()600d7ace53SVladimir Kotal     public boolean isEnabled() {
610d7ace53SVladimir Kotal         return port != 0 && host != null && !host.isEmpty() && flavor != null;
620d7ace53SVladimir Kotal     }
630d7ace53SVladimir Kotal 
640d7ace53SVladimir Kotal     /**
650d7ace53SVladimir Kotal      * Gets an instance version suitable for helper documentation by shifting
660d7ace53SVladimir Kotal      * most default properties slightly.
670d7ace53SVladimir Kotal      */
getForHelp()680d7ace53SVladimir Kotal     static StatsdConfig getForHelp() {
690d7ace53SVladimir Kotal         StatsdConfig res = new StatsdConfig();
700d7ace53SVladimir Kotal         res.setHost("foo.bar");
710d7ace53SVladimir Kotal         res.setPort(8125);
720d7ace53SVladimir Kotal         res.setFlavor(StatsdFlavor.ETSY);
730d7ace53SVladimir Kotal         return res;
740d7ace53SVladimir Kotal     }
750d7ace53SVladimir Kotal }
76