diff --git a/devstack/observabilityclient-files/prometheus.yaml b/devstack/observabilityclient-files/prometheus.yaml new file mode 100644 index 00000000..9ff13455 --- /dev/null +++ b/devstack/observabilityclient-files/prometheus.yaml @@ -0,0 +1,2 @@ +host: localhost +port: 9090 diff --git a/devstack/plugin.sh b/devstack/plugin.sh index f2734547..d6de6627 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -1,3 +1,4 @@ +### sg-core ### function preinstall_sg-core { install_package $SG_CORE_CONTAINER_EXECUTABLE } @@ -8,44 +9,118 @@ function install_sg-core { function configure_sg-core { sudo mkdir -p `dirname $SG_CORE_CONF` - sudo cp $SG_CORE_DIR/devstack/sg-core.conf.yaml $SG_CORE_CONF + sudo cp $SG_CORE_DIR/devstack/sg-core-files/sg-core.conf.yaml $SG_CORE_CONF } function init_sg-core { $SG_CORE_CONTAINER_EXECUTABLE run -v $SG_CORE_CONF:/etc/sg-core.conf.yaml --network host --name sg-core -d $SG_CORE_CONTAINER_IMAGE } +### prometheus ### +function preinstall_prometheus { + install_package $SG_CORE_CONTAINER_EXECUTABLE +} + +function install_prometheus { + $SG_CORE_CONTAINER_EXECUTABLE pull $PROMETHEUS_CONTAINER_IMAGE +} + +function configure_prometheus { + BASE_CONFIG_FILE=$SG_CORE_DIR/devstack/prometheus-files/prometheus.yml + RESULT_CONFIG_FILE=$SG_CORE_WORKDIR/prometheus.yml + + cat $BASE_CONFIG_FILE > $RESULT_CONFIG_FILE + + SERVICES=$(echo $PROMETHEUS_SERVICE_SCRAPE_TARGETS | tr "," "\n") + for SERVICE in ${SERVICES[@]} + do + cat $SG_CORE_DIR/devstack/prometheus-files/scrape_configs/$SERVICE >> $RESULT_CONFIG_FILE + done + + if [[ $PROMETHEUS_CUSTOM_SCRAPE_TARGETS != "" ]]; then + echo " - job_name: 'custom'" >> $RESULT_CONFIG_FILE + echo " static_configs:" >> $RESULT_CONFIG_FILE + echo " - targets: [$PROMETHEUS_CUSTOM_SCRAPE_TARGETS]" >> $RESULT_CONFIG_FILE + fi + + sudo mkdir -p `dirname $PROMETHEUS_CONF` + sudo cp $RESULT_CONFIG_FILE $PROMETHEUS_CONF + + sudo cp $SG_CORE_DIR/devstack/observabilityclient-files/prometheus.yaml /etc/openstack/prometheus.yaml +} + +function init_prometheus { + $SG_CORE_CONTAINER_EXECUTABLE run -v $PROMETHEUS_CONF:/etc/prometheus/prometheus.yml --network host --name prometheus -d $PROMETHEUS_CONTAINER_IMAGE --config.file=/etc/prometheus/prometheus.yml --web.enable-admin-api +} + + # check for service enabled if is_service_enabled sg-core; then - if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then - # Set up system services - echo_summary "Configuring system services sg-core" - preinstall_sg-core - - elif [[ "$1" == "stack" && "$2" == "install" ]]; then - # Perform installation of service source - echo_summary "Installing sg-core" - install_sg-core - - elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then - # Configure after the other layer 1 and 2 services have been configured - echo_summary "Configuring sg-core" - configure_sg-core - - elif [[ "$1" == "stack" && "$2" == "extra" ]]; then - # Initialize and start the sg-core service - echo_summary "Initializing sg-core" - init_sg-core - fi - - if [[ "$1" == "unstack" ]]; then - $SG_CORE_CONTAINER_EXECUTABLE stop sg-core - $SG_CORE_CONTAINER_EXECUTABLE rm sg-core - fi - - if [[ "$1" == "clean" ]]; then - $SG_CORE_CONTAINER_EXECUTABLE rmi sg-core:latest - fi + mkdir $SG_CORE_WORKDIR + if [[ $SG_CORE_ENABLE = true ]]; then + if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then + # Set up system services + echo_summary "Configuring system services for sg-core" + preinstall_sg-core + + elif [[ "$1" == "stack" && "$2" == "install" ]]; then + # Perform installation of service source + echo_summary "Installing sg-core" + install_sg-core + + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + # Configure after the other layer 1 and 2 services have been configured + echo_summary "Configuring sg-core" + configure_sg-core + + elif [[ "$1" == "stack" && "$2" == "extra" ]]; then + # Initialize and start the sg-core service + echo_summary "Initializing sg-core" + init_sg-core + fi + + if [[ "$1" == "unstack" ]]; then + $SG_CORE_CONTAINER_EXECUTABLE stop sg-core + $SG_CORE_CONTAINER_EXECUTABLE rm sg-core + fi + + if [[ "$1" == "clean" ]]; then + $SG_CORE_CONTAINER_EXECUTABLE rmi $SG_CORE_CONTAINER_IMAGE + fi + fi + if [[ $PROMETHEUS_ENABLE = true ]]; then + if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then + # Set up system services + echo_summary "Configuring system services prometheus" + preinstall_prometheus + + elif [[ "$1" == "stack" && "$2" == "install" ]]; then + # Perform installation of service source + echo_summary "Installing prometheus" + install_prometheus + + elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then + # Configure after the other layer 1 and 2 services have been configured + echo_summary "Configuring prometheus" + configure_prometheus + + elif [[ "$1" == "stack" && "$2" == "extra" ]]; then + # Initialize and start the prometheus service + echo_summary "Initializing prometheus" + init_prometheus + fi + + if [[ "$1" == "unstack" ]]; then + $PROMETHEUS_CONTAINER_EXECUTABLE stop prometheus + $PROMETHEUS_CONTAINER_EXECUTABLE rm prometheus + fi + + if [[ "$1" == "clean" ]]; then + $PROMETHEUS_CONTAINER_EXECUTABLE rmi $PROMETHEUS_CONTAINER_IMAGE + fi + + fi + rm -rf $SG_CORE_WORKDIR fi diff --git a/devstack/prometheus-files/prometheus.yml b/devstack/prometheus-files/prometheus.yml new file mode 100644 index 00000000..b0f3377c --- /dev/null +++ b/devstack/prometheus-files/prometheus.yml @@ -0,0 +1,4 @@ +global: + scrape_interval: 15s # By default, scrape targets every 15 seconds. + +scrape_configs: diff --git a/devstack/prometheus-files/scrape_configs/prometheus b/devstack/prometheus-files/scrape_configs/prometheus new file mode 100644 index 00000000..04148a41 --- /dev/null +++ b/devstack/prometheus-files/scrape_configs/prometheus @@ -0,0 +1,4 @@ + - job_name: 'prometheus' + + static_configs: + - targets: ['localhost:9090'] diff --git a/devstack/prometheus-files/scrape_configs/sg-core b/devstack/prometheus-files/scrape_configs/sg-core new file mode 100644 index 00000000..2f7229dc --- /dev/null +++ b/devstack/prometheus-files/scrape_configs/sg-core @@ -0,0 +1,4 @@ + - job_name: 'sg-core' + + static_configs: + - targets: ['localhost:3000'] diff --git a/devstack/settings b/devstack/settings index 3e00b4c4..b44f8dbb 100644 --- a/devstack/settings +++ b/devstack/settings @@ -3,12 +3,36 @@ plugin_requires sg-core ceilometer enable_service sg-core enable_service ceilometer +### sg-core ### +SG_CORE_ENABLE=${SG_CORE_ENABLE:-true} + SG_CORE_DIR=$DEST/sg-core SG_CORE_CONF_DIR=/etc/sg-core SG_CORE_CONF=$SG_CORE_CONF_DIR/sg-core.conf.yaml +SG_CORE_WORKDIR=$SG_CORE_DIR/devstack/workdir SG_CORE_CONTAINER_REPOSITORY=${SG_CORE_CONTAINER_REPOSITORY:-quay.io/infrawatch/sg-core} SG_CORE_CONTAINER_TAG=${SG_CORE_CONTAINER_TAG:-latest} SG_CORE_CONTAINER_IMAGE=$SG_CORE_CONTAINER_REPOSITORY:$SG_CORE_CONTAINER_TAG SG_CORE_CONTAINER_EXECUTABLE="podman" + +### prometheus ### +PROMETHEUS_ENABLE=${PROMETHEUS_ENABLE:-true} + +PROMETHEUS_CONF_DIR=/etc/prometheus +PROMETHEUS_CONF=$PROMETHEUS_CONF_DIR/prometheus.yml + +PROMETHEUS_CONTAINER_REPOSITORY=${PROMETHEUS_CONTAINER_REPOSITORY:-quay.io/prometheus/prometheus} +PROMETHEUS_CONTAINER_TAG=${PROMETHEUS_CONTAINER_TAG:-latest} +PROMETHEUS_CONTAINER_IMAGE=$PROMETHEUS_CONTAINER_REPOSITORY:$PROMETHEUS_CONTAINER_TAG + +# It's assumed, that each service scrape target has its own same named +# file in the scrape_configs folder +# List of "," delimited names +# Currently supported values are "sg-core" and "prometheus" +PROMETHEUS_SERVICE_SCRAPE_TARGETS=${PROMETHEUS_SERVICE_SCRAPE_TARGETS:="sg-core"} + +# List of "," delimited targets. Each target is : +PROMETHEUS_CUSTOM_SCRAPE_TARGETS=${PROMETHEUS_CUSTOM_SCRAPE_TARGETS:-""} + diff --git a/devstack/sg-core.conf.yaml b/devstack/sg-core-files/sg-core.conf.yaml similarity index 100% rename from devstack/sg-core.conf.yaml rename to devstack/sg-core-files/sg-core.conf.yaml