1 // Package splunk sends log data to a splunk server.
11 // DialTimeout limits how long a write will block
12 // while dialing the splunk server. Assuming the
13 // connection stays open for a long time, this will
14 // happen only rarely.
15 DialTimeout = 50 * time.Millisecond
17 // WriteTimeout limits how long a write will block
18 // sending data on the network. It is deliberately
19 // very small, so that writes can only be satisfied
20 // by the local network buffers. It should never
21 // block waiting for a TCP ACK for an appreciable
23 WriteTimeout = 100 * time.Microsecond
30 err error // last write error
33 // New creates a new writer that sends data
34 // to the given TCP address.
35 // It connects on the first call to Write,
36 // and attempts to reconnect when necessary,
37 // with a timeout of DialTimeout.
39 // Every write has a timeout of WriteTimeout.
40 // If the write doesn't complete in that time,
41 // the writer drops the unwritten data.
42 // For every contiguous run of dropped data,
43 // it writes dropmsg before resuming ordinary writes.
44 // As long as the remote endpoint can keep up
45 // with the averate data rate and the local
46 // network buffers in the kernel and NIC are
47 // big enough to hold traffic bursts, no data
49 func New(addr string, dropmsg []byte) io.Writer {
56 func (s *splunk) Write(p []byte) (n int, err error) {
58 s.conn, err = net.DialTimeout("tcp", s.addr, DialTimeout)
65 s.conn.SetDeadline(time.Now().Add(WriteTimeout))
66 _, s.err = s.conn.Write(s.dropmsg)
69 s.conn.SetDeadline(time.Now().Add(WriteTimeout))
70 n, s.err = s.conn.Write(p)
73 if t, ok := s.err.(net.Error); s.err != nil && (!ok || !t.Temporary()) {