api

package
v0.0.0-...-f5dc4b7 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrInternalServerError

func ErrInternalServerError(err error) render.Renderer

Types

type API

type API struct {
	BindAddress        string
	StaticCDNURL       string
	LocalUIDisabled    bool
	Endpoints          config.WebEndpoints
	DB                 MetricQueryable
	ContainerRuntime   containerInterface
	PsFact             *facts.ProcessProvider
	FactProvider       *facts.FactProvider
	Discovery          *discovery.Discovery
	AgentInfo          agentInterface
	PrometheusExporter http.Handler
	Threshold          *threshold.Registry
	LocalStore         LocalStoreInfo
	Monitors           MonitorSource
	// Config is the merged in-memory configuration. The /data/config
	// handler dumps a redacted copy (secrets stripped by
	// config.CensorSecretItem) for inspection from the UI.
	Config            config.Config
	DiagnosticPage    func(ctx context.Context) string
	DiagnosticArchive func(ctx context.Context, w types.ArchiveWriter) error
	// contains filtered or unexported fields
}

API contains API's port.

func (*API) Run

func (api *API) Run(ctx context.Context) error

Run starts our API.

type AgentInfo

type AgentInfo struct {
	RegistrationAt *time.Time `json:"registrationAt,omitempty"`
	LastReport     *time.Time `json:"lastReport,omitempty"`
	IsConnected    bool       `json:"isConnected"`
}

func (*AgentInfo) Render

func (a *AgentInfo) Render(_ http.ResponseWriter, _ *http.Request) error

type AgentStatus

type AgentStatus struct {
	ServiceName       string  `json:"serviceName"`
	Status            float64 `json:"status"`
	StatusDescription string  `json:"statusDescription"`
}

func (*AgentStatus) Render

func (a *AgentStatus) Render(_ http.ResponseWriter, _ *http.Request) error

type CPUUsage

type CPUUsage struct {
	User      float64 `json:"User"`
	Nice      float64 `json:"Nice"`
	System    float64 `json:"System"`
	Idle      float64 `json:"Idle"`
	IOWait    float64 `json:"IOWait"`
	Guest     float64 `json:"Guest"`
	GuestNice float64 `json:"GuestNice"`
	Irq       float64 `json:"IRQ"`
	SoftIrq   float64 `json:"SoftIRQ"`
	Steal     float64 `json:"Steal"`
}

type Container

type Container struct {
	Command     string     `json:"command"`
	CreatedAt   *time.Time `json:"createdAt,omitempty"`
	ID          string     `json:"id"`
	Image       string     `json:"image"`
	InspectJSON string     `json:"inspectJSON"`
	Name        string     `json:"name"`
	StartedAt   *time.Time `json:"startedAt,omitempty"`
	State       string     `json:"state"`
	FinishedAt  *time.Time `json:"finishedAt,omitempty"`
	// PrimaryAddress is the container's main IP as reported by the
	// runtime (the first non-bridge address it picks). Empty when the
	// container runs with host networking or no network attached.
	PrimaryAddress string `json:"primaryAddress"`
	// ListenAddresses lists the sockets the container is bound to,
	// rendered as "tcp/0.0.0.0:80" / "udp/0.0.0.0:53" / "unix:/var/run/docker.sock".
	ListenAddresses []string `json:"listenAddresses"`
	IoWriteBytes    float64  `json:"ioWriteBytes"`
	IoReadBytes     float64  `json:"ioReadBytes"`
	NetBitsRecv     float64  `json:"netBitsRecv"`
	NetBitsSent     float64  `json:"netBitsSent"`
	MemUsedPerc     float64  `json:"memUsedPerc"`
	CPUUsedPerc     float64  `json:"cpuUsedPerc"`
}

type Containers

type Containers struct {
	Count        int          `json:"count"`
	CurrentCount int          `json:"currentCount"`
	Containers   []*Container `json:"containers"`
}

func (*Containers) Render

func (c *Containers) Render(_ http.ResponseWriter, _ *http.Request) error

type Data

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

func (*Data) AgentInformation

func (d *Data) AgentInformation(w http.ResponseWriter, r *http.Request)

AgentInformation returns some information about agent registration to Bleemeo Cloud.

func (*Data) AgentStatus

func (d *Data) AgentStatus(w http.ResponseWriter, r *http.Request)

AgentStatus returns an integer that represent global server status over several metrics.

func (*Data) Config

func (d *Data) Config(w http.ResponseWriter, _ *http.Request)

Config writes the merged in-memory configuration as YAML, with secrets redacted (keys matching key/secret/password/passwd are replaced with "*****"). Same payload that ships in the diagnostic archive's config.yaml, exposed as its own endpoint so the panel can link to it.

func (*Data) Containers

func (d *Data) Containers(w http.ResponseWriter, r *http.Request)

Containers have 4 query parameters : - offset (string) : The offset of the first element to return. - limit (string) : The maximum number of elements to return. - allContainers (bool) : If true, return all containers, otherwise only running containers. - search (string) : The search string to filter containers.

func (*Data) Facts

func (d *Data) Facts(w http.ResponseWriter, r *http.Request)

Facts returns a list of facts discovered by agent.

func (*Data) Logs

func (d *Data) Logs(w http.ResponseWriter, _ *http.Request)

func (*Data) Monitors

func (d *Data) Monitors(w http.ResponseWriter, r *http.Request)

Monitors returns the active probe targets so the UI can build the Uptime Monitoring tab. When the blackbox manager is available (the usual case when blackbox.enable is on) we read directly from it, which transparently covers both the local `blackbox.targets` config AND any dynamic monitors provisioned by Bleemeo Cloud. As a fallback — typically when blackbox is disabled at the agent level — we still return the static config so the tab has something to show.

func (*Data) Processes

func (d *Data) Processes(w http.ResponseWriter, r *http.Request)

Processes returns a list of topInfo, they have 1 query parameter : - search (string) : The container ID to filter processes.

func (*Data) Services

func (d *Data) Services(w http.ResponseWriter, r *http.Request)

Services returns a list services discovered by agent They can be filtered by active flag.

func (*Data) StoreInfo

func (d *Data) StoreInfo(w http.ResponseWriter, r *http.Request)

StoreInfo returns metadata about the local metric store.

func (*Data) Tags

func (d *Data) Tags(w http.ResponseWriter, r *http.Request)

Tags returns a list of tags from system.

func (*Data) Thresholds

func (d *Data) Thresholds(w http.ResponseWriter, r *http.Request)

Thresholds returns every threshold rule currently active on the agent, both Bleemeo-pushed (per-instance) and locally configured (per-metric-name). The UI uses this to color KPI cards from the real bounds and to draw warn/crit reference zones on charts.

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code

	StatusText string `json:"status"`          // user-level status message
	AppCode    int64  `json:"code,omitempty"`  // application-specific error code
	ErrorText  string `json:"error,omitempty"` // application-level error message, for debugging
}

func (*ErrResponse) Render

func (e *ErrResponse) Render(_ http.ResponseWriter, r *http.Request) error

type Fact

type Fact struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

func (*Fact) Render

func (f *Fact) Render(_ http.ResponseWriter, _ *http.Request) error

type LabelInput

type LabelInput struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type LocalStoreInfo

type LocalStoreInfo interface {
	// Retention returns how far back the store is configured to keep data.
	Retention() time.Duration
	// OldestPointMs returns the timestamp (ms since epoch) of the
	// oldest queryable point, or 0 if the store has no data.
	OldestPointMs() int64
}

LocalStoreInfo describes the on-disk persistent metric store, when present. The API exposes this so the UI can decide which time-range buttons to enable.

type MemoryUsage

type MemoryUsage struct {
	Total   float64 `json:"Total"`
	Used    float64 `json:"Used"`
	Free    float64 `json:"Free"`
	Buffers float64 `json:"Buffers"`
	Cached  float64 `json:"Cached"`
}

type MetricInput

type MetricInput struct {
	Labels []*LabelInput `json:"labels"`
}

type MetricQueryable

type MetricQueryable interface {
	storage.Queryable
	Metrics(filters map[string]string) (result []types.Metric, err error)
}

func NewQueryable

func NewQueryable(store *store.Store, agentIDFunc func() string) MetricQueryable

NewQueryable returns a MetricQueryable that only do queries on the main agent.

func NewQueryableWithSecondary

func NewQueryableWithSecondary(store *store.Store, secondary storage.Queryable, agentIDFunc func() string) MetricQueryable

NewQueryableWithSecondary is like NewQueryable but also queries an additional storage.Queryable (typically the on-disk TSDB) and merges the results. The secondary may be nil.

type Monitor

type Monitor struct {
	Name   string `json:"name"`
	URL    string `json:"url"`
	Module string `json:"module"`
	Scheme string `json:"scheme"`
	// Source identifies where the target was provisioned from. "config"
	// = local `blackbox.targets` config. "bleemeo" = monitor pushed by
	// the Bleemeo Cloud platform (the agent received it via sync).
	Source string `json:"source"`
}

Monitor describes a blackbox target as seen by the UI. The `instance` label on the resulting probe_* metrics matches the name.

type MonitorSource

type MonitorSource interface {
	Targets() []blackbox.Target
}

MonitorSource produces the list of currently-active probe targets (both local-config and Bleemeo-provisioned). Implemented by *blackbox.RegisterManager; declared as an interface here so the /data/monitors handler can fall back to a config-only view when blackbox is disabled and so tests can mock it.

type MonitorsResponse

type MonitorsResponse struct {
	Monitors []Monitor `json:"monitors"`
}

MonitorsResponse is the payload returned by /data/monitors.

func (MonitorsResponse) Render

Render is a no-op required by go-chi/render.

type Pagination

type Pagination struct {
	Offset int `json:"offset"`
	Limit  int `json:"limit"`
}

type Process

type Process struct {
	Pid         int       `json:"pid"`
	Ppid        int       `json:"ppid"`
	CreateTime  time.Time `json:"create_time"`
	Cmdline     string    `json:"cmdline"`
	Name        string    `json:"name"`
	MemoryRss   int64     `json:"memory_rss"`
	CPUPercent  float64   `json:"cpu_percent"`
	CPUTime     float64   `json:"cpu_time"`
	Status      string    `json:"status"`
	Username    string    `json:"username"`
	Executable  string    `json:"executable"`
	ContainerID string    `json:"container_id"`
}

type Service

type Service struct {
	Name              string   `json:"name"`
	ContainerID       string   `json:"containerId"`
	IPAddress         string   `json:"ipAddress"`
	ListenAddresses   []string `json:"listenAddresses"`
	ExePath           string   `json:"exePath"`
	Active            bool     `json:"active"`
	Status            float64  `json:"status"`
	StatusDescription *string  `json:"statusDescription,omitempty"`
}

func (*Service) Render

func (s *Service) Render(_ http.ResponseWriter, _ *http.Request) error

type StoreInfo

type StoreInfo struct {
	Persistent       bool  `json:"persistent"`
	RetentionSeconds int64 `json:"retention_seconds"`
	OldestPointMs    int64 `json:"oldest_point_ms"`
}

StoreInfo describes the available local history depth so the UI can gate time-range buttons on what is actually queryable.

func (StoreInfo) Render

Render is a no-op required by go-chi/render.

type SwapUsage

type SwapUsage struct {
	Total float64 `json:"Total"`
	Used  float64 `json:"Used"`
	Free  float64 `json:"Free"`
}

type Tag

type Tag struct {
	TagName string `json:"tagName"`
}

func (*Tag) Render

func (t *Tag) Render(_ http.ResponseWriter, _ *http.Request) error

type ThresholdRule

type ThresholdRule struct {
	MetricName string `json:"metricName"`
	LabelsText string `json:"labelsText,omitempty"`
	// Item is the value of the `item` label when present (e.g. the
	// mountpoint for disk metrics, the interface name for network
	// metrics). Empty for rules that apply to a metric as a whole.
	Item         string   `json:"item,omitempty"`
	Source       string   `json:"source"`
	LowCritical  *float64 `json:"lowCritical"`
	LowWarning   *float64 `json:"lowWarning"`
	HighWarning  *float64 `json:"highWarning"`
	HighCritical *float64 `json:"highCritical"`
	// Soft periods, in seconds: a value must stay outside the band
	// for at least this long before the status flips. 0 = immediate.
	WarningDelaySec  int64 `json:"warningDelaySec"`
	CriticalDelaySec int64 `json:"criticalDelaySec"`
}

ThresholdRule describes a single active threshold on the agent. All four bound fields use a nullable float so the wire format can represent "unset bound" as JSON null (NaN is invalid JSON).

type ThresholdState

type ThresholdState struct {
	MetricName    string     `json:"metricName"`
	LabelsText    string     `json:"labelsText,omitempty"`
	Item          string     `json:"item,omitempty"`
	Status        string     `json:"status"` // "ok" | "warning" | "critical" | "unknown"
	WarningSince  *time.Time `json:"warningSince,omitempty"`
	CriticalSince *time.Time `json:"criticalSince,omitempty"`
	LastUpdate    *time.Time `json:"lastUpdate,omitempty"`
	// LastValue is the metric value at the last threshold evaluation
	// (~scrape cadence, default 10s). Null when no evaluation has
	// happened yet.
	LastValue *float64 `json:"lastValue,omitempty"`
}

ThresholdState is the current status of a single threshold-tracked series. The *Since fields use ISO timestamps and are null when the state has not been entered.

type ThresholdsResponse

type ThresholdsResponse struct {
	Thresholds []ThresholdRule  `json:"thresholds"`
	States     []ThresholdState `json:"states"`
}

ThresholdsResponse is the payload returned by /data/thresholds.

func (ThresholdsResponse) Render

Render is a no-op required by go-chi/render.

type Topinfo

type Topinfo struct {
	Time      time.Time    `json:"Time"`
	Uptime    int          `json:"Uptime"`
	Loads     []float64    `json:"Loads"`
	Users     int          `json:"Users"`
	Processes []*Process   `json:"Processes"`
	CPU       *CPUUsage    `json:"CPU,omitempty"`
	Memory    *MemoryUsage `json:"Memory,omitempty"`
	Swap      *SwapUsage   `json:"Swap,omitempty"`
}

func (*Topinfo) Render

func (t *Topinfo) Render(_ http.ResponseWriter, _ *http.Request) error

Jump to

Keyboard shortcuts

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