Skip to content

Commit

Permalink
Change gauges to counters (#95)
Browse files Browse the repository at this point in the history
* Add RecentRawValues field to GroupState to update prom counters

* Fix tests

* Update network_definitions gauge->counter

* Add support to count operation with Counters
  • Loading branch information
ronensc authored Feb 23, 2022
1 parent b24be79 commit 84dbf1a
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 55 deletions.
30 changes: 15 additions & 15 deletions contrib/kubernetes/flowlogs2metrics.conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,105 +7,105 @@ pipeline:
prom:
metrics:
- name: bandwidth_per_network_service
type: gauge
type: counter
valuekey: bandwidth_network_service_value
labels:
- by
- aggregate
buckets: []
- name: bandwidth_per_source_destination_subnet
type: gauge
type: counter
valuekey: bandwidth_source_destination_subnet_value
labels:
- by
- aggregate
buckets: []
- name: bandwidth_per_source_subnet
type: gauge
type: counter
valuekey: bandwidth_source_subnet_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_destination_subnet
type: gauge
type: counter
valuekey: dest_connection_subnet_count_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_source_subnet
type: gauge
type: counter
valuekey: src_connection_count_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_tcp_flags
type: gauge
type: counter
valuekey: TCPFlags_count_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_destination_as
type: gauge
type: counter
valuekey: dst_as_connection_count_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_source_as
type: gauge
type: counter
valuekey: src_as_connection_count_value
labels:
- by
- aggregate
buckets: []
- name: count_per_source_destination_subnet
type: gauge
type: counter
valuekey: count_source_destination_subnet_value
labels:
- by
- aggregate
buckets: []
- name: egress_per_destination_subnet
type: gauge
type: counter
valuekey: bandwidth_destination_subnet_value
labels:
- by
- aggregate
buckets: []
- name: egress_per_namespace
type: gauge
type: counter
valuekey: bandwidth_namespace_value
labels:
- by
- aggregate
buckets: []
- name: connections_per_destination_location
type: gauge
type: counter
valuekey: dest_connection_location_count_value
labels:
- by
- aggregate
buckets: []
- name: mice_count
type: gauge
type: counter
valuekey: mice_count_value
labels:
- by
- aggregate
buckets: []
- name: elephant_count
type: gauge
type: counter
valuekey: elephant_count_value
labels:
- by
- aggregate
buckets: []
- name: service_count
type: gauge
type: counter
valuekey: dest_service_count_value
labels:
- by
Expand Down
30 changes: 15 additions & 15 deletions docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per network service |
| **Labels** | bandwidth, graph, rate, network-service |
| **Operation** | aggregate by `service` and `sum` field `bytes` |
| **Exposed as** | `fl2m_bandwidth_per_network_service` of type `gauge` |
| **Exposed as** | `fl2m_bandwidth_per_network_service` of type `counter` |
| **Visualized as** | "Bandwidth per network service" on dashboard `details` |
|||

Expand All @@ -31,7 +31,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per source / destination subnet pair |
| **Labels** | bandwidth, graph, rate, subnet |
| **Operation** | aggregate by `dstSubnet24, srcSubnet24` and `sum` field `bytes` |
| **Exposed as** | `fl2m_bandwidth_per_source_destination_subnet` of type `gauge` |
| **Exposed as** | `fl2m_bandwidth_per_source_destination_subnet` of type `counter` |
| **Visualized as** | "Bandwidth per src and destination subnet" on dashboard `details` |
|||

Expand All @@ -43,7 +43,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per source subnet |
| **Labels** | bandwidth, graph, rate, subnet |
| **Operation** | aggregate by `srcSubnet` and `sum` field `bytes` |
| **Exposed as** | `fl2m_bandwidth_per_source_subnet` of type `gauge` |
| **Exposed as** | `fl2m_bandwidth_per_source_subnet` of type `counter` |
| **Visualized as** | "Bandwidth per source subnet" on dashboard `details` |
|||

Expand All @@ -55,7 +55,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network connections per subnet |
| **Labels** | rate, subnet |
| **Operation** | aggregate by `dstSubnet` and `sum` field `isNewFlow` |
| **Exposed as** | `fl2m_connections_per_destination_subnet` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_destination_subnet` of type `counter` |
| **Visualized as** | "Connections rate per destinationIP /16 subnets" on dashboard `details` |
|||

Expand All @@ -67,7 +67,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network connections per subnet |
| **Labels** | rate, subnet |
| **Operation** | aggregate by `srcSubnet` and `count` |
| **Exposed as** | `fl2m_connections_per_source_subnet` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_source_subnet` of type `counter` |
| **Visualized as** | "Connections rate per sourceIP /16 subnets" on dashboard `details` |
|||

Expand All @@ -79,7 +79,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate difference in connections rate of different TCP Flags. Can be used, for example, to identify syn-attacks. |
| **Labels** | rate, TCPFlags |
| **Operation** | aggregate by `TCPFlags` and `count` |
| **Exposed as** | `fl2m_connections_per_tcp_flags` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_tcp_flags` of type `counter` |
| **Visualized as** | "Connections rate per TCPFlags" on dashboard `details` |
|||

Expand All @@ -91,7 +91,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate amount of connections targeted at different Autonomous Systems |
| **Labels** | rate, count, AS |
| **Operation** | aggregate by `dstAS` and `count` |
| **Exposed as** | `fl2m_connections_per_destination_as` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_destination_as` of type `counter` |
| **Visualized as** | "Connections rate per destination AS" on dashboard `details` |
|||

Expand All @@ -103,7 +103,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate amount of connections initiated by different Autonomous Systems |
| **Labels** | rate, count, AS |
| **Operation** | aggregate by `srcAS` and `count` |
| **Exposed as** | `fl2m_connections_per_source_as` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_source_as` of type `counter` |
| **Visualized as** | "Connections rate per source AS" on dashboard `details` |
|||

Expand All @@ -115,7 +115,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per source / destination subnet pair |
| **Labels** | count, graph, rate, subnet |
| **Operation** | aggregate by `dstSubnet24, srcSubnet24` and `count` |
| **Exposed as** | `fl2m_count_per_source_destination_subnet` of type `gauge` |
| **Exposed as** | `fl2m_count_per_source_destination_subnet` of type `counter` |
| **Visualized as** | "Connections rate of src / destination subnet occurences" on dashboard `details` |
|||

Expand All @@ -127,7 +127,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per destination subnet |
| **Labels** | bandwidth, graph, rate, subnet |
| **Operation** | aggregate by `dstSubnet` and `sum` field `bytes` |
| **Exposed as** | `fl2m_egress_per_destination_subnet` of type `gauge` |
| **Exposed as** | `fl2m_egress_per_destination_subnet` of type `counter` |
| **Visualized as** | "Bandwidth per destination subnet" on dashboard `details` |
| **Visualized as** | "Total bandwidth" on dashboard `totals` |
|||
Expand All @@ -140,7 +140,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network usage breakdown per namespace |
| **Labels** | kubernetes, bandwidth, graph |
| **Operation** | aggregate by `srcK8S_Namespace, srcK8S_Type` and `sum` field `bytes` |
| **Exposed as** | `fl2m_egress_per_namespace` of type `gauge` |
| **Exposed as** | `fl2m_egress_per_namespace` of type `counter` |
| **Visualized as** | "Bandwidth per namespace" on dashboard `details` |
|||

Expand All @@ -152,7 +152,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network connections geo-location |
| **Labels** | rate, connections-count, geo-location, destinationIP |
| **Operation** | aggregate by `dstLocation_CountryName` and `count` |
| **Exposed as** | `fl2m_connections_per_destination_location` of type `gauge` |
| **Exposed as** | `fl2m_connections_per_destination_location` of type `counter` |
| **Visualized as** | "Connections rate per destinationIP geo-location" on dashboard `details` |
|||

Expand All @@ -165,8 +165,8 @@ and the transformation to generate the exported metric.
| **Labels** | bandwidth, mice, elephant, rate |
| **Operation** | aggregate by `mice_Evaluate` and `count` |
| **Operation** | aggregate by `elephant_Evaluate` and `count` |
| **Exposed as** | `fl2m_mice_count` of type `gauge` |
| **Exposed as** | `fl2m_elephant_count` of type `gauge` |
| **Exposed as** | `fl2m_mice_count` of type `counter` |
| **Exposed as** | `fl2m_elephant_count` of type `counter` |
| **Visualized as** | "Mice flows count" on dashboard `details` |
| **Visualized as** | "Elephant flows count" on dashboard `details` |
|||
Expand All @@ -179,7 +179,7 @@ and the transformation to generate the exported metric.
| **Usage** | Evaluate network services |
| **Labels** | rate, network-services, destination-port, destination-protocol |
| **Operation** | aggregate by `service` and `count` |
| **Exposed as** | `fl2m_service_count` of type `gauge` |
| **Exposed as** | `fl2m_service_count` of type `counter` |
| **Visualized as** | "Network services connections rate" on dashboard `details` |
| **Visualized as** | "Number of network services" on dashboard `totals` |
|||
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/bandwidth_per_network_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ encode:
prom:
metrics:
- name: bandwidth_per_network_service
type: gauge
type: counter
valuekey: bandwidth_network_service_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/bandwidth_per_src_dest_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ encode:
prom:
metrics:
- name: bandwidth_per_source_destination_subnet
type: gauge
type: counter
valuekey: bandwidth_source_destination_subnet_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/bandwidth_per_src_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ encode:
prom:
metrics:
- name: bandwidth_per_source_subnet
type: gauge
type: counter
valuekey: bandwidth_source_subnet_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/connection_rate_per_dest_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ encode:
prom:
metrics:
- name: connections_per_destination_subnet
type: gauge
type: counter
valuekey: dest_connection_subnet_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/connection_rate_per_src_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ encode:
prom:
metrics:
- name: connections_per_source_subnet
type: gauge
type: counter
valuekey: src_connection_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/connection_rate_per_tcp_flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ encode:
prom:
metrics:
- name: connections_per_tcp_flags
type: gauge
type: counter
valuekey: TCPFlags_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/connections_per_dst_as.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ encode:
prom:
metrics:
- name: connections_per_destination_as
type: gauge
type: counter
valuekey: dst_as_connection_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/connections_per_src_as.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ encode:
prom:
metrics:
- name: connections_per_source_as
type: gauge
type: counter
valuekey: src_as_connection_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/count_per_src_dest_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ encode:
prom:
metrics:
- name: count_per_source_destination_subnet
type: gauge
type: counter
valuekey: count_source_destination_subnet_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/egress_bandwidth_per_dest_subnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ encode:
prom:
metrics:
- name: egress_per_destination_subnet
type: gauge
type: counter
valuekey: bandwidth_destination_subnet_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/egress_bandwidth_per_namespace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ encode:
prom:
metrics:
- name: egress_per_namespace
type: gauge
type: counter
valuekey: bandwidth_namespace_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/geo-location_rate_per_dest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ encode:
prom:
metrics:
- name: connections_per_destination_location
type: gauge
type: counter
valuekey: dest_connection_location_count_value
labels:
- by
Expand Down
4 changes: 2 additions & 2 deletions network_definitions/mice_elephants.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ encode:
prom:
metrics:
- name: mice_count
type: gauge
type: counter
valuekey: mice_count_value
labels:
- by
- aggregate
- name: elephant_count
type: gauge
type: counter
valuekey: elephant_count_value
labels:
- by
Expand Down
2 changes: 1 addition & 1 deletion network_definitions/network_services_count.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ encode:
prom:
metrics:
- name: service_count
type: gauge
type: counter
valuekey: dest_service_count_value
labels:
- by
Expand Down
9 changes: 6 additions & 3 deletions pkg/pipeline/encode/encode_prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ func (e *encodeProm) EncodeMetric(metric config.GenericMap) []interface{} {
mInfo.promGauge.With(entryLabels).Set(valueFloat)
cEntry.PromMetric.promGauge = mInfo.promGauge
case api.PromEncodeOperationName("Counter"):
mInfo.promCounter.With(entryLabels).Add(valueFloat)
for _, v := range metric["recentRawValues"].([]float64) {
mInfo.promCounter.With(entryLabels).Add(v)
}
cEntry.PromMetric.promCounter = mInfo.promCounter
case api.PromEncodeOperationName("Histogram"):
// TODO: Need to perform proper function for histogram
//mInfo.promHist.With(entryLabels).Set(valueFloat)
for _, v := range metric["recentRawValues"].([]float64) {
mInfo.promHist.With(entryLabels).Observe(v)
}
cEntry.PromMetric.promHist = mInfo.promHist
}
}
Expand Down
Loading

0 comments on commit 84dbf1a

Please sign in to comment.