Skip to content

Commit

Permalink
New metric to track oplog queue (#17142)
Browse files Browse the repository at this point in the history
* New metric to track oplog queue

* Reuse mongo instance from getMongoInfo
  • Loading branch information
rodrigok authored Apr 3, 2020
1 parent 7656ae1 commit 8e634be
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
6 changes: 5 additions & 1 deletion app/metrics/server/lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import connect from 'connect';
import _ from 'underscore';
import { Meteor } from 'meteor/meteor';

import { Info } from '../../../utils';
import { Info, getOplogInfo } from '../../../utils/server';
import { Migrations } from '../../../migrations';
import { settings } from '../../../settings';
import { Statistics } from '../../../models';
Expand Down Expand Up @@ -57,6 +57,7 @@ metrics.version = new client.Gauge({ name: 'rocketchat_version', labelNames: ['v
metrics.migration = new client.Gauge({ name: 'rocketchat_migration', help: 'migration versoin' });
metrics.instanceCount = new client.Gauge({ name: 'rocketchat_instance_count', help: 'instances running' });
metrics.oplogEnabled = new client.Gauge({ name: 'rocketchat_oplog_enabled', labelNames: ['enabled'], help: 'oplog enabled' });
metrics.oplogQueue = new client.Gauge({ name: 'rocketchat_oplog_queue', labelNames: ['queue'], help: 'oplog queue' });
metrics.oplog = new client.Counter({
name: 'rocketchat_oplog',
help: 'summary of oplog operations',
Expand Down Expand Up @@ -134,6 +135,9 @@ const setPrometheusData = async () => {
metrics.totalPrivateGroupMessages.set(statistics.totalPrivateGroupMessages, date);
metrics.totalDirectMessages.set(statistics.totalDirectMessages, date);
metrics.totalLivechatMessages.set(statistics.totalLivechatMessages, date);

const oplogQueue = getOplogInfo().mongo._oplogHandle?._entryQueue?.length || 0;
metrics.oplogQueue.set(oplogQueue, date);
};

const app = connect();
Expand Down
16 changes: 10 additions & 6 deletions app/utils/server/functions/getMongoInfo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { MongoInternals } from 'meteor/mongo';

export function getOplogInfo() {
const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);

return { oplogEnabled, mongo };
}

function fallbackMongoInfo() {
let mongoVersion;
let mongoStorageEngine;

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);
const { oplogEnabled, mongo } = getOplogInfo();

try {
const { version } = Promise.await(mongo.db.command({ buildinfo: 1 }));
Expand Down Expand Up @@ -34,9 +40,7 @@ export function getMongoInfo() {
let mongoVersion;
let mongoStorageEngine;

const { mongo } = MongoInternals.defaultRemoteCollectionDriver();

const oplogEnabled = Boolean(mongo._oplogHandle && mongo._oplogHandle.onOplogEntry);
const { oplogEnabled, mongo } = getOplogInfo();

try {
const { version, storageEngine } = Promise.await(mongo.db.command({ serverStatus: 1 }));
Expand Down
2 changes: 1 addition & 1 deletion app/utils/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export { roomTypes } from './lib/roomTypes';
export { RoomTypeRouteConfig, RoomTypeConfig, RoomSettingsEnum, RoomMemberActions, UiTextContext } from '../lib/RoomTypeConfig';
export { RoomTypesCommon } from '../lib/RoomTypesCommon';
export { isDocker } from './functions/isDocker';
export { getMongoInfo } from './functions/getMongoInfo';
export { getMongoInfo, getOplogInfo } from './functions/getMongoInfo';
export { getUserAvatarURL } from '../lib/getUserAvatarURL';
export { slashCommands } from '../lib/slashCommand';
export { getUserNotificationPreference } from '../lib/getUserNotificationPreference';
Expand Down
4 changes: 2 additions & 2 deletions server/startup/serverRunning.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/rocketchat:tap-i18n';

import { SystemLogger } from '../../app/logger';
import { settings } from '../../app/settings';
import { Info, getMongoInfo } from '../../app/utils';
import { settings } from '../../app/settings/server';
import { Info, getMongoInfo } from '../../app/utils/server';
import { Users } from '../../app/models/server';
import { sendMessagesToAdmins } from '../lib/sendMessagesToAdmins';

Expand Down

0 comments on commit 8e634be

Please sign in to comment.