• Stars
    star
    230
  • Rank 174,053 (Top 4 %)
  • Language
    Shell
  • License
    BSD 2-Clause "Sim...
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Official NGINX and Amplify Dockerfiles

1. Overview

NGINX Amplify is a free monitoring tool that can be used with a microservice architecture based on NGINX and Docker. Amplify is developed and maintained by Nginx Inc. — the company behind the NGINX software.

With Amplify it is possible to collect and aggregate metrics across Docker containers, and present a coherent set of visualizations of the key NGINX performance data, such as active connections or requests per second. It is also easy to quickly check for any performance degradations, traffic anomalies, and get a deeper insight into the NGINX configuration in general.

In order to use Amplify, a small Python-based agent software Amplify Agent should be installed inside the container.

The official documentation for Amplify is available here.

1.1. NGINX Amplify Agent Inside Docker Container

The Amplify Agent can be deployed in a Docker environment to monitor NGINX instances inside Docker containers.

The "agent-inside-the-container" is currenly the only mode of operation. In other words, the agent should be running in the same container, next to the NGINX instance.

1.2. Standalone Mode

By default the agent will try to determine the OS hostname on startup (see the docs here for more information). The hostname is used to generate an UUID to uniquely identify the new object in the monitoring backend.

This means that in the absence of the additional configuration steps, each new container started from an Amplify-enabled Docker image will be reported as a standalone system in the Amplify web user interface. Moreover, the reported hostname is typically something not easily readable.

When using Amplify with Docker, another option is available and recommended — which is imagename. The imagename option tells the Amplify Agent that it's running in a container environment, and that the agent should collect and report metrics and metadata accordingly.

If you prefer to see the individual instances started from the same image as separate objects, assign different imagename to each of the running instances.

You can learn more about the agent configuration options here.

1.3. Aggregate Mode

As described above, when reporting a new object for monitoring, the agent honors the imagename configuration option in the /etc/amplify-agent/agent.conf file.

The imagename option should be set either in the Dockerfile or using the environment variables.

It is possible to explicitly specify the same imagename for multiple instances. In this scenario, the metrics received from several agents will be aggregated internally on the backend side — with a single 'container'-type object created for monitoring.

This way a combined view of various statistics can be obtained (e.g. for a "microservice"). For example, this combined view can display the total number of requests per second through all backend instances of a microservice.

Containers with a common imagename do not have to share the same local Docker image or NGINX configuration. They can be located on different physical hosts too.

To set a common imagename for several containers started from the Amplify-enabled image, you may either:

  • Configure it explicitly in the Dockerfile
# If AMPLIFY_IMAGENAME is set, the startup wrapper script will use it to
# generate the 'imagename' to put in the /etc/amplify-agent/agent.conf
# If several instances use the same 'imagename', the metrics will
# be aggregated into a single object in NGINX Amplify. Otherwise Amplify
# will create separate objects for monitoring (an object per instance).
# AMPLIFY_IMAGENAME can also be passed to the instance at runtime as
# described below.

ENV AMPLIFY_IMAGENAME my-docker-instance-123

or

  • Use the -e option with docker run as in
docker run --name mynginx1 -e API_KEY=ffeedd0102030405060708 -e AMPLIFY_IMAGENAME=my-service-123 -d nginx-amplify

1.4. Current Limitations

The following list summarizes existing limitations of monitoring Docker containers with Amplify:

  • In order for the agent to collect additional NGINX metrics the NGINX logs should be kept inside the container (by default the NGINX logs are redirected to the Docker log collector). Alternatively the NGINX logs can be fed to the agent via syslog.
  • In "aggregate" mode, some of the OS metrics and metadata are not collected (e.g. hostnames, CPU usage, Disk I/O metrics, network interface configuration).
  • The agent can only monitor NGINX from inside the container. It is not currently possible to run the agent in a separate container and monitor the neighboring containers running NGINX.

We've been working on improving the support for Docker even more. Stay tuned!

2. How to Build and Run an Amplify-enabled NGINX image?

2.1. Building an Amplify-enabled image with NGINX

(Note: If you are really new to Docker, here's how to install Docker Engine on various OS.)

Let's pick our official NGINX Docker image as a good example. The Dockerfile that we're going to use for an Amplify-enabled image is part of this repo.

Here's how you can build the Docker image with the Amplify Agent inside, based on the official NGINX image:

git clone https://github.com/nginxinc/docker-nginx-amplify.git
cd docker-nginx-amplify
docker build -t nginx-amplify .

After the image is built, check the list of Docker images:

docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx-amplify       latest              d039b39d2987        3 minutes ago       241.6 MB

2.2. Running an Amplify-enabled NGINX Docker Container

Unless already done, you have to sign up, create an account in NGINX Amplify, and obtain a valid API_KEY.

To start a container from the new image, use the command below:

docker run --name mynginx1 -e API_KEY=ffeedd0102030405060708 -e AMPLIFY_IMAGENAME=my-service-123 -d nginx-amplify

where the API_KEY is that assigned to your NGINX Amplify account, and the AMPLIFY_IMAGENAME is set to identify the running service as described in sections 1.2 and 1.3 above.

After the container has started, you may check its status with docker ps:

docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
7d7b47ba4c72        nginx-amplify       "/entrypoint.sh"    3 seconds ago       Up 2 seconds        80/tcp, 443/tcp     mynginx1

and you can also check docker logs:

docker logs 7d7b47ba4c72
starting nginx ...
updating /etc/amplify-agent/agent.conf ...
---> using api_key = ffeedd0102030405060708
---> using imagename = my-service-123
starting amplify-agent ...

Check what processes have started:

docker exec 7d7b47ba4c72 ps axu
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1   4328   676 ?        Ss   19:33   0:00 /bin/sh /entrypoint.sh
root         5  0.0  0.5  31596  2832 ?        S    19:33   0:00 nginx: master process nginx -g daemon off;
nginx       11  0.0  0.3  31988  1968 ?        S    19:33   0:00 nginx: worker process
nginx       65  0.6  9.1 111584 45884 ?        S    19:33   0:06 amplify-agent

If you see the amplify-agent process, it all went smoothly, and you should see the new container in the Amplify web user interface in about a minute or so.

Check the Amplify Agent log:

docker exec 7d7b47ba4c72 tail /var/log/amplify-agent/agent.log
2016-08-05 19:49:39,001 [65] supervisor agent started, version=0.37-1 pid=65 uuid=<..> imagename=my-service-123
2016-08-05 19:49:39,047 [65] nginx_config running nginx -t -c /etc/nginx/nginx.conf
2016-08-05 19:49:40,047 [65] supervisor post https://receiver.amplify.nginx.com:443/<..>/ffeedd0102030405060708/agent/ 200 85 4 0.096
2016-08-05 19:50:24,674 [65] bridge_manager post https://receiver.amplify.nginx.com:443/<..>/ffeedd0102030405060708/update/ 202 2370 0 0.084

When you're done with the container, you can stop it like the following:

docker stop 7d7b47ba4c72

To check the status of all containers (running and stopped):

docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                        PORTS               NAMES
7d7b47ba4c72        nginx-amplify       "/entrypoint.sh"         22 minutes ago      Exited (137) 19 seconds ago                       mynginx1

Happy monitoring, and feel free to send us questions, opinions, and any feedback in general.

More Repositories

1

kubernetes-ingress

NGINX and NGINX Plus Ingress Controllers for Kubernetes
Go
4,651
star
2

docker-nginx

Official NGINX Dockerfiles
Shell
3,236
star
3

nginx-prometheus-exporter

NGINX Prometheus Exporter for NGINX and NGINX Plus
Go
1,572
star
4

NGINX-Demos

NGINX and NGINX Plus demos
HTML
1,254
star
5

ngx-rust

Rust binding for NGINX
Rust
720
star
6

nginx-ldap-auth

Example of LDAP authentication using ngx_http_auth_request_module
Python
681
star
7

ansible-role-nginx

Ansible role for installing NGINX
Shell
633
star
8

kic-reference-architectures

MARA: Modern Application Reference Architecture
Python
633
star
9

crossplane

Quick and reliable way to convert NGINX configurations into JSON and back.
Python
620
star
10

nginmesh

Istio compatible service mesh using NGINX
Go
611
star
11

nginx-s3-gateway

NGINX S3 Caching Gateway
JavaScript
511
star
12

nginx-gateway-fabric

NGINX Gateway Fabric provides an implementation for the Gateway API using NGINX as the data plane.
Go
488
star
13

docker-nginx-unprivileged

Unprivileged NGINX Dockerfiles
Shell
376
star
14

nginx-wiki

ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com
HTML
291
star
15

nginx-amplify-doc

Public documentation for Amplify
Makefile
201
star
16

nginx-openid-connect

Reference implementation of OpenID Connect integration for NGINX Plus
JavaScript
188
star
17

nginx-otel

Perl
157
star
18

ansible-role-nginx-config

Ansible role for configuring NGINX
Jinja
154
star
19

mra-ingenious

A photo-sharing app built by NGINX and implemented using the Fabric Model from the Microservices Reference Architecture.
JavaScript
143
star
20

rtapi

Real time API latency analyzer - Create a PDF report and HDR histogram of your APIs
Go
133
star
21

nginx-service-mesh

A service mesh powered by NGINX Plus to manage container traffic in Kubernetes environments.
Go
93
star
22

ansible-collection-nginx

Ansible collection for NGINX
67
star
23

nginx-ingress-operator

WARNING - DEPRECATION NOTICE: The NGINX Ingress Operator has been updated to be a Helm based operator. This repo has been deprecated and will soon be archived - the new NGINX Ingress Operator repo can be found at https://github.com/nginxinc/nginx-ingress-helm-operator.
Go
66
star
24

nginx-loadbalancer-kubernetes

A Kubernetes Controller to synchronize NGINX+ Resources with Kubernetes Ingress Resources
Go
58
star
25

nginx-asg-sync

NGINX Plus Integration with Cloud Autoscaling
Go
56
star
26

nginx-go-crossplane

A library for working with NGINX configs in Go
Go
55
star
27

bank-of-sirius

Bank of Sirius
Java
53
star
28

helm-charts

NGINX Helm Charts repository
50
star
29

nginx-plus-go-client

A client for NGINX Plus API for Go
Go
49
star
30

nginx-openshift-router

NGINX and NGINX Plus OpenShift Routers
HTML
42
star
31

nginx-ingress-helm-operator

NGINX Ingress Operator for NGINX and NGINX Plus Ingress Controllers. Based on the Helm chart for NGINX Ingress Controller - https://github.com/nginxinc/helm-charts
Mustache
37
star
32

docker-nginx-controller

Docker support for NGINX Controller Agent in Containers
Dockerfile
29
star
33

nginx-ingress-workshops

Nginx Ingress Controller Hands on Workshops, with Lab Exercises and Guides
Shell
29
star
34

microservices-march

Examples from the Microservices March lectures and exercises.
27
star
35

ngx-istio-mixer

NGINX module for Istio mixer
Rust
24
star
36

nginx-saml

Perl
23
star
37

new-relic-agent

A new relic agent for NGINX Plus metrics
Python
23
star
38

ansible-role-nginx-app-protect

Ansible role to install and configure NGINX App Protect (WAF and DoS) for NGINX Plus on your target host
Jinja
21
star
39

router-mesh-architecture

NGINX Router Mesh Network Architecture for Microservices
CSS
19
star
40

aws-ha-elastic-ip

Active-Passive HA Deployment on AWS Using an Elastic IP Address
Shell
17
star
41

nginx-plus-dashboard

HTML
16
star
42

website-resources-conf

content for nginx.com/resources/conf/ -- configuration files shared in blog posts, etc.
16
star
43

fabric-model-architecture

Repository for the NGINX Fabric Model Architecture
CSS
15
star
44

nginx-management-suite-iac

NMS IAC repo
HCL
14
star
45

ngxinfo

Python
13
star
46

Community-Code-of-Conduct

NGINX Open Source Community's Code of Conduct
11
star
47

nginx-amplify-agent

NGINX Amplify Agent
Python
11
star
48

mra-user-manager

User manager
HTML
10
star
49

snarejs

Snare.js
JavaScript
10
star
50

nginx-ns1-gslb

ARCHIVED - NGINX Plus Integration with NS1 GSLB
Go
10
star
51

mra-auth-proxy

Auth proxy for MRA
Jinja
9
star
52

nginx-wrapper

NGINX Event Process Wrapper
Go
9
star
53

template-repository

A template repository for new NGINX projects
9
star
54

ngx-stream-nginmesh-dest

Nginx module to get dest ip and port
C
8
star
55

ansible-role-nginx-unit

Ansible role for NGINX Unit
Jinja
8
star
56

ebook-managing-kubernetes-nginx

Shell
8
star
57

nginx-basics-workshops

HTML
8
star
58

nginx-unsupported-modules

Container builds of unsupported NGINX modules
Shell
7
star
59

nginx-hugo-theme

A hugo theme for NGINX documentation
CSS
7
star
60

ansible-role-nginx-management-suite

Ansible role for the NGINX Management Suite
Jinja
7
star
61

mra-content-service

Go
6
star
62

nginx-for-azure-deploy-action

Github Actions to sync NGINX configs into the NGINX for Azure service.
TypeScript
6
star
63

mra-photouploader

HTML
5
star
64

ansible_collection_nginx_controller

Collection of NGINX Controller Roles for Ansible
5
star
65

mra-photoresizer

HTML
5
star
66

nginx-controller-lab

Shell
4
star
67

mra-pages

JavaScript
4
star
68

nginxaas-for-azure-snippets

Example ARM templates for common NGINX for Azure use cases
Python
4
star
69

.github

4
star
70

nginx-plus-install-tools

NGINX Plus Install tools
Shell
4
star
71

mra-album-manager

Ruby
4
star
72

nginx-azure-workshops

Instructor Lead and Hands-on Lab Exercises and Lab Guides for NGINX as a Service for Microsoft Azure
Shell
4
star
73

homebrew-tap

Ruby
3
star
74

ansible-role-nginx_controller_application

Jinja
3
star
75

ansible_role_nginx_controller_agent

Ansible role for installing the NGINX Controller agent
Jinja
3
star
76

nap-dos-arbitrator-helm-chart

Smarty
3
star
77

nginx-aws-signature

NGINX AWS Signature Library to authenticate AWS services such as S3 and Lambda via NGINX and NGINX Plus.
JavaScript
3
star
78

alpine-fips

Alpine Linux with FIPS OpenSSL module
Dockerfile
3
star
79

ansible-role-nginx_controller_publish_api

Jinja
2
star
80

kic-test-containers

Docker containers used by the KIC team
Go
2
star
81

ansible-role-nginx_controller_user

Jinja
2
star
82

ansible-role-nginx_controller_environment

Managing environments within NGINX Controller
Jinja
2
star
83

ansible-role-nginx_controller_api_definition_import

Jinja
2
star
84

ansible-role-nginx-controller-gateway

Jinja
2
star
85

ansible_role_nginx_controller_install

Ansible role for installing NGINX Controller
Jinja
2
star
86

ansible-role-nginx-controller-certificate

Jinja
2
star
87

ansible-role-nginx-controller-component

Jinja
2
star
88

ansible_role_nginx_controller_generate_token

Jinja
2
star
89

ansible-role-nginx_controller_location

Jinja
2
star
90

ansible-role-nginx-controller-license

Jinja
2
star
91

ansible-role-nginx_controller_integration

Jinja
2
star
92

aws-marketplace-publish

Publish Docker images to AWS Marketplace
TypeScript
2
star
93

ansible-role-nginx_controller_user_role

Jinja
1
star
94

ansible-role-nginx_controller_forwarder

Jinja
1
star