Code coverage report for hyperbahn/clients/dual-statsd.js

Statements: 60% (36 / 60)      Branches: 100% (10 / 10)      Functions: 30.77% (4 / 13)      Lines: 60% (36 / 60)      Ignored: none     

All files » hyperbahn/clients/ » dual-statsd.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152                                            1 1 1 1   1   1   554 277     277   277 277 277 277   277                     277                             1 7105   7105 7105     1             1 38662   38662 38662     1             1 13708   13708 13708     1               1               1               1               1               1             1  
// Copyright (c) 2015 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
 
'use strict';
 
var os = require('os');
var process = require('process');
var Statsd = require('uber-statsd-client');
var assert = require('assert');
 
module.exports = DualStatsd;
 
function DualStatsd(options) {
    /*eslint no-process-env: 0 */
    if (!(this instanceof DualStatsd)) {
        return new DualStatsd(options);
    }
 
    var self = this;
 
    assert(options.host, 'options.host required');
    assert(options.port, 'options.port required');
    assert(options.project, 'options.project required');
    assert(options.processTitle, 'options.processTitle required');
 
    self.perServerClient = new Statsd({
        host: options.host,
        port: options.port,
        prefix: [
            options.project,
            process.env.NODE_ENV,
            os.hostname().split('.')[0]
        ].join('.'),
        packetQueue: options.packetQueue || null,
        socketTimeout: options.socketTimeout || null
    });
    self.perWorkerClient = new Statsd({
        host: options.host,
        port: options.port,
        prefix: [
            options.project,
            'per-worker',
            process.env.NODE_ENV,
            os.hostname().split('.')[0],
            options.processTitle
        ].join('.'),
        packetQueue: options.packetQueue || null,
        socketTimeout: options.socketTimeout || null
    });
}
 
DualStatsd.prototype.gauge = function gauge(name, value) {
    var self = this;
 
    self.perServerClient.gauge(name, value);
    self.perWorkerClient.gauge(name, value);
};
 
DualStatsd.prototype.counter = function counter(name, delta) {
    var self = this;
 
    self.perServerClient.counter(name, delta);
    self.perWorkerClient.counter(name, delta);
};
 
DualStatsd.prototype.increment = function increment(name, delta) {
    var self = this;
 
    self.perServerClient.increment(name, delta);
    self.perWorkerClient.increment(name, delta);
};
 
DualStatsd.prototype.decrement = function decrement(name, delta) {
    var self = this;
 
    self.perServerClient.decrement(name, delta);
    self.perWorkerClient.decrement(name, delta);
};
 
DualStatsd.prototype.timing = function timing(name, time) {
    var self = this;
 
    self.perServerClient.timing(name, time);
    self.perWorkerClient.timing(name, time);
};
 
DualStatsd.prototype.immediateGauge =
function immediateGauge(name, value, cb) {
    var self = this;
 
    self.perServerClient.immediateGauge(name, value, cb);
    self.perWorkerClient.immediateGauge(name, value, noop);
};
 
DualStatsd.prototype.immediateCounter =
function immediateCounter(name, delta, cb) {
    var self = this;
 
    self.perServerClient.immediateCounter(name, delta, cb);
    self.perWorkerClient.immediateCounter(name, delta, noop);
};
 
DualStatsd.prototype.immediateIncrement =
function immediateIncrement(name, delta, cb) {
    var self = this;
 
    self.perServerClient.immediateIncrement(name, delta, cb);
    self.perWorkerClient.immediateIncrement(name, delta, noop);
};
 
DualStatsd.prototype.immediateDecrement =
function immediateDecrement(name, delta, cb) {
    var self = this;
 
    self.perServerClient.immediateDecrement(name, delta, cb);
    self.perWorkerClient.immediateDecrement(name, delta, noop);
};
 
DualStatsd.prototype.immediateTiming =
function immediateTiming(name, time, cb) {
    var self = this;
 
    self.perServerClient.immediateTiming(name, time, cb);
    self.perWorkerClient.immediateTiming(name, time, noop);
};
 
DualStatsd.prototype.close = function close() {
    var self = this;
 
    self.perServerClient.close();
    self.perWorkerClient.close();
};
 
function noop() {}