mkdir ${PROMETHEUS_RUNNING_DIR}
# *=*
${PROMETHEUS_SOFTWARE}/prometheus/prometheus --config.file=${PROMETHEUS_SOFTWARE}/prometheus/prometheus.yml --storage.tsdb.path=${PROMETHEUS_RUNNING_DIR}/data > /dev/null 2>&1 &
export PROMETHEUS_PID=$!
${PROMETHEUS_SOFTWARE}/node_exporter/node_exporter --web.listen-address=:9200  > /dev/null 2>&1 &
export NODE_PID=$!
# *=*
${PYTHON_INSTANCE} ${PROFILE_SCRAPE}/read_prometheus.py -o "${PROMETHEUS_RUNNING_DIR}" -s "${START}" -e "${END}" -i "${PROMETHEUS_IP}"
# *=*
sleep 1
kill -TERM ${NODE_PID}
kill -TERM ${PROMETHEUS_PID}
# *=*
echo 'Plotting Prometheus metrics to ${PROMETHEUS_RUNNING_DIR}'
if [ -f ${WORKING_DIR}/job_output_setup.txt ]; then
    ${PYTHON_INSTANCE} -c "import PyProfQueue.profilers.prometheus as prom; df, time_series = prom.load_df('${PROMETHEUS_RUNNING_DIR}/prometheus_data'); prom.plot_prom_profiling(df=df, time_series=time_series, name_prefix='${PROMETHEUS_RUNNING_DIR}/Prometheus', cwl_file='${WORKING_DIR}/job_output_setup.txt')"
else
    ${PYTHON_INSTANCE} -c "import PyProfQueue.profilers.prometheus as prom; df, time_series = prom.load_df('${PROMETHEUS_RUNNING_DIR}/prometheus_data'); prom.plot_prom_profiling(df=df, time_series=time_series, name_prefix='${PROMETHEUS_RUNNING_DIR}/Prometheus')"
fi
