Skip to content
9minutesnooze edited this page Dec 6, 2011 · 3 revisions

The following will log select MongoDB statistics from mongostat to statsd using rstatsd.

output from mongostat looks like this:

insert  query update delete getmore command flushes mapped  vsize    res faults locked % idx miss %     qr|qw   ar|aw  netIn netOut  conn               set repl       time 
     0      0     27      0      45      28       0   228g   460g  4.65g      0      0.1          0       0|0     1|0     8k    13k   385 databasename    M   15:25:09 
     0      0     30      0      49      31       0   228g   460g  4.65g      0      0.1          0       0|0     2|0     9k    14k   385 databasename    M   15:25:10

Here is what an rstatsd.yaml file would look like to dump this data into statsd:

--- 
:statsd: 
  :host: graphitehost.example.com
  :port: 8125
:logfile: "/var/log/rstatsd.log"
:cmds:
- :cmd: "/usr/bin/mongostat 1"
  :regexes:
  - :regex: '\s*(?<insert>\d+)\s*(?<query>\d+)\s*(?<update>\d+)\s*(?<delete>\d+)\s*(?<getmore>\d+)\s*(?<command>\d+)\s*(?<flushes>\d+)\s*[\d\.]+[a-z]\s*[\d\.]+[a-z]\s*[\d\.]+[a-z]\s*(?<faults>\d+)'
    :use_value: true
    :metrics:
    - "mongodb"

This works for two reasons:

  1. :use_value: true - this parameter says to use the value of the named capture group as the increment to statsd
  2. mongostat 1 - this outputs the per second data every second, which means that no matter what our aggregation interval is, statsd and graphite will process it correctly.
Clone this wiki locally