tsdb

package
v0.0.0-...-406c194 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MatcherClientIp    = 0
	MatcherQueryName   = 1
	MatcherAnswerIp    = 2
	MatcherAnswerCname = 3

	StatTypeQname  = 0
	StatTypeClient = 1

	MetricTypeGlobal   = 0
	MetricTypeDNSQType = 1

	MetricsStatDnsQuery = "dnsquery"
	MetricsStatEcsHits  = "ecshits"
	MetricsStatNxdomain = "nxdomain"
)

Variables

View Source
var DBNotConnect = errors.New("database not connect")

Functions

This section is empty.

Types

type Config

type Config struct {
	Sid      string
	Host     string
	User     string
	Password string
	Dbname   string
	Port     int
	Sslmode  string
	TimeZone string
	History  int
	Debug    bool
}

type Counter

type Counter struct {
	Name  string `json:"name"`
	Value int64  `json:"value"`
}

type LineChartData

type LineChartData struct {
	Title     string     `json:"title"`
	YaxisName string     `json:"yaxis_name"`
	Datas     []LineData `json:"datas"`
}

func NewLineChartData

func NewLineChartData(title string, yaxisName string) *LineChartData

func (*LineChartData) Add

func (d *LineChartData) Add(line ...LineData)

type LineData

type LineData struct {
	Name   string           `json:"name"`
	Values [][2]interface{} `json:"values"`
}

func NewLineData

func NewLineData(name string, values [][2]interface{}) *LineData

type MatcherCounter

type MatcherCounter struct {
	Upstream string `json:"upstream"`
	Name     string `json:"name"`
	Tag      string `json:"tag"`
	Mtype    int    `json:"mtype"`
	Value    int64  `json:"value"`
}

func NewMatcherCounter

func NewMatcherCounter(upstream string, name string, tag string, mtype int) *MatcherCounter

func (*MatcherCounter) Incr

func (d *MatcherCounter) Incr()

func (*MatcherCounter) Val

func (d *MatcherCounter) Val() int64

type MatcherCounterStat

type MatcherCounterStat struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMatcherCounterStat

func NewMatcherCounterStat() *MatcherCounterStat

func (*MatcherCounterStat) DBValues

func (c *MatcherCounterStat) DBValues(sid string) []MdnsMatcherCounter

func (*MatcherCounterStat) GetTopValues

func (c *MatcherCounterStat) GetTopValues(upstream string, mtype int, count int) []MatcherCounter

func (*MatcherCounterStat) Incr

func (c *MatcherCounterStat) Incr(upstream string, name string, tag string, mtype int)

func (*MatcherCounterStat) MtypeValues

func (c *MatcherCounterStat) MtypeValues(mtype int) []MatcherCounter

func (*MatcherCounterStat) Values

func (c *MatcherCounterStat) Values(upstream string, mtype int) []MatcherCounter

type MdnsDomain

type MdnsDomain struct {
	ID        string    `gorm:"primaryKey" json:"id" form:"id"`
	Domain    string    `gorm:"uniqueindex" json:"domain" form:"domain"`
	Tag       string    `json:"tag" form:"tag"`
	Mode      string    `json:"mode" form:"mode"`
	Isp       string    `json:"isp" form:"isp"`
	Remark    string    `json:"remark" form:"remark"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type MdnsLog

type MdnsLog struct {
	Timestamp time.Time `gorm:"primaryKey" json:"timestamp"`
	Sid       string    `gorm:"primaryKey" json:"sid"`
	MsgId     uint16    `gorm:"primaryKey" json:"msg_id"`
	Upstream  string    `json:"upstream"`
	Upserver  string    `json:"upserver"`
	Matcher   string    `json:"matcher"`
	QType     string    `json:"qtype"`
	Qname     string    `json:"qname"`
	QnameTag  string    `json:"qname_tag"`
	Client    string    `json:"client"`
	ClientTag string    `json:"client_tag"`
	ClientLoc string    `json:"client_loc"`
	Ecs       string    `json:"ecs"`
	EcsLoc    string    `json:"ecs_loc"`
	AnswerIps string    `json:"answer_ips"`
	AnswerLoc string    `json:"answer_loc"`
	LocSync   int       `json:"LocSync"` // GEO 位置同步状态 0 | 1
	Rcode     int       `json:"rcode"`
	RcodeStr  string    `json:"rcode_str"`
	Cast      int64     `json:"cast"`
	Response  string    `json:"response"`
}

func (MdnsLog) MarshalJSON

func (d MdnsLog) MarshalJSON() ([]byte, error)

type MdnsMatcher

type MdnsMatcher struct {
	ID           string    `gorm:"primaryKey" json:"id" form:"id"`
	Enabled      int       `json:"enabled" form:"enabled"`
	Upstream     string    `json:"upstream" form:"upstream"`
	Name         string    `json:"name" form:"name"`
	To           string    `json:"to" form:"to"`
	ClientIps    string    `json:"client_ips" form:"client_ips"`
	AnwserIps    string    `json:"anwser_ips" form:"anwser_ips"`
	QueryNames   string    `json:"query_names" form:"query_names"`
	AnwserCnames string    `json:"anwser_cnames" form:"anwser_cnames"`
	Notify       string    `json:"notify" form:"notify"`
	Ipset        string    `json:"ipset" form:"ipset"`
	Nxdomain     int       `json:"nxdomain" form:"nxdomain"`
	Remark       string    `json:"remark" form:"remark"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
}

type MdnsMatcherCounter

type MdnsMatcherCounter struct {
	Sid       string    `gorm:"primaryKey" json:"sid"`
	Timestamp time.Time `gorm:"primaryKey;type:timestamp" json:"timestamp"`
	Upstream  string    `gorm:"primaryKey" json:"upstream"`
	Name      string    `gorm:"primaryKey" json:"name"`
	Tag       string    `json:"tag"`
	Mtype     int       `json:"mtype"`
	Value     int64     `json:"value"`
}

MdnsMatcherCounter 应用匹配统计

type MdnsMetricCounter

type MdnsMetricCounter struct {
	Sid        string    `gorm:"primaryKey" json:"sid"`
	Timestamp  time.Time `gorm:"primaryKey;type:timestamp" json:"timestamp"`
	MetricType int       `gorm:"primaryKey" json:"metric_type"`
	Name       string    `gorm:"primaryKey" json:"name"`
	Value      int64     `json:"value"`
}

MdnsMetricCounter 指标统计

type MdnsNetwork

type MdnsNetwork struct {
	ID        string    `gorm:"primaryKey" json:"id" form:"id"`
	Network   string    `gorm:"uniqueindex" json:"network" form:"network"`
	Tag       string    `json:"tag" form:"tag"`
	Isp       string    `json:"isp" form:"isp"`
	Remark    string    `json:"remark" form:"remark"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type MdnsQueryCounter

type MdnsQueryCounter struct {
	Sid       string    `gorm:"primaryKey" json:"sid"`
	Timestamp time.Time `gorm:"primaryKey;type:timestamp" json:"timestamp"`
	Upstream  string    `gorm:"primaryKey" json:"upstream"`
	Name      string    `gorm:"primaryKey" json:"name"`
	StatType  int       `json:"stat_type"` // qname | client
	Value     int64     `json:"value"`
}

MdnsQueryCounter 查询域名统计

type MetricCounter

type MetricCounter struct {
	Metric int    `json:"metric"`
	Name   string `json:"name"`
	Value  int64  `json:"value"`
}

func NewMetricCounter

func NewMetricCounter(metric int, name string) *MetricCounter

func (*MetricCounter) Incr

func (d *MetricCounter) Incr()

func (*MetricCounter) Val

func (d *MetricCounter) Val() int64

type MetricCounterStat

type MetricCounterStat struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewMetricCounterStat

func NewMetricCounterStat() *MetricCounterStat

func (*MetricCounterStat) DBValues

func (c *MetricCounterStat) DBValues(sid string) []MdnsMetricCounter

func (*MetricCounterStat) GetTopValues

func (c *MetricCounterStat) GetTopValues(metric, count int) []MetricCounter

func (*MetricCounterStat) GetValue

func (c *MetricCounterStat) GetValue(metric int, name string) int64

func (*MetricCounterStat) Incr

func (c *MetricCounterStat) Incr(metric int, name string)

func (*MetricCounterStat) Values

func (c *MetricCounterStat) Values(metric int) []MetricCounter

type QueryCounter

type QueryCounter struct {
	Upstream string `json:"upstream"`
	Name     string `json:"name"`
	StatType int    `json:"stat_type"` // qname | client
	Value    int64  `json:"value"`
}

func NewQueryCounter

func NewQueryCounter(upstream, name string, statType int) *QueryCounter

func (*QueryCounter) Incr

func (d *QueryCounter) Incr()

func (*QueryCounter) Val

func (d *QueryCounter) Val() int64

type QueryCounterStat

type QueryCounterStat struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewQueryCounterStat

func NewQueryCounterStat() *QueryCounterStat

func (*QueryCounterStat) DBValues

func (c *QueryCounterStat) DBValues(sid string) []MdnsQueryCounter

func (*QueryCounterStat) GetTopValues

func (c *QueryCounterStat) GetTopValues(statType, count int) []QueryCounter

func (*QueryCounterStat) Incr

func (c *QueryCounterStat) Incr(upstream, name string, statType int)

func (*QueryCounterStat) Values

func (c *QueryCounterStat) Values(statType int) []QueryCounter

type TsDB

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

func New

func New(config Config) (*TsDB, error)

func NewLocalDB

func NewLocalDB() *TsDB

func (*TsDB) ClearHistory

func (t *TsDB) ClearHistory() error

func (*TsDB) Config

func (t *TsDB) Config() *Config

func (*TsDB) DropAll

func (t *TsDB) DropAll()

func (*TsDB) GetDB

func (t *TsDB) GetDB() *gorm.DB

func (*TsDB) Migrate

func (t *TsDB) Migrate()

func (*TsDB) QueryDnsQtypeMetricSumValH24

func (t *TsDB) QueryDnsQtypeMetricSumValH24(name string) int64

func (*TsDB) QueryGlobalMetricSumValH24

func (t *TsDB) QueryGlobalMetricSumValH24(name string) int64

func (*TsDB) QueryMatcherNameCounter

func (t *TsDB) QueryMatcherNameCounter(start, end time.Time) ([]Counter, error)

QueryMatcherNameCounter 查询指定时间范围内统计应用规则计数器列表 如果时间未指定, 默认最近24小时

func (*TsDB) QueryMatcherNameLine

func (t *TsDB) QueryMatcherNameLine(start, end time.Time) (*LineChartData, error)

QueryMatcherNameLine 统计应用规则匹配趋势 如果时间未指定, 默认最近24小时

func (*TsDB) QueryMatcherTagCounter

func (t *TsDB) QueryMatcherTagCounter(start, end time.Time, mtype int) ([]Counter, error)

QueryMatcherTagCounter 查询指定时间范围内统计标签计数器列表 如果时间未指定, 默认最近24小时

mtype:
MatcherClientIp    = 0
MatcherQueryName   = 1
MatcherAnswerIp    = 2
MatcherAnswerCname = 3

func (*TsDB) QueryMatcherTagLine

func (t *TsDB) QueryMatcherTagLine(start, end time.Time, mtype int) (*LineChartData, error)

QueryMatcherTagLine 统计应用规则匹配标签趋势 如果时间未指定, 默认最近24小时

mtype
MatcherClientIp    = 0
MatcherQueryName   = 1
MatcherAnswerIp    = 2
MatcherAnswerCname = 3

func (*TsDB) QueryMetricSumVal

func (t *TsDB) QueryMetricSumVal(start, end time.Time, metric int, name string) int64

QueryMetricSumVal 查询指定时间范围内某个指标的总数 如果时间未指定, 默认最近24小时

 @param metric
	MetricTypeGlobal   = 0
	MetricTypeDNSQType = 1

func (*TsDB) QueryRequestTop

func (t *TsDB) QueryRequestTop(start, end time.Time, statType, count int) ([]Counter, error)

QueryRequestTop 查询指定时间范围内统计类型排名 如果时间未指定, 默认最近24小时

statType: StatTypeQname  = 0  StatTypeClient = 1

func (*TsDB) Reconnect

func (t *TsDB) Reconnect() error

Reconnect dsl "host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai"

func (*TsDB) Sid

func (t *TsDB) Sid() string

func (*TsDB) UpdateMdnsLog

func (t *TsDB) UpdateMdnsLog(data []MdnsLog) error

func (*TsDB) UpdateMdnsMatcherCounter

func (t *TsDB) UpdateMdnsMatcherCounter(data []MdnsMatcherCounter) error

func (*TsDB) UpdateMdnsMetricCounter

func (t *TsDB) UpdateMdnsMetricCounter(data []MdnsMetricCounter) error

func (*TsDB) UpdateMdnsQueryCounter

func (t *TsDB) UpdateMdnsQueryCounter(data []MdnsQueryCounter) error

Jump to

Keyboard shortcuts

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