Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

add conntrack_count and conntrack_max #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gregleroux
Copy link

Fixes #54

Summary of changes:
add conntrack_count and conntrack
/intel/psutil/netfilter/conntrackcount
/intel/psutil/netfilter/conntrackmax

How to verify it:
load task with this metrics:
"/intel/psutil/net/netfilter/conntrackcount": {},
"/intel/psutil/net/netfilter/conntrackmax": {},

Testing done:

A picture of a snapping turtle (not required but encouraged):

@snapbot
Copy link

snapbot commented Jan 12, 2017

Can one of the admins verify this patch?

Copy link
Contributor

@candysmurf candysmurf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please update README.md if conntrackcon/conntrackmax require special test setup?

Data_: conntrack[0].ConnTrackMax,
Timestamp_: time.Now(),
Unit_: netConntrackCounterLabels[metricName].unit,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that you can combine two if statements together as data is the difference.

@@ -62,6 +62,17 @@ var netIOCounterLabels = map[string]label{
},
}

var netConntrackCounterLabels = map[string]label{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what reason you didn't want to combine netConntrackCounterLables initialization with IO but rename the variable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metric returned by GetMetricTypes is in static list (netIOCounterLabels and netConntrackCounterLabels), and in case of netfilter is not loaded in kernel, task with this metric will fail and plugin crash. In the reason why i separate "basic" net metric and netfilter metric.

@@ -102,7 +121,28 @@ func netIOCounters(nss []core.Namespace) ([]plugin.MetricType, error) {
}
results = append(results, metric)
}
} else {
case "netfilter":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case someone try to collect netfilter metrics but an error occurred line 90, it should still throw an error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gregleroux Could you address this comment?

conntrack, err := net.FilterCounters()
if err != nil {
// Conntrack probably not loaded into the kernel.
fmt.Printf("Requested netfilter statistics %s not found", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only print error and continue? I just want to make sure the desired behavior. Do you like to return the error here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with this plugin, metric list is "static", snap metric list return conntrack_count while it not available on the server. I think it good, to see this error in snap log and continue to retreive other metric of the task. With return statement, task will failed and no metric will be publish. This is why i remove the return statement.

if ns[4].Value == "conntrackcount" {
metric := plugin.MetricType{
Namespace_: ns,
Data_: conntrack[0].ConnTrackCount,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if conntrack is empty?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if conntrack is empty, it terminate in error i think.

if ns[4].Value == "conntrackmax" {
metric := plugin.MetricType{
Namespace_: ns,
Data_: conntrack[0].ConnTrackMax,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the same as above

@katarzyna-z
Copy link
Contributor

@gregleroux Could you extend tests to cover new metrics?

@gregleroux
Copy link
Author

For psutil plugin GetMetricTypes is base on static array of plugin.MetricType.
But, in some os, conntrack can be absent if it not loaded in kernel (travis vm for exemple).
For me, the best way to have this metric is to check conntrack in GetMetricTypes to display or not conntrack and make it optional in netIOCounters to avoid crash.
I will rewrite my pull request

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add conntrack counter
6 participants