Class: Skywalking::Reporter::Client::GrpcClient::ManagementServiceGrpc

Inherits:
Object
  • Object
show all
Includes:
Log::Logging
Defined in:
lib/skywalking/reporter/client/grpc_client.rb

Instance Method Summary collapse

Methods included from Log::Logging

#debug, #error, #info, #log, #warn

Constructor Details

#initialize(config) ⇒ ManagementServiceGrpc

Returns a new instance of ManagementServiceGrpc.



26
27
28
29
30
31
32
# File 'lib/skywalking/reporter/client/grpc_client.rb', line 26

def initialize(config)
  @config = config
  @management_service ||= ManagementServiceStub.new(
    @config[:collector_backend_services],
    :this_channel_is_insecure
  )
end

Instance Method Details

#gen_service_instanceObject



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
# File 'lib/skywalking/reporter/client/grpc_client.rb', line 61

def gen_service_instance
  props = []

  begin
    props.push(
      { key: 'language', value: 'ruby' },
      { key: 'OS Name', value: RbConfig::CONFIG['host_os'] },
      { key: 'Process No.', value: Process.pid.to_s },
      { key: 'hostname', value: Socket.gethostname },
      { key: 'ipv4', value: Socket.ip_address_list.select(&:ipv4?).map(&:ip_address).join('; ') },
      { key: 'ruby_engine', value: RUBY_ENGINE },
      { key: 'ruby_version', value: RUBY_VERSION }
    )
  rescue => e
    warn "Failed to get local environment information: #{e.message}"
    props = [{ key: 'language', value: 'ruby' }, { key: 'Process No.', value: Process.pid.to_s }]
  end

  namespace = @config[:namespace]
  props << { key: 'namespace', value: namespace } if namespace

  instance_properties_json = @config[:instance_properties_json]
  if instance_properties_json && !instance_properties_json.empty?
    json_properties = JSON.parse(instance_properties_json)
    json_properties.each do |key, value|
      props << { key: key, value: value }
    end
  end

  props
end

#report_heartbeatObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/skywalking/reporter/client/grpc_client.rb', line 48

def report_heartbeat
  begin
    req = InstancePingPkg.new(
      service: @config[:service_name],
      serviceInstance: @config[:instance_name]
    )

    @management_service.keep_alive(req)
  rescue => e
    error "Error to connect SkyWalking APM: #{e.message}"
  end
end

#report_instance_propertiesObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/skywalking/reporter/client/grpc_client.rb', line 34

def report_instance_properties
  begin
    req = InstanceProperties.new(
      service: @config[:service_name],
      serviceInstance: @config[:instance_name],
      properties: gen_service_instance
    )

    @management_service.report_instance_properties(req)
  rescue Exception => e
    error "Error to report instance properties: #{e.message}"
  end
end