better monitoring for python: inclusive monitoring with prometheus (pycon ireland 2015, lightning...

17
Better Monitoring for Python Inclusive Monitoring with Prometheus

Upload: brian-brazil

Post on 11-Jan-2017

1.145 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Better Monitoring for PythonInclusive Monitoring with Prometheus

Page 2: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Monitoring is often a Problem, not a SolutionThemes common among companies I 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

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

Page 3: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Fundamental Challenge is Limited Visibility

Page 4: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

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.

100+ companies using it including Digital Ocean, GoPro, Apple, Red Hat and Google.

Page 5: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Services have Internals

Page 6: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Monitor the Internals

Page 7: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Monitor as a Service, not as Machines

Page 8: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

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!

Page 9: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Let’s Talk Codepip 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)

Page 10: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Multiple Dimensions (No Evil Twins Please)from prometheus_client import CounterREQUESTS = Summary('requests_total', 'Total requests', ['method'])

def my_handler(request): REQUESTS.labels(request.method).inc() pass // Your code here

Page 11: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Exceptional Circumstances In Progressfrom prometheus_client import Counter, GaugeEXCEPTIONS = Counter('exceptions_total', 'Total exceptions')IN_PROGRESS = Gauge('inprogress_requests', 'In progress')

@EXCEPTIONS.count_exceptions()@IN_PROGRESS.track_inprogress()def my_handler(request): pass // Your code here

Page 12: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Getting Data Outfrom prometheus_client import start_http_server

if __name__ == '__main__': start_http_server(8080)

Also possible with Django, Twisted etc.

Page 13: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Oh Noes, My Vendor Lock In!from prometheus_client.bridge.graphite import GraphiteBridgegb = GraphiteBridge(('graphite.your.org', 2003))

gb.start(10.0) # Push every 10 seconds

Exposition to Prometheus doesn’t use a special API, can be hooked into whatever monitoring system you have.

Instrument once, work with everything!

Page 14: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Running PrometheusGrab binary from http://www.robustperception.io/prometheus-nightly-binaries/

Put config in prometheus.yml:

scrape_configs: - job_name: python target_groups: targets: [localhost:8000]Run it:

./prometheus

Page 15: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Dashboards

Page 16: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Prometheus is as Powerful as PythonCan slide, dice, aggregate and do math to produce your alerts

If it’s computable, Prometheus can compute it*

Alert on what matters, not on what your monitoring limit you to!

* Halting, tractability and sanity not guaranteed

Page 17: Better Monitoring for Python: Inclusive Monitoring with Prometheus (Pycon Ireland 2015, Lightning Talk)

Links!

Blog Posts: www.robustperception.io/tag/prometheus

Demo: demo.robustperception.io

Python Client: https://github.com/prometheus/client_python

Project Website: prometheus.io