Help us shape the future of Go! Take the 2026 Go Developer Survey

promver

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2019 License: MIT Imports: 6 Imported by: 0

README

promver

Export Golang Module information to Prometheus.

Usage

import (
	"fmt"
	"log"
	"net/http"

	"github.com/povilasv/promver"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
	prometheus.Register(promver.NewCollector("test_app_name"))

	http.Handle("/metrics", promhttp.Handler())

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Example Metric Output

# HELP name_go_mod_info A metric with a constant '1' value labeled by dependency name, version, from which name was built.
# TYPE name_go_mod_info gauge
name_go_mod_info{name="github.com/beorn7/perks",version="v0.0.0-20180321164747-3a771d992973"} 1
name_go_mod_info{name="github.com/golang/protobuf",version="v1.2.0"} 1
name_go_mod_info{name="github.com/matttproud/golang_protobuf_extensions",version="v1.0.1"} 1
name_go_mod_info{name="github.com/povilasv/promver",version="v0.0.2"} 1
name_go_mod_info{name="github.com/prometheus/client_golang",version="v0.9.2"} 1
name_go_mod_info{name="github.com/prometheus/client_model",version="v0.0.0-20180712105110-5c3871d89910"} 1
name_go_mod_info{name="github.com/prometheus/common",version="v0.0.0-20181126121408-4724e9255275"} 1
name_go_mod_info{name="github.com/prometheus/procfs",version="v0.0.0-20181204211112-1dc9a6cbc91a"} 1

Example Print

fmt.Println(promver.Print("app_name"))

Output:

app_name
 github.com/beorn7/perks: v0.0.0-20180321164747-3a771d992973
 github.com/golang/protobuf: v1.2.0
 github.com/matttproud/golang_protobuf_extensions: v1.0.1
 github.com/povilasv/promver: v0.0.3
 github.com/prometheus/client_golang: v0.9.2
 github.com/prometheus/client_model: v0.0.0-20180712105110-5c3871d89910
 github.com/prometheus/common: v0.0.0-20181126121408-4724e9255275
 github.com/prometheus/procfs: v0.0.0-20181204211112-1dc9a6cbc91a

Example Info

fmt.Println(promver.Info())

Output:


Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Info

func Info() string

Info returns dependency versions

func NewCollector

func NewCollector(program string) *prometheus.GaugeVec

NewCollector returns a collector which exports metrics about current dependency information.

Example
package main

import (
	"log"
	"net/http"

	"github.com/povilasv/promver"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promhttp"
)

func main() {
	prometheus.Register(promver.NewCollector("test_app_name"))

	http.Handle("/metrics", promhttp.Handler())

	log.Fatal(http.ListenAndServe(":8080", nil))
}

func Print

func Print(program string) string

Print returns module version information.

Example
package main

import (
	"fmt"

	"github.com/povilasv/promver"
)

func main() {
	fmt.Println(promver.Print("test_app_name"))
}
Output:
test_app_name

Types

This section is empty.

Jump to

Keyboard shortcuts

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