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EAAK,GAAQ,CACxC,eAAO,EAAS,YAAE,EAAc,MAAS,CAAC,GACtC,MAAO,CACH,YAAa,GAAe,CAAC,kBAC7B,OAAQ,mBAEhB,GAEJ,iBAAmB,mBAAqB,WAAW,EAC/C,EAAI,SAAS,QAAQ,CAAC,GACtB,WAAW,oBAAqB,KACjC,kBACH,QAAQ,iBAAmB","file":"/npm/nestjs-prometheus-setup@0.1.0/dist/module.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/nestjs-prometheus-setup@0.1.0/dist/module.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {\n    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;\n    if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") r = Reflect.decorate(decorators, target, key, desc);\n    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;\n    return c > 3 && r && Object.defineProperty(target, key, r), r;\n};\nvar __metadata = (this && this.__metadata) || function (k, v) {\n    if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};\nvar PrometheusModule_1;\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.Prometheus = exports.PrometheusModule = exports.MetricController = void 0;\nconst common_1 = require(\"@nestjs/common\");\nconst Prometheus = require(\"prom-client\");\nexports.Prometheus = Prometheus;\nconst LabelsHelper_1 = require(\"./LabelsHelper\");\nfunction getTimeFrom(startAt) {\n    const diff = process.hrtime(startAt);\n    return diff[0] * 1e3 + diff[1] * 1e-6;\n}\nlet MetricController = class MetricController {\n    metrics() {\n        return Prometheus.register.metrics();\n    }\n};\n__decorate([\n    (0, common_1.Get)('/metrics'),\n    __metadata(\"design:type\", Function),\n    __metadata(\"design:paramtypes\", []),\n    __metadata(\"design:returntype\", void 0)\n], MetricController.prototype, \"metrics\", null);\nMetricController = __decorate([\n    (0, common_1.Controller)()\n], MetricController);\nexports.MetricController = MetricController;\nlet PrometheusModule = PrometheusModule_1 = class PrometheusModule {\n    constructor() {\n        this.PROM_LABELS = ['method', 'route', 'status'];\n        this.httpRequestsTotal = new Prometheus.Counter({\n            name: `http_requests_total`,\n            help: 'Counter for total requests received',\n            labelNames: this.PROM_LABELS,\n        });\n        this.httpRequestDurationSeconds = new Prometheus.Histogram({\n            name: `http_request_duration_seconds`,\n            help: 'Duration of HTTP requests in seconds',\n            labelNames: this.PROM_LABELS,\n            buckets: Prometheus.exponentialBuckets(0.05, 1.75, 8),\n        });\n        this.httpRequestLengthBytes = new Prometheus.Histogram({\n            name: `http_request_length_bytes`,\n            help: 'Content-Length of HTTP request',\n            labelNames: this.PROM_LABELS,\n            buckets: [],\n        });\n        this.httpResponseLengthBytes = new Prometheus.Histogram({\n            name: `http_response_length_bytes`,\n            help: 'Content-Length of HTTP request',\n            labelNames: this.PROM_LABELS,\n            buckets: [],\n        });\n        this.LabelsHelper = LabelsHelper_1.LabelsHelper;\n    }\n    configure(consumer) {\n        consumer.apply(this.middleware()).forRoutes('*');\n    }\n    middleware() {\n        return (req, res, next) => {\n            const startAt = process.hrtime();\n            next();\n            res.on('finish', () => {\n                const time = getTimeFrom(startAt);\n                const labels = this.middlewareLabels(req, res);\n                this.httpRequestsTotal.labels(...labels).inc();\n                this.httpRequestDurationSeconds.labels(...labels).observe(time / 1000);\n                this.httpRequestLengthBytes\n                    .labels(...labels)\n                    .observe(req.get('Content-Length') ? parseInt(req.get('Content-Length')) : 0);\n                this.httpResponseLengthBytes\n                    .labels(...labels)\n                    .observe(res.get('Content-Length') ? parseInt(res.get('Content-Length')) : 0);\n                this.customMetrics(labels, req, res, time);\n            });\n        };\n    }\n    middlewareLabels(request, response) {\n        const method = LabelsHelper_1.LabelsHelper.method(request, response);\n        const route = LabelsHelper_1.LabelsHelper.route(request, response);\n        const status = LabelsHelper_1.LabelsHelper.statusCode(request, response);\n        return [method, route, status];\n    }\n    customMetrics(labels, req, res, time) { }\n    static fromRoot({ controllers = null } = {}) {\n        return {\n            controllers: controllers || [MetricController],\n            module: PrometheusModule_1,\n        };\n    }\n};\nPrometheusModule = PrometheusModule_1 = __decorate([\n    (0, common_1.Module)({}),\n    __metadata(\"design:paramtypes\", [])\n], PrometheusModule);\nexports.PrometheusModule = PrometheusModule;\n"]}