Skip to content

Commit

Permalink
Various tweakies
Browse files Browse the repository at this point in the history
  • Loading branch information
hschne committed Oct 26, 2024
1 parent 884b3cf commit d7c3509
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 45 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@

</div>

<p align="center">
<img alt="Screenshot of Puny Monitor" src="screenshot.png" width="90%">
</p>

## Features

- Just enough data to be useful 🔍
- Install in 30 seconds 🏎️
- Perfect for [Kamal](https://kamal-deploy.org/) and other containerized setups 🐋


## Getting Started

Puny Monitor works best with Docker. Run this command to check it out quickly:
Expand All @@ -26,7 +31,7 @@ docker run --rm \
hschne/puny-monitor:latest
```

Visit [localhost:4567](http://localhost:4567) to check your system data. To see how to deploy Puny Monitor in a production environment see [Deployment]
Visit [localhost:4567](http://localhost:4567) to check your system data. To see how to deploy Puny Monitor in a production environment see [Deployment].

## Deployment

Expand Down
59 changes: 24 additions & 35 deletions app/puny_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ class App < Sinatra::Base

get "/data/cpu_usage" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
cpu_loads = CpuUsage.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
cpu_loads = CpuUsage.where(created_at: start_time..)
.group_by_period(group_by, :created_at, expand_range: true)
.average(:used_percent)
.transform_values { |value| value&.round(2) }
cpu_loads.to_json
Expand All @@ -40,73 +38,64 @@ class App < Sinatra::Base
get "/data/cpu_load" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
[
{ name: "1 minute", data: CpuLoad.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
.group_by_period(group_by, :created_at)
.average(:one_minute)
.transform_values { |value| value&.round(2) } },
{ name: "5 minutes", data: CpuLoad.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
.group_by_period(group_by, :created_at)
.average(:five_minutes)
.transform_values { |value| value&.round(2) } },
{ name: "15 minutes", data: CpuLoad.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
.group_by_period(group_by, :created_at)
.average(:fifteen_minutes)
.transform_values { |value| value&.round(2) } }
].to_json
end

get "/data/memory_usage" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
memory_usage = MemoryUsage.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
memory_usage = MemoryUsage.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:used_percent)
.transform_values { |value| value&.round(2) }
memory_usage.to_json
end

get "/data/filesystem_usage" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
filesystem_usage = FilesystemUsage.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
filesystem_usage = FilesystemUsage.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:used_percent)
.transform_values { |value| value&.round(2) }
filesystem_usage.to_json
end

get "/data/disk_io" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
[
{ name: "Read MB/s", data: DiskIO.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
{ name: "Read MB/s", data: DiskIO.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:read_mb_per_sec)
.transform_values { |value| value&.round(2) } },
{ name: "Write MB/s", data: DiskIO.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
{ name: "Write MB/s", data: DiskIO.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:write_mb_per_sec)
.transform_values { |value| value&.round(2) } }
].to_json
end

get "/data/bandwidth" do
content_type :json
end_time = Time.now
start_time = start_time(end_time)
group_by = group_by()
[
{ name: "Incoming Mbps", data: Bandwidth.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
{ name: "Incoming Mbps", data: Bandwidth.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:incoming_mbps)
.transform_values { |value| value&.round(2) } },
{ name: "Outgoing Mbps", data: Bandwidth.where(created_at: start_time..end_time)
.group_by_period(group_by, :created_at, series: true)
{ name: "Outgoing Mbps", data: Bandwidth.where(created_at: start_time..)
.group_by_period(group_by, :created_at)
.average(:outgoing_mbps)
.transform_values { |value| value&.round(2) } }
].to_json
Expand All @@ -125,19 +114,19 @@ def duration
params[:duration] || "1d"
end

def start_time(end_time)
def start_time
case duration
when "1h" then end_time - 1.hour
when "3d" then end_time - 3.days
when "1w" then end_time - 1.week
when "1m" then end_time - 1.month
else end_time - 1.day
when "1h" then 1.hour.ago
when "3d" then 3.days.ago
when "1w" then 1.week.ago
when "1m" then 1.month.ago
else 1.day.ago
end
end

def group_by
case duration
when "1h" then :minute
when "1h", "1d" then :minute
else :hour
end
end
Expand Down
11 changes: 8 additions & 3 deletions app/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Puny Monitor - Lightweight System Monitoring</title>
<meta name="description" content="Puny Monitor is a lightweight system monitoring tool that tracks CPU usage, memory usage, disk I/O, and network bandwidth.">
<meta
name="description"
content="Puny Monitor is a lightweight system monitoring tool that tracks CPU usage, memory usage, disk I/O, and network bandwidth."
>
<meta name="robots" content="noindex">
<link rel="icon" href="/favicon.ico" sizes="32x32">
<link rel="icon" href="/public/puny-monitor.svg" type="image/svg+xml">
<link rel="icon" href="favicon.ico" sizes="32x32">
<link rel="icon" href="icon.svg" type="image/svg+xml">

<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chartkick.min.js"
Expand Down Expand Up @@ -36,6 +39,8 @@
<%= yield %>
</main>
<footer>
Found an issue or need a feature? File an issue on
<a href="https://github.com/hschne/puny-monitor">GitHub!</a>
</footer>
</body>
</html>
1 change: 0 additions & 1 deletion config/initializers/chartkick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# # frozen_string_literal: true

Chartkick.options = {
height: "25rem",
xtitle: "Time",
points: false,
curve: false
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions public/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ h1 {
font-size: var(--font-size-2xl);
}

a:visited {
color: var(--color-link-hover);
}

footer {
padding: var(--space-sm) 0;
}

.charts {
display: grid;
grid-template-columns: 1fr;
Expand All @@ -98,7 +106,7 @@ h1 {
padding: var(--space-md);
border: solid 1px var(--color-border);
border-radius: 10px;
height: 25rem;
height: 20rem;
}

.controls {
Expand Down Expand Up @@ -136,6 +144,10 @@ h1 {
.charts {
grid-template-columns: repeat(2, 1fr);
}

.tile {
height: 25rem;
}
}

@media (prefers-color-scheme: dark) {
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions todo.txt

This file was deleted.

0 comments on commit d7c3509

Please sign in to comment.