func newPool(server, password string, database int, isRedis bool, maxActive int, wait bool) *redis.Pool { return &redis.Pool{ MaxIdle: 50, MaxActive: maxActive, Wait: wait, IdleTimeout: 240 * time.Second, Dial: func() (redis.Conn, error) { c, err := redis.Dial("tcp", server, redis.DialDatabase(database)) if err != nil { return nil, err } if password != "" { if _, err := c.Do("AUTH", password); err != nil { c.Close() return nil, err } } if isRedis { if _, err := c.Do("CLIENT", "SETNAME", "bosun"); err != nil { c.Close() return nil, err } } return c, err }, } }
func newPool(server, password string, database int, isRedis bool) *redis.Pool { return &redis.Pool{ MaxIdle: 3, IdleTimeout: 240 * time.Second, Dial: func() (redis.Conn, error) { c, err := redis.Dial("tcp", server, redis.DialDatabase(database)) if err != nil { return nil, err } if password != "" { if _, err := c.Do("AUTH", password); err != nil { c.Close() return nil, err } } if isRedis { if _, err := c.Do("CLIENT", "SETNAME", "bosun"); err != nil { c.Close() return nil, err } } return c, err }, TestOnBorrow: func(c redis.Conn, t time.Time) error { defer collect.StartTimer("redis", opentsdb.TagSet{"op": "Ping"})() _, err := c.Do("PING") return err }, } }
func c_redis_counters(server string, db int) (opentsdb.MultiDataPoint, error) { var md opentsdb.MultiDataPoint conn, err := redis.Dial("tcp", server, redis.DialDatabase(db)) if err != nil { return md, err } defer conn.Close() if _, err := conn.Do("CLIENT", "SETNAME", "scollector"); err != nil { return md, err } cursor := 0 for { vals, err := redis.Values(conn.Do("HSCAN", collect.RedisCountersKey, cursor)) if err != nil { return md, err } if len(vals) != 2 { return md, fmt.Errorf("Unexpected number of values") } cursor, err = redis.Int(vals[0], nil) if err != nil { return md, err } pairs, err := redis.StringMap(vals[1], nil) if err != nil { return md, err } for mts, val := range pairs { parts := strings.Split(mts, ":") if len(parts) != 2 { slog.Errorf("Invalid metric tag set counter: %s", mts) continue } metric := parts[0] tags, err := opentsdb.ParseTags(parts[1]) if err != nil { slog.Errorf("Invalid tags: %s", parts[1]) continue } v, err := strconv.Atoi(val) if err != nil { slog.Errorf("Invalid counter value: %s", val) continue } Add(&md, metric, v, tags, metadata.Counter, metadata.Count, "") } if cursor == 0 { break } } return md, nil }
func newRedisPool(server string, database int) *redis.Pool { return &redis.Pool{ MaxIdle: 10, MaxActive: 10, Wait: true, IdleTimeout: 240 * time.Second, Dial: func() (redis.Conn, error) { c, err := redis.Dial("tcp", server, redis.DialDatabase(database)) if err != nil { return nil, err } if _, err := c.Do("CLIENT", "SETNAME", metricRoot+"_counters"); err != nil { c.Close() return nil, err } return c, err }, } }