func handleTCPRequest(conn net.Conn, errorChannel chan error, closeOnError bool) { defer conn.Close() remoteAddress := conn.RemoteAddr().String() errorChannel <- gotelemetry.NewDebugError("Graphite => New connection from %s", remoteAddress) r := bufio.NewScanner(conn) for r.Scan() { if err := parseRequest(remoteAddress, r.Text(), errorChannel); err != nil { errorChannel <- err if closeOnError { return } } } if err := r.Err(); err != nil && err != io.EOF { errorChannel <- err } errorChannel <- gotelemetry.NewDebugError("Graphite => Connection from %s terminated.", remoteAddress) }
// Debugf sends a formatted string to the agent's debug log, if it exists. It works like log.Logf func (m *Manager) Debugf(format string, v ...interface{}) { if m.errorChannel != nil { m.errorChannel <- gotelemetry.NewDebugError("Data Manager -> %#s", fmt.Sprintf(format, v...)) } }
func ProcessPipeRequest(configFile *config.ConfigFile, errorChannel chan error, completionChannel chan bool, data []byte) { errorChannel <- gotelemetry.NewLogError("Piped mode is on.") errorChannel <- gotelemetry.NewDebugError("Input data is %s", strings.Replace(string(data), "\n", "\\n", -1)) submissionType := gotelemetry.BatchTypePATCH if config.CLIConfig.UseJSONPatch { errorChannel <- gotelemetry.NewDebugError("Will perform a JSON-Patch operation") submissionType = gotelemetry.BatchTypeJSONPATCH } else if config.CLIConfig.UsePOST { errorChannel <- gotelemetry.NewDebugError("Will perform a POST operation") submissionType = gotelemetry.BatchTypePOST } else { errorChannel <- gotelemetry.NewDebugError("Will perform a Rails-style HTTP PATCH operation") } apiToken, err := configFile.APIToken() if err != nil { errorChannel <- err completionChannel <- true return } credentials, err := gotelemetry.NewCredentials(apiToken, configFile.APIURL()) if err != nil { errorChannel <- err completionChannel <- true return } credentials.SetDebugChannel(errorChannel) updates := map[string]interface{}{} err = json.Unmarshal(data, &updates) if err != nil { errorChannel <- err completionChannel <- true return } b := gotelemetry.Batch{} for tag, update := range updates { b.SetData(tag, update) } err = b.Publish(credentials, configFile.ChannelTag(), submissionType) if err != nil { errorChannel <- err } errorChannel <- gotelemetry.NewLogError("Processing complete. Exiting.") completionChannel <- true }
func parseTraditionalRequest(remoteAddress string, line []string, errorChannel chan error) error { seriesName := line[0] value, err := strconv.ParseFloat(line[1], 64) if err != nil { return gotelemetry.NewErrorWithFormat( 400, "Graphite => [%s] Invalid value %s: %s", nil, remoteAddress, line[1], err.Error(), ) } timestamp, err := strconv.ParseInt(line[2], 10, 64) if err != nil { return gotelemetry.NewErrorWithFormat( 400, "Graphite => [%s] Invalid timestamp %s: %s", nil, remoteAddress, line[2], err.Error(), ) } series, isCreated, err := aggregations.GetSeries(seriesName) if err != nil { return gotelemetry.NewErrorWithFormat( 500, "Graphite => [%s] Unable to get series %s: %s", nil, remoteAddress, seriesName, err.Error(), ) } if isCreated { errorChannel <- gotelemetry.NewLogError("Graphite => Started receiving graphite data for '%s'", seriesName) } ts := time.Unix(timestamp, 0) if err := series.Push(&ts, value); err != nil { return gotelemetry.NewErrorWithFormat( 500, "Graphite => [%s] Unable to push value %f with timestamp %s to series %s: %s", nil, remoteAddress, value, ts, seriesName, err.Error(), ) } errorChannel <- gotelemetry.NewDebugError( "Graphite => [%s] Pushed value %f to series %s at time %s", remoteAddress, value, seriesName, ts, ) return nil }
// Debugf sends a formatted string to the agent's debug log, if it exists. It works like log.Logf func (j *Job) Debugf(format string, v ...interface{}) { if j.errorChannel != nil { j.errorChannel <- gotelemetry.NewDebugError("%s -> %#s", j.ID, fmt.Sprintf(format, v...)) } }