Question about opcounters

I’m trying to understand why the value of the serverStatus.opcounters will go down from time to time. According to the documentation here: https://docs.mongodb.com/manual/reference/command/serverStatus/#serverstatus.opcounters the opcounter is basically a tally of each operation that occurred since the mongo server restarted.

So, if that’s truly the case, wouldn’t that number always be incremented (until it overflows I guess)? Or is there a time-frame that opstatus uses to determine how many operations occurred? Do they roll off after some time? Why would that number go down?

The reason I ask is because I was attempting to monitor one of our dev servers, and I saw the numbers going up then when I ran it again 2-3 seconds later they go down, then up again. It seems inconsistent?

Does anyone know what I should be seeing here?

Hi @Wyatt_Baggett and welcome in the MongoDB Community :muscle: !

Which command did you use? How are you monitoring this?

  • With mongostat for example, it’s just the number of commands since the last measurements: 1 sec earlier.
  • With db.serverStatus().opcounters, it should be what you are describing here, indeed.

Also, which version of MongoDB are you using? Since MongoDB 4.2, these values are implemented using 64 bits instead of 32.

Also, are you sure the devs didn’t restart your server in the meantime?

Cheers,
Maxime.

1 Like

Hey @MaBeuLux88!

It looks like the script I was using to run this command has an issue. I was comparing the previous values each time to determine the difference each time it ran the db.serverStatus().opcounters command. So that makes sense to me now why I’d see the values going down…

1 Like

Totally!
I think this script is trying to reproduce what mongostat is doing and it would also be much easier to plot these values to get something like what we have built-in MongoDB Atlas.