nqm

package
v3.14.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0, Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Larger = 1
	Equal  = 0
	Lesser = -1
)
View Source
const (
	MetricMax         = "max"
	MetricMin         = "min"
	MetricAvg         = "avg"
	MetricMed         = "med"
	MetricMdev        = "mdev"
	MetricLoss        = "loss"
	MetricCount       = "count"
	MetricPckSent     = "pck_sent"
	MetricPckReceived = "pck_received"
	MetricNumAgent    = "num_agent"
	MetricNumTarget   = "num_target"

	AgentGroupingName      = "name"
	AgentGroupingIpAddress = "ip_address"
	AgentGroupingHostname  = "hostname"

	TargetGroupingName = "name"
	TargetGroupingHost = "host"

	GroupingProvince = "province"
	GroupingCity     = "city"
	GroupingIsp      = "isp"
	GroupingNameTag  = "name_tag"

	TimeRangeAbsolute byte = 1
	TimeRangeRelative byte = 2

	TimeUnitYear   = "y"
	TimeUnitMonth  = "m"
	TimeUnitWeek   = "w"
	TimeUnitDay    = "d"
	TimeUnitHour   = "h"
	TimeUnitMinute = "n"
)

Variables

View Source
var CompareFunctions = map[string]CompareDynamicRecord{
	"agent_name": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Agent.Name, right.Agent.Name, direction); hasNil {
			return r
		}

		return utils.CompareString(*left.Agent.Name, *right.Agent.Name, direction)
	},
	"agent_hostname": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Agent.Hostname, right.Agent.Hostname, direction)
	},
	"agent_ip_address": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}

		leftIp, rightIp := net.ParseIP(left.Agent.IpAddress), net.ParseIP(right.Agent.IpAddress)
		return utils.CompareIpAddress(leftIp, rightIp, direction)
	},
	"agent_isp": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Agent.Isp, right.Agent.Isp, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Agent.Isp.Name, right.Agent.Isp.Name, direction)
	},
	"agent_province": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Agent.Province, right.Agent.Province, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Agent.Province.Name, right.Agent.Province.Name, direction)
	},
	"agent_city": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Agent.City, right.Agent.City, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Agent.City.Name, right.Agent.City.Name, direction)
	},
	"agent_name_tag": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Agent, right.Agent, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Agent.NameTag, right.Agent.NameTag, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Agent.NameTag.Value, right.Agent.NameTag.Value, direction)
	},

	"target_name": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Target.Name, right.Target.Name, direction)
	},
	"target_host": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}

		leftIfIp, rightIfIp := net.ParseIP(left.Target.Host), net.ParseIP(right.Target.Host)
		if leftIfIp != nil && rightIfIp != nil {
			return utils.CompareIpAddress(leftIfIp, rightIfIp, direction)
		}

		return utils.CompareString(left.Target.Host, right.Target.Host, direction)
	},
	"target_isp": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Target.Isp, right.Target.Isp, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Target.Isp.Name, right.Target.Isp.Name, direction)
	},
	"target_province": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Target.Province, right.Target.Province, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Target.Province.Name, right.Target.Province.Name, direction)
	},
	"target_city": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Target.City, right.Target.City, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Target.City.Name, right.Target.City.Name, direction)
	},
	"target_name_tag": func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		if r, hasNil := utils.CompareNil(left.Target, right.Target, direction); hasNil {
			return r
		}
		if r, hasNil := utils.CompareNil(left.Target.NameTag, right.Target.NameTag, direction); hasNil {
			return r
		}

		return utils.CompareString(left.Target.NameTag.Value, right.Target.NameTag.Value, direction)
	},

	MetricMax: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return compareIntWithNoData(
			int64(left.Metrics.Metrics.Max),
			int64(right.Metrics.Metrics.Max),
			direction,
		)
	},
	MetricMin: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return compareIntWithNoData(
			int64(left.Metrics.Metrics.Min),
			int64(right.Metrics.Metrics.Min),
			direction,
		)
	},
	MetricAvg: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return compareFloatWithNoData(
			left.Metrics.Metrics.Avg,
			right.Metrics.Metrics.Avg,
			direction,
		)
	},
	MetricMed: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return compareIntWithNoData(
			int64(left.Metrics.Metrics.Med),
			int64(right.Metrics.Metrics.Med),
			direction,
		)
	},
	MetricMdev: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return compareFloatWithNoData(
			left.Metrics.Metrics.Mdev,
			right.Metrics.Metrics.Mdev,
			direction,
		)
	},
	MetricLoss: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareFloat(
			left.Metrics.Metrics.Loss,
			right.Metrics.Metrics.Loss,
			direction,
		)
	},
	MetricCount: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareInt(
			int64(left.Metrics.Metrics.Count),
			int64(right.Metrics.Metrics.Count),
			direction,
		)
	},
	MetricPckSent: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareUint(
			left.Metrics.Metrics.NumberOfSentPackets,
			right.Metrics.Metrics.NumberOfSentPackets,
			direction,
		)
	},
	MetricPckReceived: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareUint(
			left.Metrics.Metrics.NumberOfReceivedPackets,
			right.Metrics.Metrics.NumberOfReceivedPackets,
			direction,
		)
	},
	MetricNumAgent: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareInt(
			int64(left.Metrics.Metrics.NumberOfAgents),
			int64(right.Metrics.Metrics.NumberOfAgents),
			direction,
		)
	},
	MetricNumTarget: func(left *DynamicRecord, right *DynamicRecord, direction byte) int {
		return utils.CompareInt(
			int64(left.Metrics.Metrics.NumberOfTargets),
			int64(right.Metrics.Metrics.NumberOfTargets),
			direction,
		)
	},
}

Functions

func ValidateTimeWithUnit

func ValidateTimeWithUnit(sl validator.StructLevel)

Types

type AgentOfQueryDetail

type AgentOfQueryDetail struct {
	Name         []string `json:"name"`
	Hostname     []string `json:"hostname"`
	IpAddress    []string `json:"ip_address"`
	ConnectionId []string `json:"connection_id"`

	Isps      []*owlModel.Isp      `json:"isps"`
	Provinces []*owlModel.Province `json:"provinces"`
	Cities    []*owlModel.City2    `json:"cities"`

	NameTags  []*owlModel.NameTag  `json:"name_tags"`
	GroupTags []*owlModel.GroupTag `json:"group_tags"`
}

type CompareDynamicRecord

type CompareDynamicRecord func(*DynamicRecord, *DynamicRecord, byte) int

Defines the function used for utils.Comparison of two dynamic records

type CompoundQuery

type CompoundQuery struct {
	Filters *CompoundQueryFilter `json:"filters" digest:"1"`

	// Grouping content of report
	Grouping *QueryGrouping `json:"grouping" digest:"11"`

	// Output content of report
	Output *QueryOutput `json:"output" digest:"21"`
	// contains filtered or unexported fields
}

The main object of query for compound report

func NewCompoundQuery

func NewCompoundQuery() *CompoundQuery

func (*CompoundQuery) GetCityRelation

func (q *CompoundQuery) GetCityRelation() PropRelation

func (*CompoundQuery) GetCompressedQuery

func (q *CompoundQuery) GetCompressedQuery() []byte

Converts this query object to compressed query

func (*CompoundQuery) GetDigestValue

func (q *CompoundQuery) GetDigestValue() []byte

func (*CompoundQuery) GetIspRelation

func (q *CompoundQuery) GetIspRelation() PropRelation

func (*CompoundQuery) GetNameTagRelation

func (q *CompoundQuery) GetNameTagRelation() PropRelation

func (*CompoundQuery) GetProvinceRelation

func (q *CompoundQuery) GetProvinceRelation() PropRelation

func (*CompoundQuery) SetMetricFilter

func (q *CompoundQuery) SetMetricFilter(filter MetricFilter)

func (*CompoundQuery) SetupDefault

func (query *CompoundQuery) SetupDefault()

func (*CompoundQuery) UnmarshalFromCompressedQuery

func (q *CompoundQuery) UnmarshalFromCompressedQuery(compressedQuery []byte)

func (*CompoundQuery) UnmarshalJSON

func (query *CompoundQuery) UnmarshalJSON(jsonSource []byte) (err error)

Processes the source of JSON to initialize query object

type CompoundQueryDetail

type CompoundQueryDetail struct {
	Time    *TimeFilterDetail    `json:"time"`
	Metrics ojson.JsonString     `json:"metrics"`
	Agent   *AgentOfQueryDetail  `json:"agent"`
	Target  *TargetOfQueryDetail `json:"target"`
	Output  *OutputDetail        `json:"output"`
}

type CompoundQueryFilter

type CompoundQueryFilter struct {
	Time    *TimeFilter            `json:"time" digest:"1"`
	Agent   *nqmModel.AgentFilter  `json:"agent" digest:"2"`
	Target  *nqmModel.TargetFilter `json:"target" digest:"3"`
	Metrics string                 `json:"metrics" digest:"4"`
}

func (*CompoundQueryFilter) UnmarshalSimpleJSON

func (f *CompoundQueryFilter) UnmarshalSimpleJSON(jsonObject *sjson.Json) (err error)

type DynamicAgentProps

type DynamicAgentProps struct {
	Id        int32
	Name      *string
	IpAddress string
	Hostname  string
	Isp       *owlModel.Isp
	Province  *owlModel.Province
	City      *owlModel.City2
	NameTag   *owlModel.NameTag
	Grouping  []string
}

func (*DynamicAgentProps) MarshalJSON

func (p *DynamicAgentProps) MarshalJSON() ([]byte, error)

type DynamicMetrics

type DynamicMetrics struct {
	Metrics *Metrics
	Output  *[]string
}

func (*DynamicMetrics) MarshalJSON

func (m *DynamicMetrics) MarshalJSON() ([]byte, error)

type DynamicRecord

type DynamicRecord struct {
	Agent   *DynamicAgentProps  `json:"agent,omitempty"`
	Target  *DynamicTargetProps `json:"target,omitempty"`
	Metrics *DynamicMetrics     `json:"metrics"`
}

type DynamicTargetProps

type DynamicTargetProps struct {
	Id       int32
	Name     string
	Host     string
	Isp      *owlModel.Isp
	Province *owlModel.Province
	City     *owlModel.City2
	NameTag  *owlModel.NameTag
	Grouping []string
}

func (*DynamicTargetProps) MarshalJSON

func (p *DynamicTargetProps) MarshalJSON() ([]byte, error)

type MetricFilter

type MetricFilter interface {
	// Checks whether or not the metrics matches conditions of filter
	IsMatch(model *Metrics) bool
}

Defines the interface for process a instance of metrics

type Metrics

type Metrics struct {
	Max                     int16   `json:"max"`
	Min                     int16   `json:"min"`
	Avg                     float64 `json:"avg"`
	Med                     int16   `json:"med"`
	Mdev                    float64 `json:"mdev"`
	Loss                    float64 `json:"loss"`
	Count                   int32   `json:"count"`
	NumberOfSentPackets     uint64  `json:"number_of_sent_packets"`
	NumberOfReceivedPackets uint64  `json:"number_of_received_packets"`
	NumberOfAgents          int32   `json:"number_of_agents"`
	NumberOfTargets         int32   `json:"number_of_targets"`
}

*

  • Macro-struct re-used by various data

func (*Metrics) UnmarshalSimpleJson

func (m *Metrics) UnmarshalSimpleJson(jsonObject *sjson.Json)

type MetricsFilterParseError

type MetricsFilterParseError struct {
	// contains filtered or unexported fields
}

type OutputDetail

type OutputDetail struct {
	Agent   []string `json:"agent"`
	Target  []string `json:"target"`
	Metrics []string `json:"metrics"`
}

type PropRelation

type PropRelation int8

Defines the IR for relation of hosts(between agent and target)

const (
	/**
	 * Input value of relation
	 */
	RelationSame    = -11
	RelationNotSame = -12

	// The relation is unknown
	NoCondition PropRelation = -1
	// Means a property of agent and target must be same
	SameValue PropRelation = 1
	// Means a property of agent and target may not be same
	NotSameValue PropRelation = 2
)

type QueryGrouping

type QueryGrouping struct {
	Agent  []string `json:"agent" digest:"1"`
	Target []string `json:"target" digest:"2"`
}

func (*QueryGrouping) IsForEachAgent

func (g *QueryGrouping) IsForEachAgent() bool

func (*QueryGrouping) IsForEachTarget

func (g *QueryGrouping) IsForEachTarget() bool

func (*QueryGrouping) UnmarshalSimpleJSON

func (g *QueryGrouping) UnmarshalSimpleJSON(jsonObject *sjson.Json) error

type QueryOutput

type QueryOutput struct {
	Metrics []string `json:"metrics" digest:"1"`
}

func (*QueryOutput) HasMetric

func (o *QueryOutput) HasMetric(metricName string) bool

func (*QueryOutput) UnmarshalSimpleJSON

func (o *QueryOutput) UnmarshalSimpleJSON(jsonObject *sjson.Json) error

type TargetOfQueryDetail

type TargetOfQueryDetail struct {
	Name []string `json:"name"`
	Host []string `json:"host"`

	Isps      []*owlModel.Isp      `json:"isps"`
	Provinces []*owlModel.Province `json:"provinces"`
	Cities    []*owlModel.City2    `json:"cities"`

	NameTags  []*owlModel.NameTag  `json:"name_tags"`
	GroupTags []*owlModel.GroupTag `json:"group_tags"`
}

type TimeFilter

type TimeFilter struct {
	StartTime ojson.JsonTime `json:"start_time"`
	EndTime   ojson.JsonTime `json:"end_time"`
	ToNow     *TimeWithUnit  `json:"to_now"`
	// contains filtered or unexported fields
}

func NewTimeFilter

func NewTimeFilter() *TimeFilter

func (*TimeFilter) GetDigest

func (f *TimeFilter) GetDigest() []byte

Implements digest.Digestor

func (*TimeFilter) GetMultipleTimeRanges

func (f *TimeFilter) GetMultipleTimeRanges(baseTime time.Time) []*TimeRange

func (*TimeFilter) GetNetTimeRange

func (f *TimeFilter) GetNetTimeRange() (time.Time, time.Time)

Retrieves the start time of net(whether or not the time is absolute or relative)

func (*TimeFilter) IsMultipleTimeRanges

func (f *TimeFilter) IsMultipleTimeRanges() bool

func (*TimeFilter) ToJsonOfRelativeTimeRange

func (f *TimeFilter) ToJsonOfRelativeTimeRange() *sjson.Json

func (*TimeFilter) UnmarshalSimpleJSON

func (f *TimeFilter) UnmarshalSimpleJSON(jsonObject *sjson.Json) error

type TimeFilterDetail

type TimeFilterDetail TimeFilter

func (*TimeFilterDetail) MarshalJSON

func (t *TimeFilterDetail) MarshalJSON() ([]byte, error)

type TimeRange

type TimeRange struct {
	StartTime time.Time
	EndTime   time.Time
}

Represents the range of time(by two point of time line)

type TimeWithUnit

type TimeWithUnit struct {
	Unit  string `json:"unit" digest:"1"`
	Value int    `json:"value" digest:"2"`

	StartTimeOfDay *string `json:"start_time_of_day,omitempty" digest:"3"`
	EndTimeOfDay   *string `json:"end_time_of_day,omitempty" digest:"4"`
}

func (*TimeWithUnit) DurationFromMidnightOfEndTime

func (tu *TimeWithUnit) DurationFromMidnightOfEndTime() *time.Duration

func (*TimeWithUnit) DurationFromMidnightOfStartTime

func (tu *TimeWithUnit) DurationFromMidnightOfStartTime() *time.Duration

func (*TimeWithUnit) String

func (tu *TimeWithUnit) String() string

Jump to

Keyboard shortcuts

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