protocol

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MetricUrl API for TSDB
	MetricUrl    = "/server/api/metrics"
	TagKeyUrl    = "/server/api/tagKeys"
	TagValueUrl  = "/server/api/tagValues"
	CurveUrl     = "/server/api/curves"
	RangeUrl     = "/server/api/range"
	TopNUrl      = "/server/api/topn"
	ChartDataUrl = "/server/api/chartData"

	// AlarmRuleUrl API for MySQL
	AlarmRuleUrl       = "/server/api/alarmRule"
	ContactUrl         = "/server/api/contact"
	MetricWhiteListUrl = "/server/api/metricWhiteList"
	DashboardUrl       = "/server/api/dashboard"
	ChartUrl           = "/server/api/chart"
	ChartListUrl       = "/server/api/chartList"

	PutMetricsUrl = "/server/api/putMetrics"
)
View Source
const (
	CodeOK                 = 0
	CodeApiNotFound        = 1
	CodeMethodNotFound     = 2
	CodeJsonDecodeError    = 3
	CodeInvalidParamError  = 4
	CodeGetConnPoolError   = 5
	CodeExecTSDBSqlError   = 6
	CodeSplitTagsError     = 7
	CodeStarKeysError      = 8
	CodeMaxQueryRangeError = 9
	CodeAggregatorError    = 10
	CodeDownSampleError    = 11
	CodeMetricError        = 12
	CodeTagCountError      = 13
	CodeOrderError         = 14
	CodeExecMySQLError     = 15
)
View Source
const (
	MagicNumber = 0x1F2E3C4D
	PduVersion  = 0x01
	PduHeadSize = 16

	PduTypeMetrics = 1
)
View Source
const MaxExpireTime = 3600

Variables

View Source
var CodeMsg = map[int]string{
	CodeOK:                 "ok",
	CodeApiNotFound:        "api not found",
	CodeMethodNotFound:     "http method not found",
	CodeJsonDecodeError:    "json decode error",
	CodeInvalidParamError:  "invalid parameter error",
	CodeGetConnPoolError:   "get conn pool error",
	CodeExecTSDBSqlError:   "TSDB SQL execution error",
	CodeSplitTagsError:     "split tags error",
	CodeStarKeysError:      "star keys error",
	CodeMaxQueryRangeError: "max query range error",
	CodeAggregatorError:    "aggregator error",
	CodeDownSampleError:    "down sample error",
	CodeMetricError:        "metric error",
	CodeTagCountError:      "too many tag count error",
	CodeOrderError:         "no such order for topN query",
	CodeExecMySQLError:     "MySQL execution error",
}

Functions

func CheckAggregator

func CheckAggregator(aggregator string) (string, error)

func CheckOrder

func CheckOrder(order string) (string, error)

func DecodeRequest

func DecodeRequest(r *http.Request, entity interface{}) error

DecodeRequest decode and write err log in one place

func GetIPFromConnAddr

func GetIPFromConnAddr(addr string) string

GetIPFromConnAddr get ip from the following format: ipv4 format: "192.0.2.1:25", ipv6 format: "[2001:db8::1]:80"

func MethodNotSupport

func MethodNotSupport(w http.ResponseWriter)

func SerializeMetricValues

func SerializeMetricValues(values []MetricValue) ([]byte, error)

func TransferDownSample

func TransferDownSample(downSample string) (int64, error)

func WriteQueryResp

func WriteQueryResp(w http.ResponseWriter, code int, data interface{})

Types

type CurveData

type CurveData struct {
	Metric string            `json:"metric"`
	Tags   map[string]string `json:"tags"`
	DPS    []TimeValuePoint  `json:"dps"`
}

type MetricReq

type MetricReq struct {
	Metric  string              `json:"metric"`
	Tags    map[string]string   `json:"tags"`
	Filters map[string][]string `json:"filters"` // tag values with ||
}

type MetricValue

type MetricValue struct {
	Metric    string            `json:"metric"`
	Tags      map[string]string `json:"tags"`
	Timestamp uint64            `json:"timestamp"`
	Value     float64           `json:"value"`
}

func CollectHttpMetrics

func CollectHttpMetrics(w http.ResponseWriter, req *http.Request) ([]MetricValue, error)

func UnmarshalPayload

func UnmarshalPayload(data []byte) ([]MetricValue, error)

func (*MetricValue) IsValid

func (m *MetricValue) IsValid() bool

type PduHeader

type PduHeader struct {
	Magic         uint32
	Version       uint16
	Protocol      uint16
	Sequence      uint32
	PayloadLength uint32
}

func DeserializePduHeader

func DeserializePduHeader(data []byte) (PduHeader, error)

type QueryResp

type QueryResp struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

type TimeSeriesDataRequest

type TimeSeriesDataRequest struct {
	Token      string      `json:"token"`
	Start      int64       `json:"start"`
	End        int64       `json:"end"`
	Last       int64       `json:"last"`
	Aggregator string      `json:"aggregator"`
	DownSample int64       `json:"down_sample"`
	Metrics    []MetricReq `json:"metrics"`
}

type TimeValuePoint

type TimeValuePoint struct {
	TimeStamp int64   `json:"ts"`
	Value     float64 `json:"v"`
}

type TopNData

type TopNData struct {
	Metric string            `json:"metric"`
	Name   string            `json:"name"`
	Tags   map[string]string `json:"tags"`
	Value  float64           `json:"value"`
}

type TopNRequest

type TopNRequest struct {
	Token      string              `json:"token"`
	Start      int64               `json:"start"`
	End        int64               `json:"end"`
	Last       int64               `json:"last"`
	Aggregator string              `json:"aggregator"`
	DownSample int64               `json:"down_sample"`
	Limit      int                 `json:"limit"`
	Order      string              `json:"order"` // desc/asc
	Metric     string              `json:"metric"`
	Tags       map[string]string   `json:"tags"`
	Filters    map[string][]string // extracted from tags with "||" in the value
	Field      string              // extracted from tags with value of "*"
}

Jump to

Keyboard shortcuts

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