Skip to content

aschmahmann/prom-metrics-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prom-metrics-client

Build Status Coverage Standard README GoDoc golang version Go Report Card

A simple client that fetches and parses metrics from a prometheus /metrics endpoint.

https://prometheus.io/docs/instrumenting/exposition_formats/

Install

go get github.com/alanshaw/prom-metrics-client

Usage

Example

package main

import (
	pmc "github.com/alanshaw/prom-metrics-client"
)

func main() {
	c := pmc.PromMetricsClient{
		URL: "http://localhost:8888/metrics",
	}

	ms, _ := c.GetMetrics() // returns []*Metric

	for _, m := range ms {
		// histogram and summary metrics can be upgraded to "richer" types
		if m.Type == pmc.HistogramType {
			hm, _ := pmc.UpgradeHistogram(m)
			fmt.Printf("%+v\n", hm)
		} else if m.Type == pmc.SummaryType {
			sm, _ := pmc.UpgradeSummary(m)
			fmt.Printf("%+v\n", sm)
		} else {
			fmt.Printf("%+v\n", m)
		}
	}
}

/*
Example output:

&{Name:http_requests_total Description:The total number of HTTP requests. Type:counter Samples:[0xc00033e8a0 0xc00033e960]}
&{Name:msdos_file_access_time_seconds Description: Type: Samples:[0xc00033ea20]}
&{Name:metric_without_timestamp_and_labels Description: Type: Samples:[0xc00033eae0]}
&{Name:something_weird Description: Type: Samples:[0xc00033eb40]}
&{Metric:{Name:http_request_duration_seconds Description:A histogram of the request duration. Type:histogram Samples:[0xc00033ebd0 0xc00033ec60 0xc00033ecf0 0xc00033ed80 0xc00033ee10 0xc00033eea0 0xc00033ef30 0xc00033ef90]} Buckets:[0xc000015520 0xc000015530 0xc000015540 0xc000015550 0xc000015560 0xc000015570] Sum:53423 Count:144320}
&{Metric:{Name:rpc_duration_seconds Description:A summary of the RPC duration in seconds. Type:summary Samples:[0xc00033eff0 0xc00033f080 0xc00033f110 0xc00033f1a0 0xc00033f230 0xc00033f2c0 0xc00033f320]} Quantiles:[0xc0000155d0 0xc0000155e0 0xc0000155f0 0xc000015600 0xc000015610] Sum:1.7560473e+07 Count:2693}
*/

API

GoDoc Reference

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw

About

A simple client that fetches and parses metrics from a prometheus /metrics endpoint.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Go 100.0%