-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Add setting and expose prometheus on port 9100 #10766
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dcc9630
Add setting and expose prometheus on port 9100
rodrigok 38a3283
Prometheus: Add number of connected users
rodrigok 5d360ab
Send statistics to prometheus
rodrigok bb4ff6a
Prometheus: Add methods, subscriptions and callbacks data
rodrigok eae40f9
Prometheus: Add metrics of REST API calls
rodrigok 983cf74
Prometheus: Record subscriptions time
rodrigok 0fafb5c
Add metrics to notifications
sampaiodiego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,150 @@ | ||
| import client from 'prom-client'; | ||
| import connect from 'connect'; | ||
| import http from 'http'; | ||
| import _ from 'underscore'; | ||
|
|
||
| RocketChat.promclient = client; | ||
| client.collectDefaultMetrics(); | ||
|
|
||
| RocketChat.metrics = {}; | ||
|
|
||
| // one sample metrics only - a counter | ||
|
|
||
| RocketChat.metrics.meteorMethods = new client.Summary({ | ||
| name: 'meteor_methods', | ||
| help: 'summary of meteor methods count and time', | ||
| labelNames: ['method'] | ||
| }); | ||
| RocketChat.metrics.meteorMethods.observe(10); | ||
|
|
||
| RocketChat.metrics.rocketchatCallbacks = new client.Summary({ | ||
| name: 'rocketchat_callbacks', | ||
| help: 'summary of rocketchat callbacks count and time', | ||
| labelNames: ['hook', 'callback'] | ||
| }); | ||
| RocketChat.metrics.meteorMethods.observe(10); | ||
|
|
||
| RocketChat.metrics.rocketchatRestApi = new client.Summary({ | ||
| name: 'rocketchat_rest_api', | ||
| help: 'summary of rocketchat rest api count and time', | ||
| labelNames: ['method', 'entrypoint', 'status'] | ||
| }); | ||
| RocketChat.metrics.meteorMethods.observe(10); | ||
|
|
||
| RocketChat.metrics.meteorSubscriptions = new client.Summary({ | ||
| name: 'meteor_subscriptions', | ||
| help: 'summary of meteor subscriptions count and time', | ||
| labelNames: ['subscription'] | ||
| }); | ||
|
|
||
| RocketChat.metrics.messagesSent = new client.Counter({'name': 'message_sent', 'help': 'cumulated number of messages sent'}); | ||
| RocketChat.metrics.audioNotificationsSent = new client.Counter({'name': 'audio_sent', 'help': 'cumulated number of audio notifications sent'}); | ||
| RocketChat.metrics.desktopNotificationsSent = new client.Counter({'name': 'desktop_sent', 'help': 'cumulated number of desktop notifications sent'}); | ||
| RocketChat.metrics.mobileNotificationsSent = new client.Counter({'name': 'mobile_sent', 'help': 'cumulated number of mobile notifications sent'}); | ||
| RocketChat.metrics.emailNotificationsSent = new client.Counter({'name': 'email_sent', 'help': 'cumulated number of email notifications sent'}); | ||
|
|
||
| RocketChat.metrics.ddpSessions = new client.Gauge({'name': 'ddp_sessions_count', 'help': 'number of open ddp sessions'}); | ||
| RocketChat.metrics.ddpConnectedUsers = new client.Gauge({'name': 'ddp_connected_users', 'help': 'number of connected users'}); | ||
|
|
||
| RocketChat.metrics.version = new client.Gauge({'name': 'version', labelNames: ['version'], 'help': 'Rocket.Chat version'}); | ||
| RocketChat.metrics.migration = new client.Gauge({'name': 'migration', 'help': 'migration versoin'}); | ||
| RocketChat.metrics.instanceCount = new client.Gauge({'name': 'instance_count', 'help': 'instances running'}); | ||
| RocketChat.metrics.oplogEnabled = new client.Gauge({'name': 'oplog_enabled', labelNames: ['enabled'], 'help': 'oplog enabled'}); | ||
|
|
||
| // User statistics | ||
| RocketChat.metrics.totalUsers = new client.Gauge({'name': 'users_total', 'help': 'total of users'}); | ||
| RocketChat.metrics.activeUsers = new client.Gauge({'name': 'users_active', 'help': 'total of active users'}); | ||
| RocketChat.metrics.nonActiveUsers = new client.Gauge({'name': 'users_non_active', 'help': 'total of non active users'}); | ||
| RocketChat.metrics.onlineUsers = new client.Gauge({'name': 'users_online', 'help': 'total of users online'}); | ||
| RocketChat.metrics.awayUsers = new client.Gauge({'name': 'users_away', 'help': 'total of users away'}); | ||
| RocketChat.metrics.offlineUsers = new client.Gauge({'name': 'users_offline', 'help': 'total of users offline'}); | ||
|
|
||
| // Room statistics | ||
| RocketChat.metrics.totalRooms = new client.Gauge({'name': 'rooms_total', 'help': 'total of rooms'}); | ||
| RocketChat.metrics.totalChannels = new client.Gauge({'name': 'channels_total', 'help': 'total of public rooms/channels'}); | ||
| RocketChat.metrics.totalPrivateGroups = new client.Gauge({'name': 'private_groups_total', 'help': 'total of private rooms'}); | ||
| RocketChat.metrics.totalDirect = new client.Gauge({'name': 'direct_total', 'help': 'total of direct rooms'}); | ||
| RocketChat.metrics.totalLivechat = new client.Gauge({'name': 'livechat_total', 'help': 'total of livechat rooms'}); | ||
|
|
||
| // Message statistics | ||
| RocketChat.metrics.totalMessages = new client.Gauge({'name': 'messages_total', 'help': 'total of messages'}); | ||
| RocketChat.metrics.totalChannelMessages = new client.Gauge({'name': 'channel_messages_total', 'help': 'total of messages in public rooms'}); | ||
| RocketChat.metrics.totalPrivateGroupMessages = new client.Gauge({'name': 'private_group_messages_total', 'help': 'total of messages in private rooms'}); | ||
| RocketChat.metrics.totalDirectMessages = new client.Gauge({'name': 'direct_messages_total', 'help': 'total of messages in direct rooms'}); | ||
| RocketChat.metrics.totalLivechatMessages = new client.Gauge({'name': 'livechat_messages_total', 'help': 'total of messages in livechat rooms'}); | ||
|
|
||
| client.register.setDefaultLabels({ | ||
| uniqueId: RocketChat.settings.get('uniqueID'), | ||
| siteUrl: RocketChat.settings.get('Site_Url') | ||
| }); | ||
|
|
||
| const setPrometheusData = () => { | ||
| const date = new Date(); | ||
|
|
||
| client.register.setDefaultLabels({ | ||
| unique_id: RocketChat.settings.get('uniqueID'), | ||
| site_url: RocketChat.settings.get('Site_Url'), | ||
| version: RocketChat.Info.version | ||
| }); | ||
|
|
||
| RocketChat.metrics.ddpSessions.set(Object.keys(Meteor.server.sessions).length, date); | ||
| RocketChat.metrics.ddpConnectedUsers.set(_.compact(_.unique(Object.values(Meteor.server.sessions).map(s => s.userId))).length, date); | ||
|
|
||
| const statistics = RocketChat.models.Statistics.findLast(); | ||
| if (!statistics) { | ||
| return; | ||
| } | ||
|
|
||
| RocketChat.metrics.version.set({version: statistics.version}, 1, date); | ||
| RocketChat.metrics.migration.set(RocketChat.Migrations._getControl().version, date); | ||
| RocketChat.metrics.instanceCount.set(statistics.instanceCount, date); | ||
| RocketChat.metrics.oplogEnabled.set({enabled: statistics.oplogEnabled}, 1, date); | ||
|
|
||
| // User statistics | ||
| RocketChat.metrics.totalUsers.set(statistics.totalUsers, date); | ||
| RocketChat.metrics.activeUsers.set(statistics.activeUsers, date); | ||
| RocketChat.metrics.nonActiveUsers.set(statistics.nonActiveUsers, date); | ||
| RocketChat.metrics.onlineUsers.set(statistics.onlineUsers, date); | ||
| RocketChat.metrics.awayUsers.set(statistics.awayUsers, date); | ||
| RocketChat.metrics.offlineUsers.set(statistics.offlineUsers, date); | ||
|
|
||
| // Room statistics | ||
| RocketChat.metrics.totalRooms.set(statistics.totalRooms, date); | ||
| RocketChat.metrics.totalChannels.set(statistics.totalChannels, date); | ||
| RocketChat.metrics.totalPrivateGroups.set(statistics.totalPrivateGroups, date); | ||
| RocketChat.metrics.totalDirect.set(statistics.totalDirect, date); | ||
| RocketChat.metrics.totalLivechat.set(statistics.totlalLivechat, date); | ||
|
|
||
| // Message statistics | ||
| RocketChat.metrics.totalMessages.set(statistics.totalMessages, date); | ||
| RocketChat.metrics.totalChannelMessages.set(statistics.totalChannelMessages, date); | ||
| RocketChat.metrics.totalPrivateGroupMessages.set(statistics.totalPrivateGroupMessages, date); | ||
| RocketChat.metrics.totalDirectMessages.set(statistics.totalDirectMessages, date); | ||
| RocketChat.metrics.totalLivechatMessages.set(statistics.totalLivechatMessages, date); | ||
| }; | ||
|
|
||
| const app = connect(); | ||
|
|
||
| // const compression = require('compression'); | ||
| // app.use(compression()); | ||
|
|
||
| app.use('/metrics', (req, res) => { | ||
| res.setHeader('Content-Type', 'text/plain'); | ||
| res.end(RocketChat.promclient.register.metrics()); | ||
| }); | ||
|
|
||
| const server = http.createServer(app); | ||
|
|
||
| let timer; | ||
| RocketChat.settings.get('Prometheus_Enabled', (key, value) => { | ||
| if (value === true) { | ||
| server.listen({ | ||
| port: 9100, | ||
| host: process.env.BIND_IP || '0.0.0.0' | ||
| }); | ||
| timer = Meteor.setInterval(setPrometheusData, 5000); | ||
| } else { | ||
| server.close(); | ||
| Meteor.clearInterval(timer); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we re-use instance ip? I don't think we are using bind ip anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geekgonecrazy that is a copy from internal meteor code