prometheus

package
v4.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: GPL-3.0 Imports: 16 Imported by: 6

README

How to monitor with prometheus

Prerequisites:

Start scrapping services

To start scrapping with prometheus you must create or edit the prometheus config file and add all the services you want to scrap, like these:

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['localhost:9090']
+  - job_name: 'beacon-chain'
+    static_configs:
+      - targets: ['localhost:8080']

After creating/updating the prometheus file run it:

$ prometheus --config.file=your-prometheus-file.yml

Now, you can add the prometheus server as a data source on grafana and start building your dashboards.

How to add additional metrics

The prometheus service export the metrics from the DefaultRegisterer so just need to register your metrics with the prometheus or promauto libraries. To know more Go application guide

Documentation

Overview

Package prometheus defines a service which is used for metrics collection and health of a node in Prysm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunSimpleServerOrDie

func RunSimpleServerOrDie(addr string)

RunSimpleServerOrDie is a blocking call to serve /metrics at the given address.

Types

type Handler

type Handler struct {
	Path    string
	Handler func(http.ResponseWriter, *http.Request)
}

Handler represents a path and handler func to serve on the same port as /metrics, /healthz, /goroutinez, etc.

type LogrusCollector

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

LogrusCollector is a logrus hook to collect log counters.

func NewLogrusCollector

func NewLogrusCollector() *LogrusCollector

NewLogrusCollector register internal metrics and return an logrus hook to collect log counters This function can be called only once, if more than one call is made an error will be returned.

func (*LogrusCollector) Fire

func (hook *LogrusCollector) Fire(entry *logrus.Entry) error

Fire is called on every log call.

func (*LogrusCollector) Levels

func (_ *LogrusCollector) Levels() []logrus.Level

Levels return a slice of levels supported by this hook;

type Service

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

Service provides Prometheus metrics via the /metrics route. This route will show all the metrics registered with the Prometheus DefaultRegisterer.

func NewService

func NewService(addr string, svcRegistry *runtime.ServiceRegistry, additionalHandlers ...Handler) *Service

NewService sets up a new instance for a given address host:port. An empty host will match with any IP so an address like ":2121" is perfectly acceptable.

func (*Service) Start

func (s *Service) Start()

Start the prometheus service.

func (*Service) Status

func (s *Service) Status() error

Status checks for any service failure conditions.

func (*Service) Stop

func (s *Service) Stop() error

Stop the service gracefully.

Jump to

Keyboard shortcuts

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