Monitoring Drupal with Sensu John VanDyk Iowa State University - - PowerPoint PPT Presentation

monitoring drupal with sensu
SMART_READER_LITE
LIVE PREVIEW

Monitoring Drupal with Sensu John VanDyk Iowa State University - - PowerPoint PPT Presentation

Monitoring Drupal with Sensu John VanDyk Iowa State University DrupalCorn Iowa City August 10, 2013 What is Sensu? Sensu architecture Sensu server Sensu client Drupal and Sensu Q: What is Sensu? A: A monitoring


slide-1
SLIDE 1

Monitoring Drupal with Sensu

John VanDyk Iowa State University DrupalCorn Iowa City August 10, 2013

slide-2
SLIDE 2
  • What is Sensu?
  • Sensu architecture
  • Sensu server
  • Sensu client
  • Drupal and Sensu
slide-3
SLIDE 3

Q: What is Sensu? A: A monitoring router

slide-4
SLIDE 4

A monitoring router

Sensu

Disk Space

Sensu is focused on monitoring; that is watching something to make sure it’s OK.

slide-5
SLIDE 5

A monitoring router

Sensu

Hey! Almost Out of Disk Space Email

It also handles routing.

slide-6
SLIDE 6

A monitoring router

Sensu

EEK! Out of Disk Space Logs Email Pager

Check results can be routed to the appropriate alerting system.

slide-7
SLIDE 7

Sensu

Check Handler

Sensu receives results from a check and gives them to a handler.

slide-8
SLIDE 8

Sensu

Check Handler

Disk space Email

slide-9
SLIDE 9

*yawn* So what's special?

What's special is very little client configuration, JSON everywhere, understandable code and little of it, and route all the things.

slide-10
SLIDE 10

Sensu Architecture

slide-11
SLIDE 11

RabbitMQ Ruby code Redis

Sensu consists of a message queue, a key/value store, and ruby code. RabbitMQ is a message broker that implements Advanced Message Queueing Protocol (AMQP). Written in Erlang, acquired by SpringSource which was then acquired by VMWare. Redis is an in-memory key/value store sponsored by VMWare.

slide-12
SLIDE 12

Ruby code RabbitMQ Base Web MySQL Redis

Sensu creates queues in RabbitMQ.

slide-13
SLIDE 13

RabbitMQ Base Checks:

  • Disk space
  • CPU%
  • Network if
  • Security

Web Checks:

  • httpd up
  • SSL current
  • varnish up
  • db connect

MySQL Checks:

  • log size OK
  • replication

running

  • long queries

Ruby code Redis

Sensu server sends checks into the queues.

slide-14
SLIDE 14

Ruby code RabbitMQ Base Web MySQL

Webservers MySQL Server

Redis

Servers subscribe to one more more queues.

slide-15
SLIDE 15

Ruby code RabbitMQ Base Web MySQL

Webservers MySQL Server

Redis

All servers can subscribe to a base queue.

slide-16
SLIDE 16

Ruby code RabbitMQ Base Web MySQL

Webservers MySQL Server

Redis

A server may subscribe to any number of appropriate queues.

slide-17
SLIDE 17

Ruby code RabbitMQ Base Web MySQL

Webservers MySQL Server

Redis

Adding monitoring for a new server is as simple as subscribing it to the proper queues.

slide-18
SLIDE 18

Sensu Server eventmachine em-redis- unified

  • j

amqp

OJ is the ruby Optimized JSON parser, a C extension to Ruby. Eventmachine is a library providing the Reactor design pattern which demultiplexes incoming events, dispatching them to individual handlers.

slide-19
SLIDE 19

Sensu configuration directory structure.

slide-20
SLIDE 20

{ "rabbitmq": { "user": "sensu", "port": 5671, "password": "secret", "vhost": "/sensu", "host": "sensuserver.example.com", "ssl": { "private_key_file": "/etc/sensu/ssl/key.pem", "cert_chain_file": "/etc/sensu/ssl/cert.pem" } } } /etc/sensu/conf.d/rabbitmq.json

Example of Sensu client configuration. Sets location of RabbitMQ so client can find queues to receive checks and publish results.

slide-21
SLIDE 21

{ "client": { "name": "www.example.com", "address": "203.0.113.5", "safe_mode": false, "subscriptions": [ "base", "drupal" ] } } /etc/sensu/conf.d/client.json

Example of Sensu client configuration. Client identifies itself and says which queues it wants to subscribe to. Safe mode means checks must be defined on client as well as server, preventing an evil server from running arbitrary code as checks on the client.

slide-22
SLIDE 22

Example: Checking that Drupal version is current

slide-23
SLIDE 23
  • 1. Create plugin (code that check will

execute on client when check runs)

  • 2. Define check configuration
  • 3. Determine appropriate handler(s)

General methodology.

slide-24
SLIDE 24
  • 1. Create plugin (code that check will

execute on client when check runs) drush @nrem.live core-status drupal-version --pipe Output: 7.20

slide-25
SLIDE 25
  • 1. Create plugin (code that check will

execute when check runs)

#!/bin/bash # Sensu check for Drupal current-ness. # # Example: check_drupal_current.sh @example.alias DRUPAL_VERSION=`drush $@ core-status drupal-version --pipe` DRUPAL_MAJOR_VERSION=${DRUPAL_VERSION:0:1} CURRENT_VERSION=$(</etc/drush/constants/currentdrupal${DRUPAL_MAJOR_VERSION}.txt) if [ $DRUPAL_VERSION != $CURRENT_VERSION ] then echo "VERSION WARNING - $@ $DRUPAL_VERSION" exit 1 else echo "VERSION OK - $@ $DRUPAL_VERSION" exit 0 fi

/etc/sensu/plugins/check_drupal_current.sh

slide-26
SLIDE 26
  • 2. Define check configuration on server

{ "checks": { "check_drupal_current": { "handlers": [ "mailer" ], "command": "/etc/sensu/plugins/check_drupal_current.sh @nrem.live", "subscribers": [ "drupal" ], "interval": 3600 "refresh": 86400 } } }

Interval means "run this check every this-many seconds." Refresh means "number of seconds handlers should wait before taking second action."

slide-27
SLIDE 27
  • 3. Determine appropriate handler(s)

{ "checks": { "check_drupal_current": { "handlers": [ "mailer" ], "command": "/etc/sensu/plugins/check_drupal_current.sh @nrem.live", "subscribers": [ "drupal" ], "interval": 3600 "refresh": 86400 } } }

slide-28
SLIDE 28

Avoid hardcoding drush alias { "checks": { "check_drupal_current": { "handlers": [ "mailer" ], "command": "/etc/sensu/plugins/check_drupal_current.sh :::drushalias:::", "subscribers": [ "drupal" ], "interval": 3600 "refresh": 86400 } } }

Use a placeholder instead of hardcoding.

slide-29
SLIDE 29

{ "client": { "name": "www.example.com", "address": "203.0.113.5", "safe_mode": false, "subscriptions": [ "base", "drupal" ], "drushalias": "@nrem.live" , } } /etc/sensu/conf.d/client.json

Arbitrary tokens can be set on the client in the client configuration JSON.

slide-30
SLIDE 30
slide-31
SLIDE 31

Example: Checking a Drupal Metric

slide-32
SLIDE 32
  • 1. Create plugin (code that check will

execute on client when check runs)

  • 2. Define check configuration
  • 3. Determine appropriate handler(s)

Same methodology for metrics.

slide-33
SLIDE 33
  • 1. Create plugin (code that check will

execute on client when check runs) drush @nrem.live sql-query "SELECT COUNT(lid) FROM linkchecker_link WHERE fail_count > 0" | sed -n 2p Output: 157

slide-34
SLIDE 34
  • 1. Create plugin (code that check will

execute on client when check runs)

#!/bin/bash # Sensu check for broken links in a Drupal site. Requires linkchecker Drupal # module. # # Example: count_broken_drupal_links.sh @example.alias BROKEN_LINK_COUNT=`drush $@ sql-query "SELECT COUNT(lid) AS broken FROM linkchecker_link WHERE fail_count > 0" | sed -n 2p` if [ $BROKEN_LINK_COUNT -gt 0 ] then echo "LINK WARNING - $@ $BROKEN_LINK_COUNT broken links" exit 1 else echo "LINK OK - $@ no broken links" exit 0 fi

/etc/sensu/plugins/count_broken_drupal_links.sh

slide-35
SLIDE 35
  • 2. Define check configuration on server

{ "checks": { "check_broken_drupal_links": { "type": "metric", "handlers": [ "mailer" ], "command": "/etc/sensu/plugins/ count_broken_drupal_links.sh :::drushalias:::", "subscribers": [ "drupal" ], "interval": 3600 "refresh": 86400 } } }

If you declare the check as a metric the results will be sent to the server even if the exit value is 0.

slide-36
SLIDE 36
  • 3. Determine appropriate handler(s)

{ "checks": { "check_broken_drupal_links": { "type": "metric", "handlers": [ "graphite" ], "command": "/etc/sensu/plugins/ count_broken_drupal_links.sh :::drushalias:::", "subscribers": [ "drupal" ], "interval": 3600 } } }

You might want to send your metrics to graphite.

slide-37
SLIDE 37
slide-38
SLIDE 38

Pushing Info from Drupal to Sensu

slide-39
SLIDE 39

(demo of logtosensu Drupal module)

slide-40
SLIDE 40

{ "timestamp":"2013-08-09T16:43:56.060628-0500", "level":"info", "message":"publishing check result", "payload": { "client":"www.example.com", "check": { "name":"watchdog", "output":"page: updated Foo.", "status":0, "handler":["default", "mailer"], "drupal_base_url":"http://local.dev/d723", "drupal_timestamp":1376084636, "drupal_type":"content", "drupal_ip":"127.0.0.1", "drupal_request_uri":"http://local.dev/d723/node/1/edit", "drupal_referer":"http://local.dev/d723/node/1/edit", "drupal_uid":"1", "drupal_link":"view", "type":"metric", "issued":1376084636 } } }

JSON event resulting from updating a page in Drupal.

slide-41
SLIDE 41

Much, much more: Any test, including Nagios scripts Any Drupal metric Any handler Mutators (not covered here) may change data before handler gets it http://sensuapp.org http://drupal.org/project/logtosensu