homebrew-core/Formula/metricbeat.rb
2017-03-28 22:54:28 -04:00

85 lines
2.5 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/archive/v5.3.0.tar.gz"
sha256 "311030e33ec6f5f335ddf9e0b8eb3a1cd9e378dbc7c0937658a02099457c5895"
head "https://github.com/elastic/beats.git"
bottle do
cellar :any_skip_relocation
sha256 "3fa90ebe8e2c68920cd34e49d52ffacdca8974d91c98ac76db6e6fa8d22a1e91" => :sierra
sha256 "9cfb4ae0772284205da5d997046c885ec1df6e4c621187078b5235b74e06a045" => :el_capitan
sha256 "834dce682e4d9422ac0c52ed394b0b10e5d28fe432e507dd5a738fba70e185ca" => :yosemite
end
depends_on "go" => :build
def install
gopath = buildpath/"gopath"
(gopath/"src/github.com/elastic/beats").install Dir["{*,.git,.gitignore}"]
ENV["GOPATH"] = gopath
cd gopath/"src/github.com/elastic/beats/metricbeat" do
system "make"
libexec.install "metricbeat"
(etc/"metricbeat").install "metricbeat.yml"
(etc/"metricbeat").install "metricbeat.template.json"
(etc/"metricbeat").install "metricbeat.template-es2x.json"
end
(bin/"metricbeat").write <<-EOS.undent
#!/bin/sh
exec "#{libexec}/metricbeat" --path.config "#{etc}/metricbeat" --path.home="#{prefix}" --path.logs="#{var}/log/metricbeat" --path.data="#{opt_prefix}" "$@"
EOS
end
plist_options :manual => "metricbeat"
def plist; <<-EOS.undent
<?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/"metricbeat.yml").write <<-EOS.undent
metricbeat.modules:
- module: system
metricsets: ["load"]
period: 1s
output.file:
enabled: true
path: #{testpath}/data
filename: metricbeat
EOS
(testpath/"logs").mkpath
(testpath/"data").mkpath
metricbeat_pid = fork do
exec bin/"metricbeat", "-c", testpath/"metricbeat.yml",
"--path.data=#{testpath}/data", "--path.logs=#{testpath}/logs"
end
begin
sleep 2
assert File.exist? testpath/"data/metricbeat"
ensure
Process.kill("TERM", metricbeat_pid)
end
end
end