Last active
February 4, 2025 21:55
-
-
Save antonmry/535c62cae03bb2df089d1d6e858371b2 to your computer and use it in GitHub Desktop.
Scripts to run MinIO in Docker with Prometheus metrics enabled
This file contains 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
#!/bin/bash | |
# --- Configuration --- | |
MINIO_CONTAINER_NAME="minio_local_alt" | |
MINIO_PORT=9002 | |
MINIO_CONSOLE_PORT=9001 | |
MINIO_DATA_DIR="./minio/data" | |
MINIO_CONFIG_DIR="./minio/config" | |
MINIO_ACCESS_KEY="minioadmin" | |
MINIO_SECRET_KEY="minioadmin" | |
# --- Check if container exists and remove it --- | |
if docker container inspect "$MINIO_CONTAINER_NAME" > /dev/null 2>&1; then | |
echo "Container $MINIO_CONTAINER_NAME already exists. Removing it..." | |
docker stop "$MINIO_CONTAINER_NAME" | |
docker rm "$MINIO_CONTAINER_NAME" | |
fi | |
# --- Create data and config dirs --- | |
mkdir -p "$MINIO_DATA_DIR" | |
mkdir -p "$MINIO_CONFIG_DIR" | |
# Create the config file | |
cat << EOF > "$MINIO_CONFIG_DIR/config.json" | |
{ | |
"version": "16", | |
"credential": { | |
"accessKey": "$MINIO_ACCESS_KEY", | |
"secretKey": "$MINIO_SECRET_KEY" | |
}, | |
"region": "us-east-1", | |
"browser": { | |
"enabled": true | |
}, | |
"prometheus": { | |
"enabled": true, | |
"address": ":9090" | |
}, | |
"logger": { | |
"console": { | |
"enabled": false, | |
"level": "info" | |
} | |
} | |
} | |
EOF | |
docker run -d \ | |
-p "$MINIO_PORT:9000" \ | |
-p "$MINIO_CONSOLE_PORT:9001" \ | |
-v "$MINIO_DATA_DIR:/mnt/data" \ | |
-v "$MINIO_CONFIG_DIR:/root/.minio.sys" \ | |
-e "MINIO_ACCESS_KEY=$MINIO_ACCESS_KEY" \ | |
-e "MINIO_SECRET_KEY=$MINIO_SECRET_KEY" \ | |
--name "$MINIO_CONTAINER_NAME" \ | |
minio/minio server \ | |
--console-address ":9001" /mnt/data |
This file contains 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
{ | |
"name": "Minio", | |
"description": null, | |
"permissions": "PUBLIC_READ_WRITE", | |
"pages": [ | |
{ | |
"name": "Minio", | |
"description": null, | |
"widgets": [ | |
{ | |
"title": "Received Bytes", | |
"layout": { | |
"column": 1, | |
"row": 1, | |
"width": 4, | |
"height": 3 | |
}, | |
"linkedEntityGuids": null, | |
"visualization": { | |
"id": "viz.line" | |
}, | |
"rawConfiguration": { | |
"nrqlQueries": [ | |
{ | |
"accountIds": [ | |
11637782 | |
], | |
"query": "SELECT latest(`minio_s3_traffic_received_bytes`)\nFROM Metric\nWHERE `minio_s3_traffic_received_bytes` IS NOT NULL\nSINCE 60 minutes ago UNTIL now\nTIMESERIES" | |
} | |
] | |
} | |
}, | |
{ | |
"title": "Request by API", | |
"layout": { | |
"column": 5, | |
"row": 1, | |
"width": 5, | |
"height": 6 | |
}, | |
"linkedEntityGuids": null, | |
"visualization": { | |
"id": "viz.line" | |
}, | |
"rawConfiguration": { | |
"facet": { | |
"showOtherSeries": false | |
}, | |
"legend": { | |
"enabled": true | |
}, | |
"markers": { | |
"displayedTypes": { | |
"criticalViolations": false, | |
"deployments": true, | |
"relatedDeployments": true, | |
"warningViolations": false | |
} | |
}, | |
"nrqlQueries": [ | |
{ | |
"accountIds": [ | |
11637782 | |
], | |
"query": "SELECT max(`minio_s3_requests_total`) FROM Metric WHERE `minio_s3_requests_total` IS NOT NULL SINCE 60 minutes ago UNTIL now TIMESERIES FACET api" | |
} | |
], | |
"platformOptions": { | |
"ignoreTimeRange": false | |
}, | |
"thresholds": { | |
"isLabelVisible": true | |
}, | |
"yAxisLeft": { | |
"zero": true | |
}, | |
"yAxisRight": { | |
"zero": true | |
} | |
} | |
}, | |
{ | |
"title": "Sent Bytes", | |
"layout": { | |
"column": 1, | |
"row": 4, | |
"width": 4, | |
"height": 3 | |
}, | |
"linkedEntityGuids": null, | |
"visualization": { | |
"id": "viz.line" | |
}, | |
"rawConfiguration": { | |
"facet": { | |
"showOtherSeries": false | |
}, | |
"legend": { | |
"enabled": true | |
}, | |
"markers": { | |
"displayedTypes": { | |
"criticalViolations": false, | |
"deployments": true, | |
"relatedDeployments": true, | |
"warningViolations": false | |
} | |
}, | |
"nrqlQueries": [ | |
{ | |
"accountIds": [ | |
11637782 | |
], | |
"query": "SELECT latest(`minio_s3_traffic_sent_bytes`)\nFROM Metric\nWHERE `minio_s3_traffic_sent_bytes` IS NOT NULL\nSINCE 60 minutes ago UNTIL now\nTIMESERIES" | |
} | |
], | |
"platformOptions": { | |
"ignoreTimeRange": false | |
}, | |
"thresholds": { | |
"isLabelVisible": true | |
}, | |
"yAxisLeft": { | |
"zero": true | |
}, | |
"yAxisRight": { | |
"zero": true | |
} | |
} | |
} | |
] | |
} | |
], | |
"variables": [] | |
} |
This file contains 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
#!/bin/bash | |
# --- Configuration --- | |
MINIO_CONTAINER_NAME="minio_local_alt" | |
MINIO_PORT=9002 | |
MINIO_ACCESS_KEY="minioadmin" | |
MINIO_SECRET_KEY="minioadmin" | |
PROMETHEUS_CONFIG_FILE="prometheus.yml" | |
OTEL_CONFIG_FILE="config.yml" | |
MINIO_PROMETHEUS_PORT=9090 # Prometheus port | |
# --- Execute mc commands inside the container --- | |
docker exec "$MINIO_CONTAINER_NAME" mc alias set 'myminio' "http://localhost:9000" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY" | |
docker exec "$MINIO_CONTAINER_NAME" mc admin prometheus metrics play system --api-version v3 | |
# Capture the output of the last command to a file | |
docker exec "$MINIO_CONTAINER_NAME" mc admin prometheus generate myminio bucket > "$PROMETHEUS_CONFIG_FILE" | |
# --- Change the port in the prometheus.yml file --- | |
awk -v port="$MINIO_PORT" '{if($0 ~ /targets: \[/){sub(/:9000/,":"port)};print}' "$PROMETHEUS_CONFIG_FILE" > tmp.prometheus.yml && mv tmp.prometheus.yml "$PROMETHEUS_CONFIG_FILE" | |
# --- Transform Prometheus config to OTel config --- | |
# Extract the bearer token | |
BEARER_TOKEN=$(awk '/bearer_token: /{print $2}' "$PROMETHEUS_CONFIG_FILE") | |
# Extract the metrics path | |
METRICS_PATH=$(awk '/metrics_path: /{print $2}' "$PROMETHEUS_CONFIG_FILE") | |
cat << EOF > "$OTEL_CONFIG_FILE" | |
receivers: | |
prometheus: | |
config: | |
scrape_configs: | |
- job_name: "minio" | |
bearer_token: "$BEARER_TOKEN" | |
scrape_interval: 15s | |
scrape_timeout: 10s | |
metrics_path: "$METRICS_PATH" | |
static_configs: | |
- targets: ["localhost:$MINIO_PORT"] | |
processors: | |
batch: | |
exporters: | |
debug: | |
verbosity: detailed | |
service: | |
pipelines: | |
metrics: | |
receivers: [prometheus] | |
processors: [batch] | |
exporters: [debug] | |
EOF | |
echo "OpenTelemetry configuration saved to $OTEL_CONFIG_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment