代码拉取完成,页面将自动刷新
#!/bin/sh
SUDO=""
PWD=`pwd`
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root, it will try 'sudo' when needed."
SUDO="sudo"
fi
case $1 in
start)
echo "Starting containers..."
cd $PWD/tools/docker
if [ ! -f prometheus.yml ]; then
# use the template as default config, to start Prometheus process
cp configs/prometheus.yml.template prometheus.yml
fi
$SUDO docker-compose up -d
# if datasource "test-cluster" doesn't exist, this is a new Grafana instahce,
# and we'll going to initial its configs
echo "Wait 30s for Grafana to finish startup..."
sleep 30 # wail Grafana to startup
DATASOURCE=$(curl -s -H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-H 'Authorization: Basic YWRtaW46YWRtaW4=' \
'http://localhost:3000/api/datasources/id/test-cluster')
if [[ $DATASOURCE = *"Data source not found"* ]]; then
echo "Initializing Grafana configuration..."
# add datasource
curl -s -H "Accept: application/json" -H "Content-Type: application/json" \
-H "Authorization: Basic YWRtaW46YWRtaW4=" -XPOST \
-d '{
"name": "test-cluster",
"type": "prometheus",
"access": "proxy",
"url": "http://prometheus:9090",
"basicAuth": false,
"withCredentials": false,
"isDefault": true,
"jsonData": {
"httpMethod": "GET",
"keepCookies": [
]
},
"readOnly": true
}' \
"http://localhost:3000/api/datasources"
# import dashboards
cd configs
./grafana-config-copy.py
else
echo "Using existing Grafana datasource $DATASOURCE"
fi
cd $PWD
;;
reload)
echo "Reloading Prometheus..."
$SUDO docker exec prometheus kill -HUP 1
;;
stop)
echo "Stopping containers..."
cd $PWD/tools/docker
$SUDO docker-compose down
cd $PWD
;;
clean)
echo "Stopping containers..."
cd $PWD/tools/docker
$SUDO docker-compose down
echo "Deleting all containers and data..."
$SUDO rm -rf data
;;
*)
echo "Setting InfluxDB database name to $1..."
sed "s/<DBNAME>/$1/g" $PWD/tools/docker/configs/prometheus.yml.template \
> $PWD/tools/docker/prometheus.yml
$SUDO docker exec prometheus kill -HUP 1
;;
esac
exit 0;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。