UNPKG

@voicenter-team/mysql-dynamic-cluster

Version:

Galera cluster with implementation of dynamic choose mysql server for queries, caching, hashing it and metrics

50 lines 1.28 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.QueryTimer = void 0; const Metrics_1 = __importDefault(require("../metrics/Metrics")); class QueryTimer { /** * @param metric metric object where to save query time */ constructor(metric) { this._metric = metric; } /** * Start counting query time */ start() { this._timeStart = QueryTimer._getTime(); } /** * Stop counting query time */ end() { this._timeEnd = QueryTimer._getTime(); this._queryTime = Math.abs(this._timeStart - this._timeEnd) / 1000; } /** * Set query time to Metric * @param options extra options for metric like pool name or service name */ save(options) { Metrics_1.default.update(this._metric, this._queryTime, options); } /** * Get query time */ get() { return this._queryTime; } /** * Get time now * @private */ static _getTime() { return new Date().getTime(); } } exports.QueryTimer = QueryTimer; //# sourceMappingURL=QueryTimer.js.map