Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache the curl #49

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# A minimal Nginx container including ContainerPilot
FROM nginx:1.11
FROM nginx:1.13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old 1.11 was too old for me to feel comfortable pushing a new image from.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, 1.11 came out a year ago.


# Add some stuff via apt-get
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bc \
ca-certificates \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be required for nginx:1.13

curl \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Install Consul
# Releases at https://releases.hashicorp.com/consul
RUN export CONSUL_VERSION=0.7.3 \
&& export CONSUL_CHECKSUM=901a3796b645c3ce3853d5160080217a10ad8d9bd8356d0b73fcd6bc078b7f82 \
RUN export CONSUL_VERSION=0.7.5 \
Copy link
Contributor Author

@misterbisson misterbisson May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The next version should probably jump to Consul 0.8.x, but I'm staying on the 0.7 branch because of some bugs in the first releases of 0.8.

&& export CONSUL_CHECKSUM=40ce7175535551882ecdff21fdd276cef6eaab96be8a8260e0599fadb6f1f5b8 \
&& curl --retry 7 --fail -vo /tmp/consul.zip "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" \
&& echo "${CONSUL_CHECKSUM} /tmp/consul.zip" | sha256sum -c \
&& unzip /tmp/consul -d /usr/local/bin \
Expand All @@ -25,18 +26,19 @@ RUN mkdir -p /etc/consul \

# Install Consul template
# Releases at https://releases.hashicorp.com/consul-template/
RUN export CONSUL_TEMPLATE_VERSION=0.18.0 \
&& export CONSUL_TEMPLATE_CHECKSUM=f7adf1f879389e7f4e881d63ef3b84bce5bc6e073eb7a64940785d32c997bc4b \
RUN export CONSUL_TEMPLATE_VERSION=0.18.3 \
&& export CONSUL_TEMPLATE_CHECKSUM=caf6018d7489d97d6cc2a1ac5f1cbd574c6db4cd61ed04b22b8db7b4bde64542 \
&& curl --retry 7 --fail -Lso /tmp/consul-template.zip "https://releases.hashicorp.com/consul-template/${CONSUL_TEMPLATE_VERSION}/consul-template_${CONSUL_TEMPLATE_VERSION}_linux_amd64.zip" \
&& echo "${CONSUL_TEMPLATE_CHECKSUM} /tmp/consul-template.zip" | sha256sum -c \
&& unzip /tmp/consul-template.zip -d /usr/local/bin \
&& rm /tmp/consul-template.zip

# Add Containerpilot and set its configuration
ENV CONTAINERPILOT_VER 2.7.2
# Releases at https://github.com/joyent/containerpilot/releases
ENV CONTAINERPILOT_VER 2.7.3
ENV CONTAINERPILOT file:///etc/containerpilot.json

RUN export CONTAINERPILOT_CHECKSUM=e886899467ced6d7c76027d58c7f7554c2fb2bcc \
RUN export CONTAINERPILOT_CHECKSUM=2511fdfed9c6826481a9048e8d34158e1d7728bf \
&& curl -Lso /tmp/containerpilot.tar.gz \
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
&& echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \
Expand Down
11 changes: 6 additions & 5 deletions bin/sensor
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ help() {
echo 'http://nginx.org/en/docs/http/ngx_http_stub_status_module.html'
}

# Cummulative number of dropped connections
# Cumulative number of dropped connections
unhandled() {
local accepts=$(curl -s --fail localhost/nginx-health | awk 'FNR == 3 {print $1}')
local handled=$(curl -s --fail localhost/nginx-health | awk 'FNR == 3 {print $2}')
local scraped=$(curl -s --fail localhost/nginx-health)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key change

local accepts=$(echo "${scraped}" | awk 'FNR == 3 {print $1}')
local handled=$(echo "${scraped}" | awk 'FNR == 3 {print $2}')
echo $(expr ${accepts} - ${handled})
}

# ratio of connections-in-use to available workers
connections_load() {
local scraped=$(curl -s --fail localhost/nginx-health)
local active=$(echo ${scraped} | awk '/Active connections/{print $3}')
local waiting=$(echo ${scraped} | awk '/Reading/{print $6}')
local active=$(echo "${scraped}" | awk '/Active connections/{print $3}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result from curl -s --fail localhost/nginx-health is a multi-line string, so we need to quote it when echoing it.

local waiting=$(echo "${scraped}" | awk '/Reading/{print $6}')
local workers=$(echo $(cat /etc/nginx/nginx.conf | perl -n -e'/worker_connections *(\d+)/ && print $1')
)
echo $(echo "scale=4; (${active} - ${waiting}) / ${workers}" | bc)
Expand Down