# mongodb

The mongodb plugin is meant to report a local MongoDB server's activity from `mongostat`.

It is not enabled in the published plugin set. The registry in `plugins/plugins/index.ts` has it commented out, so adding `mongodb` to the `plugins` array does nothing. This page documents what the code does today.

## Enable it

You can't, without code changes. The source is an older class-based plugin that extends `MonitoringPlugin`, and `plugins/lib/MonitoringPlugin.ts` no longer exports that class. Every registered plugin uses the `createMonitoringPlugin` factory instead.

The example config has this section:

```json
{
  "mongodb": {
    "refreshInterval": 30000,
    "uri": "mongodb://localhost:27017",
    "databases": []
  }
}
```

The plugin reads none of these options.

| Option | Read by the code? |
|---|---|
| `refreshInterval` | No. `mongostat` runs with a fixed 10 second interval. |
| `uri` | No. The address `mongodb://localhost:27017` is hard-coded. |
| `databases` | No. |

## What it would report

The plugin starts `mongostat --json mongodb://localhost:27017 10` and keeps it running. For each line of output, it takes the `localhost:27017` entry and sends it unchanged, with unique id `mongodb-localhost:27017`. The payload is whatever `mongostat` prints, such as `conn`, `net_in`, `net_out`, `insert`, `query`, `update`, `delete`, `res` and `vsize`.

## When it alerts

The server's `mongodb` case raises an error when `status` is not `"connected"`. The reason is `MongoDB connection failed`. `mongostat` output has no `status` field, so every report would be judged an error.

A new problem does not notify on the first bad report. The server holds it until a second consecutive report is still bad.

## On the dashboard

The card is labelled `MongoDB`.

| Reading | Source | Warn | Crit |
|---|---|---|---|
| CONNS | `conn` | none | none |
| NET IN | `net_in`, formatted as bytes | none | none |
| NET OUT | `net_out`, formatted as bytes | none | none |

The card's color follows the stored status only. 
## Requirements

- The `mongostat` binary from MongoDB Database Tools on the PATH.
- A MongoDB server on `localhost:27017` that accepts connections without credentials.

## Gotchas

- The plugin parses each chunk of `mongostat` output as one JSON document. A chunk that holds two lines, or half of one, will throw.
