analytics

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 62 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package analytics is the Visionary server: fixed dashboards over the D1 request log and system metrics, an AI analyst that investigates questions with read-only SQL, saved panels, and a request log explorer.

Index

Constants

View Source
const UserAgent = "Visionary/1.0"

UserAgent identifies Visionary to the auth API and model provider.

Variables

View Source
var (
	Version = ""
	Commit  = ""
)

Version and Commit are set at build time:

go build -ldflags "-X github.com/styropyr0/visionary/internal/analytics.Version=v0.3.2 \
  -X github.com/styropyr0/visionary/internal/analytics.Commit=e20dc71..."

A build without them falls back to the commit Railway or Go recorded.

Functions

This section is empty.

Types

type AnalystPanel

type AnalystPanel struct {
	Title       string  `json:"title"`
	Description string  `json:"description"`
	Query       string  `json:"query"`
	Viz         Viz     `json:"viz"`
	Result      *Result `json:"result"`
}

AnalystPanel is a finished chart: spec, the template SQL for saving, and data.

type Config

type Config struct {
	Addr string

	DatabaseURL  string
	D1APIBase    string
	D1AccountID  string
	D1DatabaseID string
	D1APIToken   string
}

Config is what the server needs before it can read its settings: where to listen and which database to use. Everything else is in Settings, kept in the database (settings_config.go, signin.go); VISIONARY_ENABLE_AUTH, the one other variable, is read where sign-in is decided.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads the environment. D1 variables use the same names as the API server that writes the tables.

type Panel

type Panel struct {
	ID          int64     `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Prompt      string    `json:"prompt"`
	Query       string    `json:"query"`
	Viz         Viz       `json:"viz"`
	CreatedAt   time.Time `json:"created_at"`
}

type Result

type Result struct {
	Columns    []string `json:"columns"`
	Rows       [][]any  `json:"rows"`
	Truncated  bool     `json:"truncated"`
	RowsRead   int64    `json:"rows_read"`
	DurationMs float64  `json:"duration_ms"`
	SQL        string   `json:"sql"`
	Bucket     int64    `json:"bucket"`
	From       string   `json:"from"`
	To         string   `json:"to"`
	// Source says where a fixed panel was read from: "raw", "rollup_1m" or
	// "rollup_1h" (the coarsest rollup used; ragged edges are always raw).
	Source string `json:"source,omitempty"`
}

Result is what every data endpoint returns.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config, logger *slog.Logger, static fs.FS) (*Server, error)

New wires the server. static is the built frontend (index.html at its root).

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) Init

func (s *Server) Init(ctx context.Context) error

Init creates the tables. On failure Start retries in the background, so a database that is briefly unavailable still gets them.

func (*Server) Start

func (s *Server) Start(ctx context.Context)

Start launches the features' background work. It returns at once; the work stops when ctx ends.

type UptimeCheck

type UptimeCheck struct {
	ID              int64             `json:"id"`
	Name            string            `json:"name"`
	URL             string            `json:"url"`
	Method          string            `json:"method"`
	ExpectStatus    string            `json:"expect_status"`
	BodyContains    string            `json:"body_contains"`
	Headers         map[string]string `json:"headers"`
	IntervalS       int               `json:"interval_s"`
	TimeoutMs       int               `json:"timeout_ms"`
	DegradedMs      int               `json:"degraded_ms"`
	FollowRedirects bool              `json:"follow_redirects"`
	Enabled         bool              `json:"enabled"`
	OnStatusPage    bool              `json:"on_status_page"`
	StatusShowURL   bool              `json:"status_show_url"`
	CreatedAt       string            `json:"created_at"`
	UpdatedAt       string            `json:"updated_at"`
}

UptimeCheck is one HTTP probe. Header values with secret-looking names are masked in API responses; sending the mask back keeps the stored value.

type Viz

type Viz struct {
	Type   string   `json:"type"`
	X      string   `json:"x,omitempty"`
	Y      []string `json:"y,omitempty"`
	Series string   `json:"series,omitempty"`
	Stack  bool     `json:"stack,omitempty"`
	Unit   string   `json:"unit,omitempty"`
}

Viz tells the frontend how to draw a result.

Directories

Path Synopsis
Package web embeds the built analytics frontend.
Package web embeds the built analytics frontend.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL