Skip to content

XANi/promwriter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Promwriter

Simple lib for writing Prometheus data

	cfg := Config{
		URL:              srv.URL,
		//MaxBatchDuration: time.Second * 3,
		//MaxBatchLength:   1000,
		//Logger:           zapSugaredLogger, // or 
	}
    writer, err := promwriter.New(cfg)
    metric := promwriter.Metric{
		Name:    "test_metric",
		Labels:  map[string]string{"host": "unit-test", "zone": "us-east-1"},
		Value:   42.5,
		Counter: true, // adds "_total" to metric name
		TS:      Time.Now(),
	}
    err := writer.WriteMetric(metric)

will error out if queue is full, WriteMetric waits up to MaxBatchDuration for timeout

Alternatively you can use text representation

    metric := promwriter.Metric{
		Name:    "test_metric",
		Labels:  map[string]string{"host": "unit-test", "zone": "us-east-1"},
		Value:   42.5,
		Counter: true, // adds "_total" to metric name
		TS:      Time.Now(),
	}
    n,err := metric.Write(ioWriter)

About

Prometheus writer library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages