UNPKG

skywalking-apache

Version:

The NodeJS agent for Apache SkyWalking

80 lines 4.04 kB
"use strict"; /*! * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var grpc = tslib_1.__importStar(require("grpc")); var grpc_1 = require("grpc"); var packageInfo = tslib_1.__importStar(require("../../../../../package.json")); var logging_1 = require("../../../../logging"); var Management_grpc_pb_1 = require("../../../../proto/management/Management_grpc_pb"); var AuthInterceptor_1 = tslib_1.__importDefault(require("../AuthInterceptor")); var Management_pb_1 = require("../../../../proto/management/Management_pb"); var AgentConfig_1 = tslib_1.__importDefault(require("../../../../config/AgentConfig")); var Common_pb_1 = require("../../../../proto/common/Common_pb"); var os = tslib_1.__importStar(require("os")); var logger = logging_1.createLogger(__filename); var HeartbeatClient = /** @class */ (function () { function HeartbeatClient() { this.heartbeatClient = new Management_grpc_pb_1.ManagementServiceClient(AgentConfig_1.default.collectorAddress, grpc.credentials.createInsecure(), { interceptors: [AuthInterceptor_1.default], }); } Object.defineProperty(HeartbeatClient.prototype, "isConnected", { get: function () { return this.heartbeatClient.getChannel().getConnectivityState(true) === grpc_1.connectivityState.READY; }, enumerable: false, configurable: true }); HeartbeatClient.prototype.start = function () { var _this = this; if (this.heartbeatTimer) { logger.warn("\n The heartbeat timer has already been scheduled,\n this may be a potential bug, please consider reporting\n this to " + packageInfo.bugs.url + "\n "); return; } var keepAlivePkg = new Management_pb_1.InstancePingPkg() .setService(AgentConfig_1.default.serviceName) .setServiceinstance(AgentConfig_1.default.serviceInstance); var instanceProperties = new Management_pb_1.InstanceProperties() .setService(AgentConfig_1.default.serviceName) .setServiceinstance(AgentConfig_1.default.serviceInstance) .setPropertiesList([ new Common_pb_1.KeyStringValuePair().setKey('language').setValue('NodeJS'), new Common_pb_1.KeyStringValuePair().setKey('OS Name').setValue(os.platform()), new Common_pb_1.KeyStringValuePair().setValue('hostname').setValue(os.hostname()), new Common_pb_1.KeyStringValuePair().setValue('Process No.').setValue("" + process.pid), ]); this.heartbeatTimer = setInterval(function () { _this.heartbeatClient.reportInstanceProperties(instanceProperties, function (error, _) { if (error) { logger.error('Failed to send heartbeat', error); } }); _this.heartbeatClient.keepAlive(keepAlivePkg, function (error, _) { if (error) { logger.error('Failed to send heartbeat', error); } }); }, 20000).unref(); }; return HeartbeatClient; }()); exports.default = new HeartbeatClient(); //# sourceMappingURL=HeartbeatClient.js.map