Skip to content

Commit

Permalink
Merge branch 'dev' (0.5.3-1)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosabalde committed Feb 13, 2025
2 parents 34689b5 + a854880 commit 57a879d
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- 0.5.3-1 (2025-02-13):
+ Fixed step calculation when scraper is disabled (i.e., no scraping period available).

- 0.5.2-1 (2025-02-12):
+ Improved logrotate configuration.
+ Fixed DuckDB query when normalizing input `from` and `to` timestamps.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SHELL := /bin/bash
ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
UMASK := 022

VERSION := 0.5.2
VERSION := 0.5.3
ITERATION := 1
REVISION := $(shell cd '$(ROOT)' && git rev-parse --short HEAD)
ENVIRONMENT ?= production
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ While `varnishmon` **doesn't replace a comprehensive monitoring solutions like P

`varnishmon` is a self-contained executable that allows you to start collecting data with minimal effort and explore it through a simple yet effective web interface. In addition to occasional troubleshooting, `varnishmon` can also be used as a lightweight, permanent service to collect, store, visualize, and rotate Varnish metrics. Similar to running `atop` in logging mode as a complement to regular monitoring, `varnishmon` provides valuable context during incident analysis.

## 📑 Table of Contents

- [Quick Start](#-quick-start)
- [Q & A](#-q-a)
- [Usage](#usage)
- [Configuration & Customization](#configuration-customization)
- [Running as a Service](#running-as-a-service)
- [Miscellaneous](#miscellaneous)
- [License](#-license)

## 🚀 Quick Start

1. **Download & install**
Expand Down
2 changes: 1 addition & 1 deletion assets/static/app.js

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions assets/webpack/src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ function isValidAggregatorValue(value) {
******************************************************************************/

const STEP = `${PREFIX}step`;
const DEFAULT_STEP = 60;

export function getStep() {
try {
Expand All @@ -313,7 +314,7 @@ export function getStep() {
console.error(`Failed to read '${STEP}' from local storage!`, error);
}

return varnishmon.config.scraper.period;
return varnishmon.config.scraper.enabled ? varnishmon.config.scraper.period : DEFAULT_STEP;
}

export function setStep(value) {
Expand All @@ -329,8 +330,12 @@ export function setStep(value) {
}
}

export function getMinimumStep() {
return varnishmon.config.scraper.enabled ? varnishmon.config.scraper.period : 1;
}

function isValidStepValue(value) {
return Number.isInteger(value) && value >= varnishmon.config.scraper.period;
return Number.isInteger(value) && value >= getMinimumStep();
}

/******************************************************************************
Expand Down
19 changes: 9 additions & 10 deletions assets/webpack/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,35 +72,34 @@ function syncConfigWithUI() {

// Step.
const stepSelector = document.getElementById('step');
stepSelector.min = varnishmon.config.scraper.period;
stepSelector.min = config.getMinimumStep();
stepSelector.value = config.getStep();
stepSelector.addEventListener('change', (event) => {
const value = parseInt(event.target.value, 10);
if (value >= varnishmon.config.scraper.period) {
const minimum = config.getMinimumStep();
if (value >= minimum) {
config.setStep(value);
} else {
event.stopPropagation();
stepSelector.value = varnishmon.config.scraper.period;
helpers.notify(
'error',
`Step must be at least ${varnishmon.config.scraper.period} seconds, ` +
'which is the metrics scraping period');
stepSelector.value = minimum;
helpers.notify('error', `Step must be at least ${minimum} seconds`);
}
});
}

function getRefreshInterval() {
let value = parseInt(document.getElementById('refresh-interval').value, 10);
if (value < 0) {
value = varnishmon.config.scraper.period;
value = getStep();
}
return value;
}

function getStep() {
let value = parseInt(document.getElementById('step').value, 10);
if (value < varnishmon.config.scraper.period) {
value = varnishmon.config.scraper.period;
const minimum = config.getMinimumStep();
if (value < minimum) {
value = minimum;
}
return value;
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/workers/api/web-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ func (h *Handler) handleHomeRequest(rctx *fasthttp.RequestCtx) {
}

// Prepare template data & render it.
scraperPeriod := 0
if h.app.Cfg().ScraperEnabled() {
scraperPeriod = int(h.app.Cfg().ScraperPeriod().Seconds())
}
cfg, err := json.Marshal(map[string]interface{}{
"version": config.Version(),
"revision": config.Revision(),
"config": map[string]interface{}{
"scraper": map[string]interface{}{
"enabled": h.app.Cfg().ScraperEnabled(),
"period": h.app.Cfg().ScraperPeriod().Seconds(),
"period": scraperPeriod,
},
},
"storage": map[string]interface{}{
Expand Down
8 changes: 6 additions & 2 deletions pkg/workers/storage/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ func (stg *Storage) PushMetricSamples(timestamp time.Time, samples []*MetricSamp

func (stg *Storage) unsafeNormalizeFromToAndStep(
from, to time.Time, step int) (time.Time, time.Time, int, error) {
// Ensure 'step' is at least the scraper period.
period := int(stg.app.Cfg().ScraperPeriod().Seconds())
// Ensure 'step' is at least the scraper period, if enabled. If disabled,
// 1s is the minimum resolution.
period := 1
if stg.app.Cfg().ScraperEnabled() {
period = int(stg.app.Cfg().ScraperPeriod().Seconds())
}
if step < period {
step = period
}
Expand Down
Loading

0 comments on commit 57a879d

Please sign in to comment.