Skip to content

Commit

Permalink
Add node_exporter to the image
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed May 13, 2019
1 parent 03dc212 commit 6135dc0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
10 changes: 10 additions & 0 deletions pgsql11-primary-centos7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ENV PGROOT="/usr/pgsql-${PGVERSION}"

RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm \
&& yum -y install wget tar \
&& yum -y update \
&& yum -y install postgresql11 postgresql11-server postgresql11-contrib postgresql11-libs \
&& yum -y clean all
Expand All @@ -45,9 +46,18 @@ COPY conf/* /conf/
RUN chown -R postgres:postgres /conf /pgconf /pgdata /pgwal
RUN chmod 700 /conf /pgconf /pgdata /pgwal

RUN mkdir -p /usr/local/bin
RUN cd /tmp \
&& wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz \
&& tar xzf node_exporter-0.18.0.linux-amd64.tar.gz \
&& mv node_exporter-0.18.0.linux-amd64/node_exporter /usr/local/bin/node_exporter \
&& rm -Rf node_exporter-0.18.0.linux-amd64 node_exporter-0.18.0.linux-amd64.tar.gz \
&& chown postgres:postgres /usr/local/bin/node_exporter

VOLUME ["/pgconf", "/pgdata", "/pgwal"]

EXPOSE 5432
EXPOSE 9100

USER 26

Expand Down
2 changes: 1 addition & 1 deletion pgsql11-primary-centos7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project contains the PostgreSQL Primary image.
make build

# Run, and register the container under postgresql-primary
podman run -p 5432:5432 --name postgresql-primary -d -e PG_DATABASE=mydb -e PG_USER_NAME=myuser -e PG_USER_PASSWORD=mypass -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_NETWORK_MASK=all pgsql11-primary-centos7
podman run -p 5432:5432 -p 9100:9100 --name postgresql-primary -d -e PG_DATABASE=mydb -e PG_USER_NAME=myuser -e PG_USER_PASSWORD=mypass -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_NETWORK_MASK=all pgsql11-primary-centos7

# psql to postgresql-primary
psql -h localhost -p 5432 -U myuser mydb
Expand Down
11 changes: 11 additions & 0 deletions pgsql11-primary-centos7/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

NODE_EXPORTER_PIDFILE=/tmp/node_exporter.pid

function trap_sigterm() {
kill -SIGINT $(head -1 $NODE_EXPORTER_PIDFILE)
}

trap 'trap_sigterm' SIGINT SIGTERM

if [ ! -f /pgdata/PG_VERSION ]; then
export PG_MAX_CONNECTIONS=${PG_MAX_CONNECTIONS:-100}
export PG_SHARED_BUFFERS=${PG_SHARED_BUFFERS:-256}
Expand Down Expand Up @@ -104,4 +112,7 @@ if [ ! -f /pgdata/PG_VERSION ]; then
/usr/pgsql-11/bin/pg_ctl -D /pgdata/ stop
fi

/usr/local/bin/node_exporter >> /tmp/node_exporter.log 2>&1 &
echo $! > $NODE_EXPORTER_PIDFILE

exec /usr/pgsql-11/bin/postgres -D /pgdata/ "$@"
10 changes: 10 additions & 0 deletions pgsql11-replica-centos7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ENV PGROOT="/usr/pgsql-${PGVERSION}"

RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
&& rpm -Uvh https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm \
&& yum -y install wget tar \
&& yum -y update \
&& yum -y install postgresql11 postgresql11-server postgresql11-contrib postgresql11-libs \
&& yum -y clean all
Expand All @@ -45,9 +46,18 @@ COPY conf/* /conf/
RUN chown -R postgres:postgres /conf /pgconf /pgdata /pgwal
RUN chmod 700 /conf /pgconf /pgdata /pgwal

RUN mkdir -p /usr/local/bin
RUN cd /tmp \
&& wget https://github.com/prometheus/node_exporter/releases/download/v0.18.0/node_exporter-0.18.0.linux-amd64.tar.gz \
&& tar xzf node_exporter-0.18.0.linux-amd64.tar.gz \
&& mv node_exporter-0.18.0.linux-amd64/node_exporter /usr/local/bin/node_exporter \
&& rm -Rf node_exporter-0.18.0.linux-amd64 node_exporter-0.18.0.linux-amd64.tar.gz \
&& chown postgres:postgres /usr/local/bin/node_exporter

VOLUME ["/pgconf", "/pgdata", "/pgwal"]

EXPOSE 5432
EXPOSE 9100

USER 26

Expand Down
2 changes: 1 addition & 1 deletion pgsql11-replica-centos7/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This project contains the PostgreSQL Replica image.
make build

# Run, and register the container under postgresql-replica
podman run -p 5433:5432 --name postgresql-replica -d -e PG_MASTER=192.168.1.2 -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_SLOT_NAME=replica1 pgsql11-replica-centos7
podman run -p 5433:5432 -p 9101:9100 --name postgresql-replica -d -e PG_MASTER=192.168.1.2 -e PG_REPLICATION_NAME=repl -e PG_REPLICATION_PASSWORD=replpass -e PG_SLOT_NAME=replica1 pgsql11-replica-centos7

# psql to postgresql-replica
psql -h localhost -p 5433 -U myuser -c 'SELECT pg_is_in_recovery();' mydb
Expand Down
11 changes: 11 additions & 0 deletions pgsql11-replica-centos7/root/usr/bin/run-postgresql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

NODE_EXPORTER_PIDFILE=/tmp/node_exporter.pid

function trap_sigterm() {
kill -SIGINT $(head -1 $NODE_EXPORTER_PIDFILE)
}

trap 'trap_sigterm' SIGINT SIGTERM

if [ ! -f /pgdata/PG_VERSION ]; then
export PG_MASTER=${PG_MASTER}
export PG_REPLICATION_NAME=${PG_REPLICATION_NAME}
Expand Down Expand Up @@ -56,4 +64,7 @@ if [ ! -f /pgdata/PG_VERSION ]; then
cp /conf/recovery.conf /pgdata/
fi

/usr/local/bin/node_exporter >> /tmp/node_exporter.log 2>&1 &
echo $! > $NODE_EXPORTER_PIDFILE

exec /usr/pgsql-11/bin/postgres -D /pgdata/ "$@"

0 comments on commit 6135dc0

Please sign in to comment.