stathat

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: MIT Imports: 9 Imported by: 399

README

stathat

This is a Go package for posting stats to your StatHat account.

For more information about StatHat, visit www.stathat.com.

Installation

Use go get:

go get github.com/stathat/go

That's it.

Import it like this:

import (
        "github.com/stathat/go"
)

Usage

The easiest way to use the package is with the EZ API functions. You can add stats directly in your code by just adding a call with a new stat name. Once StatHat receives the call, a new stat will be created for you.

To post a count of 1 to a stat:

stathat.PostEZCountOne("messages sent - female to male", "something@stathat.com")

To specify the count:

stathat.PostEZCount("messages sent - male to male", "something@stathat.com", 37)

To post a value:

stathat.PostEZValue("ws0 load average", "something@stathat.com", 0.372)

There are also functions for the classic API. The drawback to the classic API is that you need to create the stats using the web interface and copy the keys it gives you into your code.

To post a count of 1 to a stat using the classic API:

stathat.PostCountOne("statkey", "userkey")

To specify the count:

stathat.PostCount("statkey", "userkey", 37)

To post a value:

stathat.PostValue("statkey", "userkey", 0.372)

Contact us

We'd love to hear from you if you are using this in your projects! Please drop us a line: @stat_hat or contact us here.

About

Written by Patrick Crosby at StatHat. Twitter: @stat_hat

Documentation

Overview

The stathat package makes it easy to post any values to your StatHat account.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultReporter = NewReporter(100000, 10, nil)

DefaultReporter is the default instance of *Reporter.

View Source
var Verbose = false

The Verbose flag determines if the package should write verbose output to stdout.

Functions

func PostCount

func PostCount(statKey, userKey string, count int) error

Using the classic API, posts a count to a stat using DefaultReporter.

func PostCountOne

func PostCountOne(statKey, userKey string) error

Using the classic API, posts a count of 1 to a stat using DefaultReporter.

func PostCountTime

func PostCountTime(statKey, userKey string, count int, timestamp int64) error

Using the classic API, posts a count to a stat using DefaultReporter at a specific time.

func PostEZCount

func PostEZCount(statName, ezkey string, count int) error

Using the EZ API, posts a count to a stat using DefaultReporter.

func PostEZCountOne

func PostEZCountOne(statName, ezkey string) error

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

func PostEZCountTime(statName, ezkey string, count int, timestamp int64) error

Using the EZ API, posts a count to a stat at a specific time using DefaultReporter.

func PostEZValue

func PostEZValue(statName, ezkey string, value float64) error

Using the EZ API, posts a value to a stat using DefaultReporter.

func PostEZValueTime

func PostEZValueTime(statName, ezkey string, value float64, timestamp int64) error

Using the EZ API, posts a value to a stat at a specific time using DefaultReporter.

func PostValue

func PostValue(statKey, userKey string, value float64) error

Using the classic API, posts a value to a stat using DefaultReporter.

func PostValueTime

func PostValueTime(statKey, userKey string, value float64, timestamp int64) error

Using the classic API, posts a value to a stat at a specific time using DefaultReporter.

func WaitUntilFinished

func 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()

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

type BatchReporter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func NewBatchReporter(reporter Reporter, interval time.Duration) Reporter

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.

Jump to

Keyboard shortcuts

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