Skip to content

Commit

Permalink
detach collector process
Browse files Browse the repository at this point in the history
  • Loading branch information
smithclay committed Aug 5, 2024
1 parent c8d65c3 commit ad103cd
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions sensu-plugin/bin/otel-metric-collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
DEFAULT_TIMEOUT = 10
DEFAULT_PATH = '/metrics'
PROCESS_NAME = 'otelcol-servicenow'
LAUNCH_COLLECTOR_CMD = "HOSTNAME=#{Socket.gethostname} ./#{PROCESS_NAME} --config config.yaml &"
LOG_FILE = '/tmp/sn-collector.log' # TODO: change this?
LAUNCH_COLLECTOR_CMD = "HOSTNAME=#{Socket.gethostname} ./#{PROCESS_NAME} --config config.yaml > #{LOG_FILE} 2>&1 &"

class CollectOTelMetrics < Sensu::Plugin::Check::CLI
option :timeout,
Expand Down Expand Up @@ -79,14 +80,8 @@ def fetch_and_process_metrics()

def run
if !process_running?
output = %x{#{LAUNCH_COLLECTOR_CMD} 2>&1} # Capture both stdout and stderr
status = $?.exitstatus
if status != 0
puts output
puts status
critical "Failed to launch collector: #{output}"
exit 1
end
pid = Process.spawn(LAUNCH_COLLECTOR_CMD)
Process.detach(pid)

sleep 15
end
Expand Down

0 comments on commit ad103cd

Please sign in to comment.