solid_apm 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6233330338e9044097e1315840f1bbc7f2cdeb1677df3dac3261c2a50666046
4
- data.tar.gz: 37f306cf60295e74485092216c4bdbe2ba2c824ce08d279424e15c631543b33f
3
+ metadata.gz: f8623eafef426a98627eef8810538b4ad1100a125eadcdb99bf2db0df21cadc1
4
+ data.tar.gz: 386f31259d69c1ae17a182c1b6faf6368b8802c2bccf2985fa9e7853f9fc3ddb
5
5
  SHA512:
6
- metadata.gz: 18d46f142b8bc401acc9dcd3417c9782d04a6e2beabda8d3c7dbafd62429f8bcf13e69ecf2e7fe51049f17da8b35411c3b1239c3f9476950590917990d0c7aba
7
- data.tar.gz: a0140e3fdb51254f8c615ed7cd4002f851d0c1ef11b71d408c4966581b1638f475ada593977a53761631493201e53641df382b9c8d9c10598935fe7ae8b50da3
6
+ metadata.gz: 2cc471473ae3e41df512e12b6183c0410aaae6325f8a21db2f78e6f84caf22824b503e411eaa8f4508b40250511c9c4ea597f7de2929693ae30959977f6e4097
7
+ data.tar.gz: 03e17274e463f8e60fe50c9d22220a5f930570da6000802d227a9da2f28b4a51e84ba06af1009d6e32479f2a54a3ea95c21999ec2b06d0f18d00d94ecd17c5aa
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  # SolidApm
4
4
  Rails engine to manage APM data without using a third party service.
5
5
 
6
- <img src="./docs/img.png" width="400px">
7
- <img src="./docs/img_1.png" width="400px">
6
+ <img src="./docs/img.png" width="600px">
7
+ <img src="./docs/img_1.png" width="600px">
8
8
 
9
9
  ## Installation
10
10
 
@@ -70,7 +70,7 @@ Contribution directions go here.
70
70
 
71
71
  ```shell
72
72
  gem bump -v minor
73
- bundle install && git add . && git commit --amend --no-edit
73
+ bundle install && git add Gemfile.lock && git commit --amend --no-edit && git push
74
74
  gem tag -p
75
75
  ```
76
76
 
@@ -28,6 +28,9 @@ window.Stimulus.register('transaction-chart',
28
28
  xaxis: {
29
29
  type: 'datetime'
30
30
  },
31
+ dataLabels: {
32
+ enabled: false
33
+ },
31
34
  tooltip: {
32
35
  x: {
33
36
  formatter: function (value) {
@@ -37,9 +40,16 @@ window.Stimulus.register('transaction-chart',
37
40
  }
38
41
  }
39
42
 
40
- let path = 'transactions/count_by_minutes'
43
+ let path = window.location.pathname.includes('transactions') ? 'count_by_minutes' : 'transactions/count_by_minutes';
44
+ path = path + "?";
41
45
  if (this.nameValue) {
42
- path = path + "?name=" + encodeURIComponent(this.nameValue);
46
+ path = path + "name=" + encodeURIComponent(this.nameValue);
47
+ }
48
+
49
+ const fromValue = document.querySelector('input[name="from_value"]').value
50
+ const fromUnit = document.querySelector('select[name="from_unit"]').value;
51
+ if (fromValue && fromUnit) {
52
+ path = path + "&from_value=" + fromValue + "&from_unit=" + fromUnit;
43
53
  }
44
54
 
45
55
  fetch(path)
@@ -2,18 +2,20 @@
2
2
 
3
3
  module SolidApm
4
4
  class TransactionsController < ApplicationController
5
- TransactionAggregation = Struct.new(:name, :tmp, :latency, :impact)
5
+ TransactionAggregation = Struct.new(:name, :tmp, :latency, :percentile_95, :impact)
6
6
 
7
7
  def index
8
- @aggregated_transactions = Transaction.where(created_at: 1.hour.ago..).group_by(&:name)
8
+ @aggregated_transactions = Transaction.where(created_at: from_to_range).group_by(&:name)
9
9
  @aggregated_transactions.transform_values! do |transactions|
10
10
  latency = transactions.map(&:duration).sum / transactions.size
11
- tmp = transactions.size.to_f / 60
11
+ tmp = transactions.size.to_f / ((from_to_range.end - from_to_range.begin) / 60).to_i
12
12
  impact = latency * tmp
13
+ percentile_95 = transactions[transactions.size * 0.95].duration
13
14
  TransactionAggregation.new(
14
15
  transactions.first.name,
15
16
  tmp,
16
17
  latency,
18
+ percentile_95,
17
19
  impact
18
20
  )
19
21
  end
@@ -24,7 +26,8 @@ module SolidApm
24
26
  # Normalize impact 0-100
25
27
  @aggregated_transactions.each do |_, aggregation|
26
28
  normalized_impact = ((aggregation.impact - min_impact) / (max_impact - min_impact)) * 100
27
- aggregation.impact = normalized_impact.to_i
29
+ normalized_impact = 0 if normalized_impact.nan?
30
+ aggregation.impact = normalized_impact.to_i || 0
28
31
  end
29
32
  @aggregated_transactions = @aggregated_transactions.sort_by { |_, v| -v.impact }.to_h
30
33
  end
@@ -45,7 +48,7 @@ module SolidApm
45
48
 
46
49
  def count_by_minutes
47
50
  scope = Transaction.all.order(timestamp: :desc)
48
- .where(created_at: 1.hour.ago..)
51
+ .where(created_at: from_to_range)
49
52
 
50
53
  if params[:name].present?
51
54
  scope = scope.where(name: params[:name])
@@ -54,5 +57,15 @@ module SolidApm
54
57
  render json: scope.group_by { |t| t.created_at.beginning_of_minute }
55
58
  .transform_values!(&:count)
56
59
  end
60
+
61
+ private
62
+
63
+ def from_to_range
64
+ params[:from_value] ||= 60
65
+ params[:from_unit] ||= 'minutes'
66
+ from = params[:from_value].to_i.public_send(params[:from_unit].to_sym).ago
67
+ to = Time.current
68
+ (from..to)
69
+ end
57
70
  end
58
71
  end
@@ -1,6 +1,25 @@
1
1
  <h1 class="title">Transactions</h1>
2
2
 
3
- <h2 class="title is-4 has-text-grey">Last hour</h2>
3
+ <%= form_with path: transactions_path, method: :get do |f| %>
4
+ <div class="is-flex is-flex-direction-row is-justify-content-center is-align-items-center" style="gap: 1em">
5
+ <%= f.label 'From' %>
6
+ <%= f.number_field :from_value, value: params[:from_value] || 60, min: 1, class: 'input', style: 'width: 6em' %>
7
+ <div class="select">
8
+ <%= f.select :from_unit, {
9
+ "minutes" => "minutes",
10
+ "hours" => "hours",
11
+ "days" => "days",
12
+ "weeks" => "weeks",
13
+ "months" => "months",
14
+ "years" => "years"
15
+ }, {selected: params[:from_unit] || 'minutes' } %>
16
+ </div>
17
+ <span class="has-text-white-ter">ago</span>
18
+ <b>→</b>
19
+ <span class="has-text-white-ter">now</span>
20
+ <%= f.submit 'Apply', class: 'button' %>
21
+ </div>
22
+ <% end %>
4
23
  <div data-controller="transaction-chart"></div>
5
24
 
6
25
  <table class="table is-fullwidth">
@@ -9,6 +28,7 @@
9
28
  <th>Name</th>
10
29
  <th>Latency</th>
11
30
  <th>tmp</th>
31
+ <th>95p</th>
12
32
  <th>Impact</th>
13
33
  </tr>
14
34
  </thead>
@@ -18,6 +38,7 @@
18
38
  <td><%= link_to name, transaction_by_name_path(name) %></td>
19
39
  <td><%= aggregation.latency.round(2) %> ms</td>
20
40
  <td><%= aggregation.tmp.round(2) %></td>
41
+ <td><%= aggregation.percentile_95.round(2) %> ms</td>
21
42
  <td>
22
43
  <progress class="progress is-warning" value="<%= aggregation.impact %>" max="100"></progress>
23
44
  </td>
@@ -1,3 +1,3 @@
1
1
  module SolidApm
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Francis Bastien
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-14 00:00:00.000000000 Z
11
+ date: 2024-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack