UNPKG

@kangc/skywalking-backend-js

Version:

The NodeJS agent for Apache SkyWalking

82 lines 4.28 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/grpc-js")); var grpc_js_1 = require("@grpc/grpc-js"); 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.managementServiceClient = new Management_grpc_pb_1.ManagementServiceClient(AgentConfig_1.default.collectorAddress, AgentConfig_1.default.secure ? grpc.credentials.createSsl() : grpc.credentials.createInsecure()); } Object.defineProperty(HeartbeatClient.prototype, "isConnected", { get: function () { return this.managementServiceClient.getChannel().getConnectivityState(true) === grpc_js_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().setKey('hostname').setValue(os.hostname()), new Common_pb_1.KeyStringValuePair().setKey('Process No.').setValue("" + process.pid), ]); this.heartbeatTimer = setInterval(function () { _this.managementServiceClient.reportInstanceProperties(instanceProperties, AuthInterceptor_1.default(), function (error, _) { if (error) { logger.error('Failed to send heartbeat', error); } }); _this.managementServiceClient.keepAlive(keepAlivePkg, AuthInterceptor_1.default(), function (error, _) { if (error) { logger.error('Failed to send heartbeat', error); } }); }, 20000).unref(); }; HeartbeatClient.prototype.flush = function () { logger.warn('HeartbeatClient does not need flush().'); return null; }; return HeartbeatClient; }()); exports.default = HeartbeatClient; //# sourceMappingURL=HeartbeatClient.js.map