本文整理匯總了Golang中github.com/cactus/go-statsd-client/statsd.Statter類的典型用法代碼示例。如果您正苦於以下問題:Golang Statter類的具體用法?Golang Statter怎麽用?Golang Statter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Statter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: EmitError
// Emit errors as `error.$event-name`
func EmitError(stats statsd.Statter, eventName string) (err error) {
eventName = CleanStatsdComponent(eventName)
if stats != nil {
err = stats.Inc(StatsdEventName("error", eventName), 1, StatsSampleRate)
}
return
}
示例2: timedHandler
func timedHandler(fn func(w http.ResponseWriter, r *http.Request), stats statsd.Statter) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
fn(w, r)
stats.TimingDuration("request", time.Since(start), 1)
}
}
示例3: EmitStopSignal
// Emit stop signals as `stop.$signal`
func EmitStopSignal(stats statsd.Statter, signal string) (err error) {
signal = CleanStatsdComponent(signal)
if stats != nil {
err = stats.Inc(StatsdEventName("stop", signal), 1, StatsSampleRate)
}
return
}
示例4: EmitActionSuccessTiming
// Emit successful actions as `$action.success.$event-name`
func EmitActionSuccessTiming(stats statsd.Statter, action, eventName string, took time.Duration) (err error) {
action = CleanStatsdComponent(action)
eventName = CleanStatsdComponent(eventName)
if stats != nil {
err = stats.TimingDuration(StatsdEventName(action, eventName), took, StatsSampleRate)
}
return
}
示例5: EmitActionSuccess
// Emit successful actions as `$action.success.$event-name`
func EmitActionSuccess(stats statsd.Statter, action, eventName string) (err error) {
action = CleanStatsdComponent(action)
eventName = CleanStatsdComponent(eventName)
if stats != nil {
err = stats.Inc(StatsdEventName("success", action, eventName), 1, StatsSampleRate)
}
return
}
示例6: send_gauge
func send_gauge(client statsd.Statter, v []string, name string, position int64) {
stat := fmt.Sprint(v[0], ".", name)
value, _ := strconv.ParseInt(v[position], 10, 64)
fmt.Println(fmt.Sprint(stat, ":", value, "|g"))
err := client.Gauge(stat, value, 1.0)
if err != nil {
log.Printf("Error sending metric: %+v", err)
}
}
示例7: send_counter
func send_counter(previous int64, client statsd.Statter, v []string, name string, position int64) {
stat := fmt.Sprint(v[0], ".", name)
value_at_interval, _ := strconv.ParseInt(v[position], 10, 64)
value := value_at_interval - previous
fmt.Println(fmt.Sprint(stat, ":", value, "|c"))
err := client.Inc(stat, value, 1)
if err != nil {
log.Printf("Error sending metric: %+v", err)
}
}
示例8: pushMem
func pushMem(client statsd.Statter, mem Mem) error {
var err error
err = client.Gauge("mem.resident", mem.Resident, 1.0)
if err != nil {
return err
}
err = client.Gauge("mem.virtual", mem.Virtual, 1.0)
if err != nil {
return err
}
err = client.Gauge("mem.mapped", mem.Mapped, 1.0)
if err != nil {
return err
}
err = client.Gauge("mem.mapped_with_journal", mem.MappedWithJournal, 1.0)
if err != nil {
return err
}
return nil
}
示例9: recordStats
func (r *requestContext) recordStats(statter statsd.Statter) {
prefix := strings.Join([]string{
r.Method,
strings.Replace(r.Endpoint, ".", "_", -1),
strconv.Itoa(r.Status),
}, ".")
for stat, duration := range r.Timers {
statter.Timing(prefix+"."+stat, duration.Nanoseconds(), 0.1)
}
if r.BadClient {
// We expect these to be infrequent. We may want to decreate this
// if it turns out not to be the case
statter.Inc("bad_client", 1, 1.0)
}
}
示例10: pushExtraInfo
func pushExtraInfo(client statsd.Statter, info ExtraInfo) error {
var err error
err = client.Gauge("extra.page_faults", info.PageFaults, 1.0)
if err != nil {
return err
}
err = client.Gauge("extra.heap_usage", info.HeapUsageInBytes, 1.0)
if err != nil {
return err
}
return nil
}
示例11: test
func test(target string, s statsd.Statter, debug bool) {
tuple := strings.Split(target, ":")
host := tuple[0]
port := tuple[1]
subhost := strings.Replace(host, ".", "_", -1)
pre := time.Now()
conn, err := net.Dial("tcp", target)
if err != nil {
if debug {
fmt.Println("connect error:", subhost, port)
}
s.Inc(fmt.Sprintf("%s.%s.dial_failed", subhost, port), 1, 1)
return
}
conn.Close()
duration := time.Since(pre)
ms := int64(duration / time.Millisecond)
if debug {
fmt.Printf("%s.%s.duration %d\n", subhost, port, ms)
}
s.Timing(fmt.Sprintf("%s.%s", subhost, port), ms, 1)
}
示例12: pushConnections
func pushConnections(client statsd.Statter, connections Connections) error {
var err error
// Connections
err = client.Gauge("connections.current", int64(connections.Current), 1.0)
if err != nil {
return err
}
err = client.Gauge("connections.available", int64(connections.Available), 1.0)
if err != nil {
return err
}
err = client.Gauge("connections.created", int64(connections.TotalCreated), 1.0)
if err != nil {
return err
}
return nil
}
示例13: EmitReload
// Emit reloads as `reload`
func EmitReload(stats statsd.Statter) (err error) {
if stats != nil {
err = stats.Inc(StatsdEventName("reload"), 1, StatsSampleRate)
}
return
}
示例14: NewAmqpRPCClient
// NewAmqpRPCClient constructs an RPC client using AMQP
func NewAmqpRPCClient(
clientQueuePrefix string,
amqpConf *cmd.AMQPConfig,
rpcConf *cmd.RPCServerConfig,
stats statsd.Statter,
) (rpc *AmqpRPCCLient, err error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
randID := make([]byte, 3)
_, err = rand.Read(randID)
if err != nil {
return nil, err
}
clientQueue := fmt.Sprintf("%s.%s.%x", clientQueuePrefix, hostname, randID)
reconnectBase := amqpConf.ReconnectTimeouts.Base.Duration
if reconnectBase == 0 {
reconnectBase = 20 * time.Millisecond
}
reconnectMax := amqpConf.ReconnectTimeouts.Max.Duration
if reconnectMax == 0 {
reconnectMax = time.Minute
}
timeout := rpcConf.RPCTimeout.Duration
if timeout == 0 {
timeout = 10 * time.Second
}
rpc = &AmqpRPCCLient{
serverQueue: rpcConf.Server,
clientQueue: clientQueue,
connection: newAMQPConnector(clientQueue, reconnectBase, reconnectMax),
pending: make(map[string]chan []byte),
timeout: timeout,
log: blog.Get(),
stats: stats,
}
err = rpc.connection.connect(amqpConf)
if err != nil {
return nil, err
}
go func() {
for {
select {
case msg, ok := <-rpc.connection.messages():
if ok {
corrID := msg.CorrelationId
rpc.mu.RLock()
responseChan, present := rpc.pending[corrID]
rpc.mu.RUnlock()
if !present {
// occurs when a request is timed out and the arrives
// afterwards
stats.Inc("RPC.AfterTimeoutResponseArrivals."+clientQueuePrefix, 1, 1.0)
continue
}
responseChan <- msg.Body
rpc.mu.Lock()
delete(rpc.pending, corrID)
rpc.mu.Unlock()
} else {
// chan has been closed by rpc.connection.Cancel
rpc.log.Info(fmt.Sprintf(" [!] Client reply channel closed: %s", rpc.clientQueue))
continue
}
case err = <-rpc.connection.closeChannel():
rpc.log.Info(fmt.Sprintf(" [!] Client reply channel closed : %s", rpc.clientQueue))
rpc.connection.reconnect(amqpConf, rpc.log)
}
}
}()
return rpc, err
}
示例15: sendGauges
func sendGauges(client statsd.Statter, gauges map[string]int64) {
for gauge, value := range gauges {
client.Gauge(gauge, value, 1.0)
}
}