{"id":15767151,"url":"https://github.com/robertslando/statistics-server","last_synced_at":"2026-01-25T17:02:11.373Z","repository":{"id":51208281,"uuid":"349118594","full_name":"robertsLando/statistics-server","owner":"robertsLando","description":"Statistics server","archived":false,"fork":false,"pushed_at":"2021-05-20T06:37:27.000Z","size":441,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-05T13:21:00.874Z","etag":null,"topics":["mongodb","mongodb-charts","statistics","usage-reports"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertsLando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-18T15:11:20.000Z","updated_at":"2021-12-28T07:50:23.000Z","dependencies_parsed_at":"2022-09-23T02:13:00.673Z","dependency_job_id":null,"html_url":"https://github.com/robertsLando/statistics-server","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/robertsLando/statistics-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertsLando%2Fstatistics-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertsLando%2Fstatistics-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertsLando%2Fstatistics-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertsLando%2Fstatistics-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertsLando","download_url":"https://codeload.github.com/robertsLando/statistics-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertsLando%2Fstatistics-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28755561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-25T16:32:25.380Z","status":"ssl_error","status_checked_at":"2026-01-25T16:32:09.189Z","response_time":113,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["mongodb","mongodb-charts","statistics","usage-reports"],"created_at":"2024-10-04T13:20:49.294Z","updated_at":"2026-01-25T17:02:11.355Z","avatar_url":"https://github.com/robertsLando.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Statistics\r\n\r\nFull stack that provides all the tools to store and visualize custom usage statistics using docker\r\n\r\n- mongodb\r\n- node-red: \u003chttp://localhost:1880\u003e\r\n- Backend (for apis): \u003chttp://localhost:5000\u003e\r\n- MongoDB charts: \u003chttp://localhost:9999\u003e\r\n\r\n## Install\r\n\r\n```bash\r\ngit clone https://github.com/robertsLando/statistics-server.git\r\ncd statistics-server\r\ndocker-compose up\r\n```\r\n\r\n## Update\r\n\r\n```bash\r\ngit pull\r\ndocker-compose down \u0026\u0026 docker-compose up --build\r\n```\r\n\r\n`docker-compose up --build` is needed to force re-build of backend apis container\r\n\r\n## Credentials\r\n\r\nSet up the MongoDB Charts credentials with:\r\n```bash\r\ndocker exec -it \\\r\n  $(docker container ls --filter name=charts_ -q) \\\r\n  charts-cli add-user --first-name \"\u003cFirst\u003e\" --last-name \"\u003cLast\u003e\" \\\r\n  --email \"\u003cuser@example.com\u003e\" --password \"\u003cPassword\u003e\" \\\r\n  --role \"\u003cUserAdmin|User\u003e\"\r\n```\r\n\r\nExample creating a default admin user:\r\n\r\n```bash\r\ndocker exec -it \\\r\n  $(docker container ls --filter name=charts_ -q) \\\r\n  charts-cli add-user --first-name \"Admin\" --last-name \"MongoDB\" \\\r\n  --email \"admin@example.com\" --password \"mongodb\" \\\r\n  --role \"UserAdmin\"\r\n```\r\n\r\n## Proxy\r\n\r\nWhen behind a reverse proxy, you have to enable the `proxy` option in `config/app.js`. Make sure that your reverse proxy is configured correctly, or the rate limiter can be circumvented. Details can be found at: http://expressjs.com/en/guide/behind-proxies.html\r\n\r\n## Statistics pipeline for \"last 24 hours\"\r\n\r\nBy default, one statistics entry per ID and day is created. If your charts should operate on the most recent unique entries, you can add this pipeline to a new data source:\r\n```jsonc\r\n[\r\n  // Select only the last 24 hours of reports\r\n  {\r\n    $addFields: {\r\n      ts: { $ifNull: [\"$ts\", \"$date\"] }\r\n    }\r\n  },\r\n  {\r\n    \"$match\": {\r\n      \"ts\": { $gt: new Date(Date.now() - 24*60*60 * 1000) }\r\n    }\r\n  },\r\n  // And make sure there are no duplicate records (keep last)\r\n  {$sort: {ts: 1}},\r\n  {\r\n    $group: {\r\n      _id: \"$id\",\r\n      fields: {$last: \"$$ROOT\"}\r\n    }\r\n  },\r\n  {$replaceRoot: { newRoot: \"$fields\"}},\r\n\r\n  // If you want to clean up the data afterwards, you can do that here with $addFields, $set, etc.\r\n]\r\n```\r\n\r\n## Backend\r\n\r\nUses an Express server to provide apis to store statistics to MongoDB. The only thing that needs to be configured are the database name, the collections with their unique fields and (optionally) your apis validators. Unique fields are necessary to identify a document uniquely in the DB, validators are required to validate body, headers, query of api requests. This can be done [here](backend/config)\r\n\r\n### APIs\r\n\r\n#### Auth\r\n\r\nAuth protected routes expect an header `x-api-token` with content `\u003ckey\u003e` where `key` is the key you have set on config/app.js file.\r\n\r\n#### POST `/statistics`\r\n\r\n**Requires AUTH**\r\n\r\nUsed to add statistics to the db. The individual docs are added using `upsert`, it means that if the document exists in the db it will be updated, otherwise a new doc will be added. The expected payload is:\r\n\r\n```js\r\n{\r\n    \"collection\": \"collectionName\", // optional\r\n    \"data\": [{...}, {...}, ...], // array of documents to add to the collection\r\n}\r\n```\r\n\r\nIf no collection name is provided the default collection will be used: `statistics`. The default collection has a unique field named `id` that the user can use to uniquely identify an entry in the collection\r\n\r\n## Projects\r\n\r\nHere is a list of projects that are currently using this as stack as base:\r\n\r\n- [zwave-js/statistics-server](https://github.com/zwave-js/statistics-server)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertslando%2Fstatistics-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertslando%2Fstatistics-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertslando%2Fstatistics-server/lists"}