spool

package
v0.0.0-...-a0d7459 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package spool contains the implementation of a worker that extracts the spool directory path from the agent config and enables other workers to write and read metrics to and from a the spool directory using a writer and a reader.

Index

Constants

View Source
const (
	// DefaultTimeout specifies the default socket read and write timeout.
	DefaultTimeout = 3 * time.Second
)

Variables

This section is empty.

Functions

func APIMetricBatch

func APIMetricBatch(batch MetricBatch) params.MetricBatchParam

APIMetricBatch converts the specified MetricBatch to a params.MetricBatch, which can then be sent to the controller.

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency.Manifold that extracts the metrics spool directory path from the agent.

func NewPeriodicWorker

func NewPeriodicWorker(do jworker.PeriodicWorkerCall, period time.Duration, newTimer func(time.Duration) jworker.PeriodicTimer, stop func()) worker.Worker

NewPeriodicWorker returns a periodic worker, that will call a stop function when it is killed.

func NewSocketListener

func NewSocketListener(socketPath string, handler ConnectionHandler) (*socketListener, error)

NewSocketListener returns a new socket listener struct.

Types

type ConnectionHandler

type ConnectionHandler interface {
	Handle(net.Conn, <-chan struct{}) error
}

ConnectionHandler defines the method needed to handle socket connections.

type JSONMetricReader

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

JSONMetricsReader reads metrics batches stored in the spool directory.

func NewJSONMetricReader

func NewJSONMetricReader(spoolDir string) (*JSONMetricReader, error)

NewJSONMetricsReader creates a new JSON metrics reader for the specified spool directory.

func (*JSONMetricReader) Close

func (r *JSONMetricReader) Close() error

Close implements the MetricsReader interface.

func (*JSONMetricReader) Read

func (r *JSONMetricReader) Read() ([]MetricBatch, error)

Read implements the MetricsReader interface. Due to the way the batches are stored in the file system, they will be returned in an arbitrary order. This does not affect the behavior.

func (*JSONMetricReader) Remove

func (r *JSONMetricReader) Remove(uuid string) error

Remove implements the MetricsReader interface.

type JSONMetricRecorder

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

JSONMetricRecorder implements the MetricsRecorder interface and writes metrics to a spool directory for store-and-forward.

func NewJSONMetricRecorder

func NewJSONMetricRecorder(config MetricRecorderConfig) (rec *JSONMetricRecorder, rErr error)

NewJSONMetricRecorder creates a new JSON metrics recorder.

func (*JSONMetricRecorder) AddMetric

func (m *JSONMetricRecorder) AddMetric(key, value string, created time.Time) error

AddMetric implements the MetricsRecorder interface.

func (*JSONMetricRecorder) Close

func (m *JSONMetricRecorder) Close() error

Close implements the MetricsRecorder interface.

func (*JSONMetricRecorder) IsDeclaredMetric

func (m *JSONMetricRecorder) IsDeclaredMetric(key string) bool

IsDeclaredMetric returns true if the metric recorder is permitted to store this metric. Returns false if the uniter using this recorder doesn't define this metric.

type ManifoldConfig

type ManifoldConfig engine.AgentManifoldConfig

ManifoldConfig specifies names a spooldirectory manifold should use to address its dependencies.

type MetricBatch

type MetricBatch struct {
	CharmURL string         `json:"charmurl"`
	UUID     string         `json:"uuid"`
	Created  time.Time      `json:"created"`
	Metrics  []jujuc.Metric `json:"metrics"`
	UnitTag  string         `json:"unit-tag"`
}

MetricBatch stores the information relevant to a single metrics batch.

type MetricFactory

type MetricFactory interface {
	// Recorder returns a new MetricRecorder.
	Recorder(metrics map[string]corecharm.Metric, charmURL, unitTag string) (MetricRecorder, error)

	// Reader returns a new MetricReader.
	Reader() (MetricReader, error)
}

MetricFactory contains the metrics reader and recorder factories.

type MetricMetadata

type MetricMetadata struct {
	CharmURL string    `json:"charmurl"`
	UUID     string    `json:"uuid"`
	Created  time.Time `json:"created"`
	UnitTag  string    `json:"unit-tag"`
}

MetricMetadata is used to store metadata for the current metric batch.

type MetricReader

type MetricReader interface {
	// Read returns all metric batches stored in the spool directory.
	Read() ([]MetricBatch, error)
	// Remove removes the metric batch with the specified uuid
	// from the spool directory.
	Remove(uuid string) error
	// Close implements io.Closer.
	Close() error
}

MetricReader reads metrics from a spool directory.

type MetricRecorder

type MetricRecorder interface {
	// AddMetric records a metric with the specified key, value and create time
	// to a spool directory.
	AddMetric(key, value string, created time.Time) error
	// Close implements io.Closer.
	Close() error
	// IsDeclaredMetrics returns true if the metric recorder
	// is permitted to store metrics with the specified key.
	IsDeclaredMetric(key string) bool
}

MetricRecorder records metrics to a spool directory.

type MetricRecorderConfig

type MetricRecorderConfig struct {
	SpoolDir string
	Metrics  map[string]corecharm.Metric
	CharmURL string
	UnitTag  string
}

MetricRecorderConfig stores configuration data for a metrics recorder.

Jump to

Keyboard shortcuts

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