omq

package module
v0.0.0-...-2d19bad Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 9 Imported by: 0

README

omq

A text processor of the OpenMetrics format for the command-line, and Go library.

WIP WIP WIP

Usage Example

Convert OpenMetrics text to JSON
$ cat <<EOF | omq -j
# HELP http_response_latency_seconds the HTTP response latency for the client request
# TYPE http_response_latency_seconds histogram
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.005",status="2xx"} 4.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.01",status="2xx"} 3.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.025",status="2xx"} 2.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.05",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.075",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.1",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="+Inf",status="2xx"} 1.0
http_response_latency_seconds_count{http_method="GET",path="/index.html",status="2xx"} 4.0
http_response_latency_seconds_sum{http_method="GET",path="/index.html",status="2xx"} 0.001654784
EOF
[{"name":"http_response_latency_seconds","help":"the HTTP response latency for the client request","type":"HISTOGRAM","metrics":[{"type":"HISTOGRAM","labels":{"http_method":"GET","path":"/index.html","status":"2xx"},"data":{"values":{"+Inf":1,"0.005000":4,"0.010000":3,"0.025000":2,"0.050000":1,"0.075000":1,"0.100000":1},"sampleSum":0.001654784,"sampleCount":4}}]}]
Convert JSON to OpenMetrics text
$ echo '[{"name":"http_response_latency_seconds","help":"the HTTP response latency for the client request","type":"HISTOGRAM","metrics":[{"type":"HISTOGRAM","labels":{"http_method":"GET","path":"/index.html","status":"2xx"},"data":{"values":{"+Inf":1,"0.005000":4,"0.010000":3,"0.025000":2,"0.050000":1,"0.075000":1,"0.100000":1},"sampleSum":0.001654784,"sampleCount":4}}]}]' | omq -o
# HELP http_response_latency_seconds the HTTP response latency for the client request
# TYPE http_response_latency_seconds histogram
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="+Inf"} 1
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.005"} 4
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.01"} 3
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.025"} 2
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.05"} 1
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.075"} 1
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",status="2xx",le="0.1"} 1
http_response_latency_seconds_sum{http_method="GET",path="/index.html",status="2xx"} 0.001654784
http_response_latency_seconds_count{http_method="GET",path="/index.html",status="2xx"} 4
Query by jq equivalent query
$ echo -n "==> " && cat <<EOF | go run ./cmd/omq/main.go -q '.[] | select(.name == "http_response_latency_seconds") | .metrics[].data.values."0.025000"'
# HELP http_response_latency_seconds the HTTP response latency for the client request
# TYPE http_response_latency_seconds histogram
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.005",status="2xx"} 4.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.01",status="2xx"} 3.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.025",status="2xx"} 2.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.05",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.075",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="0.1",status="2xx"} 1.0
http_response_latency_seconds_bucket{http_method="GET",path="/index.html",le="+Inf",status="2xx"} 1.0
http_response_latency_seconds_count{http_method="GET",path="/index.html",status="2xx"} 4.0
http_response_latency_seconds_sum{http_method="GET",path="/index.html",status="2xx"} 0.001654784
EOF
==> 2

Author

moznion (moznion@mail.moznion.net)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertJSONBytesToOpenMetricsText

func ConvertJSONBytesToOpenMetricsText(inputBytes []byte) ([]byte, error)

func ConvertJSONToOpenMetricsText

func ConvertJSONToOpenMetricsText(reader io.ReadCloser) ([]byte, error)

func ConvertOpenMetricsTextToJSON

func ConvertOpenMetricsTextToJSON(reader io.ReadCloser) ([]byte, error)

func Query

func Query(reader io.ReadCloser, query string) ([]byte, error)

Types

type CounterMetric

type CounterMetric struct {
	Value float64 `json:"value,omitempty"`
}

func (*CounterMetric) ToPromMetrics

func (m *CounterMetric) ToPromMetrics() *pmodel.Counter

type CounterProcessor

type CounterProcessor struct{}

func (*CounterProcessor) Process

type GaugeMetric

type GaugeMetric struct {
	Value float64 `json:"value,omitempty"`
}

func (*GaugeMetric) ToPromMetrics

func (m *GaugeMetric) ToPromMetrics() *pmodel.Gauge

type GaugeProcessor

type GaugeProcessor struct{}

func (*GaugeProcessor) Process

type HistogramMetric

type HistogramMetric struct {
	Values      map[string]uint64 `json:"values,omitempty"`
	SampleSum   *float64          `json:"sampleSum,omitempty"`
	SampleCount *uint64           `json:"sampleCount,omitempty"`
}

func (*HistogramMetric) ToPromMetrics

func (m *HistogramMetric) ToPromMetrics() (*pmodel.Histogram, error)

type HistogramProcessor

type HistogramProcessor struct{}

func (*HistogramProcessor) Process

type Metric

type Metric struct {
	Type   string            `json:"type"` // for JSON unmarshalling
	Labels map[string]string `json:"labels,omitempty"`
	Data   ValueMetricData   `json:"data"`
}

func (*Metric) UnmarshalJSON

func (met *Metric) UnmarshalJSON(inputBytes []byte) error

type MetricsEnvelope

type MetricsEnvelope struct {
	Name    string    `json:"name"`
	Help    string    `json:"help,omitempty"`
	Type    string    `json:"type"`
	Metrics []*Metric `json:"metrics,omitempty"`
}

type MetricsSlice

type MetricsSlice []*MetricsEnvelope

func (MetricsSlice) MarshallOpenMetricsText

func (m MetricsSlice) MarshallOpenMetricsText() ([]byte, error)

type SummaryMetric

type SummaryMetric struct {
	Values      map[string]float64 `json:"values,omitempty"`
	SampleSum   *float64           `json:"sampleSum,omitempty"`
	SampleCount *uint64            `json:"sampleCount,omitempty"`
}

func (*SummaryMetric) ToPromMetrics

func (m *SummaryMetric) ToPromMetrics() (*pmodel.Summary, error)

type SummaryProcessor

type SummaryProcessor struct{}

func (*SummaryProcessor) Process

type UntypedMetric

type UntypedMetric struct {
	Value float64 `json:"value,omitempty"`
}

func (*UntypedMetric) ToPromMetrics

func (m *UntypedMetric) ToPromMetrics() *pmodel.Untyped

type UntypedProcessor

type UntypedProcessor struct{}

func (*UntypedProcessor) Process

type ValueMetricData

type ValueMetricData interface {
	// contains filtered or unexported methods
}

type ValueMetricDataProcessor

type ValueMetricDataProcessor interface {
	Process(m *pmodel.Metric) ValueMetricData
}

Directories

Path Synopsis
cmd
omq

Jump to

Keyboard shortcuts

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