117 lines
3.6 KiB
Ruby
117 lines
3.6 KiB
Ruby
class Metricbeat < Formula
|
|
desc "Collect metrics from your systems and services"
|
|
homepage "https://www.elastic.co/products/beats/metricbeat"
|
|
url "https://github.com/elastic/beats.git",
|
|
:tag => "v6.7.0",
|
|
:revision => "14ca49c28a6e10b84b4ea8cdebdc46bd2eab3130"
|
|
head "https://github.com/elastic/beats.git"
|
|
|
|
bottle do
|
|
cellar :any_skip_relocation
|
|
sha256 "b1684c5638b0b4ce9684d8349536edb4ce04899bd0393865d8fb8114068f1766" => :mojave
|
|
sha256 "6ef807634a5f7bd5845acb27f935bf2a2294d0f763186c59cbd095a222b8239c" => :high_sierra
|
|
sha256 "6568b383c2a1a7397bfa0795e7e94d413e3586d8e4aed9b009fee498c8db7998" => :sierra
|
|
end
|
|
|
|
depends_on "go" => :build
|
|
depends_on "python@2" => :build
|
|
|
|
resource "virtualenv" do
|
|
url "https://files.pythonhosted.org/packages/8b/f4/360aa656ddb0f4168aeaa1057d8784b95d1ce12f34332c1cf52420b6db4e/virtualenv-16.3.0.tar.gz"
|
|
sha256 "729f0bcab430e4ef137646805b5b1d8efbb43fe53d4a0f33328624a84a5121f7"
|
|
end
|
|
|
|
def install
|
|
# remove non open source files
|
|
rm_rf "x-pack"
|
|
|
|
ENV["GOPATH"] = buildpath
|
|
(buildpath/"src/github.com/elastic/beats").install buildpath.children
|
|
|
|
ENV.prepend_create_path "PYTHONPATH", buildpath/"vendor/lib/python2.7/site-packages"
|
|
|
|
resource("virtualenv").stage do
|
|
system "python", *Language::Python.setup_install_args(buildpath/"vendor")
|
|
end
|
|
|
|
ENV.prepend_path "PATH", buildpath/"vendor/bin" # for virtualenv
|
|
ENV.prepend_path "PATH", buildpath/"bin" # for mage (build tool)
|
|
|
|
cd "src/github.com/elastic/beats/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 "Makefile", "collect: assets collect-docs configs kibana imports",
|
|
"collect: assets configs kibana imports"
|
|
|
|
system "make", "mage"
|
|
# prevent downloading binary wheels during python setup
|
|
system "make", "PIP_INSTALL_COMMANDS=--no-binary :all", "python-env"
|
|
system "mage", "-v", "build"
|
|
system "mage", "-v", "update"
|
|
|
|
(etc/"metricbeat").install Dir["metricbeat.*", "fields.yml", "modules.d"]
|
|
(libexec/"bin").install "metricbeat"
|
|
prefix.install "_meta/kibana.generated"
|
|
end
|
|
|
|
prefix.install_metafiles buildpath/"src/github.com/elastic/beats"
|
|
|
|
(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
|
|
|
|
plist_options :manual => "metricbeat"
|
|
|
|
def plist; <<~EOS
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
|
|
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
<plist version="1.0">
|
|
<dict>
|
|
<key>Label</key>
|
|
<string>#{plist_name}</string>
|
|
<key>Program</key>
|
|
<string>#{opt_bin}/metricbeat</string>
|
|
<key>RunAtLoad</key>
|
|
<true/>
|
|
</dict>
|
|
</plist>
|
|
EOS
|
|
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
|
|
|
|
pid = fork do
|
|
exec bin/"metricbeat", "-path.config", testpath/"config", "-path.data",
|
|
testpath/"data"
|
|
end
|
|
|
|
begin
|
|
sleep 30
|
|
assert_predicate testpath/"data/metricbeat", :exist?
|
|
ensure
|
|
Process.kill "SIGINT", pid
|
|
Process.wait pid
|
|
end
|
|
end
|
|
end
|