statscloud-plugin-system-monitor 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 868d383ba83d61a5b80be41e3b7312b96920895255d03f15c795d36425054ff6
4
+ data.tar.gz: 478a00b96e2a7840968eb27d2840768d583ecdaece31372f9a07069b725603ea
5
+ SHA512:
6
+ metadata.gz: 34edc7774cdf39e51343eceb26274043678ee6f809c6018fa6a5668a3fe5f95160ce1069d14ab93617c90bfa1edbbd20c7675d51a7e52d5a8bf2e1a09677bef2
7
+ data.tar.gz: 982e9809a49e1e73a2f9b1bcbec5651dc3134fbc020e6f5e83cd52afcb8b191b9b28bae7c3bbbd005e363600f44ed8a3821c014a1e77dd14ddad724425ce8374
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ .idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,19 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
6
+
7
+ Style/StringLiterals:
8
+ EnforcedStyle: double_quotes
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - spec/**/*
13
+ - statscloud-plugin-system-monitor.gemspec
14
+
15
+ Layout/EmptyLineAfterGuardClause:
16
+ Enabled: true
17
+
18
+ Naming/FileName:
19
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in statscloud-plugin-system-monitor.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ statscloud-plugin-system-monitor (0.1.0)
5
+ activesupport (~> 5.2)
6
+ battery (~> 1.0)
7
+ eventmachine (~> 1.2)
8
+ fileutils (~> 1.1)
9
+ logger (~> 1.2)
10
+ ohai (~> 13.12)
11
+ usagewatch_ext (~> 0.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activesupport (5.2.1.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ addressable (2.5.2)
22
+ public_suffix (>= 2.0.2, < 4.0)
23
+ ast (2.4.0)
24
+ battery (1.0.0)
25
+ chef-config (13.12.3)
26
+ addressable
27
+ fuzzyurl
28
+ mixlib-config (>= 2.2.12, < 3.0)
29
+ mixlib-shellout (~> 2.0)
30
+ tomlrb (~> 1.2)
31
+ concurrent-ruby (1.1.3)
32
+ diff-lcs (1.3)
33
+ eventmachine (1.2.7)
34
+ ffi (1.9.25)
35
+ ffi-yajl (2.3.1)
36
+ libyajl2 (~> 1.2)
37
+ fileutils (1.1.0)
38
+ fuzzyurl (0.9.0)
39
+ i18n (1.1.1)
40
+ concurrent-ruby (~> 1.0)
41
+ ipaddress (0.8.3)
42
+ jaro_winkler (1.5.1)
43
+ libyajl2 (1.2.0)
44
+ logger (1.2.8)
45
+ minitest (5.11.3)
46
+ mixlib-cli (1.7.0)
47
+ mixlib-config (2.2.13)
48
+ tomlrb
49
+ mixlib-log (1.7.1)
50
+ mixlib-shellout (2.4.0)
51
+ ohai (13.12.4)
52
+ chef-config (>= 12.5.0.alpha.1, < 14)
53
+ ffi (~> 1.9)
54
+ ffi-yajl (~> 2.2)
55
+ ipaddress
56
+ mixlib-cli
57
+ mixlib-config (~> 2.0)
58
+ mixlib-log (>= 1.7.1, < 2.0)
59
+ mixlib-shellout (~> 2.0)
60
+ plist (~> 3.1)
61
+ systemu (~> 2.6.4)
62
+ wmi-lite (~> 1.0)
63
+ parallel (1.12.1)
64
+ parser (2.5.3.0)
65
+ ast (~> 2.4.0)
66
+ plist (3.4.0)
67
+ powerpack (0.1.2)
68
+ public_suffix (3.0.3)
69
+ rainbow (3.0.0)
70
+ rake (10.5.0)
71
+ rspec (3.8.0)
72
+ rspec-core (~> 3.8.0)
73
+ rspec-expectations (~> 3.8.0)
74
+ rspec-mocks (~> 3.8.0)
75
+ rspec-core (3.8.0)
76
+ rspec-support (~> 3.8.0)
77
+ rspec-expectations (3.8.2)
78
+ diff-lcs (>= 1.2.0, < 2.0)
79
+ rspec-support (~> 3.8.0)
80
+ rspec-mocks (3.8.0)
81
+ diff-lcs (>= 1.2.0, < 2.0)
82
+ rspec-support (~> 3.8.0)
83
+ rspec-support (3.8.0)
84
+ rubocop (0.60.0)
85
+ jaro_winkler (~> 1.5.1)
86
+ parallel (~> 1.10)
87
+ parser (>= 2.5, != 2.5.1.1)
88
+ powerpack (~> 0.1)
89
+ rainbow (>= 2.2.2, < 4.0)
90
+ ruby-progressbar (~> 1.7)
91
+ unicode-display_width (~> 1.4.0)
92
+ ruby-progressbar (1.10.0)
93
+ systemu (2.6.5)
94
+ thread_safe (0.3.6)
95
+ tomlrb (1.2.7)
96
+ tzinfo (1.2.5)
97
+ thread_safe (~> 0.1)
98
+ unicode-display_width (1.4.0)
99
+ usagewatch (0.0.7)
100
+ usagewatch_ext (0.2.1)
101
+ usagewatch (~> 0.0.6)
102
+ wmi-lite (1.0.0)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ bundler (~> 1.17)
109
+ rake (~> 10.0)
110
+ rspec (~> 3.0)
111
+ rubocop (~> 0.60)
112
+ statscloud-plugin-system-monitor!
113
+
114
+ BUNDLED WITH
115
+ 1.17.1
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # statscloud.io-ruby-plugin-system-monitor
2
+
3
+
4
+ To use this plugin with your StatsCloud client install this gem
5
+ ```
6
+ gem install stats_cloud-plugin-system_monitor
7
+ ```
8
+ and add plugins section configuration in `.statscloud.yml` file:
9
+
10
+ ```markdown
11
+ ...
12
+ plugins:
13
+ - system-monitor
14
+
15
+ ```
16
+ You can customize plugin settings as well:
17
+
18
+ ```markdown
19
+ ...
20
+ plugins:
21
+ - name: system-monitor
22
+ settings:
23
+ collectIntervalInSeconds: 1 # interval to collect metrics in seconds, default value is 1
24
+ flushIntervalInSeconds: 60 # how often to capture the metric values, default value is specified in .statscloud.json on top level
25
+ retention: # how long to store metrics for and at which granularity, default value is specified in .statscloud.json on top level
26
+ - frequency: 1m
27
+ keep: 3d
28
+ intervals: # interval to count metrics during, default value is ["1m"]
29
+ - 1m
30
+ enableAlerts: false # you can enable or disable alerts, default value is false
31
+ admins: [] # list of admin names no notify about plugin alerts, default value is an empty array
32
+ channels: [] # list of channels to send notifications via, default value is an empty array
33
+ alertsRepeatInterval: 15m # how often to repeat the alerts, default value is "15m"
34
+ alertsUnhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is "5m"
35
+ alertsHealthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is "2m"
36
+ alerts: # you can specify settings for each alert
37
+ memory-percent-overlimit: # alert that raised when memory usage overruns limit
38
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
39
+ threshold: 80 # max memory usage in percent, default value is 80
40
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
41
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
42
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
43
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
44
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
45
+ cpu-percent-overlimit: # alert that raised when cpu usage overruns limit
46
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
47
+ threshold: 70 # max cpu usage in percent, default value is 70
48
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
49
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
50
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
51
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
52
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
53
+ disk-belowlimit: # alert that raised when disk free space is too low
54
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
55
+ threshold: 1 # min disk free space in Gb, default value is 1
56
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
57
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
58
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
59
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
60
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
61
+ disk-percent-overlimit: # alert that raised when disk usage overruns limit
62
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
63
+ threshold: 90 # max disk usage in percent, default value is 90
64
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
65
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
66
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
67
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
68
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
69
+ battery-belowlimit: # alert that raised when battery is too low
70
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
71
+ threshold: 10 # min battery percent value, default value is 10
72
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
73
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
74
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
75
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
76
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
77
+ system-load-overlimit: # alert that raised when system load overruns limit
78
+ enabled: true # enable this alert, default value is taken from enableAlerts setting from top-level plugin configuration
79
+ threshold: 2 # max system load, default value is 2
80
+ repeatInterval: 15m # how often to repeat the alerts, default value is taken from alertsRepeatInterval setting from top-level plugin configuration
81
+ unhealthyDelay: 5m # how much time the metric is allowed to stay in unhealthy zone before alert is raised, default value is taken from alertsUnhealthyDelay setting from top-level plugin configuration
82
+ healthyDelay: 2m # how much time the metric should stay in healthy zone before alert is removed, default value is taken from alertsHealthyDelay setting from top-level plugin configuration
83
+ admins: [] # list of admin names no notify about this alert, default value is taken from admins setting from top-level plugin configuration
84
+ channels: [] # list of channels to send notifications via, default value is taken from channels setting from top-level plugin configuration
85
+
86
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "stats_cloud/plugin/system_monitor"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/bytes_converter"
4
+ require "battery"
5
+
6
+ module StatsCloud
7
+ module Plugin
8
+ module SystemMonitor
9
+ # Provides information about battery charge.
10
+ module BatteryInfo
11
+ def record_battery_info
12
+ return unless battery
13
+
14
+ update_battery_info
15
+ meter.record_event("system-monitor.battery.percent", energy_left)
16
+ end
17
+
18
+ private
19
+
20
+ def battery
21
+ @battery ||= Battery.new
22
+ end
23
+
24
+ def update_battery_info
25
+ battery.update
26
+ end
27
+
28
+ def energy_left
29
+ battery.energy_left * 100
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/bytes_converter"
4
+ require "usagewatch_ext"
5
+
6
+ module StatsCloud
7
+ module Plugin
8
+ module SystemMonitor
9
+ # Provides information about system load and cpu statistic.
10
+ module CPU
11
+ def record_cpu_info
12
+ meter.record_event("system-monitor.cpu.used-percent", current_load)
13
+ meter.record_event("system-monitor.system.load", avg_load)
14
+ end
15
+
16
+ private
17
+
18
+ def current_load
19
+ usage_watch.uw_cpuused
20
+ end
21
+
22
+ def avg_load
23
+ usage_watch.uw_load
24
+ end
25
+
26
+ def usage_watch
27
+ Usagewatch
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ohai"
4
+ require "eventmachine"
5
+ require_relative "cpu"
6
+ require_relative "memory"
7
+ require_relative "network"
8
+ require_relative "filesystem"
9
+ require_relative "battery_info"
10
+
11
+ module StatsCloud
12
+ module Plugin
13
+ module SystemMonitor
14
+ # Collects all system metrics and periodically records them to statscloud client.
15
+ class Engine
16
+ include CPU
17
+ include Memory
18
+ include Network
19
+ include FileSystem
20
+ include BatteryInfo
21
+
22
+ def initialize(meter, mutex, settings = {})
23
+ @meter = meter
24
+ @mutex = mutex
25
+ @interval = settings["collectIntervalInSeconds"] || 1
26
+ end
27
+
28
+ def join_collect_stats_thread
29
+ collect_stats_thread.join
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :meter
35
+
36
+ def collect_stats_thread
37
+ Thread.new do
38
+ event_machine.run do
39
+ event_machine.add_periodic_timer(@interval) do
40
+ @mutex.synchronize do
41
+ load_ohai_plugins
42
+ collect_stats
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ def collect_stats
50
+ return unless meter && ohai
51
+
52
+ record_cpu_info
53
+ record_memory_info
54
+ record_network_info
55
+ record_filesystem_info
56
+ record_battery_info
57
+ end
58
+
59
+ def ohai
60
+ @ohai ||= Ohai::System.new
61
+ end
62
+
63
+ def load_ohai_plugins
64
+ ohai.all_plugins(plugins_filter)
65
+ end
66
+
67
+ def plugins_filter
68
+ %w[memory filesystem network]
69
+ end
70
+
71
+ def event_machine
72
+ ::EventMachine
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/bytes_converter"
4
+
5
+ module StatsCloud
6
+ module Plugin
7
+ module SystemMonitor
8
+ # Provides information about filesystem.
9
+ module FileSystem
10
+ include BytesConverter
11
+
12
+ def record_filesystem_info
13
+ return unless filesystem_info_present?
14
+
15
+ meter.record_event("system-monitor.disk.used-percent", root_info_percent_used)
16
+ meter.record_event("system-monitor.disk.free-gb", kilobytes_to_gigabytes(root_info_free))
17
+ meter.record_event("system-monitor.disk.free-percent", 100 - root_info_percent_used)
18
+ end
19
+
20
+ private
21
+
22
+ def filesystem_info_present?
23
+ filesystem_info && root_info
24
+ end
25
+
26
+ def filesystem_info
27
+ ohai["filesystem"]
28
+ end
29
+
30
+ def root_info
31
+ filesystem_info["by_mountpoint"]["/"]
32
+ end
33
+
34
+ def root_info_percent_used
35
+ root_info["percent_used"].to_f
36
+ end
37
+
38
+ def root_info_total
39
+ root_info["kb_size"].to_f
40
+ end
41
+
42
+ def root_info_used
43
+ root_info["kb_used"].to_f
44
+ end
45
+
46
+ def root_info_free
47
+ root_info_total - root_info_used
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StatsCloud
4
+ module Plugin
5
+ module SystemMonitor
6
+ # Helps to convert metrics to the right value.
7
+ module BytesConverter
8
+ def bytes_to_megabytes(bytes)
9
+ bytes / 1024 / 1024
10
+ end
11
+
12
+ def kilobytes_to_gigabytes(kilobytes)
13
+ kilobytes / 1024 / 1024
14
+ end
15
+
16
+ def kilobytes_to_megabytes(kilobytes)
17
+ kilobytes / 1024
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/bytes_converter"
4
+
5
+ module StatsCloud
6
+ module Plugin
7
+ module SystemMonitor
8
+ # Provides information about system memory.
9
+ module Memory
10
+ include BytesConverter
11
+
12
+ def record_memory_info
13
+ return unless memory_info
14
+
15
+ meter.record_event("system-monitor.memory.available-gb", available_memory_in_gigabytes)
16
+ meter.record_event("system-monitor.memory.active-gb", active_memory_in_gigabytes)
17
+ meter.record_event("system-monitor.memory.active-percent", percent_of_active_memory)
18
+ meter.record_event("system-monitor.memory.swap-gb", swap_memory_in_gigabytes)
19
+ end
20
+
21
+ private
22
+
23
+ def memory_info
24
+ ohai["memory"]
25
+ end
26
+
27
+ def available_memory_in_gigabytes
28
+ kilobytes_to_gigabytes(available_memory)
29
+ end
30
+
31
+ def active_memory_in_gigabytes
32
+ kilobytes_to_gigabytes(active_memory)
33
+ end
34
+
35
+ def percent_of_active_memory
36
+ 100 * active_memory / total_memory
37
+ end
38
+
39
+ def swap_memory_in_gigabytes
40
+ kilobytes_to_gigabytes(memory_swapused)
41
+ end
42
+
43
+ def available_memory
44
+ memory_info["available"].to_f
45
+ end
46
+
47
+ def active_memory
48
+ memory_info["active"].to_f
49
+ end
50
+
51
+ def total_memory
52
+ memory_info["total"].to_f
53
+ end
54
+
55
+ def memory_swapused
56
+ memory_info["swap"]["cached"].to_f
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "helpers/bytes_converter"
4
+
5
+ module StatsCloud
6
+ module Plugin
7
+ module SystemMonitor
8
+ # Provides information about network flow.
9
+ module Network
10
+ include BytesConverter
11
+
12
+ def record_network_info
13
+ return unless counters_info
14
+
15
+ meter.record_event("system-monitor.net.rx-mb-per-s", bytes_to_megabytes(total_bandwidth_received))
16
+ meter.record_event("system-monitor.net.tx-mb-per-s", bytes_to_megabytes(total_bandwidth_transmitted))
17
+ end
18
+
19
+ private
20
+
21
+ def counters_info
22
+ ohai["counters"]
23
+ end
24
+
25
+ def network_interface_counters
26
+ counters_info["network"]["interfaces"]
27
+ end
28
+
29
+ def total_bandwidth_received
30
+ network_interface_counters&.inject(0) { |sum, interface| sum + rx_in_bytes_from_array(interface) }
31
+ end
32
+
33
+ def total_bandwidth_transmitted
34
+ network_interface_counters&.inject(0) { |sum, interface| sum + tx_in_bytes_from_array(interface) }
35
+ end
36
+
37
+ def rx_in_bytes_from_array(interface)
38
+ interface[1]["rx"]["bytes"].to_f
39
+ end
40
+
41
+ def tx_in_bytes_from_array(interface)
42
+ interface[1]["tx"]["bytes"].to_f
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StatsCloud
4
+ module Plugin
5
+ module SystemMonitor
6
+ VERSION = "0.1.0"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stats_cloud/plugin/system_monitor/version"
4
+ require "stats_cloud/plugin/system_monitor/engine"
5
+
6
+ module StatsCloud
7
+ module Plugin
8
+ # SystemMonitor plugin provides information about system metrics.
9
+ module SystemMonitor
10
+ class << self
11
+ def start(meter, mutex, settings)
12
+ engine.new(meter, mutex, settings).join_collect_stats_thread
13
+ end
14
+
15
+ private
16
+
17
+ def engine
18
+ Engine
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "stats_cloud/plugin/system_monitor/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "statscloud-plugin-system-monitor"
9
+ spec.version = StatsCloud::Plugin::SystemMonitor::VERSION
10
+ spec.authors = ["Roman O."]
11
+ spec.email = ["roman.o.as@agiliumlabs.com"]
12
+
13
+ spec.summary = "System monitor statistic plugin for StatsCloud client."
14
+ spec.description = "Simple monitoring of your system environment."
15
+ spec.homepage = "https://statscloud.io"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ else
24
+ raise "RubyGems 2.0 or newer is required to protect against " \
25
+ "public gem pushes."
26
+ end
27
+
28
+ # Specify which files should be added to the gem when it is released.
29
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
30
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
31
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "activesupport", "~> 5.2"
38
+ spec.add_dependency "battery", "~> 1.0"
39
+ spec.add_dependency "eventmachine", "~> 1.2"
40
+ spec.add_dependency "fileutils", "~> 1.1"
41
+ spec.add_dependency "logger", "~> 1.2"
42
+ spec.add_dependency "ohai", "~> 13.12"
43
+ spec.add_dependency "usagewatch_ext", "~> 0.2"
44
+
45
+ spec.add_development_dependency "bundler", "~> 1.17"
46
+ spec.add_development_dependency "rake", "~> 10.0"
47
+ spec.add_development_dependency "rspec", "~> 3.0"
48
+ spec.add_development_dependency "rubocop", "~> 0.60"
49
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statscloud-plugin-system-monitor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Roman O.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: battery
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: fileutils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: logger
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ohai
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '13.12'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '13.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: usagewatch_ext
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.17'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.17'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '10.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '10.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.60'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.60'
167
+ description: Simple monitoring of your system environment.
168
+ email:
169
+ - roman.o.as@agiliumlabs.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rspec"
176
+ - ".rubocop.yml"
177
+ - Gemfile
178
+ - Gemfile.lock
179
+ - README.md
180
+ - Rakefile
181
+ - bin/console
182
+ - bin/setup
183
+ - lib/stats_cloud/plugin/system_monitor/battery_info.rb
184
+ - lib/stats_cloud/plugin/system_monitor/cpu.rb
185
+ - lib/stats_cloud/plugin/system_monitor/engine.rb
186
+ - lib/stats_cloud/plugin/system_monitor/filesystem.rb
187
+ - lib/stats_cloud/plugin/system_monitor/helpers/bytes_converter.rb
188
+ - lib/stats_cloud/plugin/system_monitor/memory.rb
189
+ - lib/stats_cloud/plugin/system_monitor/network.rb
190
+ - lib/stats_cloud/plugin/system_monitor/version.rb
191
+ - lib/statscloud-plugin-system-monitor.rb
192
+ - statscloud-plugin-system-monitor.gemspec
193
+ homepage: https://statscloud.io
194
+ licenses: []
195
+ metadata:
196
+ allowed_push_host: https://rubygems.org
197
+ homepage_uri: https://statscloud.io
198
+ post_install_message:
199
+ rdoc_options: []
200
+ require_paths:
201
+ - lib
202
+ required_ruby_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ required_rubygems_version: !ruby/object:Gem::Requirement
208
+ requirements:
209
+ - - ">="
210
+ - !ruby/object:Gem::Version
211
+ version: '0'
212
+ requirements: []
213
+ rubyforge_project:
214
+ rubygems_version: 2.7.7
215
+ signing_key:
216
+ specification_version: 4
217
+ summary: System monitor statistic plugin for StatsCloud client.
218
+ test_files: []