Documentation
¶
Overview ¶
The stathat package makes it easy to post any values to your StatHat account.
Index ¶
- Variables
- func PostCount(statKey, userKey string, count int) error
- func PostCountOne(statKey, userKey string) error
- func PostCountTime(statKey, userKey string, count int, timestamp int64) error
- func PostEZCount(statName, ezkey string, count int) error
- func PostEZCountOne(statName, ezkey string) error
- func PostEZCountTime(statName, ezkey string, count int, timestamp int64) error
- func PostEZValue(statName, ezkey string, value float64) error
- func PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error
- func PostValue(statKey, userKey string, value float64) error
- func PostValueTime(statKey, userKey string, value float64, timestamp int64) error
- func WaitUntilFinished(timeout time.Duration) bool
- type BasicReporter
- func (r *BasicReporter) PostCount(statKey, userKey string, count int) error
- func (r *BasicReporter) PostCountOne(statKey, userKey string) error
- func (r *BasicReporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error
- func (r *BasicReporter) PostEZCount(statName, ezkey string, count int) error
- func (r *BasicReporter) PostEZCountOne(statName, ezkey string) error
- func (r *BasicReporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error
- func (r *BasicReporter) PostEZValue(statName, ezkey string, value float64) error
- func (r *BasicReporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error
- func (r *BasicReporter) PostValue(statKey, userKey string, value float64) error
- func (r *BasicReporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error
- func (r *BasicReporter) WaitUntilFinished(timeout time.Duration) bool
- type BatchReporter
- func (br *BatchReporter) PostCount(statKey, userKey string, count int) error
- func (br *BatchReporter) PostCountOne(statKey, userKey string) error
- func (br *BatchReporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error
- func (br *BatchReporter) PostEZCount(statName, ezkey string, count int) error
- func (br *BatchReporter) PostEZCountOne(statName, ezkey string) error
- func (br *BatchReporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error
- func (br *BatchReporter) PostEZValue(statName, ezkey string, value float64) error
- func (br *BatchReporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error
- func (br *BatchReporter) PostValue(statKey, userKey string, value float64) error
- func (br *BatchReporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error
- func (br *BatchReporter) WaitUntilFinished(timeout time.Duration) bool
- type Reporter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultReporter = NewReporter(100000, 10, nil)
DefaultReporter is the default instance of *Reporter.
var Verbose = false
The Verbose flag determines if the package should write verbose output to stdout.
Functions ¶
func PostCountOne ¶
Using the classic API, posts a count of 1 to a stat using DefaultReporter.
func PostCountTime ¶
Using the classic API, posts a count to a stat using DefaultReporter at a specific time.
func PostEZCount ¶
Using the EZ API, posts a count to a stat using DefaultReporter.
func PostEZCountOne ¶
Using the EZ API, posts a count of 1 to a stat using DefaultReporter.
Example ¶
package main import ( "log" stathat "github.com/stathat/go" ) func main() { log.Printf("starting example") stathat.Verbose = true err := stathat.PostEZCountOne("go example test run", "nobody@stathat.com") if err != nil { log.Printf("error posting ez count one: %v", err) return } // If using this with a valid account, this could be helpful in a short script: /* ok := stathat.WaitUntilFinished(5 * time.Second) if ok { fmt.Println("ok") } */
Output:
func PostEZCountTime ¶
Using the EZ API, posts a count to a stat at a specific time using DefaultReporter.
func PostEZValue ¶
Using the EZ API, posts a value to a stat using DefaultReporter.
func PostEZValueTime ¶
Using the EZ API, posts a value to a stat at a specific time using DefaultReporter.
func PostValueTime ¶
Using the classic API, posts a value to a stat at a specific time using DefaultReporter.
func WaitUntilFinished ¶
Wait for all stats to be sent, or until timeout. Useful for simple command- line apps to defer a call to this in main()
Types ¶
type BasicReporter ¶
type BasicReporter struct {
// contains filtered or unexported fields
}
BasicReporter is a StatHat client that can report stat values/counts to the servers.
func (*BasicReporter) PostCount ¶
func (r *BasicReporter) PostCount(statKey, userKey string, count int) error
Using the classic API, posts a count to a stat.
func (*BasicReporter) PostCountOne ¶
func (r *BasicReporter) PostCountOne(statKey, userKey string) error
Using the classic API, posts a count of 1 to a stat.
func (*BasicReporter) PostCountTime ¶
func (r *BasicReporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error
Using the classic API, posts a count to a stat at a specific time.
func (*BasicReporter) PostEZCount ¶
func (r *BasicReporter) PostEZCount(statName, ezkey string, count int) error
Using the EZ API, posts a count to a stat.
func (*BasicReporter) PostEZCountOne ¶
func (r *BasicReporter) PostEZCountOne(statName, ezkey string) error
Using the EZ API, posts a count of 1 to a stat.
func (*BasicReporter) PostEZCountTime ¶
func (r *BasicReporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error
Using the EZ API, posts a count to a stat at a specific time.
func (*BasicReporter) PostEZValue ¶
func (r *BasicReporter) PostEZValue(statName, ezkey string, value float64) error
Using the EZ API, posts a value to a stat.
func (*BasicReporter) PostEZValueTime ¶
func (r *BasicReporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error
Using the EZ API, posts a value to a stat at a specific time.
func (*BasicReporter) PostValue ¶
func (r *BasicReporter) PostValue(statKey, userKey string, value float64) error
Using the classic API, posts a value to a stat.
func (*BasicReporter) PostValueTime ¶
func (r *BasicReporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error
Using the classic API, posts a value to a stat at a specific time.
func (*BasicReporter) WaitUntilFinished ¶
func (r *BasicReporter) WaitUntilFinished(timeout time.Duration) bool
Wait for all stats to be sent, or until timeout. Useful for simple command- line apps to defer a call to this in main()
type BatchReporter ¶
BatchReporter wraps an existing Reporter in order to implement sending stats to the StatHat server in batch. The flow is only available for the EZ API. The following describes how stats are sent: 1.) PostEZCountOne is called and adds the stat request to a queue. 2.) PostEZCountOne is called again on the same stat, the value in the queue is incremented. 3.) After batchInterval amount of time, all stat requests from the queue are
sent to the server.
func (*BatchReporter) PostCount ¶
func (br *BatchReporter) PostCount(statKey, userKey string, count int) error
func (*BatchReporter) PostCountOne ¶
func (br *BatchReporter) PostCountOne(statKey, userKey string) error
func (*BatchReporter) PostCountTime ¶
func (br *BatchReporter) PostCountTime(statKey, userKey string, count int, timestamp int64) error
func (*BatchReporter) PostEZCount ¶
func (br *BatchReporter) PostEZCount(statName, ezkey string, count int) error
func (*BatchReporter) PostEZCountOne ¶
func (br *BatchReporter) PostEZCountOne(statName, ezkey string) error
func (*BatchReporter) PostEZCountTime ¶
func (br *BatchReporter) PostEZCountTime(statName, ezkey string, count int, timestamp int64) error
func (*BatchReporter) PostEZValue ¶
func (br *BatchReporter) PostEZValue(statName, ezkey string, value float64) error
func (*BatchReporter) PostEZValueTime ¶
func (br *BatchReporter) PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error
func (*BatchReporter) PostValue ¶
func (br *BatchReporter) PostValue(statKey, userKey string, value float64) error
func (*BatchReporter) PostValueTime ¶
func (br *BatchReporter) PostValueTime(statKey, userKey string, value float64, timestamp int64) error
func (*BatchReporter) WaitUntilFinished ¶
func (br *BatchReporter) WaitUntilFinished(timeout time.Duration) bool
type Reporter ¶
type Reporter interface { PostCount(statKey, userKey string, count int) error PostCountTime(statKey, userKey string, count int, timestamp int64) error PostCountOne(statKey, userKey string) error PostValue(statKey, userKey string, value float64) error PostValueTime(statKey, userKey string, value float64, timestamp int64) error PostEZCountOne(statName, ezkey string) error PostEZCount(statName, ezkey string, count int) error PostEZCountTime(statName, ezkey string, count int, timestamp int64) error PostEZValue(statName, ezkey string, value float64) error PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error WaitUntilFinished(timeout time.Duration) bool }
Reporter describes an interface for communicating with the StatHat API
func NewBatchReporter ¶
NewBatchReporter creates a batching stat reporter. The interval parameter specifies how often stats should be posted to the StatHat server.
func NewReporter ¶
func NewReporter(bufferSize, poolSize int, transport http.RoundTripper) Reporter
NewReporter returns a new Reporter. You must specify the channel bufferSize and the goroutine poolSize. You can pass in nil for the transport and it will create an http transport with MaxIdleConnsPerHost set to the goroutine poolSize. Note if you pass in your own transport, it's a good idea to have its MaxIdleConnsPerHost be set to at least the poolSize to allow for effective connection reuse.