prometheus_client

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

README

prometheus GoDoc

Usage

local prometheus = require("prometheus")

local pp = prometheus.register(":8080")
pp:start()

-- gauge / counter
local gauge = prometheus.gauge({ -- prometheus.counter
     namespace="node_scout",
     subsystem="nf_conntrack",
     name="insert_failed",
     help="insert_failed from nf_conntrack",
})
gauge:set(100)
gauge:inc()
gauge:add(1)

-- gauge vector / counter vector
local gauge = prometheus.gauge({  -- prometheus.counter
     namespace="node_scout",
     subsystem="nf_conntrack",
     name="insert_failed",
     help="insert_failed from nf_conntrack",
     labels = {"label_1", "label_2"}
})
gauge:set(100, {"label_1":"one", "label_2":"two"})
gauge:inc({"label_1":"one", "label_2":"two"})
gauge:add(1, {"label_1":"one", "label_2":"two"})

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(L *lua.LState) int

Add lua prometheus_client_metric_ud:add(value)

func Counter

func Counter(L *lua.LState) int

Counter prometheus.counter(config) return lua (user data, error) config table:

{
  namespace="node_scout",
  subsystem="nf_conntrack",
  name="insert_failed",
  help="insert_failed from nf_conntrack",
  labels={"one", "two"}, -- optional
}

func Gauge

func Gauge(L *lua.LState) int

Gauge prometheus.gauge(config) return lua (user data, error) config table:

{
  namespace="node_scout",
  subsystem="nf_conntrack",
  name="insert_failed",
  help="insert_failed from nf_conntrack",
  labels={"one", "two"}, -- optional
}

func Inc

func Inc(L *lua.LState) int

Inc lua prometheus_client_metric_ud:inc()

func Loader

func Loader(L *lua.LState) int

Loader is the module loader function.

func Preload

func Preload(L *lua.LState)

Preload adds prometheus to the given Lua state's package.preload table. After it has been preloaded, it can be loaded using require:

local prometheus = require("prometheus")

func Register

func Register(L *lua.LState) int

Register(string): return (prometheus_client_ud, err)

func Set

func Set(L *lua.LState) int

Set lua prometheus_client_metric_ud:set(value)

func Start

func Start(L *lua.LState) int

Start prometheus_client_ud

Example

prometheus:start(string)

package main

import (
	"log"

	"github.com/vadv/gopher-lua-libs/http"
	prometheus "github.com/vadv/gopher-lua-libs/prometheus/client"
	"github.com/vadv/gopher-lua-libs/time"

	lua "github.com/yuin/gopher-lua"
)

func main() {
	state := lua.NewState()
	prometheus.Preload(state)
	time.Preload(state)
	http.Preload(state)

	source := `
    local prometheus = require("prometheus")
	local time = require("time")
	local http = require("http_client")

	local pp = prometheus.register(":18080")
	pp:start()
    time.sleep(1)

	local client = http.client({timeout=5})

	local request = http.request("GET", "http://127.0.0.1:18080/")
	local result = client:do_request(request)
	print(result.code)

	local request = http.request("GET", "http://127.0.0.1:18080/metrics")
	local result = client:do_request(request)
	print(result.code)
`
	if err := state.DoString(source); err != nil {
		log.Fatal(err.Error())
	}
}
Output:

404
200

func Stop

func Stop(L *lua.LState) int

Stop prometheus_client_ud stop

Types

This section is empty.

Jump to

Keyboard shortcuts

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