Skip to content

[receiver/mongodbreceiver] Added new mongodb metrics to achieve parity with Telegraf #37227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
42aeaf8
Added queries_per_second Telegraf metric in mongodbreceiver
chan-tim-sumo Dec 19, 2024
9d09c39
Added rest of operation metrics
chan-tim-sumo Dec 20, 2024
802a27c
Added in replica metrics and routing logic for replica/secondary inst…
chan-tim-sumo Dec 27, 2024
60313de
Added active read/write metrics and removed debug statements
chan-tim-sumo Jan 7, 2025
d1eb7d4
fixed flushes per sec metric
chan-tim-sumo Jan 8, 2025
9c33d36
Wrapped up mongodb telegraf metrics
chan-tim-sumo Jan 8, 2025
d70e456
Merge branch 'main' into chan-tim_mongodbMetrics
chan-tim-sumo Jan 14, 2025
60368d1
fixed build error
chan-tim-sumo Jan 15, 2025
d558ff7
fixed make generate error
chan-tim-sumo Jan 15, 2025
cbe7cfd
disable metrics, users can enable if they want to see the new metrics
chan-tim-sumo Jan 16, 2025
2f06b9e
fixed lifecycle test taking too long
chan-tim-sumo Jan 16, 2025
4531088
fixed small comments on PR
chan-tim-sumo Jan 27, 2025
abdd742
fixed empty spaces
chan-tim-sumo Jan 27, 2025
36b0bb5
removed replica metrics and routing logic into a new PR
chan-tim-sumo Jan 27, 2025
591d125
removed repl metrics metadata
chan-tim-sumo Jan 27, 2025
aae695d
fixed make generate error
chan-tim-sumo Jan 28, 2025
7cdac15
Merge remote-tracking branch 'origin/main' into chan-tim_mongodbMetrics
chan-tim-sumo Jan 28, 2025
c9651fc
Merge branch 'main' into chan-tim_mongodbMetrics
chan-tim-sumo Jan 30, 2025
e66d4e9
fixed comments
chan-tim-sumo Feb 26, 2025
ab9fee4
fixed lint
chan-tim-sumo Feb 26, 2025
4b7896b
fixed lint
chan-tim-sumo Feb 26, 2025
ec4795b
fixed merge conflicts
chan-tim-sumo Mar 6, 2025
671cad6
fixed make generate
chan-tim-sumo Mar 6, 2025
fc8efe4
Merge branch 'main' into chan-tim_mongodbMetrics
chan-tim-sumo Mar 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/chan-tim_mongodbMetrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: mongodbreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added new mongodb metrics to acheive parity with Telegraf

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [37227]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
17 changes: 17 additions & 0 deletions receiver/mongodbreceiver/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ func (fc *fakeClient) IndexStats(ctx context.Context, dbName, collectionName str
return args.Get(0).([]bson.M), args.Error(1)
}

func (fc *fakeClient) RunCommand(ctx context.Context, db string, command bson.M) (bson.M, error) {
args := fc.Called(ctx, db, command)
if args.Get(0) == nil {
return nil, args.Error(1)
}

result, ok := args.Get(0).(bson.M)
if !ok {
err := errors.New("mock returned invalid type")
zap.L().Error("type assertion failed",
zap.String("expected", "bson.M"))
return nil, err
}

return result, args.Error(1)
}

func TestListDatabaseNames(t *testing.T) {
mont := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))

Expand Down
104 changes: 104 additions & 0 deletions receiver/mongodbreceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,70 @@ metrics:
enabled: true
```

### mongodb.active.reads

The number of read operations currently being processed.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {reads} | Sum | Int | Cumulative | false |

### mongodb.active.writes

The number of write operations currently being processed.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {writes} | Sum | Int | Cumulative | false |

### mongodb.cache.dirty.percent

The percentage of WiredTiger cache that is dirty.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |

### mongodb.cache.used.percent

The percentage of WiredTiger cache in use.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |

### mongodb.commands_per_sec

The number of commands executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {command}/s | Gauge | Double |

### mongodb.deletes_per_sec

The number of deletes executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {delete}/s | Gauge | Double |

### mongodb.flushes_per_sec

The number of flushes executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {flush}/s | Gauge | Double |

### mongodb.getmores_per_sec

The number of getmores executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {getmore}/s | Gauge | Double |

### mongodb.health

The health status of the server.
Expand All @@ -252,6 +316,14 @@ A value of '1' indicates healthy. A value of '0' indicates unhealthy.
| ---- | ----------- | ---------- |
| 1 | Gauge | Int |

### mongodb.inserts_per_sec

The number of insertions executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {insert}/s | Gauge | Double |

### mongodb.lock.acquire.count

Number of times the lock was acquired in the specified mode.
Expand Down Expand Up @@ -340,6 +412,30 @@ The number of replicated operations executed.
| ---- | ----------- | ------ |
| operation | The MongoDB operation being counted. | Str: ``insert``, ``query``, ``update``, ``delete``, ``getmore``, ``command`` |

### mongodb.page_faults

The number of page faults.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {faults} | Sum | Int | Cumulative | true |

### mongodb.queries_per_sec

The number of queries executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {query}/s | Gauge | Double |

### mongodb.updates_per_sec

The number of updates executed per second.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {update}/s | Gauge | Double |

### mongodb.uptime

The amount of time that the server has been running.
Expand All @@ -348,6 +444,14 @@ The amount of time that the server has been running.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| ms | Sum | Int | Cumulative | true |

### mongodb.wtcache.bytes.read

The number of bytes read into the WiredTiger cache.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | true |

## Resource Attributes

| Name | Description | Values | Enabled |
Expand Down
52 changes: 52 additions & 0 deletions receiver/mongodbreceiver/internal/metadata/generated_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading