fakescraper

package module
v0.0.0-...-75715f1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2024 License: MIT Imports: 4 Imported by: 5

README

fakescraper

Scrape Prometheus metrics from inside the app. Handy for testing.

I use this when I'm writing Prometheus exporters and want to test them from the command line. Before this I would start the daemon, run curl to fetch the metrics, then kill it. Now I simply do something like:

func main() {
	var (
		onceToStdout = flag.Bool("once-to-stdout", false,
			"Don't bind, instead just print the metrics once to stdout and exit")
	)

	flag.Parse()

	if *onceToStdout {
		fs := fakescraper.NewFakeScraper()
		fmt.Print(fs.Scrape())
		return
	}

	...

	if err := http.ListenAndServe(*listenAddress, nil); err != nil {
		log.Fatalf("Unable to setup HTTP server: %v", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeScraper

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

func NewFakeScraper

func NewFakeScraper() *FakeScraper

func (*FakeScraper) Header

func (d *FakeScraper) Header() http.Header

func (*FakeScraper) Scrape

func (fs *FakeScraper) Scrape() string

Scrape asks prometheus to handle a scrape request so we can capture and return the output.

func (*FakeScraper) WriteHeader

func (d *FakeScraper) WriteHeader(code int)

Jump to

Keyboard shortcuts

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