Skip to content

Commit

Permalink
Merge pull request #1202 from radoondas/radoondas-var-refractoring
Browse files Browse the repository at this point in the history
Rename variables and output fields
  • Loading branch information
ruflin committed Mar 22, 2016
2 parents e9160f8 + ea9a13b commit 5827b44
Showing 1 changed file with 96 additions and 96 deletions.
192 changes: 96 additions & 96 deletions metricbeat/module/apache/status/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@ import (
func eventMapping(body io.ReadCloser, hostname string, metricset string) common.MapStr {

var (
totalAccess int
totalKB int
uptime int
cpu_load float64
cpu_user float64
cpu_system float64
cpu_children_user float64
cpu_children_system float64
req_per_sec float64
bytes_per_sec float64
bytes_per_req float64
busy_workers int
idle_workers int
conns_total int
conns_async_writing int
conns_async_keep_alive int
conns_async_closing int
server_uptime_seconds int
load1 float64
load5 float64
load15 float64
tot_s int
tot_r int
tot_w int
tot_k int
tot_d int
tot_c int
tot_l int
tot_g int
tot_i int
tot_dot int
tot_underscore int
tot_total int
totalAccesses int
totalKBytes int
uptime int
cpuLoad float64
cpuUser float64
cpuSystem float64
cpuChildrenUser float64
cpuChildrenSystem float64
reqPerSec float64
bytesPerSec float64
bytesPerReq float64
busyWorkers int
idleWorkers int
connsTotal int
connsAsyncWriting int
connsAsyncKeepAlive int
connsAsyncClosing int
serverUptimeSeconds int
load1 float64
load5 float64
load15 float64
totalS int
totalR int
totalW int
totalK int
totalD int
totalC int
totalL int
totalG int
totalI int
totalDot int
totalUnderscore int
totalAll int
)

var re *regexp.Regexp
Expand All @@ -62,13 +62,13 @@ func eventMapping(body io.ReadCloser, hostname string, metricset string) common.
// Total Accesses: 16147
re = regexp.MustCompile("Total Accesses: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
totalAccess, _ = strconv.Atoi(matches[1])
totalAccesses, _ = strconv.Atoi(matches[1])
}

//Total kBytes: 12988
re = regexp.MustCompile("Total kBytes: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
totalKB, _ = strconv.Atoi(matches[1])
totalKBytes, _ = strconv.Atoi(matches[1])
}

// Uptime: 3229728
Expand All @@ -80,91 +80,91 @@ func eventMapping(body io.ReadCloser, hostname string, metricset string) common.
// CPULoad: .000408393
re = regexp.MustCompile("CPULoad: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
cpu_load = ParseMatchFloat(matches[1], hostname, "cpu_load")
cpuLoad = ParseMatchFloat(matches[1], hostname, "cpuLoad")
}

// CPUUser: 0
re = regexp.MustCompile("CPUUser: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
cpu_user = ParseMatchFloat(matches[1], hostname, "cpu_user")
cpuUser = ParseMatchFloat(matches[1], hostname, "cpuUser")
}

// CPUSystem: .01
re = regexp.MustCompile("CPUSystem: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
cpu_system = ParseMatchFloat(matches[1], hostname, "cpu_system")
cpuSystem = ParseMatchFloat(matches[1], hostname, "cpuSystem")
}

// CPUChildrenUser: 0
re = regexp.MustCompile("CPUChildrenUser: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
cpu_children_user = ParseMatchFloat(matches[1], hostname, "cpu_children_user")
cpuChildrenUser = ParseMatchFloat(matches[1], hostname, "cpuChildrenUser")
}

// CPUChildrenSystem: 0
re = regexp.MustCompile("CPUChildrenSystem: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
cpu_children_system = ParseMatchFloat(matches[1], hostname, "cpu_children_system")
cpuChildrenSystem = ParseMatchFloat(matches[1], hostname, "cpuChildrenSystem")
}

// ReqPerSec: .00499949
re = regexp.MustCompile("ReqPerSec: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
req_per_sec = ParseMatchFloat(matches[1], hostname, "req_per_sec")
reqPerSec = ParseMatchFloat(matches[1], hostname, "reqPerSec")
}

// BytesPerSec: 4.1179
re = regexp.MustCompile("BytesPerSec: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
bytes_per_sec = ParseMatchFloat(matches[1], hostname, "bytes_per_sec")
bytesPerSec = ParseMatchFloat(matches[1], hostname, "bytesPerSec")
}

// BytesPerReq: 823.665
re = regexp.MustCompile("BytesPerReq: (\\d*.*\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
bytes_per_req = ParseMatchFloat(matches[1], hostname, "bytes_per_req")
bytesPerReq = ParseMatchFloat(matches[1], hostname, "bytesPerReq")
}

// BusyWorkers: 1
re = regexp.MustCompile("BusyWorkers: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
busy_workers, _ = strconv.Atoi(matches[1])
busyWorkers, _ = strconv.Atoi(matches[1])
}

// IdleWorkers: 8
re = regexp.MustCompile("IdleWorkers: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
idle_workers, _ = strconv.Atoi(matches[1])
idleWorkers, _ = strconv.Atoi(matches[1])
}

// ConnsTotal: 4940
re = regexp.MustCompile("ConnsTotal: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
conns_total, _ = strconv.Atoi(matches[1])
connsTotal, _ = strconv.Atoi(matches[1])
}

// ConnsAsyncWriting: 527
re = regexp.MustCompile("ConnsAsyncWriting: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
conns_async_writing, _ = strconv.Atoi(matches[1])
connsAsyncWriting, _ = strconv.Atoi(matches[1])
}

// ConnsAsyncKeepAlive: 1321
re = regexp.MustCompile("ConnsAsyncKeepAlive: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
conns_async_keep_alive, _ = strconv.Atoi(matches[1])
connsAsyncKeepAlive, _ = strconv.Atoi(matches[1])
}

// ConnsAsyncClosing: 2785
re = regexp.MustCompile("ConnsAsyncClosing: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
conns_async_closing, _ = strconv.Atoi(matches[1])
connsAsyncClosing, _ = strconv.Atoi(matches[1])
}

// ServerUptimeSeconds: 43
re = regexp.MustCompile("ServerUptimeSeconds: (\\d+)")
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
server_uptime_seconds, _ = strconv.Atoi(matches[1])
serverUptimeSeconds, _ = strconv.Atoi(matches[1])
}

//Load1: 0.01
Expand Down Expand Up @@ -195,56 +195,56 @@ func eventMapping(body io.ReadCloser, hostname string, metricset string) common.
if matches := re.FindStringSubmatch(scanner.Text()); matches != nil {
scr := strings.Split(scanner.Text(), " ")

tot_underscore = strings.Count(scr[1], "_")
tot_s = strings.Count(scr[1], "S")
tot_r = strings.Count(scr[1], "R")
tot_w = strings.Count(scr[1], "W")
tot_k = strings.Count(scr[1], "K")
tot_d = strings.Count(scr[1], "D")
tot_c = strings.Count(scr[1], "C")
tot_l = strings.Count(scr[1], "L")
tot_g = strings.Count(scr[1], "G")
tot_i = strings.Count(scr[1], "I")
tot_dot = strings.Count(scr[1], ".")
tot_total = tot_underscore + tot_s + tot_r + tot_w + tot_k + tot_d + tot_c + tot_l + tot_g + tot_i + tot_dot
totalUnderscore = strings.Count(scr[1], "_")
totalS = strings.Count(scr[1], "S")
totalR = strings.Count(scr[1], "R")
totalW = strings.Count(scr[1], "W")
totalK = strings.Count(scr[1], "K")
totalD = strings.Count(scr[1], "D")
totalC = strings.Count(scr[1], "C")
totalL = strings.Count(scr[1], "L")
totalG = strings.Count(scr[1], "G")
totalI = strings.Count(scr[1], "I")
totalDot = strings.Count(scr[1], ".")
totalAll = totalUnderscore + totalS + totalR + totalW + totalK + totalD + totalC + totalL + totalG + totalI + totalDot
}
}

event := common.MapStr{
"total_access": totalAccess,
"total_kb": totalKB,
"uptime": uptime,
"cpu_load": cpu_load,
"cpu_user": cpu_user,
"cpu_system": cpu_system,
"cpu_children_user": cpu_children_user,
"cpu_children_system": cpu_children_system,
"req_per_sec": req_per_sec,
"bytes_per_sec": bytes_per_sec,
"bytes_per_req": bytes_per_req,
"busy_workers": busy_workers,
"idle_workers": idle_workers,
"conns_total": conns_total,
"conns_async_writing": conns_async_writing,
"conns_async_keep_alive": conns_async_keep_alive,
"conns_async_closing": conns_async_closing,
"server_uptime_seconds": server_uptime_seconds,
"load1": load1,
"load5": load5,
"load15": load15,
"scb_starting_up": tot_s,
"scb_reading_request": tot_r,
"scb_sending_reply": tot_w,
"scb_keepalive": tot_k,
"scb_dns_lookup": tot_d,
"scb_closing_connection": tot_c,
"scb_logging": tot_l,
"scb_gracefully_finishing": tot_g,
"scb_idle_cleanup": tot_i,
"scb_open_slot": tot_dot,
"scb_waiting_for_connection": tot_underscore,
"scb_total": tot_total,
"hostname": hostname,
"totalAccesses": totalAccesses,
"totalKBytes": totalKBytes,
"uptime": uptime,
"cpuLoad": cpuLoad,
"cpuUser": cpuUser,
"cpuSystem": cpuSystem,
"cpuChildrenUser": cpuChildrenUser,
"cpuChildrenSystem": cpuChildrenSystem,
"reqPerSec": reqPerSec,
"bytesPerSec": bytesPerSec,
"bytesPerReq": bytesPerReq,
"busyWorkers": busyWorkers,
"idleWorkers": idleWorkers,
"connsTotal": connsTotal,
"connsAsyncWriting": connsAsyncWriting,
"connsAsyncKeepAlive": connsAsyncKeepAlive,
"connsAsyncClosing": connsAsyncClosing,
"serverUptimeSeconds": serverUptimeSeconds,
"load1": load1,
"load5": load5,
"load15": load15,
"scbStartingUp": totalS,
"scbReadingRequest": totalR,
"scbSendingReply": totalW,
"scbKeepalive": totalK,
"scbDnsLookup": totalD,
"scbClosingConnection": totalC,
"scbLogging": totalL,
"scbGracefullyFinishing": totalG,
"scbIdleCleanup": totalI,
"scbOpenSlot": totalDot,
"scbWaitingForConnection": totalUnderscore,
"scbTotal": totalAll,
"hostname": hostname,
}

return event
Expand Down

0 comments on commit 5827b44

Please sign in to comment.