hermes

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Config *HermesConfig

	// define maps used to store metrics
	Gauges     = map[string]*prometheus.GaugeVec{}
	Counters   = map[string]*prometheus.CounterVec{}
	Histograms = map[string]*prometheus.HistogramVec{}
	Summaries  = map[string]*prometheus.SummaryVec{}

	// define custom errors for application
	ErrInvalidGauge          = errors.New("Invalid gauge configuration")
	ErrInvalidCounter        = errors.New("Invalid gauge configuration")
	ErrUnregisteredMetric    = errors.New("Unregistered metric")
	ErrInvalidGaugeOperation = errors.New("Invalid gauge operation")
	ErrInvalidLabels         = errors.New("Invalid label configuration")
)
View Source
var (
	ErrInvalidConfig = errors.New("Invalid hermes configuration")
)

Functions

func DecrementGauge

func DecrementGauge(name string, gaugeJson GaugeJSON) error

function used to decrement a particular gauge value

func GenerateLabels

func GenerateLabels(labels map[string]string, metricType,
	metricName string) (prometheus.Labels, error)

function used to generate prometheus labels based on config. note that the labels provided in the UDP packet are not set on the counter/gauge unless they have also been defined in the JSON config file

func GetMetricType

func GetMetricType(metric string) (string, error)

function used to determine the metric type based on a particular metric name

func IncrementCounter

func IncrementCounter(name string, counterJson CounterJSON) error

function used to increment a particular counter

func IncrementGauge

func IncrementGauge(name string, gaugeJson GaugeJSON) error

function used to increment gauge a particular gauge value

func InitializeMetrics

func InitializeMetrics(config HermesConfig) error

function used to initialize hermes metrics by iterating over the JSON configuration file and generating prometheus Gauges/Counters for all the specified metrics

func IsValidLabelConfig

func IsValidLabelConfig(receivedLabels map[string]string, expectedLabels []string) bool

function used to determine if a given set of labels matches the label configuration expected for the specified metric

func ListenPrometheus

func ListenPrometheus(config HermesConfig, listenPort int)

function used to start new prometheus server to scrape metrics from Hermes

func NewCounter

func NewCounter(counter HermesCounter) error

function used to create new counter instance. Pointers to the prometheus counters are stored in the global Gauges map, which maps the name of the counter/metric to the prometheus pointer that stores the metrics themselves

func NewGauge

func NewGauge(gauge HermesGauge) error

function used to create new gauge instance. Pointers to the prometheus gauges are stored in the global Gauges map, which maps the name of the gauge/metric to the prometheus pointer that stores the metrics themselves

func NewHistogram

func NewHistogram(histogram HermesHistogram) error

function used to create a new histogram instance. Pointers to the prometheus histograms are stored in the global histogram map, which maps the name of the histogram/metric to the prometheus pointer that stores the metrics themselves

func NewSummary

func NewSummary(summary HermesSummary) error

function used to create a new histogram instance. Pointers to the prometheus histograms are stored in the global histogram map, which maps the name of the histogram/metric to the prometheus pointer that stores the metrics themselves

func ObserveHistogram

func ObserveHistogram(name string, histogramJson HistogramJSON) error

function used to make an observation on a particular histogram

func ObserveSummary

func ObserveSummary(name string, summaryJson SummaryJSON) error

function used to make an observation on a particular histogram

func ProcessGauge

func ProcessGauge(name string, gaugeJson GaugeJSON) error

function used to call correct handler for gauge operations. currently, gauge operations support incrementing, deprecating, and setting of values.

func SetGauge

func SetGauge(name string, gaugeJson GaugeJSON) error

function used to set the value on a particular gauge

func SetPrometheusLabels

func SetPrometheusLabels(labels map[string]string, labelConfig []string) (prometheus.Labels, error)

function used to convert labels into prometheus.Labels instance by filtering out the lables that are included both on the global hermes configuration file and the JSON from the UDP packet

Types

type CounterJSON

type CounterJSON struct {
	Labels map[string]string `json:"labels"`
}

struct used to define JSON format of UDP packets for counters

type GaugeJSON

type GaugeJSON struct {
	Labels    map[string]string `json:"labels"`
	Value     *float64          `json:"value"`
	Operation string            `json:"operation"`
}

struct used to define JSON format of UDP packets for Gauges. Note that the operation field determines whether or not gauges are incremented, decremented or set with a particular value

type HermesConfig

type HermesConfig struct {
	ServiceName string            `json:"service_name"`
	Gauges      []HermesGauge     `json:"gauges"`
	Counters    []HermesCounter   `json:"counters"`
	Histograms  []HermesHistogram `json:"histograms"`
	Summaries   []HermesSummary   `json:"summaries"`
}

struct used to define the global hermes configuration loaded for the local JSON file

func LoadHermesConfig

func LoadHermesConfig(path string) (HermesConfig, error)

function used to generate HermesConfig instance from the local JSON configuration file. Additionally, if the listen address and port are not specified, the default values are assigned to the config

type HermesCounter

type HermesCounter struct {
	Labels            []string `json:"labels"`
	MetricName        string   `json:"metric_name"`
	MetricDescription string   `json:"metric_description"`
}

struct used to define a Counter from the Hermes config used to create a prometheus counter instance

type HermesGauge

type HermesGauge struct {
	Labels            []string `json:"labels"`
	MetricName        string   `json:"metric_name"`
	MetricDescription string   `json:"metric_description"`
}

struct used to define a Gauge from the Hermes config used to create a prometheus gauge instance

type HermesHistogram

type HermesHistogram struct {
	Labels            []string `json:"labels"`
	MetricName        string   `json:"metric_name"`
	MetricDescription string   `json:"metric_description"`
}

struct used to define a Counter from the Hermes config used to create a prometheus counter instance

type HermesPayload

type HermesPayload struct {
	MetricName string      `json:"metric_name"`
	Payload    interface{} `json:"payload"`
}

struct used to define format of UDP packets sent from a hermes client

type HermesServer

type HermesServer struct {
	// UDP socket to listen for packets
	Socket        *net.UDPConn
	ListenAddress *net.UDPAddr

	// hermes config containing data about metrics
	Config HermesConfig
}

func New

func New(configPath, listenAddress string, listenPort int) *HermesServer

function used to create new hermes service instance

func (*HermesServer) Listen

func (server *HermesServer) Listen()

function used to start listening on the specified UDP ports for JSON messages from a Hermes client. All incoming messages are read into a buffer and then converted to JSON format by the handler function

func (*HermesServer) ProcessPayload

func (server *HermesServer) ProcessPayload(packet []byte)

function used to process UDP packets sent over UDP interface. all packets are read into a buffer, and the contents of the buffer are then converted into JSON format. The metric name is sent with all JSON packets, which is then used to determine the type of metric that the JSON packet corresponds to (i.e. counter or gauge) and the payload is then processed depending on the type of metric

func (*HermesServer) RestartServerGracefully

func (server *HermesServer) RestartServerGracefully()

function used to safely restart hermes server. the UDP connection is first closed via the socket connection. The connection is then re-established. If the re-creation of the socket fails, the go-routine will wait 10 seconds before attempting to re-open the connection

type HermesSummary

type HermesSummary struct {
	Labels            []string `json:"labels"`
	MetricName        string   `json:"metric_name"`
	MetricDescription string   `json:"metric_description"`
}

struct used to define a Counter from the Hermes config used to create a prometheus counter instance

type HistogramJSON

type HistogramJSON struct {
	Labels      map[string]string `json:"labels"`
	Observation float64           `json:"observation"`
}

struct used to define JSON format of UDP packets for counters

type SummaryJSON

type SummaryJSON struct {
	Labels      map[string]string `json:"labels"`
	Observation float64           `json:"observation"`
}

Jump to

Keyboard shortcuts

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