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.5.0.tar.gz" sha256 "3f826ce614b6caef12a5584d3c97a4496222a70b02b818b3ec5bb08dc3aa6994" head "https://github.com/elastic/beats.git" bottle do cellar :any_skip_relocation sha256 "5044e6d752338ad17ec707b6f5e592ec5c4b925ab0adf2b131b1d69cd885e8d2" => :sierra sha256 "4bf47ad50d16c80de07f75c26213d926cf60098ec8add1fe315849c155001a9b" => :el_capitan sha256 "19f721ecf23ec0982cc2e6d1df6fed3c4584010dc01ff7fa732d1a491a4d7a5d" => :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.full.yml" (etc/"metricbeat").install "metricbeat.yml" (etc/"metricbeat").install "metricbeat.template.json" (etc/"metricbeat").install "metricbeat.template-es2x.json" (etc/"metricbeat").install "metricbeat.template-es6x.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