rb2db 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/rb2db +15 -12
- data/lib/rb2db/version.rb +2 -1
- data/lib/rb2db.rb +15 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bef17bdc60b58352015d49fe9157754faf09864
|
4
|
+
data.tar.gz: b730d15a6ffe12a27db8d585afdc04f303d1f78e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492f4cd0df9ca222609d3a4c9c356b41dd5d23965b4915ae884e6a22711c34526ed53f1bd28c4a3456972223b4d6e993eb264962c0283b59ca01379003832ada
|
7
|
+
data.tar.gz: 4684574c238edfdced88ae9c8cb1ef98ba522103241b79a04fe7006c5d2fde25de69a52385e46d4f4dbd0ee101be0ccf3f129bf10ea18eefd307f6939973d1a0
|
data/exe/rb2db
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'duffy'
|
3
3
|
require 'influxdb'
|
4
|
+
require_relative "../lib/rb2db.rb"
|
4
5
|
|
5
6
|
# CONFIG #
|
6
7
|
# InfluxDB Server:
|
7
|
-
influx_host = ENV['INFLUX_HOST']
|
8
|
+
influx_host = ENV['INFLUX_HOST']
|
9
|
+
abort('[!] INFLUX_HOST not specified. Bye.') unless influx_host
|
8
10
|
|
9
11
|
# InfluxDB Database:
|
10
12
|
influx_db = ENV['INFLUX_DB'] || 'rb2db'
|
@@ -18,16 +20,17 @@ InfluxDB::Client.new(host: influx_host).create_database(influx_db)
|
|
18
20
|
# Connect to InfluxDB with database for this hostname selected
|
19
21
|
influxdb = InfluxDB::Client.new(influx_db, host: influx_host)
|
20
22
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
fork do
|
24
|
+
Rb2db.pid_check
|
25
|
+
while sleep 1
|
26
|
+
data = [
|
27
|
+
{ series: 'cpu_percent', tags: { host: influx_localhost }, values: { value: Duffy::System.cpu_percent } },
|
28
|
+
{ series: 'mem_total', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_total } },
|
29
|
+
{ series: 'mem_used', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_used } },
|
30
|
+
{ series: 'mem_percent', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_percent } }
|
31
|
+
]
|
32
|
+
influxdb.write_points(data)
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
36
|
+
puts "Starting: #{influx_localhost} => #{influx_host}:#{influx_db}"
|
data/lib/rb2db/version.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
module Rb2db
|
2
|
-
VERSION = "0.
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
|
4
4
|
|
5
5
|
# CHANGELOG
|
6
|
+
# 0.2.0 Added PID checking to prevent multiple instances.
|
6
7
|
# 0.1.4 Replace mem_available with mem_percent.
|
7
8
|
# 0.1.3 Bump 'duffy' gem version to fix mem_available detection on older linux
|
8
9
|
# 0.1.2 Tag 'host' correctly. Works nicely in Grafana.
|
data/lib/rb2db.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
require "rb2db/version"
|
2
2
|
|
3
3
|
module Rb2db
|
4
|
-
|
4
|
+
def self.pid_check
|
5
|
+
|
6
|
+
# PID file to use.
|
7
|
+
pid_file = ENV['XDG_RUNTIME_DIR'] || '/tmp' + '/.rb2db.pid'
|
8
|
+
|
9
|
+
# If the file exists, check if the pid inside is still running
|
10
|
+
if (pid = File.file?(pid_file) && File.read(pid_file))
|
11
|
+
if pid.to_i > 0 && `ps -p #{pid}`.include?(pid)
|
12
|
+
abort "[!] rb2db already running on pid #{pid}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Write new PID file.
|
17
|
+
File.write(pid_file, $$)
|
18
|
+
end
|
5
19
|
end
|