#!/bin/sh
#
#  Copyright 2005-2018 Red Hat, Inc.
#
#  Red Hat licenses this file to you under the Apache License, version
#  2.0 (the "License"); you may not use this file except in compliance
#  with the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
#  implied.  See the License for the specific language governing
#  permissions and limitations under the License.
#

detectPrometheusConfig() {
    if [ -f "${KARAF_HOME}/etc/prometheus-config.yml" ] || [ -f "${KARAF_HOME}/etc/prometheus-config.yaml" ]; then

        if [ -f "${KARAF_HOME}/etc/prometheus-config.yml" ]; then
            KARAF_PROMETHEUS_CONFIG="${KARAF_HOME}/etc/prometheus-config.yml"
        else
            KARAF_PROMETHEUS_CONFIG="${KARAF_HOME}/etc/prometheus-config.yaml"
        fi

        # if there's no prometheus port set, let's set the port to 9779
        if [ "x${KARAF_PROMETHEUS_PORT}" = "x" ]; then
            KARAF_PROMETHEUS_PORT=9779
        fi
        KARAF_PROMETHEUS_VERSION="0.13.0"

        KARAF_PROMETHEUS_OPTS="-javaagent:${KARAF_HOME}/lib/jmx_prometheus_javaagent-${KARAF_PROMETHEUS_VERSION}.jar=${KARAF_PROMETHEUS_PORT}:${KARAF_PROMETHEUS_CONFIG}"
    fi
}
