stathat

package
v0.0.0-...-ddb7c7b Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2015 License: MIT, Apache-2.0 Imports: 8 Imported by: 0

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
log.Printf("starting example")
stathat.Verbose = true
err := stathat.PostEZCountOne("go example test run", "patrick@stathat.com")
if err != nil {
	log.Printf("error posting ez count one: %v", err)
	return
}
ok := stathat.WaitUntilFinished(5 * time.Second)
if ok {
	fmt.Println("ok")
}
Output:

ok

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 Reporter

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

Reporter is a StatHat client that can report stat values/counts to the servers.

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 use the default http transport.

func (*Reporter) PostCount

func (r *Reporter) PostCount(statKey, userKey string, count int) error

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

func (*Reporter) PostCountOne

func (r *Reporter) PostCountOne(statKey, userKey string) error

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

func (*Reporter) PostCountTime

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

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

func (*Reporter) PostEZCount

func (r *Reporter) PostEZCount(statName, ezkey string, count int) error

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

func (*Reporter) PostEZCountOne

func (r *Reporter) PostEZCountOne(statName, ezkey string) error

Using the EZ API, posts a count of 1 to a stat.

func (*Reporter) PostEZCountTime

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

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

func (*Reporter) PostEZValue

func (r *Reporter) PostEZValue(statName, ezkey string, value float64) error

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

func (*Reporter) PostEZValueTime

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

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

func (*Reporter) PostValue

func (r *Reporter) PostValue(statKey, userKey string, value float64) error

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

func (*Reporter) PostValueTime

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

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

func (*Reporter) WaitUntilFinished

func (r *Reporter) 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()

Jump to

Keyboard shortcuts

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