-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update metrics collect to nebula 3.0 #38
Conversation
kqzh
commented
Dec 28, 2021
•
edited
Loading
edited
- support collect space metric
- support collect nebula 3.0 metric
- remove bare-metal namespace label
exporter/convert.go
Outdated
} | ||
|
||
func convertToMap(metrics []string) map[string]MetricValue { | ||
matches := make(map[string]MetricValue) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give a default length of len(metrics)
?
exporter/convert.go
Outdated
|
||
type MetricValue struct { | ||
Value string | ||
Label map[string]string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to Labels
?
exporter/convert.go
Outdated
if start == -1 { | ||
return metric, nil | ||
} | ||
end := strings.LastIndex(metric, "}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if end
is -1
, will panic?
exporter/type.go
Outdated
GraphdComponent ComponentType = "graphd" | ||
MetadComponent ComponentType = "metad" | ||
StoragedComponent ComponentType = "storaged" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it if no more used.
exporter/metric.go
Outdated
Timeout: time.Second * 2, | ||
} | ||
|
||
resp, err := httpClient.Get(fmt.Sprintf("http://%s:%d/stats?stats=", ipAddress, port)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove ?stats=
?
exporter/metric.go
Outdated
countStr := "count=0" | ||
if status.Status == "running" { | ||
countStr = strings.Replace(countStr, "0", "1", 1) | ||
} | ||
statusMetrics := []string{countStr} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's no good to usestrings.Replace(countStr, "0", "1", 1)
?
} | ||
|
||
func (exporter *NebulaExporter) Describe(ch chan<- *prometheus.Desc) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more used ?
exporter/exporter.go
Outdated
ch <- prometheus.MustNewConstMetric(prometheus.NewDesc( | ||
fmt.Sprintf("%s_%s_%s", FQNamespace, componentType, strings.ReplaceAll(metric, ".", "_")), | ||
"", labels, | ||
nil), | ||
prometheus.GaugeValue, | ||
v, | ||
labelValues..., | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
} | ||
|
||
label := make(map[string]string) | ||
labelsStr := strings.Split(metric[start+1:end], ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the sep is ","
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
becase the metric may like this num_queries{space=nba,partition=1}
} | ||
} | ||
|
||
func (exporter *NebulaExporter) collect(wg *sync.WaitGroup, namespace, clusterName string, instance Instance, ch chan<- prometheus.Metric) { | ||
podIpAddress := instance.EndpointIP | ||
podHttpPort := instance.EndpointPort | ||
|
||
if podHttpPort == 0 { | ||
if podHttpPort <= 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<0 means?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because port < 0 also invalid
|
||
// FQNamespace represents the prometheus FQName | ||
FQNamespace = "nebula" | ||
NonNamespace = "none_namespace" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none seems more concise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider concise name may easy to used by user, so I use a long name none_namespace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM