class Opentsdb < Formula
desc "Scalable, distributed Time Series Database"
homepage "http://opentsdb.net/"
url "https://github.com/OpenTSDB/opentsdb/releases/download/v2.4.0/opentsdb-2.4.0.tar.gz"
sha256 "a2d6a34369612b3f91bf81bfab24ec573ab4118127dc1c0f0ed6fc57318d102c"
license "LGPL-2.1"
livecheck do
url "https://github.com/OpenTSDB/opentsdb/releases/latest"
regex(%r{href=.*?/tag/v?(\d+(?:\.\d+)+)["' >]}i)
end
bottle do
cellar :any_skip_relocation
sha256 "31e57ba38c568eb7a41a6129a55aac5a9b443301578475702cdab5fb891faaa2" => :catalina
sha256 "ec077c13211eac9912661ff0e3e1165162f251c3408fdf36b709e0e98af34aa2" => :mojave
sha256 "5bcdc828069e124c16e1e6c8b2eb6732d0ef88533c27f60fcbb0bec369aca375" => :high_sierra
end
deprecate! because: :does_not_build
depends_on "gnuplot"
depends_on "hbase"
depends_on "lzo"
depends_on "openjdk@8"
def install
system "./configure",
"--disable-silent-rules",
"--prefix=#{prefix}",
"--mandir=#{man}",
"--sysconfdir=#{etc}",
"--localstatedir=#{var}/opentsdb"
system "make"
bin.mkpath
(pkgshare/"static/gwt/opentsdb/images/ie6").mkpath
system "make", "install"
env = {
HBASE_HOME: Formula["hbase"].opt_libexec,
COMPRESSION: "LZO",
}
env = Language::Java.java_home_env("1.8").merge(env)
create_table = pkgshare/"tools/create_table_with_env.sh"
create_table.write_env_script pkgshare/"tools/create_table.sh", env
create_table.chmod 0755
inreplace pkgshare/"etc/opentsdb/opentsdb.conf", "/usr/share", "#{HOMEBREW_PREFIX}/share"
etc.install pkgshare/"etc/opentsdb"
(pkgshare/"plugins/.keep").write ""
(bin/"start-tsdb.sh").write <<~EOS
#!/bin/sh
exec "#{opt_bin}/tsdb" tsd \\
--config="#{etc}/opentsdb/opentsdb.conf" \\
--staticroot="#{opt_pkgshare}/static/" \\
--cachedir="#{var}/cache/opentsdb" \\
--port=4242 \\
--zkquorum=localhost:2181 \\
--zkbasedir=/hbase \\
--auto-metric \\
"$@"
EOS
(bin/"start-tsdb.sh").chmod 0755
libexec.mkpath
bin.env_script_all_files(libexec, env)
end
def post_install
(var/"cache/opentsdb").mkpath
system "#{Formula["hbase"].opt_bin}/start-hbase.sh"
begin
sleep 2
system "#{pkgshare}/tools/create_table_with_env.sh"
ensure
system "#{Formula["hbase"].opt_bin}/stop-hbase.sh"
end
end
plist_options manual: "#{HOMEBREW_PREFIX}/opt/opentsdb/bin/start-tsdb.sh"
def plist
<<~EOS
KeepAlive
OtherJobEnabled
#{Formula["hbase"].plist_name}
Label
#{plist_name}
ProgramArguments
#{opt_bin}/start-tsdb.sh
WorkingDirectory
#{HOMEBREW_PREFIX}
StandardOutPath
#{var}/opentsdb/opentsdb.log
StandardErrorPath
#{var}/opentsdb/opentsdb.err
EOS
end
test do
cp_r (Formula["hbase"].opt_libexec/"conf"), testpath
inreplace (testpath/"conf/hbase-site.xml") do |s|
s.gsub! /(hbase.rootdir.*)\n.*/, "\\1\nfile://#{testpath}/hbase"
s.gsub! /(hbase.zookeeper.property.dataDir.*)\n.*/, "\\1\n#{testpath}/zookeeper"
end
ENV.prepend "_JAVA_OPTIONS", "-Djava.io.tmpdir=#{testpath}/tmp"
ENV["HBASE_LOG_DIR"] = testpath/"logs"
ENV["HBASE_CONF_DIR"] = testpath/"conf"
ENV["HBASE_PID_DIR"] = testpath/"pid"
system "#{Formula["hbase"].opt_bin}/start-hbase.sh"
begin
sleep 2
system "#{pkgshare}/tools/create_table_with_env.sh"
tsdb_err = "#{testpath}/tsdb.err"
tsdb_out = "#{testpath}/tsdb.out"
fork do
$stderr.reopen(tsdb_err, "w")
$stdout.reopen(tsdb_out, "w")
exec("#{bin}/start-tsdb.sh")
end
sleep 15
pipe_output("nc localhost 4242 2>&1", "put homebrew.install.test 1356998400 42.5 host=webserver01 cpu=0\n")
system "#{bin}/tsdb", "query", "1356998000", "1356999000", "sum",
"homebrew.install.test", "host=webserver01", "cpu=0"
ensure
system "#{Formula["hbase"].opt_bin}/stop-hbase.sh"
end
end
end