{"id":28501956,"url":"https://github.com/fluent/cmetrics","last_synced_at":"2026-04-02T13:05:46.540Z","repository":{"id":38040830,"uuid":"344850649","full_name":"fluent/cmetrics","owner":"fluent","description":"A standalone library to create and manipulate metrics in C ","archived":false,"fork":false,"pushed_at":"2025-05-23T19:22:03.000Z","size":1202,"stargazers_count":18,"open_issues_count":5,"forks_count":19,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-08T16:08:28.889Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/fluent.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-05T15:22:32.000Z","updated_at":"2025-05-23T19:13:46.000Z","dependencies_parsed_at":"2024-03-31T04:20:45.272Z","dependency_job_id":"9da7bf1d-139b-48ea-b21e-d80fad126b5d","html_url":"https://github.com/fluent/cmetrics","commit_stats":null,"previous_names":["calyptia/cmetrics"],"tags_count":53,"template":false,"template_full_name":null,"purl":"pkg:github/fluent/cmetrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Fcmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Fcmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Fcmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Fcmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluent","download_url":"https://codeload.github.com/fluent/cmetrics/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluent%2Fcmetrics/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263671744,"owners_count":23494026,"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":"2025-06-08T16:08:33.561Z","updated_at":"2026-04-02T13:05:46.532Z","avatar_url":"https://github.com/fluent.png","language":"C","readme":"# CMetrics\n\n\u003e DISCLAIMER: THIS LIBRARY IS STILL IN ACTIVE DEVELOPMENT\n\n[CMetrics](https://github.com/calyptia/cmetrics) is a standalone C library to\ncreate, mutate, aggregate, encode, and decode metrics contexts.\n\n## Supported Metric Types\n\n- Counter\n- Gauge\n- Untyped\n- Histogram\n- Exponential Histogram\n- Summary\n\nAll metric points store a sample `timestamp` in nanoseconds.\n\n## Datapoint Start Timestamp (OTLP)\n\nCMetrics also supports an optional native `start_timestamp` per datapoint.\nThis is primarily relevant for OTLP cumulative streams.\n\nAPI (`cmt_metric.h`):\n\n- `cmt_metric_set_start_timestamp(...)`\n- `cmt_metric_unset_start_timestamp(...)`\n- `cmt_metric_has_start_timestamp(...)`\n- `cmt_metric_get_start_timestamp(...)`\n\nBackward compatibility: existing code that only uses `timestamp` is unchanged.\n\n## Supported Encoders\n\n- OpenTelemetry Metrics (OTLP protobuf)\n- Prometheus text exposition\n- Prometheus Remote Write\n- Influx line protocol\n- Splunk HEC\n- CloudWatch EMF\n- CMetrics msgpack (internal format)\n- Text (human-readable)\n\n## Supported Decoders\n\n- OpenTelemetry Metrics (OTLP protobuf)\n- Prometheus text exposition\n- Prometheus Remote Write\n- StatsD\n- CMetrics msgpack (internal format)\n\n## OTLP and `start_timestamp`\n\n- OTLP decoder populates native `start_timestamp` from\n  `start_time_unix_nano`.\n- OTLP encoder prefers native `start_timestamp` and falls back to OTLP metadata\n  when needed.\n- Internal CMetrics msgpack supports optional `start_ts` to preserve this value\n  across internal encode/decode flows.\n\nNon-OTLP formats (for example Prometheus text, Influx, Splunk HEC, and\nCloudWatch EMF) do not define an OTLP-style start timestamp field, so they\nserialize sample timestamps only.\n\n## C Usage Example\n\n```c\n#include \u003cstdint.h\u003e\n#include \u003cstdio.h\u003e\n\n#include \u003ccmetrics/cmetrics.h\u003e\n#include \u003ccmetrics/cmt_counter.h\u003e\n#include \u003ccmetrics/cmt_map.h\u003e\n#include \u003ccmetrics/cmt_metric.h\u003e\n#include \u003ccmetrics/cmt_encode_opentelemetry.h\u003e\n\nint main(void)\n{\n    struct cmt *ctx;\n    struct cmt_counter *requests_total;\n    struct cmt_metric *sample;\n    cfl_sds_t otlp_payload;\n    uint64_t start_ns;\n    uint64_t sample_ns;\n\n    ctx = cmt_create();\n    if (ctx == NULL) {\n        return 1;\n    }\n\n    requests_total = cmt_counter_create(ctx,\n                                        \"demo\",      /* namespace   */\n                                        \"service\",   /* subsystem   */\n                                        \"requests_total\",\n                                        \"Total requests\",\n                                        0,           /* label keys  */\n                                        NULL);\n    if (requests_total == NULL) {\n        cmt_destroy(ctx);\n        return 1;\n    }\n\n    start_ns = 1700000000000000000ULL;\n    sample_ns = start_ns + 5000000000ULL;\n\n    /* Write sample value (cumulative stream example). */\n    if (cmt_counter_set(requests_total, sample_ns, 42.0, 0, NULL) != 0) {\n        cmt_destroy(ctx);\n        return 1;\n    }\n\n    /* Access the same datapoint and attach native start timestamp. */\n    sample = cmt_map_metric_get(\u0026requests_total-\u003eopts,\n                                requests_total-\u003emap,\n                                0, NULL,\n                                CMT_FALSE);\n    if (sample == NULL) {\n        cmt_destroy(ctx);\n        return 1;\n    }\n    cmt_metric_set_start_timestamp(sample, start_ns);\n\n    /* Encode OTLP metrics payload. */\n    otlp_payload = cmt_encode_opentelemetry_create(ctx);\n    if (otlp_payload == NULL) {\n        cmt_destroy(ctx);\n        return 1;\n    }\n\n    printf(\"Encoded OTLP payload size: %zu bytes\\n\", cfl_sds_len(otlp_payload));\n\n    cmt_encode_opentelemetry_destroy(otlp_payload);\n    cmt_destroy(ctx);\n    return 0;\n}\n```\n\n## Design Reference\n\nCMetrics is heavily inspired by the Go Prometheus Client API design:\n\n- https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#section-documentation\n\n## License\n\nThis program is under the terms of the\n[Apache License v2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\n## Authors\n\n[Calyptia Team](https://www.calyptia.com)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Fcmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluent%2Fcmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluent%2Fcmetrics/lists"}