Example #1
0
// Collect periodically call smem periodically
func (s *SmemStats) Collect() {
	if s.whitelistedProcs == "" || s.user == "" || s.smemPath == "" {
		return
	}

	for _, stat := range getSmemStats(s) {
		for _, element := range s.whitelistedMetrics {
			switch element {
			case "pss":
				s.Channel() <- metric.WithValue(stat.proc+".smem.pss", stat.pss)
			case "vss":
				s.Channel() <- metric.WithValue(stat.proc+".smem.vss", stat.vss)
			case "rss":
				s.Channel() <- metric.WithValue(stat.proc+".smem.rss", stat.rss)
			}
		}
	}
}
Example #2
0
func buildApacheMetric(key, value string) (metric.Metric, error) {
	var tmpMetric metric.Metric
	if _, ok := knownApacheMetrics[key]; ok {
		whiteRegexp := regexp.MustCompile(`\s+`)
		metricName := whiteRegexp.ReplaceAllString(key, "")
		metricValue, err := strconv.ParseFloat(value, 64)

		if err != nil {
			return tmpMetric, err
		}
		return metric.WithValue(metricName, metricValue), nil
	}
	return tmpMetric, errors.New("invalid metric")
}
Example #3
0
// Collect calls smem periodically
func (s *SmemStats) Collect() {
	if s.whitelistedProcs == "" || s.user == "" || s.smemPath == "" {
		return
	}

	for _, stat := range getSmemStats(s) {
		dims := s.getCustomDimensions(stat.pid)
		for _, element := range s.whitelistedMetrics {
			var m metric.Metric
			switch element {
			case "pss":
				m = metric.WithValue(stat.proc+".smem.pss", stat.pss)
			case "uss":
				m = metric.WithValue(stat.proc+".smem.uss", stat.uss)
			case "vss":
				m = metric.WithValue(stat.proc+".smem.vss", stat.vss)
			case "rss":
				m = metric.WithValue(stat.proc+".smem.rss", stat.rss)
			}
			m.AddDimensions(dims)
			s.Channel() <- m
		}
	}
}
Example #4
0
func (ss SocketQueue) emitSocketQueueMetrics(output []byte) {
	// Capture the receive queue size and the corres. port number from the output.
	lines := strings.Split(string(output), "\n")

	pmap := make(map[string]float64)
	for _, line := range lines[1:] {
		res := queueDataRegex.FindAllStringSubmatch(line, -1)
		for _, v := range res {
			sport, qsize := v[2], v[1]
			pmap[sport] = util.StrToFloat(qsize)
		}
	}

	for sport, qsize := range pmap {
		m := metric.WithValue("sq.listen", qsize)
		m.AddDimension("port", sport)
		ss.Channel() <- m
	}
}
// Counts status stats from JSON content
func parseJSONData(raw []byte) ([]metric.Metric, error) {
	result := make(map[string]interface{})
	err := json.Unmarshal(raw, &result)
	results := []metric.Metric{}
	if err != nil {
		return results, err
	}
	registry := make(map[string]int)
	registry["IdleWorkers"] = 0
	registry["BusyWorkers"] = 0
	registry["SigWorkers"] = 0
	registry["PauseWorkers"] = 0
	registry["CheapWorkers"] = 0
	registry["UnknownStateWorkers"] = 0
	workers, ok := result["workers"].([]interface{})
	if !ok {
		return results, fmt.Errorf("\"workers\" field not found or not an array")
	}
	for _, worker := range workers {
		workerMap, ok := worker.(map[string]interface{})
		if !ok {
			return results, fmt.Errorf("worker record is not a map")
		}
		status, ok := workerMap["status"].(string)
		if !ok {
			return results, fmt.Errorf("status not found or not a string")
		}
		if strings.Index(status, "sig") == 0 {
			status = "sig"
		}
		metricName := strings.Title(status) + "Workers"
		_, exists := registry[metricName]
		if !exists {
			metricName = "UnknownStateWorkers"
		}
		registry[metricName]++
	}
	for key, value := range registry {
		results = append(results, metric.WithValue(key, float64(value)))
	}
	return results, err
}
Example #6
0
func extractScoreBoardMetrics(key, value string) []metric.Metric {
	results := []metric.Metric{}
	charCounter := func(str string, pattern string) float64 {
		return float64(strings.Count(str, pattern))
	}
	results = append(results, metric.WithValue("IdleWorkers", charCounter(value, "_")))
	results = append(results, metric.WithValue("StartingWorkers", charCounter(value, "S")))
	results = append(results, metric.WithValue("ReadingWorkers", charCounter(value, "R")))
	results = append(results, metric.WithValue("WritingWorkers", charCounter(value, "W")))
	results = append(results, metric.WithValue("KeepaliveWorkers", charCounter(value, "K")))
	results = append(results, metric.WithValue("DnsWorkers", charCounter(value, "D")))
	results = append(results, metric.WithValue("ClosingWorkers", charCounter(value, "C")))
	results = append(results, metric.WithValue("LoggingWorkers", charCounter(value, "L")))
	results = append(results, metric.WithValue("FinishingWorkers", charCounter(value, "G")))
	results = append(results, metric.WithValue("CleanupWorkers", charCounter(value, "I")))
	results = append(results, metric.WithValue("StandbyWorkers", charCounter(value, "_")))
	return results
}