{"id":19284934,"url":"https://github.com/orca-zhang/influxdb-c","last_synced_at":"2025-04-22T03:32:31.333Z","repository":{"id":54846186,"uuid":"113639754","full_name":"orca-zhang/influxdb-c","owner":"orca-zhang","description":"💙 C write client for InfluxDB.","archived":false,"fork":false,"pushed_at":"2021-01-25T20:24:58.000Z","size":35,"stargazers_count":31,"open_issues_count":3,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T11:38:22.016Z","etag":null,"topics":["c","header-only","influxdb","influxdb-c-client","no-dependencies"],"latest_commit_sha":null,"homepage":"","language":"C","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/orca-zhang.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}},"created_at":"2017-12-09T03:51:39.000Z","updated_at":"2024-12-11T02:15:37.000Z","dependencies_parsed_at":"2022-08-14T04:40:18.287Z","dependency_job_id":null,"html_url":"https://github.com/orca-zhang/influxdb-c","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orca-zhang%2Finfluxdb-c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orca-zhang%2Finfluxdb-c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orca-zhang%2Finfluxdb-c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/orca-zhang%2Finfluxdb-c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/orca-zhang","download_url":"https://codeload.github.com/orca-zhang/influxdb-c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250167611,"owners_count":21386004,"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":["c","header-only","influxdb","influxdb-c-client","no-dependencies"],"created_at":"2024-11-09T21:40:57.678Z","updated_at":"2025-04-22T03:32:31.064Z","avatar_url":"https://github.com/orca-zhang.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# influxdb-c\n\nA header-only C write client for InfluxDB.\n\n[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/orca-zhang/influxdb-c/blob/master/LICENSE)\n[![Build Status](https://semaphoreci.com/api/v1/orca-zhang-91/influxdb-c/branches/master/shields_badge.svg)](https://semaphoreci.com/orca-zhang-91/influxdb-c)\n\n- Supported versions:\n  - InfluxDB v0.9 ~ v1.4\n  - Check yourself while using other versions.\n\n### Why use influxdb-c?\n\n- **Exactly small**:\n  - Less than 300 lines and only about 10KB.\n- **Easy to use**:\n  - It's designed to be used without extra studies.\n- **Easy to assemble**:\n  - Only a tiny header file needs to be included.\n- **No dependencies**:\n  - Unless std C libraries.\n- **Under serious testing**:\n  - Uses gtest \u0026 [mockcpp](https://github.com/ez8-co/mockcpp)\n\n### Examples\n\n#### Before using\n\n- The very simple thing you should do before using is only:\n\n    ```c\n    #include \"influxdb.h\"\n    ```\n\n#### Write example\n\n- You should according to the [write syntax](https://docs.influxdata.com/influxdb/v1.4/write_protocols/line_protocol_reference/) while writing series(metrics).\n\n    ```\n    measurement[,tag-key=tag-value...] field-key=field-value[,field2-key=field2-value...] [unix-nano-timestamp]\n    ```\n\n\n- You can rapidly start writing series by using one of the following examples:\n\n- Client configurations:\n\n    ```c\n    influx_client_t c;\n    c.host = strdup(\"127.0.0.1\");\n    c.port = 8086;\n    c.db = strdup(\"db\");\n    c.usr = strdup(\"usr\");\n    c.pwd = strdup(\"pwd\");\n    ```\n\n- Under C99, you can use:\n\n    ```c\n    influx_client_t c = {\n        .host = strdup(\"127.0.0.1\"),\n        .port = 8086,\n        .db = strdup(\"db\"),\n        .usr = strdup(\"usr\"),\n        .pwd = strdup(\"pwd\")\n    };\n    ```\n\n- Then send out the series by calling `post_http`:\n\n    ```c\n    post_http(\u0026c,\n        INFLUX_MEAS(\"foo\"),\n        INFLUX_TAG(\"k\", \"v\"),\n        INFLUX_TAG(\"x\", \"y\"),\n        INFLUX_F_INT(\"x\", 10),\n        INFLUX_F_FLT(\"y\", 10.3, 2),\n        INFLUX_F_FLT(\"z\", 10.3456, 2),\n        INFLUX_F_BOL(\"b\", 10),\n        INFLUX_TS(1512722735522840439),\n        INFLUX_END);\n    ```\n\n  - **NOTE**:\n    - 3rd parameter of `INFLUX_F_FLT()` is `precision` for floating point value.\n    - `usr` and `pwd` is optional for authorization.\n    - `INFLUX_END` is the delimiter for variable arguments list that **should not be ommitted**.\n\n- The series sent is:\n\n    ```\n    foo,k=v,x=y x=10i,y=10.30,z=10.35,b=t 1512722735522840439\n    ```\n\n- You could change `post_http` to `send_udp` for UDP request. And only `host` and `port` are required for UDP operation.\n\n    ```c\n    influx_client_t c = {strdup(\"127.0.0.1\"), 8091, NULL, NULL, NULL};\n\n    send_udp(\u0026c,\n        INFLUX_MEAS(\"foo\"),\n        INFLUX_TAG(\"k\", \"v\"),\n        INFLUX_F_INT(\"x\", 10),\n        INFLUX_END);\n    ```\n\n- Bulk/batch write is also supported:\n\n    ```c\n    send_udp(\u0026c,\n        INFLUX_MEAS(\"foo\"),  // series 1\n        INFLUX_F_INT(\"x\", 10),\n\n        INFLUX_MEAS(\"foo\"),  // series 2\n        INFLUX_F_FLT(\"y\", 10.3, 2),\n\n        INFLUX_END);\n    ```\n\n- The series sent are:\n\n    ```\n    foo x=10i\n    bar y=10.30\n    ```\n\n- If measurement data is sent from within a loop, but higher write performance\n  is needed, one has to format each measurement separately, then at the end\n  send the formatted line to the database. This example sends 10 measurements\n  with a single http request:\n\n  ```c\n  influx_client_t c = {strdup(\"127.0.0.1\"), 8091, NULL, NULL, NULL};\n  char *line = NULL;\n  int len = 0;\n  int used = 0;\n\n  for (int i = 0; i \u003c 10; ++i) {\n      used = format_line(line, \u0026len, used,\n          INFLUX_MEAS(\"foo\"),\n          INFLUX_TAG(\"k\", \"v\"),\n          INFLUX_F_INT(\"x\", i),\n          INFLUX_END);\n  }\n\n  post_http_send_line(\u0026c, line, used);\n  ```\n\n### TODO\n\n- Add more test cases for send functions.\n- Supports DSN initializatin for influx_client_t.\n- Add query function.\n- Do not need to connect every time.\n\n### Misc\n\n- Please feel free to use influxdb-c.\n- Looking forward to your suggestions.\n- If your project is using influxdb-c, you can show your project or company here by creating a issue or let me know.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forca-zhang%2Finfluxdb-c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Forca-zhang%2Finfluxdb-c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Forca-zhang%2Finfluxdb-c/lists"}