{"id":15041235,"url":"https://github.com/maxmindlin/telegraf-rust","last_synced_at":"2025-09-08T22:39:36.818Z","repository":{"id":39872718,"uuid":"244067943","full_name":"maxmindlin/telegraf-rust","owner":"maxmindlin","description":"Lightweight client library for the telegraf/influxdb protocol","archived":false,"fork":false,"pushed_at":"2023-09-01T00:29:20.000Z","size":28533,"stargazers_count":17,"open_issues_count":2,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T19:51:55.294Z","etag":null,"topics":["databases","influxdata","influxdata-telegraf","influxdb","metrics","rust","telegraf"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/telegraf","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxmindlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-01T01:28:54.000Z","updated_at":"2024-11-22T10:34:41.000Z","dependencies_parsed_at":"2024-09-25T01:35:01.964Z","dependency_job_id":"1be48057-1b02-4614-8789-e48983d138d4","html_url":"https://github.com/maxmindlin/telegraf-rust","commit_stats":{"total_commits":60,"total_committers":4,"mean_commits":15.0,"dds":"0.19999999999999996","last_synced_commit":"e2ebca471ed1153bb2dc9ce2324c83a055869d33"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/maxmindlin/telegraf-rust","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmindlin%2Ftelegraf-rust","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmindlin%2Ftelegraf-rust/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmindlin%2Ftelegraf-rust/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmindlin%2Ftelegraf-rust/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxmindlin","download_url":"https://codeload.github.com/maxmindlin/telegraf-rust/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxmindlin%2Ftelegraf-rust/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265617286,"owners_count":23799014,"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":["databases","influxdata","influxdata-telegraf","influxdb","metrics","rust","telegraf"],"created_at":"2024-09-24T20:45:47.613Z","updated_at":"2025-07-17T14:35:09.482Z","avatar_url":"https://github.com/maxmindlin.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Telegraf-rust\n\n[![Telegraf crate](https://img.shields.io/crates/v/telegraf.svg)](https://crates.io/crates/telegraf)\n[![Telegraf crate downloads](https://img.shields.io/crates/d/telegraf)](https://crates.io/crates/telegraf)\n[![Telegraf documentation](https://docs.rs/telegraf/badge.svg)](https://docs.rs/telegraf)\n\nTelegraf-rust is a lightweight client library for general metrics writing using Telegraf. Telegraf is a micro-service provided\nby InfluxData for making metrics reporting easy for distributed services - see their [docs](https://docs.influxdata.com/telegraf/v1.13/introduction/installation/) for more information.\n\nThis library does not provide querying or other InfluxDB client-library features. This is meant to be lightweight and simple for services to report metrics.\n\nTelegraf-rust supports all socket connection types, such as UDS (unix domain socket):\n- TCP (`tcp://`)\n- UDP (`udp://`)\n- UDS Stream (`unix://`)\n- UDS Datagram (`unixgram://`)\n\n# Install\n\nAdd it to your Cargo.toml:\n\n```toml\n[dependencies]\ntelegraf = \"*\"\n```\n\n# How to use\n\nUsing this library assumes you have a socket listener setup in your Telegraf configuration file. An example TCP connection looks like so:\n\n```toml\n[[inputs.socket_listener]]\n  service_address = \"tcp://localhost:8094\"\n```\n\nAll usage will start by creating a socket connection via a `Client`. This supports multiple connection protocols - which one you use will be determined by how your Telegraf `input.socket_listener` configuration is setup. \n\nOnce a client is setup there are multiple different ways to write points:\n\n## Define structs that represent metrics using the derive macro\n\n```rust\nuse telegraf::*;\n\nlet mut client = Client::new(\"tcp://localhost:8094\").unwrap();\n\n#[derive(Metric)]\nstruct MyMetric {\n    field1: i32,\n    #[telegraf(tag)]\n    tag1: String,\n}\n\nlet point = MyMetric { field1: 1, tag1: \"tag\" };\nclient.write(\u0026point);\n```\n\nBy default the measurement name will be the same as the struct. You can override this via derive attributes:\n\n```rust\nuse telegraf::*;\n\n#[derive(Metric)]\n#[measurement = \"custom_name\"]\nstruct MyMetric {\n    field1: i32,\n}\n```\n\nAs with any Telegraf point, tags are optional but at least one field is required.\n\nTimestamps are optional and can be set via the `timestamp` attribute:\n\n```rust\nuse telegraf::*;\n\n#[derive(Metric)]\nstruct MyMetric {\n    #[telegraf(timestamp)]\n    ts: u64,\n    field1: i32,\n}\n```\n\n## Use the `point` macro to do ad-hoc metrics\n\n```rust\nuse telegraf::*;\n\nlet mut client = Client::new(\"tcp://localhost:8094\").unwrap();\n\nlet p = point!(\"measurement\", (\"tag1\", \"tag1Val\"), (\"field1\", \"val\") (\"field2\", 10); 100);\nclient.write_point(\u0026p);\n```\n\nThe macro syntax is the following format:\n\n```\n(\u003cmeasurement\u003e, [(\u003ctagName\u003e, \u003ctagVal\u003e)], [(\u003cfieldName\u003e, \u003cfieldVal\u003e)]; \u003ctimestamp\u003e)\n```\n\nMeasurement name, tag set, and field set are comma separated. Tag and field tuples are space separated. Timestamp is semicolon separated. The tag set and timestamp are optional.\n\n## Manual `Point` initialization\n\n```rust\nuse telegraf::{Client, Point};\n\nlet c = Client::new(\"tcp://localhost:8094\").unwrap();\n\nlet p = Point::new(\n    String::from(\"measurement\"),\n    vec![\n        (String::from(\"tag1\"), String::from(\"tag1value\"))\n    ],\n    vec![\n        (String::from(\"field1\"), Box::new(10)),\n        (String::from(\"field2\"), Box::new(20.5)),\n        (String::from(\"field3\"), Box::new(\"anything!\"))\n    ],\n    Some(100),\n);\n\nc.write_point(p)\n```\n\n### Field Data\n\nAny attribute that will be the value of a field must implement the `IntoFieldData` trait provided by this library.\n\n```rust\npub trait IntoFieldData {\n    fn field_data(\u0026self) -\u003e FieldData;\n}\n```\n\nOut of the box implementations are provided for many common data types, but manual implementation is possible for other data types.\n\n### Timestamps\n\nTimestamps are optional. If not present, the Telegraf daemon will set the timestamp using the current time.\nTimestamps are specified in nanosecond-precision Unix time, therefore `u64` must implement the `From\u003cT\u003e` trait for the field type, if the implementation is not already present:\n\n```rust\nuse telegraf::*;\n\n#[derive(Copy, Clone)]\nstruct MyType {\n    // ...\n}\n\nimpl From\u003cMyType\u003e for u64 {\n    fn from(my_type: MyType) -\u003e Self {\n        todo!()\n    }\n}\n\n#[derive(Metric)]\nstruct MyMetric {\n    #[telegraf(timestamp)]\n    ts: MyType,\n    field1: i32,\n}\n\n```\n\nMore information about timestamps can be found [here](https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/#timestamp).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmindlin%2Ftelegraf-rust","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxmindlin%2Ftelegraf-rust","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxmindlin%2Ftelegraf-rust/lists"}