Skip to content

Instantly share code, notes, and snippets.

@lijunle
Last active December 22, 2018 15:54
Show Gist options
  • Save lijunle/93b1ceef964e1bfb422c22d1bb760c3e to your computer and use it in GitHub Desktop.
Save lijunle/93b1ceef964e1bfb422c22d1bb760c3e to your computer and use it in GitHub Desktop.
container-insights
#
# container-insights
#
# Send the docker container status to Azure Application Insight on every minute.
#
# Run it:
# docker run -d --privileged --restart always \
# -v /var/run/docker.sock:/var/run/docker.sock \
# -e IKEY=12345678-1234-1234-1234-1234567890xx \
# -e PREFIX=docker-01 \
# lijunle/container-insights
#
# Environment variable:
# IKEY: The Instrumentation key for the Application Insight instance.
# PREFIX: The prefix of the metric name.
#
FROM alpine
LABEL maintainer="Junle Li <lijunle@gmail.com>"
ENV IKEY=
ENV PREFIX=docker
WORKDIR /app
RUN apk add --no-cache curl jq findutils
COPY ./insights.sh ./
ENTRYPOINT [ "sh", "./insights.sh" ]
#!/bin/sh
while true
do
date
curl --silent --unix-socket /var/run/docker.sock http://localhost/containers/json \
| jq ".[].Names[0]" \
| xargs -i curl --silent -d \
'{"name":"MetricData","time":"'`date +%Y-%m-%dT%H:%M:%S%z`'","iKey":"'"$IKEY"'",
"data":{"baseType":"MetricData","baseData":{"metrics":[{"name":"'"$PREFIX"'{}","value":1}]}}}
' https://dc.services.visualstudio.com/v2/track
# Wait one minute
echo ''
sleep 60s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment