cat

package
v0.0.0-...-57214d0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2015 License: Apache-2.0, Apache-2.0 Imports: 15 Imported by: 0

README

#How to use cat.go Package cat works as a client for Central Application Tracking(CAT).

###Import import cat "/your/path/to/cat" ###Config cat.DOMAIN = "your appid" cat.HOSTNAME = "your hostname" //optional cat.IP = "your hostip" //optional cat.TEMPFILE = ".cat" //optional, "your/path/to/.cat" cat.CAT_HOST = cat.UAT //or "http://cat.uat.qa.nt.ctripcorp.com" ###Use Transaction mycat := cat.Instance() func() { t := mycat.NewTransaction("URL", "Page") defer func() { err := recover() t.SetStatus(err) t.Complete() }() // do your bussiness here t.Add("k1", "v1") t.Add("k2", "v2") t.Add("k3", "v3") }() ###Use Event mycat := cat.Instance() func() { e := mycat.NewEvent("Review", "New") e.Add("id", 12345) e.Add("user", "john") e.SetStatus("0") e.Complete() }() ###Use Heartbeat mycat := cat.Instance() func() { h := mycat.NewHeartbeat("Heartbeat", "192.168.141.131") h.Set("System", "CPU", "0.3") h.Set("System", "DISK", "0.9") h.SetStatus("0") h.Complete() }() ###Log Error As Event mycat := cat.Instance() func() { err, ret := someMethod() mycat.LogError(err) }()

Documentation

Overview

Package cat works as a client for Central Application Tracking(CAT).

Import

import cat "/your/path/to/cat"

Config

cat.DOMAIN   = "your appid"
cat.HOSTNAME = "your hostname" //optional
cat.IP       = "your hostip"   //optional
cat.TEMPFILE = ".cat"          //optional, "your/path/to/.cat"
cat.CAT_HOST = cat.UAT         //or "http://cat.uat.qa.nt.ctripcorp.com"

Use Transaction

mycat := cat.Instance()
func() {
	t := mycat.NewTransaction("URL", "Page")
	defer func() {
		p := recover()
		mycat.LogPanic(p)
		t.SetStatus(p)
		t.Complete()
	}()
	// do your bussiness here
	// perhaps panic
	t.AddData("k0", "v0")
	t.AddData("k1", "v1")
}()

Use Event

mycat := cat.Instance()
func() {
	e := mycat.NewEvent("Review", "New")
	e.AddData("k0", "v0")
	e.AddData("k1", "v1")
	e.SetStatus("0")
	e.Complete()
}()

Use Heartbeat

mycat := cat.Instance()
func() {
	h := mycat.NewHeartbeat("Heartbeat", "192.168.141.131")
	h.Set("System", "CPU", "0.3")
	h.Set("System", "DISK", "0.9")
	h.SetStatus("0")
	h.Complete()
}()

Log Error As Event

mycat := cat.Instance()
func() {
	err, ret := someMethod()
	mycat.LogError(err)
}()

Index

Constants

This section is empty.

Variables

View Source
var (
	PROD        string = "http://cat.ctripcorp.com"
	FAT         string = "http://cat.fws.qa.nt.ctripcorp.com"
	UAT         string = "http://cat.uat.qa.nt.ctripcorp.com"
	CAT_HOST    string = FAT
	CAT_SERVERS []string
	DOMAIN      string = "900407"
	HOSTNAME    string = ""
	IP          string = ""
	TEMPFILE    string = ".cat"
)

Configs about cat is required to be correct. The client is able to complement some of the configs, but is incapable of validation. Fortunately invalid configs causes failure of cat's init, thus users can be immediately aware of config fault.

View Source
var (
	CONN_FACTORY = func() (conn net.Conn, err error) {
		servers := CAT_SERVERS
		size := len(servers)
		for i := 0; i < size; i++ {
			conn, err = net.Dial("tcp", servers[i])
			if err == nil {
				return conn, err
			}
		}
		return nil, errors.New("Unable to access cat servers including backups.")
	}
)
View Source
var LF = "\n"
View Source
var TAB = "\t"

Functions

func Cat_init_if

func Cat_init_if()

Cat_init_if initialize cat.go, which must be down before any other operations, for which Instance called it automatically.

func Invoke

func Invoke(f Function, values ...interface{}) ([]reflect.Value, error)

Invoke panics if f's Kind is not Func. As accurate validation is skipped for performance concern, don't call Invoke unless you know what you're doing.

Types

type Cat

type Cat interface {
	//Tree provides methods to create different kinds of messages
	Tree
	//Create a new simple Event without tags.
	LogEvent(t string, n string)
	//Create a new Event whose type is error and status is ERROR,
	//nil is ignored
	LogError(e error)
	//Create a new Event whose type is panic and status is ERROR,
	//nil is ignored
	LogPanic(e Panic)
}

A tool instance for CAT. Use it to create Transaction, Event, Heartbeat, Trace... Every Cat instance has 1 Tree instance.

func Instance

func Instance() Cat

As it's not recommended to apply thread local in go, apps with cat.go have to call Instance, keep and manage the instance returned properly.

type Encodable

type Encodable interface {
	Encode(*bytes.Buffer) error
}

type Event

type Event interface {
	Message
	Complete()
}

func NewEvent

func NewEvent(t string, n string, f Function) Event

type Function

type Function interface{}
type Header interface {
	Encodable
	GetDomain() string
	GetHostname() string
	GetIpAddress() string
}

func NewHeader

func NewHeader() Header

type Heartbeat

type Heartbeat interface {
	Message
	Set(extension_id string, extension_detail_id string, value string)
	Complete()
}

func NewHeartbeat

func NewHeartbeat(t string, n string, f Function) Heartbeat

type Message

type Message interface {
	Meta
	Encodable
}

type MessageId

type MessageId interface {
	Encodable
	SetIndex(index uint64)
	SetTsh(tsh uint64)
}

func NewMessageId

func NewMessageId() MessageId

type MessageIdFactory

type MessageIdFactory interface {
	Next() (MessageId, error)
}
var MESSAGE_ID_FACTORY MessageIdFactory = NewMessageIdFactory()

func NewMessageIdFactory

func NewMessageIdFactory() MessageIdFactory

type Meta

type Meta interface {
	SetStatus(Panic)
	AddData(string, string)
	GetType() string
	GetName() string
	GetStatus() string
	GetTimestamp() time.Time
	SetData([]byte)
	GetData() []byte
}

func NewMeta

func NewMeta(t string, n string) Meta

type Panic

type Panic interface{}

type Transaction

type Transaction interface {
	Message
	AddChild(Message) Transaction
	Complete()
}

func NewTransaction

func NewTransaction(t string, n string, f Function) Transaction

type Tree

type Tree interface {
	NewTransaction(string, string) Transaction
	NewEvent(string, string) Event
	NewHeartbeat(string, string) Heartbeat
}

func NewTree

func NewTree() Tree

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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