Created
March 4, 2020 13:55
-
-
Save hexfusion/edda3cddf344b362201fecc4307ec3bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # https://grafana.com/docs/grafana/latest/http_api/auth/#create-api-token | |
| GRAFANA_TOKEN="" | |
| if [ "$1" = "" ]; then | |
| echo "url to prometheus.tar required" | |
| exit 1 | |
| fi | |
| LINK=$1 | |
| SUB_DIR=$2 | |
| if [ "$2" = "" ]; then | |
| SUB_DIR=sbatsche-$(date '+%Y-%m-%d-%s') | |
| fi | |
| INSTALL_DIR="${HOME}/prometheus/$SUB_DIR" | |
| IP=$((1 + RANDOM % 253)) | |
| init () { | |
| mkdir -p $INSTALL_DIR | |
| cd $INSTALL_DIR | |
| mkdir prometheus | |
| curl $LINK > prometheus.tar | |
| tar -xzf "$INSTALL_DIR/prometheus.tar" -C "$INSTALL_DIR/prometheus" | |
| BASE_LINK=$(echo $LINK | grep -oP '(.+?(?=artifacts))') | |
| echo "BASE ${BASE_LINK}finished.json" | |
| curl -s ${BASE_LINK}finished.json > ./finished.json | |
| sudo chmod -R 777 prometheus | |
| } | |
| gen_config() { | |
| cat > $INSTALL_DIR/docker-compose.yml << EOF | |
| version: '2' | |
| services: | |
| prom1: | |
| image: prom/prometheus:v2.14.0 | |
| restart: always | |
| ports: | |
| - 9090 | |
| volumes: | |
| - ./prometheus/:/prometheus/ | |
| networks: | |
| prom_net: | |
| ipv4_address: 172.24.${IP}.10 | |
| networks: | |
| prom_net: | |
| driver: bridge | |
| driver_opts: | |
| com.docker.network.enable_ipv6: "false" | |
| ipam: | |
| driver: default | |
| config: | |
| - subnet: 172.24.${IP}.0/24 | |
| gateway: 172.24.${IP}.1 | |
| EOF | |
| } | |
| start() { | |
| echo "Installing to $INSTALL_DIR" | |
| cd $INSTALL_DIR; docker-compose up -d | |
| END_TIME="$(jq -r '.timestamp' "./finished.json")" | |
| END_TIME_PARSED=$(date --date @${END_TIME} +"%Y-%m-%d %H:%M") | |
| START_TIME="$((END_TIME + 4600*3))" | |
| START_TIME_PARSED=$(date --date @${START_TIME} +"%Y-%m-%d %H:%M") | |
| echo "Now available via http://172.24.${IP}.10:9090/graph?g0.range_input=15m&g0.end_input=${START_TIME_PARSED}&g0.expr=etcd_debugging_mvcc_db_total_size_in_bytes&g0.tab=0" | |
| if [ "$GRAFANA_TOKEN" != "" ]; then | |
| BASE_LINK=$(echo $LINK | grep -oP '(.+?(?=artifacts))') | |
| echo "creating new grafana datasource $BASE_LINK " | |
| curl -X POST http://localhost:3000/api/datasources \ | |
| -H "Authorization: Bearer $GRAFANA_TOKEN" \ | |
| -H "content-type: application/json" \ | |
| --data @<(cat <<EOF | |
| { | |
| "name": "$BASE_LINK", | |
| "type": "prometheus", | |
| "url": "http://172.24.${IP}.10:9090", | |
| "access": "browser", | |
| "basicAuth": false | |
| } | |
| EOF | |
| ) | |
| fi | |
| } | |
| init | |
| gen_config | |
| start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment