Skip to content

Commit d7180a3

Browse files
committed
EC feedback
1 parent dcb0c6d commit d7180a3

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

source/includes/monitoring/sdam.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,35 @@ typedef struct {
99
static void
1010
server_opening (const mongoc_apm_server_opening_t *event)
1111
{
12-
stats_t *context;
13-
14-
context = (stats_t *) mongoc_apm_server_opening_get_context (event);
15-
context->server_opening_events++;
12+
stats_t *stats = (stats_t *) mongoc_apm_server_opening_get_context (event);
13+
stats->server_opening_events += 1;
1614

1715
printf ("Server opening: %s\n", mongoc_apm_server_opening_get_host (event)->host_and_port);
1816
}
1917

2018
int
2119
main (void)
2220
{
23-
mongoc_client_t *client;
24-
mongoc_apm_callbacks_t *cbs
25-
stats_t stats = {0};
2621
mongoc_init ();
2722

28-
client = mongoc_client_new ("<connection string URI>");
23+
stats_t stats = {0};
2924

30-
cbs = mongoc_apm_callbacks_new ();
31-
mongoc_apm_set_server_opening_cb (cbs, server_opening);
32-
mongoc_client_set_apm_callbacks (client, cbs, (void *) &stats);
25+
mongoc_client_t *client = mongoc_client_new ("<connection string URI>");
26+
27+
{
28+
mongoc_apm_callbacks_t *cbs = mongoc_apm_callbacks_new ();
29+
mongoc_apm_set_server_opening_cb (cbs, server_opening);
30+
mongoc_client_set_apm_callbacks (client, cbs, &stats);
31+
mongoc_apm_callbacks_destroy (cbs);
32+
}
3333

3434
// Perform database operations
3535

36-
mongoc_client_destroy (client);
37-
mongoc_apm_callbacks_destroy (cbs);
36+
mongoc_client_destroy (client);
37+
38+
printf ("Observed %d server opening events\n", stats.server_opening_events);
3839

3940
mongoc_cleanup ();
4041

4142
return EXIT_SUCCESS;
42-
}
43+
}

source/monitoring/cluster-monitoring.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@ Subscribe to Events
3636
-------------------
3737

3838
You can access details about SDAM events by subscribing to them
39-
in your application. To subscribe to an event, create a value of
40-
type ``mongoc_apm_callbacks_t`` and create an event callback function
41-
for the event you want to subscribe to. Use the callback's corresponding
42-
setter method to set the callback on the ``mongoc_apm_callbacks_t`` and
43-
pass this type to the ``mongoc_client_set_apm_callbacks()`` function.
39+
in your application. To subscribe to an event, define an Application
40+
Performance Monitoring (APM) callback function to handle each event
41+
type you want to subscribe to. Use a ``mongoc_apm_callbacks_t`` object
42+
to register the list of APM callbacks with a client using the
43+
``mongoc_client_set_apm_callbacks()`` function.
4444

4545
This code monitors server opening events by performing the following
4646
actions:
4747

48-
- Defines a ``server_opening()`` event handler function, or callback
49-
- Creates a ``mongoc_apm_callbacks_t`` structure to store callbacks
50-
- Calls the ``mongoc_apm_set_server_opening_cb()`` function, which instructs
51-
the ``mongoc_apm_callbacks_t`` type to store a pointer to the ``server_opening()``
52-
callback
48+
- Defines a ``server_opening()`` APM callback function
49+
- Creates a ``mongoc_apm_callbacks_t`` object to store callbacks
50+
- Calls the ``mongoc_apm_set_server_opening_cb()`` function, which
51+
stores a pointer to the provided APM callback function in the
52+
``mongoc_apm_callbacks_t`` object
5353
- Calls the ``mongoc_client_set_apm_callbacks()`` function, which registers
54-
the callback with the client
54+
the callback in the ``mongoc_apm_callbacks_t`` object with the client
5555

5656
.. literalinclude:: /includes/monitoring/sdam.c
5757
:language: c

0 commit comments

Comments
 (0)