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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/rb2db +15 -12
  3. data/lib/rb2db/version.rb +2 -1
  4. data/lib/rb2db.rb +15 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f53f6edb35402b7f5e53e3c9c8c78241f894ce26
4
- data.tar.gz: f75d98630b2f9a619ec52faae7a6b5e525fd17cc
3
+ metadata.gz: 1bef17bdc60b58352015d49fe9157754faf09864
4
+ data.tar.gz: b730d15a6ffe12a27db8d585afdc04f303d1f78e
5
5
  SHA512:
6
- metadata.gz: 5a83406ae4e792e1ac6ebe91d8378a91d2a275e0e08c8235320ef5d556720690d2f925136f8bc9752eba2572827c7fcb76aa28fcd3c052f6d7eb4559694fc378
7
- data.tar.gz: 71f65f993cdc33ad49e5b318e17aa8e173daf0a89f7310cd3a7ce44b683cb7a1ce81ae0f2cab74236aa219eac58ee63405fd7dc989f4572cf110021933027d48
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'] || 'localhost'
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
- puts "Logging Started: #{influx_localhost} => #{influx_host}:#{influx_db}"
22
- Process.daemon
23
-
24
- while sleep 1
25
- data = [
26
- { series: 'cpu_percent', tags: { host: influx_localhost }, values: { value: Duffy::System.cpu_percent } },
27
- { series: 'mem_total', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_total } },
28
- { series: 'mem_used', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_used } },
29
- { series: 'mem_percent', tags: { host: influx_localhost }, values: { value: Duffy::System.mem_percent } }
30
- ]
31
- influxdb.write_points(data)
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.1.4"
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
- # Your code goes here...
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb2db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Duffy