{"_id":"@doubret/inspector-elasticsearch","_rev":"1-c7915845517e818aa4bcdce64636bcb0","name":"@doubret/inspector-elasticsearch","dist-tags":{"latest":"2.0.0"},"versions":{"2.0.0":{"name":"@doubret/inspector-elasticsearch","description":"Elasticsearch metric reporter for nodejs","homepage":"https://rstiller.github.io/inspector-elasticsearch/","version":"2.0.0","main":"./build/lib/metrics/index.js","typings":"./build/lib/metrics/index.d.ts","license":"MIT","licenses":[{"type":"MIT","url":"https://www.opensource.org/licenses/mit-license.php"}],"repository":{"type":"git","url":"git+https://github.com/rstiller/inspector-elasticsearch.git"},"keywords":["metrics","monitoring","typescript","elasticsearch"],"engines":{"node":">= 6","npm":">= 3"},"devDependencies":{"@compodoc/compodoc":"^1.1.6","@types/chai":"^4.1.7","@types/elasticsearch":"^5.0.28","@types/lodash":"^4.14.118","@types/mocha":"^5.2.5","@types/node":"^10.12.10","mocha":"^5.2.0","mocha-typescript":"^1.1.17","npm-check":"^5.9.0","nyc":"^13.1.0","reflect-metadata":"^0.1.12","rimraf":"^2.6.2","ts-node":"^7.0.1","tslint":"^5.11.0","typescript":"^3.1.6"},"dependencies":{"elasticsearch":"^15.2.0","inspector-metrics":"^1.16.0","source-map-support":"^0.5.9"},"peerDependencies":{"inspector-metrics":"^1.16.0"},"scripts":{"build":"npm run clean && npm run lint && npm run compile && npm run compodoc","clean":"rimraf build coverage docs","compile":"tsc -p .","compodoc":"compodoc lib -p tsconfig.json --output docs --disableGraph --unitTestCoverage ./coverage/coverage-summary.json","coverage":"nyc npm run test","deps":"npm-check --ignore @types/* --no-spinner --no-emoji --no-color","lint":"tslint -c tslint.json lib/**/*.ts test/**/*.ts","publishDocs":"cd docs && git add --all . && git commit -m 'Deploy to gh-pages' && git push origin gh-pages && cd ..","precompodoc":"npm run coverage","prepublishDocs":"npm run compodoc","prepublishOnly":"npm run build","test":"mocha --opts mocha.opts"},"nyc":{"include":["lib/*.ts","lib/**/*.ts"],"exclude":["test/*"],"extension":[".ts"],"require":[],"reporter":["json-summary"],"all":true},"gitHead":"ebe464a65ee5bdc09e3be7ddfc9434e057a0de5f","bugs":{"url":"https://github.com/rstiller/inspector-elasticsearch/issues"},"_id":"@doubret/inspector-elasticsearch@2.0.0","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"doubret","email":"doubret@yahoo.co.uk"},"dist":{"integrity":"sha512-phCnESpqYOckWYWy8UWoZZy3WHtK0hwITOhUc5yKqBHWJZq0S14VGO6rxshw7leua1uRFI1yXZjGolkx6pvXoQ==","shasum":"f897debee9fbec800b919cdcf39f34a1ea977c37","tarball":"https://registry.npmjs.org/@doubret/inspector-elasticsearch/-/inspector-elasticsearch-2.0.0.tgz","fileCount":28,"unpackedSize":73892,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb/bkeCRA9TVsSAnZWagAAKjoP/2VpMfha02yxMjJw/kTv\n3LURexhDP3llJq0nxukBTagozcLyV1JHGX4A9QG5N1gkZy5EAtOeEu7V2JOW\nUW8TnCA01/hxltQBw2X/44MWm349MjXmA7PwPWuYKn6DYEpdTIyhRVCmKZNB\ntG+mFjsha2AxGWJvO45eEstk7juTOaLc5L+/f+sG0ncqyjf3DN3LkSoyONyt\nrrjKGRBWTvKTAlBTypyYIeQQ25UWCg7mFEbVOIY+r8eyThGHp+1hplhuaoPU\nlw3MyvPHPIKGYfIhFccLp+u8yZC+vTjgPEzVniiQ8G2a3HmAmX6GN7yJ8kAp\nWQr4HTOdXqH9VXdFGuPOUHnTpuNJhvC/WyLhMbf68Lq+92qcTYMP2QSwZ8+6\nTRPD8jYV5tP2mJrNUTSVWWlWCNlp9siz3jpf8rfjg4yTpPg8vxsdgtvBoNM7\nz0euWQa6azJNXBtcNPK/q1ZNaTwHH/KEzLWANoBEh0bZzbqTI0QVCyjdAGQC\noQKm88apI+QjEbNi8tUiJcsQ3yUBc/+MQsNHTF1nHltHra8MF3WJStxpLh1S\n+FcYoP4Emq8dqjzyn8Ctq61nLamOTtF8zUxwmvxdT+FM7CsER2XzZdPfvz9V\nzSf4jUHO1a0A4M3PMt8w7+qgTgyqCAfQmVXsbKr2JEaTTL/Qn6AACeOp+5Un\n0Awp\r\n=d+E1\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCWgxVCOK1MqAQ8EyZc9GeGGmdTzeuAIo5mEu3AcRjAOAIhAJjEg5YG0S/HEVMRoCiAq3aRzKmUTXdwABIWn3t6E866"}]},"maintainers":[{"name":"doubret","email":"doubret@yahoo.co.uk"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/inspector-elasticsearch_2.0.0_1543354654135_0.6878739654036263"},"_hasShrinkwrap":false}},"time":{"created":"2018-11-27T21:37:33.968Z","2.0.0":"2018-11-27T21:37:34.281Z","modified":"2022-04-05T05:30:20.958Z"},"maintainers":[{"name":"doubret","email":"doubret@yahoo.co.uk"}],"description":"Elasticsearch metric reporter for nodejs","homepage":"https://rstiller.github.io/inspector-elasticsearch/","keywords":["metrics","monitoring","typescript","elasticsearch"],"repository":{"type":"git","url":"git+https://github.com/rstiller/inspector-elasticsearch.git"},"bugs":{"url":"https://github.com/rstiller/inspector-elasticsearch/issues"},"license":"MIT","readme":"# inspector-elasticsearch\r\nTypescript [Metrics Reporter](https://github.com/rstiller/inspector-metrics/blob/master/lib/metrics/metric-reporter.ts) for\r\n[elasticsearch](https://www.elastic.co/de/products/elasticsearch).\r\n\r\n<p align=\"center\">\r\n    <a href=\"https://www.npmjs.org/package/inspector-elasticsearch\">\r\n        <img src=\"https://img.shields.io/npm/v/inspector-elasticsearch.svg\" alt=\"NPM Version\">\r\n    </a>\r\n    <a href=\"https://www.npmjs.org/package/inspector-elasticsearch\">\r\n        <img src=\"https://img.shields.io/npm/l/inspector-elasticsearch.svg\" alt=\"License\">\r\n    </a>\r\n    <a href=\"https://travis-ci.org/rstiller/inspector-elasticsearch\">\r\n        <img src=\"http://img.shields.io/travis/rstiller/inspector-elasticsearch/master.svg\" alt=\"Build Status\">\r\n    </a>\r\n    <a href=\"https://david-dm.org/rstiller/inspector-elasticsearch\">\r\n        <img src=\"https://img.shields.io/david/rstiller/inspector-elasticsearch.svg\" alt=\"Dependencies Status\">\r\n    </a>\r\n</p>\r\n\r\nThis library is made for [inspector-metrics](https://github.com/rstiller/inspector-metrics) node module and\r\nis meant to be used with `typescript` / `nodejs`.  \r\nIt uses [elasticsearch-js](https://github.com/elastic/elasticsearch-js) as elasticsearch client.\r\n\r\n## install\r\n\r\n`npm install --save inspector-elasticsearch`\r\n\r\n## basic usage\r\n\r\n```typescript\r\nimport { MetricRegistry } from \"inspector-metrics\";\r\nimport { ElasticsearchMetricReporter } from \"inspector-elasticsearch\";\r\nimport { ConfigOptions } from \"elasticsearch\";\r\n\r\nconst clientOptions: ConfigOptions = {\r\n    apiVersion: \"6.0\",\r\n    host: \"localhost:9200\",\r\n};\r\n// instance the elasticsearch reporter\r\nconst reporter: ElasticsearchMetricReporter = new ElasticsearchMetricReporter({\r\n    clientOptions,\r\n});\r\nconst registry: MetricRegistry = new MetricRegistry();\r\n\r\n// add the registry to the reporter\r\nreporter.addMetricRegistry(registry);\r\n// start reporting\r\nreporter.start();\r\n```\r\n\r\n### determine the indexname for a metric\r\n\r\n```typescript\r\nimport { MetricRegistry } from \"inspector-metrics\";\r\nimport {\r\n    ElasticsearchMetricReporter,\r\n    MetricInfoDeterminator\r\n} from \"inspector-elasticsearch\";\r\nimport { ConfigOptions } from \"elasticsearch\";\r\n\r\nconst clientOptions: ConfigOptions = { ... };\r\n// computes the name of the index using the timestamp of the metric\r\nconst indexnameDeterminator: MetricInfoDeterminator = (\r\n    registry: MetricRegistry,\r\n    metric: Metric,\r\n    type: MetricType,\r\n    date: Date) => {\r\n    \r\n    const day = date.getDate();\r\n    const dayPrefix: string = (day >= 10) ? \"\" : \"0\";\r\n    const month = date.getMonth() + 1;\r\n    const monthPrefix: string = (month >= 10) ? \"\" : \"0\";\r\n    return `metrics-${date.getFullYear()}-${monthPrefix}${month}-${dayPrefix}${day}`;\r\n};\r\n// the indexname generator needs to be specified when instancing the reporter\r\nconst reporter: ElasticsearchMetricReporter = new ElasticsearchMetricReporter({\r\n    clientOptions,\r\n    indexnameDeterminator, \r\n}\r\n);\r\n```\r\n\r\n### build a metric document\r\n\r\n```typescript\r\nimport { MetricRegistry } from \"inspector-metrics\";\r\nimport {\r\n    ElasticsearchMetricReporter,\r\n    MetricDocumentBuilder,\r\n    MetricType\r\n} from \"inspector-elasticsearch\";\r\nimport { ConfigOptions } from \"elasticsearch\";\r\n\r\nconst clientOptions: ConfigOptions = { ... };\r\n// only build documents for counter metrics\r\nconst metricDocumentBuilder: MetricDocumentBuilder = (\r\n    registry: MetricRegistry,\r\n    metric: Metric,\r\n    type: MetricType,\r\n    timestamp: Date,\r\n    commonTags: Map<string, string>) => {\r\n\r\n    if (metric instanceof Counter) {\r\n        const tags = ElasticsearchMetricReporter.buildTags(commonTags, metric);\r\n        const name = metric.getName();\r\n        const group = metric.getGroup();\r\n        return { name, group, tags, timestamp, values: { 'count': metric.getCount() }, type };\r\n\r\n    } else {\r\n        // null values will not be reported / published\r\n        return null;\r\n    }\r\n};\r\n\r\n// the document builder needs to be specified when instancing the reporter\r\nconst reporter: ElasticsearchMetricReporter = new ElasticsearchMetricReporter({\r\n    clientOptions,\r\n    metricDocumentBuilder,\r\n});\r\n```\r\n\r\n## dev\r\n\r\n### using the playground\r\n\r\nTo use the playground you need to have `docker` and `docker-compose` installed.\r\n\r\n```bash\r\nnpm run compile\r\n# running playground script\r\n./playground.sh\r\n```\r\n\r\n### view data in grafana\r\n\r\n1. Navigate to `http://localhost:3000`\r\n1. Add a new Data Source (type: elasticsearch, host / url: http://elasticsearch:9200)\r\n1. Create a new graph\r\n\r\n![](assets/grafana.png)\r\n\r\n### view data in kibana\r\n\r\n1. Navigate to `http://localhost:5601`\r\n1. Add a new index pattern like `metric-*`\r\n1. Discover data\r\n\r\n![](assets/kibana.png)\r\n\r\n## local dev\r\n\r\n### compile & test with different nodejs versions\r\n\r\nbuild docker images:  \r\n```bash\r\ndocker-compose build\r\n```\r\n\r\nrun tests:  \r\n```bash\r\ndocker-compose run node6\r\ndocker-compose run node7\r\ndocker-compose run node8\r\ndocker-compose run node9\r\ndocker-compose run node10\r\n```\r\n\r\n## License\r\n\r\n[MIT](https://www.opensource.org/licenses/mit-license.php)\r\n","readmeFilename":"README.md"}