Skip to content

Commit

Permalink
Add prometheus to devstack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzigold committed Nov 7, 2023
1 parent d1e61d5 commit b2ee6d9
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 30 deletions.
2 changes: 2 additions & 0 deletions devstack/observabilityclient-files/prometheus.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
host: localhost
port: 9090
135 changes: 105 additions & 30 deletions devstack/plugin.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### sg-core ###
function preinstall_sg-core {
install_package $SG_CORE_CONTAINER_EXECUTABLE
}
Expand All @@ -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

4 changes: 4 additions & 0 deletions devstack/prometheus-files/prometheus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.

scrape_configs:
4 changes: 4 additions & 0 deletions devstack/prometheus-files/scrape_configs/prometheus
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- job_name: 'prometheus'

static_configs:
- targets: ['localhost:9090']
4 changes: 4 additions & 0 deletions devstack/prometheus-files/scrape_configs/sg-core
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- job_name: 'sg-core'

static_configs:
- targets: ['localhost:3000']
24 changes: 24 additions & 0 deletions devstack/settings
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ip>:<port>
PROMETHEUS_CUSTOM_SCRAPE_TARGETS=${PROMETHEUS_CUSTOM_SCRAPE_TARGETS:-""}

File renamed without changes.

0 comments on commit b2ee6d9

Please sign in to comment.