homebrew-core/Formula/metricbeat.rb

87 lines
2.8 KiB
Ruby

class Metricbeat < Formula
desc "Collect metrics from your systems and services"
homepage "https://www.elastic.co/beats/metricbeat"
url "https://github.com/elastic/beats.git",
tag: "v8.4.1",
revision: "fe210d46ebc339459e363ac313b07d4a9ba78fc7"
license "Apache-2.0"
head "https://github.com/elastic/beats.git", branch: "master"
bottle do
sha256 cellar: :any_skip_relocation, arm64_monterey: "0f96cd56551ebac8c4041b9365dcde10ea8afaf426d890a969bea2464f8c0e58"
sha256 cellar: :any_skip_relocation, arm64_big_sur: "593109e03e08a06e78beb3184f8cbfd5e92b785a1aec7e37126eeb105bc2c9eb"
sha256 cellar: :any_skip_relocation, monterey: "bcb39421f9e4905754d8b4399150da2c99368ba15b97eed60fc988fc604f48f4"
sha256 cellar: :any_skip_relocation, big_sur: "8a30c0d94146dd8c2cefba7f1a1a2acc3b503d44b1e1c49043abb5219cfaf0ed"
sha256 cellar: :any_skip_relocation, catalina: "b95acafa8f57f0ecf37bd223cc973a607dc47b8746d9eb09b705b4a13f5805bd"
sha256 cellar: :any_skip_relocation, x86_64_linux: "9080bf48ef6bb15b2c00e409d484560daa5eaeea5af53617703f30828a3432ec"
end
depends_on "go" => :build
depends_on "mage" => :build
depends_on "python@3.10" => :build
def install
# remove non open source files
rm_rf "x-pack"
cd "metricbeat" do
# don't build docs because it would fail creating the combined OSS/x-pack
# docs and we aren't installing them anyway
inreplace "magefile.go", "mg.Deps(CollectDocs, FieldsDocs)", ""
system "mage", "-v", "build"
ENV.deparallelize
system "mage", "-v", "update"
(etc/"metricbeat").install Dir["metricbeat.*", "fields.yml", "modules.d"]
(libexec/"bin").install "metricbeat"
prefix.install "build/kibana"
end
(bin/"metricbeat").write <<~EOS
#!/bin/sh
exec #{libexec}/bin/metricbeat \
--path.config #{etc}/metricbeat \
--path.data #{var}/lib/metricbeat \
--path.home #{prefix} \
--path.logs #{var}/log/metricbeat \
"$@"
EOS
end
service do
run opt_bin/"metricbeat"
end
test do
(testpath/"config/metricbeat.yml").write <<~EOS
metricbeat.modules:
- module: system
metricsets: ["load"]
period: 1s
output.file:
enabled: true
path: #{testpath}/data
filename: metricbeat
EOS
(testpath/"logs").mkpath
(testpath/"data").mkpath
fork do
exec bin/"metricbeat", "-path.config", testpath/"config", "-path.data",
testpath/"data"
end
sleep 15
output = JSON.parse((testpath/"data/meta.json").read)
assert_includes output, "first_start"
(testpath/"data").glob("metricbeat-*.ndjson") do |file|
s = JSON.parse(file.read.lines.first.chomp)
assert_match "metricbeat", s["@metadata"]["beat"]
end
end
end