process-instrumentation 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 884e34d5b80ad72326ee07ca0c154b4b7415e848
4
+ data.tar.gz: 9a3e73f618a51936b03a4c428a6e57258ce3c1f3
5
+ SHA512:
6
+ metadata.gz: 5b787e31bda339cee7fc5ca44fb5fa9d42682a852c8ac73c0cfa1ffb001d7505094a6a1b2d324cc2b96bd953880139728094358964756d907c16c7822401807d
7
+ data.tar.gz: 2b846bc5a29e4b88e699d2592d44f7b762129ba18dd1daea7f45ca5e198314bb4a45ea07c46beec42705d63db6659b606b19e675afe388b22a5b0083b324793e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at felipeelias@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'pry', '~> 0.10'
7
+ gem 'rubocop', '~> 0.45'
8
+ gem 'yard', '~> 0.9'
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Felipe Elias Philipp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Instrumentation
2
+
3
+ [![Build Status](https://travis-ci.org/felipeelias/instrumentation.svg?branch=master)](https://travis-ci.org/felipeelias/instrumentation)
4
+
5
+ Monitor any system stats and process memory usage over time.
6
+
7
+ ![Example](https://github.com/felipeelias/instrumentation/blob/4d74af4a8ad0c97cc2940dec92399e54dbfd4d5e/example.gif "Example")
8
+
9
+ ## Installation
10
+
11
+ ```
12
+ gem install process-instrumentation
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ To monitor a process, get its PID from the system (using `ps aux | grep PROCESS_NAME`) and start the command:
18
+
19
+ ```
20
+ $ instrument <pid>
21
+ ```
22
+
23
+ Then go to `http://localhost:8080` and you'll see the graph of memory usage over time.
24
+
25
+ ## Development/Testing
26
+
27
+ Install dependencies with:
28
+
29
+ ```
30
+ bin/setup
31
+ ```
32
+
33
+ Run tests with:
34
+
35
+ ```
36
+ rake test
37
+ ```
38
+
39
+ Run the local binary with:
40
+
41
+ ```
42
+ exe/instrument <pid>
43
+ ```
44
+
45
+ An interactive console with all files loaded is available on:
46
+
47
+ ```
48
+ bin/console
49
+ ```
50
+
51
+ ## Documentation
52
+
53
+ You can generate documentation locally:
54
+
55
+ ```
56
+ rake yard
57
+ ```
58
+
59
+ Then open `doc/index.html` in your browser.
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/felipeelias/instrumentation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
64
+
65
+ Make sure that the code passes the style guidelines with:
66
+
67
+ ```
68
+ rake rubocop
69
+ ```
70
+
71
+ If you want to contribute with anything but don't know where to start, check the project's to-do list:
72
+
73
+ - [x] Auto-refresh report (fetch datapoints dynamically)
74
+ - [x] Implement Load average reader
75
+ - [x] Setup rubocop task
76
+ - [ ] Implement option parser for command line tool
77
+ - [ ] Add tests when the interface and functionality is defined
78
+ - [ ] Implement memory reader for Linux, that reads from `/proc/<pid>/statm`, example [here][linux-statm]
79
+ - [ ] Implement CPU % reader
80
+ - [ ] Let user customize HTTP server port via command line
81
+ - [ ] Setup continuous integration
82
+ - [ ] Setup code climate
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
87
+
88
+ [linux-statm]: https://gist.github.com/pvdb/6240788
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+ require 'yard'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ end
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ YARD::Rake::YardocTask.new
15
+
16
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'instrumentation'
4
+ require 'pry'
5
+
6
+ Pry.start
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
data/example.gif ADDED
Binary file
data/exe/instrument ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'instrumentation'
7
+
8
+ pid = ARGV.first || Process.pid
9
+ Instrumentation.start_server(pid: pid)
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'instrumentation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'process-instrumentation'
8
+ spec.version = Instrumentation::VERSION
9
+ spec.authors = ['Felipe Philipp']
10
+ spec.email = ['felipeelias@gmail.com']
11
+
12
+ spec.summary = 'Monitor process stats over time'
13
+ spec.description = 'Monitor process memory and CPU over time'
14
+ spec.homepage = 'https://github.com/felipeelias/instrumentation'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.13'
26
+ spec.add_development_dependency 'rake', '~> 11.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'minitest-rg', '~> 5.0'
29
+
30
+ spec.add_dependency 'rack', '2.0.1'
31
+ spec.add_dependency 'tubesock', '0.2.7'
32
+ spec.add_dependency 'puma', '3.6.0'
33
+ spec.add_dependency 'erb-view', '~> 0.1'
34
+ end
@@ -0,0 +1,87 @@
1
+ function updateChart(chart, data) {
2
+ var values = data.map(function(value) { return value[1] });
3
+ var labels = data.map(function(value) { return value[0] });
4
+
5
+ chart.data.labels = labels;
6
+ chart.data.datasets[0].data = values;
7
+ chart.update();
8
+ }
9
+
10
+ function formatBytes(bytes) {
11
+ if (bytes <= 1024) {
12
+ return bytes.toString().concat("B");
13
+ } else if (bytes > 1024 && bytes <= 1000*1024) {
14
+ return (bytes / 1024).toFixed(1).toString().concat("MB");
15
+ } else {
16
+ return (bytes / 1024 / 1024).toFixed(1).toString().concat("GB");
17
+ }
18
+ }
19
+
20
+ Chart.defaults.global.defaultFontSize = 8;
21
+ Chart.defaults.global.animation.duration = 500;
22
+ Chart.defaults.global.legend.display = false;
23
+ Chart.defaults.global.elements.line.backgroundColor = "rgba(0,0,0,0)";
24
+ Chart.defaults.global.elements.line.borderColor = "rgba(0,0,0,0.9)";
25
+ Chart.defaults.global.elements.line.borderWidth = 2;
26
+
27
+ var defaultOptions = {
28
+ type: 'line',
29
+ data: {
30
+ labels: [],
31
+ datasets: [{
32
+ label: '',
33
+ data: [],
34
+ lineTension: 0.2,
35
+ pointRadius: 0
36
+ }]
37
+ },
38
+ options: {
39
+ scales: {
40
+ yAxes: [{
41
+ ticks: {
42
+ beginAtZero:true
43
+ }
44
+ }],
45
+ xAxes: [{
46
+ type: 'time',
47
+ time: {
48
+ unitStepSize: 110
49
+ },
50
+ minUnit: 'second',
51
+ gridLines: {
52
+ display: false
53
+ }
54
+ }]
55
+ }
56
+ },
57
+ tooltips: {
58
+ enabled: false
59
+ },
60
+ responsive: true,
61
+ maintainAspectRatio: false,
62
+ animation: false
63
+ }
64
+
65
+ var memoryChart = new Chart(document.getElementById('memory'), defaultOptions);
66
+ var loadavgChart = new Chart(document.getElementById('loadavg'), defaultOptions);
67
+
68
+ var lastMemory = document.getElementById('last-memory');
69
+ var lastLoadavg = document.getElementById('last-loadavg');
70
+
71
+ var socket = new WebSocket("ws://localhost:8080/");
72
+ socket.onmessage = function (raw_event) {
73
+ var event = JSON.parse(raw_event.data)
74
+
75
+ switch (event.data_type) {
76
+ case 'memory':
77
+ updateChart(memoryChart, event.data)
78
+ lastMemory.textContent = formatBytes(event.data[event.data.length - 1][1]);
79
+ break;
80
+ case 'loadavg':
81
+ updateChart(loadavgChart, event.data)
82
+ lastLoadavg.textContent = event.data[event.data.length - 1][1];
83
+ break;
84
+ default:
85
+ break;
86
+ }
87
+ }