parseMetrics parses metric strings like "count:processed=100,error_count:failed=2"
(metricStr string)
| 121 | |
| 122 | // parseMetrics parses metric strings like "count:processed=100,error_count:failed=2" |
| 123 | func parseMetrics(metricStr string) map[string]int { |
| 124 | metrics := make(map[string]int) |
| 125 | parts := strings.Split(metricStr, ",") |
| 126 | for _, part := range parts { |
| 127 | part = strings.TrimSpace(part) |
| 128 | if part == "" { |
| 129 | continue |
| 130 | } |
| 131 | // Format: type:name=value (e.g., count:processed=100) |
| 132 | eqIdx := strings.LastIndex(part, "=") |
| 133 | if eqIdx == -1 { |
| 134 | continue |
| 135 | } |
| 136 | key := strings.TrimSpace(part[:eqIdx]) |
| 137 | valStr := strings.TrimSpace(part[eqIdx+1:]) |
| 138 | if val, err := strconv.Atoi(valStr); err == nil { |
| 139 | metrics[key] = val |
| 140 | } |
| 141 | } |
| 142 | return metrics |
| 143 | } |
| 144 | |
| 145 | func init() { |
| 146 | RootCmd.AddCommand(pingCmd) |