{"id":22052026,"url":"https://github.com/balena-io-examples/network-metrics-logger","last_synced_at":"2025-05-11T04:41:58.744Z","repository":{"id":44490479,"uuid":"512766700","full_name":"balena-io-examples/network-metrics-logger","owner":"balena-io-examples","description":"Log metrics on network I/O","archived":false,"fork":false,"pushed_at":"2022-08-23T11:51:58.000Z","size":55,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-31T21:51:22.961Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/balena-io-examples.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-11T13:24:58.000Z","updated_at":"2024-01-27T02:47:27.000Z","dependencies_parsed_at":"2022-08-03T18:15:29.690Z","dependency_job_id":null,"html_url":"https://github.com/balena-io-examples/network-metrics-logger","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balena-io-examples%2Fnetwork-metrics-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balena-io-examples%2Fnetwork-metrics-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balena-io-examples%2Fnetwork-metrics-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/balena-io-examples%2Fnetwork-metrics-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/balena-io-examples","download_url":"https://codeload.github.com/balena-io-examples/network-metrics-logger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252896204,"owners_count":21821262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T15:12:51.824Z","updated_at":"2025-05-11T04:41:58.682Z","avatar_url":"https://github.com/balena-io-examples.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Network Metrics Logger\n\n*Log metrics on network I/O*\n\nThis fleet logs network I/O metrics on a configurable interval from data provided by [System Metrics](https://github.com/balena-io-examples/system-metrics) block. The logger generates minimal output to avoid creation of more network I/O itself.\n\n## Getting Started\n\nSimply click on the *Deploy with balena* button below to create a fleet from the [docker-compose](https://github.com/balena-io-examples/network-metrics-logger/blob/master/docker-compose.yml) file in this repository.\n\n[![balena deploy button](https://www.balena.io/deploy.svg)](https://dashboard.balena-cloud.com/deploy?repoUrl=https://github.com/balena-io-examples/network-metrics-logger)\n\nBy default the fleet publishes bytes transmitted and received every five minutes on the first interface received from the System Metrics block. Output is formatted as CSV. You should see messages like below.\n\n```\n11.07.22 12:54:36 (+0000)  network-metrics-logger  Received initial loggable message for interface lo; starting publish interval\n11.07.22 12:59:36 (+0000)  network-metrics-logger  elapsedRx,elapsedTx\n11.07.22 12:59:36 (+0000)  network-metrics-logger  40976,40976\n11.07.22 13:04:36 (+0000)  network-metrics-logger  42868,42868\n```\nNotice the first message includes the name of the interface, in this case the loopback interface `lo`. See METRICS_REQUEST configuration below to specify a different interface.\n\n## Configuration\nEnvironment variables you may configure are listed in the sections below.\n\n### METRICS_REQUEST\n\nThe METRICS_REQUEST variable is [defined](https://github.com/balena-io-examples/system-metrics#metrics_request) by the System Metrics block to collect network I/O readings. The fleet collects metrics on **all** interfaces by default to help you get started, as you can see by the asterisk (*) in the first term of the request text below.\n\n```\nnetworkStats/(*), networkStats/iface, networkStats/rx_bytes, networkStats/tx_bytes\n```\n\nHowever, the network metrics logger service only reports data from the **first** interface it receives from System Metrics. Often this interface is `lo`, the loopback interface, which probably is not what you want.\n\nSo create/update a `METRICS_REQUEST` environment variable with the single interface of interest. For example, if you are interested in interface `eth0`, set METRICS_REQUEST like below.\n\n```\nnetworkStats/(eth0), networkStats/rx_bytes, networkStats/tx_bytes\n```\n\nIf you don't know the name of the interface, use the `ifconfig` command to find it. The example below includes an Ethernet interface, `eth0`, and a cellular interface, `wwp1s0u1u1i4`.\n\n\u003cdetails\u003e\u003csummary\u003eClick for ifconfig command example\u003c/summary\u003e\n\u003cp\u003e\n\n```\nroot@abcdef0:~# ifconfig |grep -B 1 inet\n\nbalena0   Link encap:Ethernet  HWaddr 02:42:83:5E:26:AC  \n          inet addr:10.114.101.1  Bcast:10.114.101.255  Mask:255.255.255.0\n--\nbr-233ab2d0cdb1 Link encap:Ethernet  HWaddr 02:42:DE:0E:DC:2A  \n          inet addr:172.17.0.1  Bcast:172.17.255.255  Mask:255.255.0.0\n          inet6 addr: fe80::42:deff:fe0e:dc2a/64 Scope:Link\n--\neth0      Link encap:Ethernet  HWaddr DC:A6:32:E8:C9:56  \n          inet addr:192.168.1.127  Bcast:192.168.1.255  Mask:255.255.255.0\n          inet6 addr: fe80::aa2f:7f31:b094:9181/64 Scope:Link\n          inet6 addr: fd25:36da:e8ec::e1d/128 Scope:Global\n          inet6 addr: fd25:36da:e8ec:0:99aa:a2bd:39d5:f53f/64 Scope:Global\n--\nlo        Link encap:Local Loopback  \n          inet addr:127.0.0.1  Mask:255.0.0.0\n          inet6 addr: ::1/128 Scope:Host\n--\nresin-dns Link encap:Ethernet  HWaddr 2E:ED:31:EB:05:35  \n          inet addr:10.114.102.1  Bcast:0.0.0.0  Mask:255.255.255.0\n--\nresin-vpn Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  \n          inet addr:10.246.34.90  P-t-P:52.4.252.97  Mask:255.255.255.255\n          inet6 addr: fe80::a238:945a:e93b:c106/64 Scope:Link\n--\nsupervisor0 Link encap:Ethernet  HWaddr 02:42:58:E8:D0:F7  \n          inet addr:10.114.104.1  Bcast:10.114.104.127  Mask:255.255.255.128\n--\nveth43d6399 Link encap:Ethernet  HWaddr AA:CC:21:F4:A0:E6  \n          inet6 addr: fe80::a8cc:21ff:fef4:a0e6/64 Scope:Link\n--\nwwp1s0u1u1i4 Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  \n          inet addr:100.56.81.95  P-t-P:100.65.50.81  Mask:255.255.255.252\n```\n\n\u003c/p\u003e\n\u003c/details\u003e\n\n### READING_INTERVAL_SEC\n\nThe READING_INTERVAL_SEC variable is [defined](https://github.com/balena-io-examples/system-metrics#reading_interval_sec) by the System Metrics block as the interval between metrics readings, in seconds. The logger service receives these raw readings from MQTT, accumulates totals and logs them. The default interval for a fleet is 300 seconds or 5 minutes.\n\nThe logger service itself also provides a `PUBLISH_INTERVAL_SEC` variable to allow accumulating byte totals across readings from the metrics block before publishing them to the system log. Defaults to `0`, which publishes totals as readings are received.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalena-io-examples%2Fnetwork-metrics-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbalena-io-examples%2Fnetwork-metrics-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbalena-io-examples%2Fnetwork-metrics-logger/lists"}