Skip to content

Commit

Permalink
Initial Grafana/Prometheus/TimescaleSB image
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed May 22, 2019
1 parent 537ac00 commit e1c3ea5
Show file tree
Hide file tree
Showing 10 changed files with 1,702 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ The images makes use of
* SSL support
* `pg_stat_statements` integration
* Backup using [barman](https://www.pgbarman.org/)
* Administration with [pgadmin4](https://www.pgadmin.org/)
* Monitoring with [Grafana](https://grafana.com/), [Prometheus](https://prometheus.io/) and [TimescaleDB](https://www.timescale.com/)
* Asynchronous replication, up to 5 slaves
* Volumes for `/pgconf`, `/pgdata`, `/pgwal` and `/pgbackup`.

Expand Down
93 changes: 93 additions & 0 deletions pgsql11-grafana-centos7/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Jesper Pedersen <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# pgsql11-grafana-centos7
FROM centos:centos7

LABEL maintainer="Jesper Pedersen <[email protected]>"

LABEL summary="PostgreSQL 11 Grafana" \
description="PostgreSQL 11 Grafana"

# COPY conf/licenses /licenses

ENV PGVERSION="11"
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 centos-release-scl-rh \
&& yum -y install wget tar git gcc llvm5.0 llvm5.0-static make \
&& yum -y install devtoolset-7 llvm-toolset-7 \
&& yum -y update \
&& yum -y install postgresql11 postgresql11-server postgresql11-devel postgresql11-contrib postgresql11-libs \
&& yum install -y timescaledb_11 \
&& yum -y clean all

COPY root/ /

RUN mkdir -p /conf /pgconf /pgdata /pgwal
COPY conf/* /conf/
RUN chown -R postgres:postgres /conf /pgconf /pgdata /pgwal
RUN chmod 700 /conf /pgconf /pgdata /pgwal

RUN cd /tmp \
&& git clone https://github.com/timescale/pg_prometheus.git \
&& cd pg_prometheus \
&& export PATH=/usr/pgsql-11/bin:$PATH \
&& make \
&& make install \
&& cd .. \
&& rm -Rf pg_prometheus

RUN cd /tmp \
&& wget https://github.com/timescale/prometheus-postgresql-adapter/releases/download/0.4.1/prometheus-postgresql-adapter-0.4.1-linux-amd64.tar.gz \
&& tar xzf prometheus-postgresql-adapter-0.4.1-linux-amd64.tar.gz \
&& mv prometheus-postgresql-adapter /usr/local/bin/prometheus-postgresql-adapter \
&& rm -Rf prometheus-postgresql-adapter-0.4.1-linux-amd64.tar.gz \
&& chown postgres:postgres /usr/local/bin/prometheus-postgresql-adapter

RUN cd /tmp \
&& wget https://github.com/prometheus/prometheus/releases/download/v2.9.2/prometheus-2.9.2.linux-amd64.tar.gz \
&& mkdir -p /usr/local/ \
&& cd /usr/local \
&& tar xzf /tmp/prometheus-2.9.2.linux-amd64.tar.gz \
&& mv prometheus-2.9.2.linux-amd64 prometheus \
&& chown -R postgres:postgres prometheus \
&& rm -Rf /tmp/prometheus-2.9.2.linux-amd64.tar.gz

RUN cd /tmp \
&& wget https://dl.grafana.com/oss/release/grafana-6.2.0.linux-amd64.tar.gz \
&& mkdir -p /usr/local/ \
&& cd /usr/local \
&& tar xzf /tmp/grafana-6.2.0.linux-amd64.tar.gz \
&& mv grafana-6.2.0 grafana \
&& chown -R postgres:postgres grafana \
&& rm -Rf /tmp/grafana-6.2.0.linux-amd64.tar.gz

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

EXPOSE 9090
EXPOSE 3000

USER 26

CMD ["/usr/bin/run-grafana"]
26 changes: 26 additions & 0 deletions pgsql11-grafana-centos7/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# The MIT License (MIT)
#
# Copyright (c) 2019 Jesper Pedersen <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
IMAGE_NAME = pgsql11-grafana-centos7

.PHONY: build
build:
podman build --no-cache -t $(IMAGE_NAME) .
63 changes: 63 additions & 0 deletions pgsql11-grafana-centos7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# PostgreSQL Grafana

This project contains the PostgreSQL Grafana/Prometheus/TimescaleDB image.

## Getting Started

```bash
# Create the image
make build

# Run, and register the container under postgresql-grafana
podman run -p 9090:9090 -p 3000:3000 --name postgresql-grafana -d -e PG_USER_NAME=monuser -e PG_USER_PASSWORD=monpass -e PG_NETWORK_MASK=all -e PG_MONITOR1=192.168.1.2:9100 -e PG_MONITOR2=192.168.1.2:9187 pgsql11-grafana-centos7

# Shell to postgresql-grafana
podman exec -it postgresql-grafana /usr/bin/bash

# Get the IP address of the postgresql-grafana container
podman inspect postgresql-grafana | grep IPAddress

# Stop the container
podman stop postgresql-grafana

# Start the container
podman start postgresql-grafana

# Remove the container
podman rm postgresql-grafana
```

## Configuration

| Property | Default | Unit | Required | Description |
|----------|---------|------|----------|-------------|
| PG_USER_NAME | | | Yes | The user name |
| PG_USER_PASSWORD | | | Yes | The password for the user |
| PG_NETWORK_MASK | | | Yes | The network mask for database access |
| PG_MAX_CONNECTIONS | 100 | | | `max_connections` setting |
| PG_SHARED_BUFFERS | 256 | MB | | `shared_buffers` setting |
| PG_WORK_MEM | 8 | MB | | `work_mem` setting |
| PG_MAX_PARALLEL_WORKERS | 8 | | | `max_parallel_workers` setting |
| PG_EFFECTIVE_CACHE_SIZE | 1 | GB | | `effective_cache_size` setting |
| PG_MAX_WAL_SIZE | 1 | GB | | `max_wal_size` setting |
| PG_MONITOR1 | | | Yes | The first monitoring point |
| PG_MONITOR2 | | | | The second monitoring point |
| PG_MONITOR3 | | | | The third monitoring point |
| PG_MONITOR4 | | | | The fourth monitoring point |

## Volumes

| Name | Description |
|------|-------------|
| `/pgconf` | Volume for SSL configuration |
| `/pgdata` | PostgreSQL data directory |
| `/pgwal` | PostgreSQL Write-Ahead Log (WAL) |

## SSL support

SSL support will be enabled when `/pgconf` contains the files `root.crt`, `server.crt` and `server.key`.

Remember to disable passphase such that the server can boot without a password prompt.

A guide to this can be found [here](https://www.howtoforge.com/postgresql-ssl-certificates).
Test and production environments should **NOT** be using self-signed certificates.
Loading

0 comments on commit e1c3ea5

Please sign in to comment.