├── 30-docker.conf ├── logrotate.conf ├── identidock ├── README.md ├── docker-compose.yml ├── Dockerfile ├── logstash.conf ├── cmd.sh ├── prod.yml ├── app │ ├── tests.py │ └── identidock.py └── prod-with-logging.yml ├── README.md ├── prometheus.conf └── LICENSE /30-docker.conf: -------------------------------------------------------------------------------- 1 | :syslogtag,startswith,"docker/" @@localhost:5544 2 | &stop 3 | -------------------------------------------------------------------------------- /logrotate.conf: -------------------------------------------------------------------------------- 1 | /var/lib/docker/containers/*/*.log { 2 | daily 3 | rotate 3 4 | compress 5 | delaycompress 6 | missingok 7 | copytruncate 8 | } 9 | -------------------------------------------------------------------------------- /identidock/README.md: -------------------------------------------------------------------------------- 1 | identidock 2 | ========== 3 | 4 | Simple identicon server based on monsterid from Kevin Gaudin. 5 | 6 | From "Using Docker" by Adrian Mouat published by O'Reilly media. 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using Docker Code Examples 2 | ## "Logging and Monitoring" 3 | 4 | NOTE: It is strongly recommended that you use the "pinned_images" branch rather 5 | than "master" in order to avoid problems with incompatabilities between versions 6 | of the ELK stack and logspout. 7 | -------------------------------------------------------------------------------- /prometheus.conf: -------------------------------------------------------------------------------- 1 | global: 2 | scrape_interval: 1m 3 | scrape_timeout: 10s 4 | evaluation_interval: 1m 5 | 6 | scrape_configs: 7 | 8 | - job_name: prometheus 9 | scheme: http 10 | target_groups: 11 | - targets: 12 | - 'cadvisor:8080' 13 | - 'localhost:9090' 14 | -------------------------------------------------------------------------------- /identidock/docker-compose.yml: -------------------------------------------------------------------------------- 1 | identidock: 2 | image: amouat/identidock:1.0 3 | ports: 4 | - "5000:5000" 5 | - "9000:9000" 6 | environment: 7 | ENV: DEV 8 | links: 9 | - dnmonster 10 | - redis 11 | dnmonster: 12 | image: amouat/dnmonster:1.0 13 | redis: 14 | image: redis:3 15 | -------------------------------------------------------------------------------- /identidock/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.4 2 | 3 | FROM python:3.4 4 | 5 | RUN groupadd -r uwsgi && useradd -r -g uwsgi uwsgi 6 | RUN pip install Flask==0.10.1 uWSGI==2.0.8 requests==2.5.1 redis==2.10.3 7 | WORKDIR /app 8 | COPY app /app 9 | COPY cmd.sh / 10 | 11 | EXPOSE 9090 9191 12 | USER uwsgi 13 | 14 | CMD ["/cmd.sh"] 15 | -------------------------------------------------------------------------------- /identidock/logstash.conf: -------------------------------------------------------------------------------- 1 | input { 2 | syslog { 3 | type => syslog 4 | port => 5544 5 | } 6 | } 7 | 8 | filter { 9 | if [type] == "syslog" { 10 | syslog_pri { } 11 | date { 12 | match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] 13 | } 14 | } 15 | } 16 | 17 | output { 18 | elasticsearch { host => "elasticsearch" } 19 | stdout { codec => rubydebug } 20 | } 21 | -------------------------------------------------------------------------------- /identidock/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | if [ "$ENV" = 'DEV' ]; then 5 | echo "Running Development Server" 6 | exec python "identidock.py" 7 | elif [ "$ENV" = 'UNIT' ]; then 8 | echo "Running Unit Tests" 9 | exec python "tests.py" 10 | else 11 | echo "Running Production Server" 12 | exec uwsgi --http 0.0.0.0:9090 --wsgi-file /app/identidock.py \ 13 | --callable app --stats 0.0.0.0:9191 14 | fi 15 | -------------------------------------------------------------------------------- /identidock/prod.yml: -------------------------------------------------------------------------------- 1 | proxy: 2 | image: proxy:1.0 3 | links: 4 | - identidock 5 | ports: 6 | - "80:80" 7 | environment: 8 | - NGINX_HOST=45.55.251.164 9 | - NGINX_PROXY=http://identidock:9090 10 | identidock: 11 | image: amouat/identidock:1.0 12 | links: 13 | - dnmonster 14 | - redis 15 | environment: 16 | ENV: PROD 17 | dnmonster: 18 | image: amouat/dnmonster:1.0 19 | redis: 20 | image: redis:3 21 | -------------------------------------------------------------------------------- /identidock/app/tests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | import identidock 3 | 4 | 5 | class TestCase(unittest.TestCase): 6 | 7 | def setUp(self): 8 | identidock.app.config["TESTING"] = True 9 | self.app = identidock.app.test_client() 10 | 11 | def test_get_mainpage(self): 12 | page = self.app.post("/", data=dict(name="Moby Dock")) 13 | assert page.status_code == 200 14 | assert 'Hello' in str(page.data) 15 | assert 'Moby Dock' in str(page.data) 16 | 17 | def test_html_escaping(self): 18 | page = self.app.post("/", data=dict(name='">TEST