func processGroups(groups []string, topic string, pids map[int32]int64) []common.MapStr { var events []common.MapStr for _, group := range groups { pid_offsets, err := getConsumerOffsets(group, topic, pids) if err == nil { for pid, offset := range pid_offsets { event := common.MapStr{ "@timestamp": common.Time(time.Now()), "type": "consumer", "partition": pid, "topic": topic, "group": group, "offset": offset, } size, ok := pids[pid] if ok { event.Update(common.MapStr{"lag": size - offset}) } events = append(events, event) } } else { logp.Debug("kafkabeat", "No offsets for group %s on topic %s", group, topic) } } return events }
func newTCPMonitorHostJob( scheme, host string, port uint16, tls *transport.TLSConfig, config *Config, ) (monitors.Job, error) { typ := config.Name timeout := config.Timeout jobName := jobName(typ, jobType(scheme), host, []uint16{port}) validator := makeValidateConn(config) pingAddr := net.JoinHostPort(host, strconv.Itoa(int(port))) taskDialer, err := buildDialerChain(scheme, tls, config) if err != nil { return nil, err } return monitors.MakeSimpleJob(jobName, typ, func() (common.MapStr, error) { event := common.MapStr{ "scheme": scheme, "port": port, "host": host, } dialer, err := taskDialer.BuildWithMeasures(event) if err != nil { return event, err } results, err := pingHost(dialer, pingAddr, timeout, validator) event.Update(results) return event, err }), nil }
func getArray(fields common.MapStr, data []byte, offset uint32) (next uint32, err bool, exists bool) { ret := common.MapStr{} length := binary.BigEndian.Uint32(data[offset : offset+4]) // size declared too big if length > uint32(len(data[offset+4:])) { return 0, true, false } if length > 0 { exists = true err := fieldUnmarshal(ret, data[offset+4:offset+4+length], 0, length, 0) if err { logp.Warn("Error while parsing a field array") return 0, true, false } if fields == nil { fields = ret } else { fields.Update(ret) } } return length + 4 + offset, false, exists }
func createPingFactory( makeDialerChain func(string) *dialchain.DialerChain, addr connURL, timeout time.Duration, validator ConnCheck, ) func(*net.IPAddr) monitors.TaskRunner { fields := common.MapStr{"scheme": addr.Scheme} return monitors.MakePingAllIPPortFactory(fields, addr.Ports, func(ip *net.IPAddr, port uint16) (common.MapStr, error) { host := net.JoinHostPort(ip.String(), strconv.Itoa(int(port))) pingAddr := net.JoinHostPort(addr.Host, strconv.Itoa(int(port))) event := common.MapStr{} dialer, err := makeDialerChain(host).BuildWithMeasures(event) if err != nil { return event, err } results, err := pingHost(dialer, pingAddr, timeout, validator) event.Update(results) return event, err }) }