prometheus and docker (docker galway, november 2015)

33
Prometheus and Docker Monitoring and Management Brian Brazil Founder

Upload: brian-brazil

Post on 11-Jan-2017

2.652 views

Category:

Internet


5 download

TRANSCRIPT

Prometheus and DockerMonitoring and Management

Brian BrazilFounder

Who am I?Engineer passionate about running software reliably in production.

● TCD CS Degree● Google SRE for 7 years, working on high-scale reliable systems such as

Adwords, Adsense, Ad Exchange, Billing, Database● Boxever TL Systems&Infrastructure, applied processes and technology to let

allow company to scale and reduce operational load● Contributor to many open source projects, including Prometheus, Ansible,

Python, Aurora and Zookeeper.● Founder of Robust Perception, making scalability and efficiency available to

everyone

Why monitor?

● Know when things go wrong○ To call in a human to prevent a business-level issue, or prevent an issue in advance

● Be able to debug and gain insight● Trending to see changes over time, and drive technical/business decisions● To feed into other systems/processes (e.g. QA, security, automation)

Common Monitoring ChallengesThemes common among companies I’ve talk to:

● Monitoring tools are limited, both technically and conceptually● Tools don’t scale well and are unwieldy to manage● Operational practices don’t align with the business

For example:

Your customers care about increased latency and it’s in your SLAs. You can only alert on individual machine CPU usage.

Result: Engineers continuously woken up for non-issues, get fatigued

Fundamental Challenge is Limited Visibility

PrometheusInspired by Google’s Borgmon monitoring system.

Started in 2012 by ex-Googlers working in Soundcloud as an open source project, mainly written in Go. Publically launched in early 2015, and continues to be independent of any one company.

Over 100 companies have started relying on it since then.

What does Prometheus offer?● Inclusive Monitoring● Manageable and Reliable● Easy to integrate with● Dashboards● Powerful data model● Powerful query language● Efficient● Scalable

Services have Internals

Monitor the Internals

Monitor as a Service, not as Machines

Inclusive MonitoringDon’t monitor just at the edges:

● Instrument client libraries● Instrument server libraries (e.g. HTTP/RPC)● Instrument business logic

Library authors get information about usage.

Application developers get monitoring of common components for free.

Dashboards and alerting can be provided out of the box, customised for your organisation!

Python Instrumentation Examplepip install prometheus_client

from prometheus_client import Summary, start_http_serverREQUEST_DURATION = Summary('request_duration_seconds', 'Request duration in seconds')

@REQUEST_DURATION.time()def my_handler(request): pass # Your code here

start_http_server(8000)

Manageable and ReliableCore Prometheus server is a single binary.

Doesn’t depend on Zookeeper, Consul, Cassandra, Hadoop or the Internet.

Only requires local disk (SSD recommended). No potential for cascading failure.

Pull based, so easy to on run a workstation for testing and rogue servers can’t push bad metrics.

Advanced service discovery finds what to monitor.

Running Prometheus with DockerDocker images at https://hub.docker.com/r/prom/

To run Prometheus:

docker run -p 9090:9090 prom/prometheus:latest

This monitors itself.

http://localhost:9090/consoles/prometheus.html has a console.

Easy to integrate withMany existing integrations: Java, JMX, Python, Go, Ruby, .Net, Machine, Cloudwatch, EC2, MySQL, PostgreSQL, Haskell, Bash, Node.js, SNMP, Consul, HAProxy, Mesos, Bind, CouchDB, Django, Mtail, Heka, Memcached, RabbitMQ, Redis, RethinkDB, Rsyslog, Meteor.js, Minecraft...

Graphite, Statsd, Collectd, Scollector, Munin, Nagios integrations aid transition.

It’s so easy, most of the above were written without the core team even knowing about them!

Cadvisor natively supports PrometheusRun Cadvisor:

docker run -v /var/run/:/var/run -v /sys:/sys -p 8080:8080 google/cadvisor

http://localhost:8080/metrics will have metrics for all your containers

Service DiscoveryIt’s vital to know where each of your instances is meant to be running.

Systems such as Docker Swarm spread applications across machines, so we need some form of service discovery to find them.

Both Swarm and Prometheus support Consul, so let’s try that.

Setting up Swarm on localhost (1)MY_IP=1.2.3.4# - Run consuldocker run -d --name=consul --net=host gliderlabs/consul-server \ -bootstrap

# - Pass the docker daemon -H tcp://0.0.0.0:2375 so it’ll do TCP

# - Register services in Consuldocker run -d --net=host -v /var/run/docker.sock:/tmp/docker.sock \ gliderlabs/registrator consul://localhost:8500

# - Join the swarmdocker run -d swarm join --addr=$MY_IP:2375 \ consul://$MY_IP:8500/swarm

Setting up Swarm on localhost (2)# - Run some machine monitoringdocker run -d -v /var/run/:/var/run -v /sys:/sys -p 8080:8080 \ google/cadvisordocker run -d -v /:/rootfs:ro -p 9100:9100 --net=host \ -e SERVICE_NAME=node prom/node-exporter

# - Start the Swarm Managerdocker run -d -p 2376:2375 swarm manage consul://$MY_IP:8500/swarm

# - Check it’s workingdocker -H tcp://127.0.0.1:2376 info

Prometheus configuration to use Consulscrape_configs: - job_name: 'consul' consul_sd_configs: - server: 127.0.0.1:8500 relabel_configs: - source_labels: [__meta_consul_service] regex: (.*) # Default next release replacement: $1 # Default next release target_label: job

Run Prometheus

docker run -d --net=host -p 9090:9090 \ -e SERVICE_NAME=prometheus \ robustperception/prometheus_local_consul

Visit http://localhost:9090/status to see it running

Automatic service discovery!

Dashboards

Many Dashboarding Options● Grafana

○ Latest release has full Prometheus support

● Promdash○ Prometheus-specific Ruby-on-Rails dashboarding solution○ Direction is moving towards Grafana instead

● Console templates○ Templating language inside Prometheus○ Good for having your dashboards checked in, and for fully-custom dashboards

● Expression Browser○ Included in Prometheus, good for ad-hoc debugging

● Roll your own○ JSON API

Powerful Data ModelAll metrics have arbitrary multi-dimensional labels.

No need to force your model into dotted strings.

Can aggregate, cut, and slice along them.

Supports any double value, labels support full unicode.

Example: Labels from Node Exporter

Powerful Query LanguageCan multiply, add, aggregate, join, predict, take quantiles across many metrics in the same query. Can evaluate right now, and graph back in time.

Answer questions like:

● What’s the 95th percentile latency in the European datacenter?● How full will the disks be in 4 hours?● Which services are the top 5 users of CPU?

Can alert based on any query.

Example: Top 5 Docker images by CPU

topk(5, sum by (image)(

rate(container_cpu_usage_seconds_total{id=~"/system.slice/docker.*"}[5m]

) ))

EfficientInstrumenting everything means a lot of data.

Prometheus is best in class for lossless storage efficiency, 3.5 bytes per datapoint.

A single server can handle:

● millions of metrics● hundreds of thousands of datapoints per second

ScalablePrometheus is easy to run, can give one to each team in each datacenter.

Federation allows pulling key metrics from other Prometheus servers.

When one job is too big for a single Prometheus server, can use sharding+federation to scale out. Needed with thousands of machines.

Final Thought: Instrument Once, Use EverywhereWhen an application is instrumented, tends to be limited in which monitoring systems it supports.

You’re left with a choice: Have N monitoring systems, or run extra services to act as shims to translate.

Prometheus clients aren’t just limited to outputting metrics in the Prometheus format, can also output to Graphite and other monitoring systems. Prometheus clients can also take in metrics from other monitoring systems.

Prometheus clients can be your instrumentation and metrics interchange, even when not using Prometheus itself!

What do we do?Robust Perception provides consulting and training to give you confidence in your production service's ability to run efficiently and scale with your business.

We can help you:

● Decide if Prometheus is for you● Manage your transition to Prometheus and resolve issues that arise● With capacity planning, debugging, infrastructure etc.

We are proud to be among the core contributors to the Prometheus project.

ResourcesOfficial Project Website: prometheus.io

Official Mailing List: [email protected]

Demo: demo.robustperception.io

Dockerfiles: https://github.com/RobustPerception/docker_examples

Robust Perception Website: www.robustperception.io

Queries: [email protected]