Exemple #1
0
// parseKeyspaceStats resolves the overloaded value string that Redis returns for keyspace
func parseKeyspaceStats(keyspaceMap map[string]string) map[string]common.MapStr {
	keyspace := map[string]common.MapStr{}
	for k, v := range keyspaceMap {

		// Extract out the overloaded values for db keyspace
		// fmt: info[db0] = keys=795341,expires=0,avg_ttl=0
		dbInfo := redis.ParseRedisLine(v, ",")

		if len(dbInfo) == 3 {
			db := map[string]string{}
			for _, dbEntry := range dbInfo {
				stats := redis.ParseRedisLine(dbEntry, "=")

				if len(stats) == 2 {
					db[stats[0]] = stats[1]
				}
			}
			keyspace[k] = common.MapStr{
				"keys":    h.ToInt("keys", db),
				"expires": h.ToInt("expires", db),
				"avg_ttl": h.ToInt("avg_ttl", db),
			}
		}
	}
	return keyspace
}
Exemple #2
0
// Map body to MapStr
func eventMapping(body io.ReadCloser, hostname string) common.MapStr {
	var (
		totalS          int
		totalR          int
		totalW          int
		totalK          int
		totalD          int
		totalC          int
		totalL          int
		totalG          int
		totalI          int
		totalDot        int
		totalUnderscore int
		totalAll        int
	)

	fullEvent := map[string]string{}
	scanner := bufio.NewScanner(body)

	// Iterate through all events to gather data
	for scanner.Scan() {
		if match := matchNumber.FindStringSubmatch(scanner.Text()); len(match) == 3 {
			// Total Accesses: 16147
			//Total kBytes: 12988
			// Uptime: 3229728
			// CPULoad: .000408393
			// CPUUser: 0
			// CPUSystem: .01
			// CPUChildrenUser: 0
			// CPUChildrenSystem: 0
			// ReqPerSec: .00499949
			// BytesPerSec: 4.1179
			// BytesPerReq: 823.665
			// BusyWorkers: 1
			// IdleWorkers: 8
			// ConnsTotal: 4940
			// ConnsAsyncWriting: 527
			// ConnsAsyncKeepAlive: 1321
			// ConnsAsyncClosing: 2785
			// ServerUptimeSeconds: 43
			//Load1: 0.01
			//Load5: 0.10
			//Load15: 0.06
			fullEvent[match[1]] = match[2]

		} else if match := scoreboardRegexp.FindStringSubmatch(scanner.Text()); len(match) == 4 {
			// Scoreboard Key:
			// "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
			// "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
			// "C" Closing connection, "L" Logging, "G" Gracefully finishing,
			// "I" Idle cleanup of worker, "." Open slot with no current process
			// Scoreboard: _W____........___...............................................................................................................................................................................................................................................

			totalUnderscore = strings.Count(match[2], "_")
			totalS = strings.Count(match[2], "S")
			totalR = strings.Count(match[2], "R")
			totalW = strings.Count(match[2], "W")
			totalK = strings.Count(match[2], "K")
			totalD = strings.Count(match[2], "D")
			totalC = strings.Count(match[2], "C")
			totalL = strings.Count(match[2], "L")
			totalG = strings.Count(match[2], "G")
			totalI = strings.Count(match[2], "I")
			totalDot = strings.Count(match[2], ".")
			totalAll = totalUnderscore + totalS + totalR + totalW + totalK + totalD + totalC + totalL + totalG + totalI + totalDot
		} else {
			debugf("Unexpected line in apache server-status output: %s", scanner.Text())
		}
	}

	event := common.MapStr{
		"hostname":          hostname,
		"total_accesses":    h.ToInt("Total Accesses", fullEvent),
		"total_kbytes":      h.ToInt("Total kBytes", fullEvent),
		"requests_per_sec":  h.ToFloat("ReqPerSec", fullEvent),
		"bytes_per_sec":     h.ToFloat("BytesPerSec", fullEvent),
		"bytes_per_request": h.ToFloat("BytesPerReq", fullEvent),
		"workers": common.MapStr{
			"busy": h.ToInt("BusyWorkers", fullEvent),
			"idle": h.ToInt("IdleWorkers", fullEvent),
		},
		"uptime": common.MapStr{
			"server_uptime": h.ToInt("ServerUptimeSeconds", fullEvent),
			"uptime":        h.ToInt("Uptime", fullEvent),
		},
		"cpu": common.MapStr{
			"load":            h.ToFloat("CPULoad", fullEvent),
			"user":            h.ToFloat("CPUUser", fullEvent),
			"system":          h.ToFloat("CPUSystem", fullEvent),
			"children_user":   h.ToFloat("CPUChildrenUser", fullEvent),
			"children_system": h.ToFloat("CPUChildrenSystem", fullEvent),
		},
		"connections": common.MapStr{
			"total": h.ToInt("ConnsTotal", fullEvent),
			"async": common.MapStr{
				"writing":    h.ToInt("ConnsAsyncWriting", fullEvent),
				"keep_alive": h.ToInt("ConnsAsyncKeepAlive", fullEvent),
				"closing":    h.ToInt("ConnsAsyncClosing", fullEvent),
			},
		},
		"load": common.MapStr{
			"1":  h.ToFloat("Load1", fullEvent),
			"5":  h.ToFloat("Load5", fullEvent),
			"15": h.ToFloat("Load15", fullEvent),
		},
		"scoreboard": common.MapStr{
			"starting_up":            totalS,
			"reading_request":        totalR,
			"sending_reply":          totalW,
			"keepalive":              totalK,
			"dns_lookup":             totalD,
			"closing_connection":     totalC,
			"logging":                totalL,
			"gracefully_finishing":   totalG,
			"idle_cleanup":           totalI,
			"open_slot":              totalDot,
			"waiting_for_connection": totalUnderscore,
			"total":                  totalAll,
		},
	}

	return event
}
Exemple #3
0
// Map data to MapStr of server stats variables: http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html
// This is only a subset of the available values
func eventMapping(status map[string]string) common.MapStr {

	event := common.MapStr{
		"aborted": common.MapStr{
			"clients":  h.ToInt("Aborted_clients", status),
			"connects": h.ToInt("Aborted_connects", status),
		},
		"binlog": common.MapStr{
			"cache": common.MapStr{
				"disk_use": h.ToInt("Binlog_cache_disk_use", status),
				"use":      h.ToInt("Binlog_cache_use", status),
			},
		},
		"bytes": common.MapStr{
			"received": h.ToInt("Bytes_received", status),
			"sent":     h.ToInt("Bytes_sent", status),
		},
		"connections": h.ToInt("Connections", status),
		"created": common.MapStr{
			"tmp": common.MapStr{
				"disk_tables": h.ToInt("Created_tmp_disk_tables", status),
				"files":       h.ToInt("Created_tmp_files", status),
				"tables":      h.ToInt("Created_tmp_tables", status),
			},
		},
		"delayed": common.MapStr{
			"errors":         h.ToInt("Delayed_errors", status),
			"insert_threads": h.ToInt("Delayed_insert_threads", status),
			"writes":         h.ToInt("Delayed_writes", status),
		},
		"flush_commands":       h.ToInt("Flush_commands", status),
		"max_used_connections": h.ToInt("Max_used_connections", status),
		"open": common.MapStr{
			"files":   h.ToInt("Open_files", status),
			"streams": h.ToInt("Open_streams", status),
			"tables":  h.ToInt("Open_tables", status),
		},
		"opened_tables": h.ToInt("Opened_tables", status),
	}

	return event
}
Exemple #4
0
func eventMapping(response io.Reader) common.MapStr {
	fullEvent := map[string]string{}
	scanner := bufio.NewScanner(response)

	// Iterate through all events to gather data
	for scanner.Scan() {
		if match := paramMatcher.FindStringSubmatch(scanner.Text()); len(match) == 3 {
			fullEvent[match[1]] = match[2]
		} else {
			logp.Warn("Unexpected line in mntr output: %s", scanner.Text())
		}
	}

	// Manually convert and select fields which are used
	event := common.MapStr{
		"version": h.ToStr("zk_version", fullEvent),
		"latency": common.MapStr{
			"avg": h.ToInt("zk_avg_latency", fullEvent),
			"min": h.ToInt("zk_min_latency", fullEvent),
			"max": h.ToInt("zk_max_latency", fullEvent),
		},
		"packets": common.MapStr{
			"received": h.ToInt("zk_packets_received", fullEvent),
			"sent":     h.ToInt("zk_packets_sent", fullEvent),
		},
		"num_alive_connections": h.ToInt("zk_num_alive_connections", fullEvent),
		"outstanding_requests":  h.ToInt("zk_outstanding_requests", fullEvent),
		"server_state":          h.ToStr("zk_server_state", fullEvent),
		"znode_count":           h.ToInt("zk_znode_count", fullEvent),
		"watch_count":           h.ToInt("zk_watch_count", fullEvent),
		"ephemerals_count":      h.ToInt("zk_ephemerals_count", fullEvent),
		"approximate_data_size": h.ToInt("zk_approximate_data_size", fullEvent),
	}

	// only exposed by the Leader
	if _, ok := fullEvent["zk_followers"]; ok {
		event["followers"] = h.ToInt("zk_followers", fullEvent)
		event["synced_followers"] = h.ToInt("zk_synced_followers", fullEvent)
		event["pending_syncs"] = h.ToInt("zk_pending_syncs", fullEvent)
	}

	// only available on Unix platforms
	if _, ok := fullEvent["open_file_descriptor_count"]; ok {
		event["open_file_descriptor_count"] = h.ToInt("zk_open_file_descriptor_count", fullEvent)
		event["max_file_descriptor_count"] = h.ToInt("zk_max_file_descriptor_count", fullEvent)
	}

	return event
}
Exemple #5
0
// Map data to MapStr
func eventMapping(info map[string]string) common.MapStr {

	// Full mapping from info
	event := common.MapStr{
		"clients": common.MapStr{
			"connected":           h.ToInt("connected_clients", info),
			"longest_output_list": h.ToInt("client_longest_output_list", info),
			"biggest_input_buf":   h.ToInt("client_biggest_input_buf", info),
			"blocked":             h.ToInt("blocked_clients", info),
		},
		"cluster": common.MapStr{
			"enabled": h.ToBool("cluster_enabled", info),
		},
		"cpu": common.MapStr{
			"used": common.MapStr{
				"sys":           h.ToFloat("used_cpu_sys", info),
				"user":          h.ToFloat("used_cpu_user", info),
				"sys_children":  h.ToFloat("used_cpu_sys_children", info),
				"user_children": h.ToFloat("used_cpu_user_children", info),
			},
		},
		"memory": common.MapStr{
			"used": common.MapStr{
				"value": h.ToInt("used_memory", info), // As it is a top key, this goes into value
				"rss":   h.ToInt("used_memory_rss", info),
				"peak":  h.ToInt("used_memory_peak", info),
				"lua":   h.ToInt("used_memory_lua", info),
			},
			"allocator": h.ToStr("mem_allocator", info), // Could be moved to server as it rarely changes
		},
		"persistence": common.MapStr{
			"loading": h.ToBool("loading", info),
			"rdb": common.MapStr{
				"changes_since_last_save": h.ToInt("rdb_changes_since_last_save", info),
				"bgsave_in_progress":      h.ToBool("rdb_bgsave_in_progress", info),
				"last_save_time":          h.ToInt("rdb_last_save_time", info),
				"last_bgsave_status":      h.ToStr("rdb_last_bgsave_status", info),
				"last_bgsave_time_sec":    h.ToInt("rdb_last_bgsave_time_sec", info),
				"current_bgsave_time_sec": h.ToInt("rdb_current_bgsave_time_sec", info),
			},
			"used": common.MapStr{
				"enabled":                  h.ToBool("aof_enabled", info),
				"rewrite_in_progress":      h.ToBool("aof_rewrite_in_progress", info),
				"rewrite_scheduled":        h.ToBool("aof_rewrite_scheduled", info),
				"last_rewrite_time_sec":    h.ToInt("aof_last_rewrite_time_sec", info),
				"current_rewrite_time_sec": h.ToInt("aof_current_rewrite_time_sec", info),
				"last_bgrewrite_status":    h.ToStr("aof_last_bgrewrite_status", info),
				"last_write_status":        h.ToStr("aof_last_write_status", info),
			},
		},
		"replication": common.MapStr{
			"role":             h.ToStr("role", info),
			"connected_slaves": h.ToInt("connected_slaves", info),
			"master_offset":    h.ToInt("master_repl_offset", info),
			"backlog": common.MapStr{
				"active":            h.ToInt("repl_backlog_active", info),
				"size":              h.ToInt("repl_backlog_size", info),
				"first_byte_offset": h.ToInt("repl_backlog_first_byte_offset", info),
				"histlen":           h.ToInt("repl_backlog_histlen", info),
			},
		},
		"server": common.MapStr{
			"version":          h.ToStr("redis_version", info),
			"git_sha1":         h.ToStr("redis_git_sha1", info),
			"git_dirty":        h.ToStr("redis_git_dirty", info),
			"build_id":         h.ToStr("redis_build_id", info),
			"mode":             h.ToStr("redis_mode", info),
			"os":               h.ToStr("os", info),
			"arch_bits":        h.ToStr("arch_bits", info),
			"multiplexing_api": h.ToStr("multiplexing_api", info),
			"gcc_version":      h.ToStr("gcc_version", info),
			"process_id":       h.ToInt("process_id", info),
			"run_id":           h.ToStr("run_id", info),
			"tcp_port":         h.ToInt("tcp_port", info),
			"uptime":           h.ToInt("uptime_in_seconds", info), // Uptime days was removed as duplicate
			"hz":               h.ToInt("hz", info),
			"lru_clock":        h.ToInt("lru_clock", info),
			"config_file":      h.ToStr("config_file", info),
		},
		"stats": common.MapStr{
			"connections": common.MapStr{
				"received": h.ToInt("total_connections_received", info),
				"rejected": h.ToInt("rejected_connections", info),
			},
			"total_commands_processed":  h.ToInt("total_commands_processed", info),
			"total_net_input_bytes":     h.ToInt("total_net_input_bytes", info),
			"total_net_output_bytes":    h.ToInt("total_net_output_bytes", info),
			"instantaneous_ops_per_sec": h.ToInt("instantaneous_ops_per_sec", info),
			"instantaneous_input_kbps":  h.ToFloat("instantaneous_input_kbps", info),
			"instantaneous_output_kbps": h.ToFloat("instantaneous_output_kbps", info),
			"sync": common.MapStr{
				"full":        h.ToInt("sync_full", info),
				"partial_ok":  h.ToInt("sync_partial_ok", info),
				"partial_err": h.ToInt("sync_partial_err", info),
			},
			"keys": common.MapStr{
				"expired": h.ToInt("expired_keys", info),
				"evicted": h.ToInt("evicted_keys", info),
			},
			"keyspace": common.MapStr{
				"hits":   h.ToInt("keyspace_hits", info),
				"misses": h.ToInt("keyspace_misses", info),
			},
			"pubsub_channels":        h.ToInt("pubsub_channels", info),
			"pubsub_patterns":        h.ToInt("pubsub_patterns", info),
			"latest_fork_usec":       h.ToInt("latest_fork_usec", info),
			"migrate_cached_sockets": h.ToInt("migrate_cached_sockets", info),
		},
	}

	return event
}