HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: //usr/share/systemtap/examples/network/netfilter_summary_json.stp
#!/usr/bin/stap

global packets

// Set up the metrics
probe begin
{
  // Set the prefix to be used instead of the module name (optional).
  json_set_prefix("netfilter")

  // Add the metrics
  json_add_array("netfilter_data",
		 "Network data indexed by source and destination addresses.")
  json_add_array_numeric_metric("netfilter_data", "packets",
				"Number of packets transferred.", "")
  json_add_array_numeric_metric("netfilter_data", "bytes","Bytes transferred.",
				"bytes")
}

probe netfilter.ipv4.pre_routing {
      // Using aggregates avoids contention from packets being sent in
      // parallel from different processors:
      packets[saddr, daddr] <<< length
}

probe json_data
{
  @json_output_data_start

  foreach ([saddr, daddr] in packets-) {
    index = sprintf("%15s --> %15s", saddr, daddr)
    @json_output_array_numeric_value("netfilter_data", index, "packets",
				     @count(packets[saddr,daddr]))
    @json_output_array_numeric_value("netfilter_data", index, "bytes",
				     @sum(packets[saddr,daddr]))
  }
  @json_output_data_end
}