move node exporter and backup docker script
This commit is contained in:
1 parent
95c2f90031
commit
0e52aefa07
3 files changed
+2
No files matched your search
+40
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
OUT=/docker/monitoring/node_exporter/textfile_collector/custom.prom
|
||||
TS=$(date +%s%3N)
|
||||
if [[ "$(hostname)" == "mediahost" ]]; then
|
||||
DOCKER_CONTAINER_NUM=51
|
||||
elif [[ "$(hostname)" == "serverhost" ]]; then
|
||||
DOCKER_CONTAINER_NUM=4
|
||||
elif [[ "$(hostname)" == "quiethost" ]]; then
|
||||
DOCKER_CONTAINER_NUM=1
|
||||
fi
|
||||
{
|
||||
# Docker container states
|
||||
docker ps -a --format '{{.Names}}' | while read -r name; do
|
||||
if docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null | grep -q true; then
|
||||
echo "docker_container_state{name=\"$name\"} 1"
|
||||
else
|
||||
echo "docker_container_state{name=\"$name\"} 0"
|
||||
fi
|
||||
done
|
||||
|
||||
echo docker_container_number $DOCKER_CONTAINER_NUM
|
||||
|
||||
# Public IP information
|
||||
IP_JSON=$(curl -fsSL http://ip-api.com/json)
|
||||
|
||||
IP=$(jq -r '.query' <<< "$IP_JSON")
|
||||
COUNTRY=$(jq -r '.country' <<< "$IP_JSON")
|
||||
CITY=$(jq -r '.city' <<< "$IP_JSON")
|
||||
ISP=$(jq -r '.isp' <<< "$IP_JSON" | sed 's/"/\\"/g')
|
||||
COUNTRYCODE=$(jq -r '.countryCode' <<< "$IP_JSON")
|
||||
LAT=$(jq -r '.lat' <<< "$IP_JSON")
|
||||
LON=$(jq -r '.lon' <<< "$IP_JSON")
|
||||
|
||||
echo "public_ip_info{ip=\"$IP\",country=\"$COUNTRY\",city=\"$CITY\",isp=\"$ISP\",countrycode=\"$COUNTRYCODE\",lat=\"$LAT\",lon=\"$LON\"} 1"
|
||||
echo "custom_metrics_last_update_timestamp_seconds $(date +%s)"
|
||||
} > "$OUT.$$"
|
||||
|
||||
mv "$OUT.$$" "$OUT"
|
||||
|
||||
Reference in new issue
Block a user