From 826e9292172f659cc3f3ae7f04a23c43070360f8 Mon Sep 17 00:00:00 2001 From: smithclay Date: Wed, 31 Jul 2024 14:23:50 -0700 Subject: [PATCH] initial commit: acc-m plugin wrapper for collector --- sensu-plugin/allow_list/check-allow-list.json | 9 ++++ sensu-plugin/bin/.gitignore | 1 + sensu-plugin/bin/config.yaml | 34 ++++++++++++++ sensu-plugin/bin/otel-metrics.rb | 47 +++++++++++++++++++ sensu-plugin/readme.md | 3 ++ 5 files changed, 94 insertions(+) create mode 100644 sensu-plugin/allow_list/check-allow-list.json create mode 100644 sensu-plugin/bin/.gitignore create mode 100644 sensu-plugin/bin/config.yaml create mode 100644 sensu-plugin/bin/otel-metrics.rb create mode 100644 sensu-plugin/readme.md diff --git a/sensu-plugin/allow_list/check-allow-list.json b/sensu-plugin/allow_list/check-allow-list.json new file mode 100644 index 0000000..50903ba --- /dev/null +++ b/sensu-plugin/allow_list/check-allow-list.json @@ -0,0 +1,9 @@ +[ + { + "args": [ + "" + ], + "exec": "otel-metrics.rb", + "skip_arguments": true + } +] \ No newline at end of file diff --git a/sensu-plugin/bin/.gitignore b/sensu-plugin/bin/.gitignore new file mode 100644 index 0000000..380cb15 --- /dev/null +++ b/sensu-plugin/bin/.gitignore @@ -0,0 +1 @@ +otelcol-contrib \ No newline at end of file diff --git a/sensu-plugin/bin/config.yaml b/sensu-plugin/bin/config.yaml new file mode 100644 index 0000000..44fdea9 --- /dev/null +++ b/sensu-plugin/bin/config.yaml @@ -0,0 +1,34 @@ +receivers: + hostmetrics: + collection_interval: 10s + scrapers: + cpu: + memory: + disk: + filesystem: + load: + network: + paging: + processes: + +processors: + batch: + timeout: 5s + resourcedetection: + detectors: [env,system] + +exporters: + carbon: + endpoint: "localhost:2003" # The address of the Carbon/Graphite server + timeout: 10s + +service: + pipelines: + metrics: + receivers: [hostmetrics] + processors: [batch, resourcedetection] + exporters: [carbon] + +extensions: + health_check: + pprof: diff --git a/sensu-plugin/bin/otel-metrics.rb b/sensu-plugin/bin/otel-metrics.rb new file mode 100644 index 0000000..0a0a789 --- /dev/null +++ b/sensu-plugin/bin/otel-metrics.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +# This is just a simple TCP server that proxies metrics output from the +# carbonreceiver to stdout so it can be read by a sensu metrics plugin. + +require 'socket' +require 'timeout' + +PORT = 2003 +HOST = '0.0.0.0' +TIMEOUT = 15 + +# TODO: run the collector binary / check if it's running. + +def start_server + server = TCPServer.new(HOST, PORT) + #puts "Server started on #{HOST}:#{PORT}" + + begin + Timeout.timeout(TIMEOUT) do + loop do + client = server.accept + Thread.new(client) do |client_connection| + handle_client(client_connection) + end + end + end + rescue Timeout::Error + #puts "Server timeout reached. Shutting down..." + ensure + server.close + end +end + +def handle_client(client) + loop do + line = client.gets + break if line.nil? || line.chomp.empty? + + puts line.chomp + client.puts line + end + + client.close +end + +start_server \ No newline at end of file diff --git a/sensu-plugin/readme.md b/sensu-plugin/readme.md new file mode 100644 index 0000000..82c3ff0 --- /dev/null +++ b/sensu-plugin/readme.md @@ -0,0 +1,3 @@ +## Experimental OpenTelemetry ACC-M plugin + +Work in progress.