mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-09-10 22:54:45 +08:00
Update metrics with signalfx - report # of syncing accts per host
This commit is contained in:
parent
0c900b072d
commit
16b91ea394
7 changed files with 59 additions and 24 deletions
|
@ -19,6 +19,7 @@
|
|||
"redis": "2.x.x",
|
||||
"rx": "4.x.x",
|
||||
"sequelize": "3.x.x",
|
||||
"signalfx": "^3.0.1",
|
||||
"underscore": "1.x.x",
|
||||
"utf7": "https://github.com/truebit/utf7/archive/1f753bac59b99d93b17a5ef11681e232465e2558.tar.gz"
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {Metrics} = require(`nylas-core`)
|
||||
Metrics.startCapturing()
|
||||
Metrics.startCapturing('nylas-k2-api')
|
||||
|
||||
const Hapi = require('hapi');
|
||||
const HapiSwagger = require('hapi-swagger');
|
||||
|
|
|
@ -1,26 +1,54 @@
|
|||
const {NODE_ENV} = process.env
|
||||
const {env: {NODE_ENV, SIGNALFX_TOKEN}, pid} = process
|
||||
const os = require('os')
|
||||
const signalfx = require('signalfx')
|
||||
|
||||
class Metrics {
|
||||
constructor() {
|
||||
this.newrelic = null
|
||||
this.shouldReport = NODE_ENV && NODE_ENV !== 'development'
|
||||
}
|
||||
let newrelicClient = null
|
||||
let signalfxClient = null
|
||||
|
||||
startCapturing() {
|
||||
if (this.shouldReport) {
|
||||
this.newrelic = require('newrelic')
|
||||
}
|
||||
}
|
||||
const MetricTypes = {
|
||||
Gauge: 'gauges',
|
||||
Counter: 'counters',
|
||||
CumulativeCounter: 'cumulative_counters',
|
||||
}
|
||||
const shouldReport = NODE_ENV && NODE_ENV !== 'development'
|
||||
|
||||
|
||||
const Metrics = {
|
||||
|
||||
MetricTypes,
|
||||
|
||||
startCapturing(name) {
|
||||
if (!shouldReport) { return }
|
||||
newrelicClient = require('newrelic')
|
||||
signalfxClient = new signalfx.Ingest(SIGNALFX_TOKEN, {
|
||||
dimensions: {
|
||||
name,
|
||||
host: os.hostname(),
|
||||
pid: pid.toString(),
|
||||
env: NODE_ENV,
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
reportError(error) {
|
||||
if (this.newrelic && this.shouldReport) {
|
||||
this.newrelic.noticeError(error)
|
||||
}
|
||||
}
|
||||
|
||||
reportMetric() {
|
||||
if (!newrelicClient || !shouldReport) { return }
|
||||
newrelicClient.noticeError(error)
|
||||
},
|
||||
|
||||
reportMetric({name, value, type, dimensions = {}} = {}) {
|
||||
if (!signalfxClient || !shouldReport) { return }
|
||||
if (!name) {
|
||||
throw new Error('Metrics.reportMetric requires a metric.name')
|
||||
}
|
||||
if (value == null) {
|
||||
throw new Error('Metrics.reportMetric requires a metric.value')
|
||||
}
|
||||
if (!type) {
|
||||
throw new Error('Metrics.reportMetric requires a metric.type from Metrics.MetricTypes')
|
||||
}
|
||||
const metric = {metric: name, value, timestamp: Date.now(), dimensions}
|
||||
signalfxClient.send({[type]: [metric]})
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = new Metrics()
|
||||
module.exports = Metrics
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {Metrics} = require(`nylas-core`)
|
||||
Metrics.startCapturing()
|
||||
Metrics.startCapturing('nylas-k2-dashboard')
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {Metrics} = require(`nylas-core`)
|
||||
Metrics.startCapturing()
|
||||
Metrics.startCapturing('nylas-k2-message-processor')
|
||||
|
||||
const {PubsubConnector, DatabaseConnector, Logger} = require(`nylas-core`)
|
||||
const {processors} = require('./processors')
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
const {Metrics} = require(`nylas-core`)
|
||||
Metrics.startCapturing()
|
||||
Metrics.startCapturing('nylas-k2-sync')
|
||||
|
||||
const {DatabaseConnector, Logger} = require('nylas-core')
|
||||
const SyncProcessManager = require('./sync-process-manager');
|
||||
|
|
|
@ -64,9 +64,15 @@ class SyncProcessManager {
|
|||
client.setAsync(key, Date.now())
|
||||
.then(() => client.expireAsync(key, HEARTBEAT_EXPIRES))
|
||||
.then(() => {
|
||||
const accountsSyncing = Object.keys(this._workers).length
|
||||
this._logger.info({
|
||||
accounts_syncing_count: Object.keys(this._workers).length,
|
||||
accounts_syncing_count: accountsSyncing,
|
||||
}, "ProcessManager: 💘")
|
||||
global.Metrics.reportMetric({
|
||||
name: 'accounts_syncing_count',
|
||||
value: accountsSyncing,
|
||||
type: global.Metrics.MetricTypes.CumulativeCounter,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue