code: func (g *Graphite) writer() {
  	var conn net.Conn
  	var err error
  	var wg sync.WaitGroup
  
  	assureConn := func() {
  		connected.Set(conn != nil)
  		for conn == nil {
  			time.Sleep(time.Second)
  			conn, err = net.Dial("tcp", g.addr)
  			if err == nil {
  				log.Infof("stats now connected to %s", g.addr)
  				wg.Add(1)
  				go g.checkEOF(conn, &wg)
  			} else {
  				log.Warnf("stats dialing %s failed: %s. will retry", g.addr, err.Error())
  			}
  			connected.Set(conn != nil)
  		}
  	}
  
  	for buf := range g.toGraphite {
  		queueItems.Value(len(g.toGraphite))
  		var ok bool
  		for !ok {
  			assureConn()
  			conn.SetWriteDeadline(time.Now().Add(g.timeout))
  			pre := time.Now()
  			_, err = conn.Write(buf)
  			if err == nil {
  				ok = true
  				flushDuration.Value(time.Since(pre))
  			} else {
  				log.Warnf("stats failed to write to graphite: %s (took %s). will retry...", err, time.Now().Sub(pre))
  				conn.Close()
  				wg.Wait()
  				conn = nil
  			}
  		}
  	}
  }
docs: // writer connects to graphite and submits all pending data to it