homebrew-core/Formula/telegraf.rb
2015-11-14 19:19:28 +08:00

76 lines
2.3 KiB
Ruby

require "language/go"
class Telegraf < Formula
desc "Server-level metric gathering agent for InfluxDB"
homepage "https://influxdb.com"
url "https://github.com/influxdb/telegraf/archive/v0.2.0.tar.gz"
sha256 "f11d2f13b2370c91e3ec557d30f20d28da1bf4a4642b8871ccee50d6b361f8a4"
bottle do
cellar :any_skip_relocation
revision 1
sha256 "becca945bdf93c78240d3600c09896361ef35f8821d21ba10446e1dd50d6999a" => :el_capitan
sha256 "26eeb48c9f92bb460b8fec922b313e497ca67fb0e6d7815494e445e67be81431" => :yosemite
sha256 "9838c07339909f3936ed9b34df8dc94db417a4cdb53033ada1af224455b50e5e" => :mavericks
end
depends_on "go" => :build
depends_on "godep" => :build
def install
ENV["GOPATH"] = buildpath
telegraf_path = buildpath/"src/github.com/influxdb/telegraf"
telegraf_path.install Dir["*"]
Language::Go.stage_deps resources, buildpath/"src"
cd telegraf_path do
system "godep", "go", "build", "-o", "telegraf",
"-ldflags", "-X main.Version #{version}",
"cmd/telegraf/telegraf.go"
end
bin.install telegraf_path/"telegraf"
etc.install telegraf_path/"etc/config.sample.toml" => "telegraf.conf"
end
plist_options :manual => "telegraf -config #{HOMEBREW_PREFIX}/etc/telegraf.conf"
def plist; <<-EOS.undent
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
<string>#{plist_name}</string>
<key>ProgramArguments</key>
<array>
<string>#{opt_bin}/telegraf</string>
<string>-config</string>
<string>#{HOMEBREW_PREFIX}/etc/telegraf.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>#{var}</string>
<key>StandardErrorPath</key>
<string>#{var}/log/telegraf.log</string>
<key>StandardOutPath</key>
<string>#{var}/log/telegraf.log</string>
</dict>
</plist>
EOS
end
test do
(testpath/"config.toml").write shell_output("telegraf -sample-config")
system "telegraf", "-config", testpath/"config.toml", "-test",
"-filter", "cpu:mem"
end
end