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.2.2.tar.gz" sha256 "45c89fab339de3d3e7f9a83c7a48312ede147d5989b67b8619d9128353c891c3" head "https://github.com/elastic/beats.git" bottle do cellar :any_skip_relocation sha256 "daa6f3197e7daa192845d7bb645e50653a4693f81f3176349811ecde2044c4a9" => :sierra sha256 "8a2f6ffe3f23aed40e31b4258f1034be0f3869309dad3e1b7af41ac7b5ed2c2a" => :el_capitan sha256 "233ef879beca1f354b8ef38038f315edf814d72b64adf77b825cd134285c35bd" => :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 Label #{plist_name} Program #{opt_bin}/metricbeat RunAtLoad 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