forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Network Scraper Translation to ES Metrics (open-telemetry#3)
* Network scrapper * Add network scrapper to hostmetrics * Add system.network.packets * Add more metrics to network scrapper * Move attribute addition to the network.go file * Add code for Network Scraper * remove disk for now * comment a particular part * Have just a single metric * Uncomment the code * update process.go * Improve the code of Network Scraper * Change in network scraper code * Update the metric.attributes
- Loading branch information
1 parent
80c19e9
commit fdd9e5b
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
processor/elasticprocessor/internal/hostmetrics/network.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package hostmetrics | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/pmetric" | ||
) | ||
|
||
func addNetworkMetrics(metrics pmetric.MetricSlice, resource pcommon.Resource, dataset string) error { | ||
for i := 0; i < metrics.Len(); i++ { | ||
metric := metrics.At(i) | ||
dataPoints := metric.Sum().DataPoints() | ||
for j := 0; j < dataPoints.Len(); j++ { | ||
dp := dataPoints.At(j) | ||
|
||
var device string | ||
if d, ok := dp.Attributes().Get("device"); ok { | ||
device = d.Str() | ||
} else { | ||
continue | ||
} | ||
|
||
if direction, ok := dp.Attributes().Get("direction"); ok { | ||
name := metric.Name() | ||
timestamp := dp.Timestamp() | ||
value := dp.IntValue() | ||
|
||
switch direction.Str() { | ||
case "receive": | ||
addDeviceMetric(metrics, resource, dataset, name, device, "in", timestamp, value) | ||
case "transmit": | ||
addDeviceMetric(metrics, resource, dataset, name, device, "out", timestamp, value) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func addDeviceMetric(metrics pmetric.MetricSlice, resource pcommon.Resource, | ||
dataset, name, device, direction string, timestamp pcommon.Timestamp, value int64) { | ||
|
||
metricsToAdd := map[string]string{ | ||
"system.network.io": "system.network.%s.bytes", | ||
"system.network.packets": "system.network.%s.packets", | ||
"system.network.dropped": "system.network.%s.dropped", | ||
"system.network.errors": "system.network.%s.errors", | ||
} | ||
|
||
if metricNetworkES, ok := metricsToAdd[name]; ok { | ||
attributes := pcommon.NewMap() | ||
attributes.PutStr("system.network.name", device) | ||
|
||
addMetrics(metrics, resource, dataset, | ||
metric{ | ||
dataType: Sum, | ||
name: fmt.Sprintf(metricNetworkES, direction), | ||
timestamp: timestamp, | ||
intValue: &value, | ||
attributes: &attributes, | ||
}) | ||
} | ||
} |