{"_id":"@azure/ai-metrics-advisor","_rev":"106-2688aa7ef75c8207e7a27b74d639e83f","name":"@azure/ai-metrics-advisor","dist-tags":{"latest":"1.0.0","dev":"1.0.1-alpha.20230419.1"},"versions":{"1.0.0-alpha.20201006.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20201006.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20201006.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"862fdc98a5dfebd73173b61fab15fd5a12dad56f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20201006.1.tgz","fileCount":37,"integrity":"sha512-SNqSx7hITrcby5VY+du3w0E0VwtXeKYfq7Y0IgL/HO816cSDe0PZ8S9nA+JuvZkFDbABuxR8SCH3QoiqTKJCFQ==","signatures":[{"sig":"MEYCIQDRLvXxn7HsLxbgp6yxaWFa6JhyfMH0yTYrAWkZ/JG/7wIhAImRPYN3C1wsJEGLOnwnXBz+nTFwzmOkoSVSOI2Cpjch","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1816791,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffPw1CRA9TVsSAnZWagAARxEP/0k0kebA8v3uAMgZ+zUG\nPlFHk6yob6PIWMx7zq6ifQ3rNgxP4RumCROGGWhu9aLJkNyiMgB5af91GYzx\nSLcxlwZ4Pu11k7An8uZrRnowFujv9V++Kjz94d4Jqe7Q0lEBOhc9L/Dz3jvY\nE+7ENB1ijT//JIdBktuePGrB/LiM4JmUWiDEYziS3Oe2K2t8yVhR0ymkn3X0\naqg2IwxDUDRGwnU7Z2wL5vw0FLM7vC+PlZUyISE6t7XGFAPkZIjt4mCGnm7p\nk1OhM0kdeHGTOob0yx7Nd7oromTNifQqeeCZ/gPqZnEA6fPExcjUmMCehRDR\nXU9GGtT5DrEWrYrSOgoQnvleeOHphBhmldGboy8jPu9m8kUsMMSp9amrc7mv\nreWRe+J7rqxloX2Uutxu28K+E9yo4wFVcH9I73hAr9RijpSXe/tdI+wK1v/Z\nAKWCSLbNUp25QsD0qFdLZqB33NX99fUXZsjYm9ObIusHL5aMYZljlnBHYZb0\nImuVSLA5UPo9sQudBfEbgSBdRHk2GeBhDWH0Rkr9MqQTk2ukkXB8lKdFq43Q\nbiX5wGBVUyFwwVjAJV0fMFwuGTsza0DecBi0ZWVqImmh9gVvur6wezupJB9i\nUrWbzyM1Blx3paKvLyvYV/NsGMeNj5NKqW1D1de+5ay9pPh29ZTxHYWzDp1X\n0NtW\r\n=4SPr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20201006.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/*.spec.js dist-esm/test/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.8","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"12.18.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.1.6","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^6.1.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~3.9.3","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20201006.1_1602026549242_0.20415254009990158","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-beta.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-beta.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-beta.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"11d8fa936b35d5550c819d647506134b8e79afad","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-beta.1.tgz","fileCount":37,"integrity":"sha512-MJnDd+djJKojJxBRtLJ8vDczxR+/BVDfJxuNp9HABYOeP1LMWqTkM/fGSs1jRbt123SZnXc9JsPvpZkvZ3pCXQ==","signatures":[{"sig":"MEYCIQCPqzL3SqRdn4L9g6JWOw1b61tebYt7OFQYV47nJcJHawIhALdU8jtkNDOJhBWo6o43aWdiezFpPZCOv1tpTe0iYYLJ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1816766,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJffjKDCRA9TVsSAnZWagAAgVEP/24lzWYjyI32umV+8UUQ\n7a2hRXdJ7wgF5XBJZZEkfBcNp7LRW6GV4mf94WlLCEQuko5O4qIiJlUhuPAT\n3+MMvdhu+tPA2HDBMIQ1ymOII05ukIDc+6pndiglDxPAKXoubS6CVSh+niMn\ngrnXLBFTdTUNhZENdjr+MtlVgle8Owf4UGQ/WnRSJOyA9Lzb4Mgz1dulfvCd\neQ4qNT/X8bPesKCMNOuIAr17hK30AFvDRxq9nhhPRQGPttz6pNDupLxFEkEw\nGBrewh3DInH4A7A52w5RmReNEEiUIsSeLiQt9JTY2VsRWUWrSk/FLTlqSS27\nJFrnmFsRkTmSWOTKIkK6L4BOycDU3t5zBAhLDJjYjof11irj7TV8j1g7cdWW\nxVcxz8chlR4irCYpQbpkm+osbjt7+SJEbQSDYBjW7EgXpNHCYiIF4Qjx3NrL\nsl5X9aSzVqbxXum/3SC5adGQ/mXAFFpjzSGgryJ4gV41cDPoiPxjd5LwLWim\nvSnob++im45EgL8o3tXXte2E3MFyFF8xCiTYEFFJHVkm7/lz8SPH1ZGAiRH1\nF+E9kR2twgLV6qpR1gx05SvbXhFLQ+Hy23qCagQP+rT36hntYL2C+GboZ75R\nybMUsFws33rFX2t8K9cGOkgenyCJjMagtG/Jyj/F1MJDFEDTqd3FSFkYti+N\nqN1r\r\n=x9qJ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-beta.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/*.spec.js dist-esm/test/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.8","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"12.18.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.1.6","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"1.0.0-preview.9"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^6.1.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~3.9.3","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-beta.1_1602105986667_0.12173176206177061","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-beta.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-beta.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-beta.2","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"03d4572158de19cc1a26df535d52a75e4366f905","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-beta.2.tgz","fileCount":37,"integrity":"sha512-8skoGRX9VIywb5lZVe7lWe0m2rgvQOjHMZEuop99x2f2e+SqD8Ma3VgjnmS2BvjfBPPcQiNn5kA3CSzX77fSYA==","signatures":[{"sig":"MEUCID2mB8meCw9AVxqLvgsXMbUBbyJTLFfm4BUg/+/kYCBRAiEAj7wMRcIEtYGv5S6lxw+RR/WYAdg1kVtssx6Vgu8up7c=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1895629,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfqzz4CRA9TVsSAnZWagAASCQQAJCdomPKNCVmt+4XUnon\n8+2yBXvt7L3Rp7YfmfRbNXVQJ/U0JeGEv8RK46/zmR20PRombQT2KUJGAFUo\nYxgUPoxIz9RlIr+KQJES8JKbar4wJ0nwBdAsNYJ6cyefuPiAIu+5GJ+I1E1n\nS6WBHC62WdHlwWHuhgoYACnwQ/VN/CJEZ4ZBYnYXFZjKQsJj/9z+tYJ1WDXe\n0gWVaQEYFPkJ2aNGzbaIterpyyb1MTWakps5xrpLjF5LRqe+czowzvJ/X6ol\nWy64FB+eISp/AmAq45vT5EB7cSORWl6ZfoB+0ETuxslGi/pfqKGN4LYV726j\nJUlpYUN2qdrEiZhuekdfC7aVbMBNvlZf0u8THVrXqexseT8XUpkSo9Aqjjy/\n2wwTwBb57QnHni2Inc+ZRGZZPIn0Nh+GM4WjfWrk7pfiKtxnJANzRY8ZUHII\nam0PMHmFvDgA1tmFeX3550wgtwCLpWYArVBrS2ScynPk4t0VewL0LV3n8LJX\nwnms6wo/zuC/QTgp+llG1Cryxs7rlgb4VPfRnpR0Blf5DrqN6IOJyfzarwJ8\nwZiOzxKYJapMqi8rtHR06HdHeEBSOrTPqX8ujeHvaNZUfvmcgMoE81rzFTh4\nAqMAOo11CgmHrt4zBb4WJOtZJSWlLe5i1wqfT7rvlSLrmi0gCTorU0Db5M25\ntiKV\r\n=NmCF\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-beta.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/*.spec.js dist-esm/test/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.8","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"1.0.0-preview.9"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^6.1.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~3.9.3","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-beta.2_1605057783398_0.3043834713271274","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20201211.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20201211.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20201211.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"db5d32f46d5a327b4b81bba794b911d0cb362c1a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20201211.1.tgz","fileCount":37,"integrity":"sha512-loO/LRSvnWfQttJGoOKUbaNXtUsOT7pFdOhwEoKYtJ7D5lMyKMfpnnnj/7/6GaXpF7fYXqkW4+RE3ZZaUsN18g==","signatures":[{"sig":"MEQCIHNckUX/J4fFcCrRovnyM7hsrKx/CEttpWW8DxViQ5qcAiA1/CHpPKZjIs1PokWK90c6kZ+B2anKHoEhU+87idXm0w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1895770,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf0/nuCRA9TVsSAnZWagAAX2UQAJjJTOtJQZZ251uP7Flc\nB7z3/wcJok2LvO94453C/w2/4t8YYEjKF6LRhI9SQNwad9vx42Q9Sc8MPtbF\ngPgVrVcGl2iMfcwsmtXBr4aw98jyt7wis5oe041vJkldPTkJTHZaUVDwQZ56\nZmZlQg98OfrHiFYjLmoDeuLTN6mvdGsjYJmbVFaprGH6yZjh2+Eq43gX7kcQ\nkvy6OiZGBOUL5TCL6b4IwnVvUb9QBD89n6oIvXr8Ca4hBPIETSNQD1PqzWy/\nilCnF6FX+vZc/pJoJ+KbFIsguTT2Nue49zFPKktNA5Xo2t6wqFhLdsCOcaLu\nXiwDHhc9jASt7R8mZVpthFHsw2BXsWdb+eXX6pMFiq1QhrY7KaKHEUwAsV0l\nFRleLFfxqudi52hwrG0DNvTjCbogGuxh/vdAvv4aAoN7Bt2BgJhrcMuoZnec\n8rDBILv6BpMEEIS6xitKKoRwk1ya4MxrcDe1gqpYtxJR8DywJjd3XDrJLGbY\n6dwHQuNBOaOTSLYbGOaHK0KIxTYc84V+R0fswJXmGbPcDuysFIq+xR78o32u\nLsb4H2w8ck73unPElPoXlhAetyne1FKHdHnEL6gCjkBpABc1idMo1RKk3TYg\nr5GbxBsBLiqpmPKcSE/nGuVxigk4I8etzVca6RqL+SBkMVUtFXFPBWSoTGFs\nMC3v\r\n=bj7p\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20201211.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^6.1.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~3.9.3","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20201211.1_1607727597726_0.3065145997352945","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20201214.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20201214.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20201214.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"82d0bbcc4e003dd495c81aaa44a111c8a291f40a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20201214.1.tgz","fileCount":37,"integrity":"sha512-cGPXEh6O/ObDSZiuIxzu8KFsSGWQ9nwRMY1IBtXgvY78kebdFh+6ThQD65NMHn9ggGFa1K5ATq8DqkiRdjTj9g==","signatures":[{"sig":"MEUCICMWDYxrYT356wwUsi9fUDpPzRXlLZvNyl2Zz+/uzU4aAiEA+XUUH5BkTpXSc0qaeQbhOdefahxWTvtcnx7bL8dpca8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1895761,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf1+7RCRA9TVsSAnZWagAAuCYP/iGUXAW3QD6RqKDvW4ZZ\nrnsRhKJk/Bia6UiyefDwHlP5EAVCXgSlcg0NJ5zzbSguFMtqLnKWRvzYakKg\nmN7ONtwGR7WqZaLY92j5uybgO2cjLXJjmkoIpegFmK0aCps5mVtpPWFAuOk/\n4WlVuK80w4oXNAhR8w0uvMCwn2bLkHxuGrfTQqjOlcjSW05wPd+xClUCJkdB\nvyEGNjAdQjOEwAXPFB/X7NZAl4MnhnWED6alBpnIlRP/uV+5oJ/ryK1f+8Pp\nYHlQ+UNOLj+FOhJlSOj3rJUNstz4eJqBvnAJtyFdg7cVArY8sdkkP29KH6Po\nmb4+jYSXZmfTN3KKK1IhLAM+HAYuame0hryZ8QVGuQ3vEQvaaJXkPac2nLx7\nFPpCiL7wdqWZ5L+SjO12TZaCu4AsXzqZiU+ILFS0xzy1JJnNIS0w3HTd24+X\nc3j7vg0dhhocyyd+Vk8zGRT/k+evdmBjTe5ivZawWiG7fG38KjFnPl4lzQbd\nIULqpp3ROPbCS4TXVa7Bl5/ccjkscxBuU1ko+38HXBq0HIOc/Xf3HKs2uNsW\nO2i8oYw5rqT3pGMiwj/0MArXKWcAKYH8DiM+ITjLYior0qTb39tDKf3RGHaD\n6kz6k3AbfFPxEPMfnxfwnP3Uhi1IJIzlhrIWQk//ts02unLcCzeBSjzm9FP3\ns+ir\r\n=VGXr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20201214.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^6.1.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20201214.1_1607986896963_0.9579799586351792","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20201215.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20201215.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20201215.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"1180cee3b3bff01f5dd38163b08cf2ee74f546f4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20201215.1.tgz","fileCount":37,"integrity":"sha512-bwGANLZIUBz8MntAdvLpdC8ZoPladkrFNwRF44F4x+FfitNx8gN0gB7uHT6afTylgeTCW3/ZHTDRW5a4GAQiKA==","signatures":[{"sig":"MEUCICz0Af9kR2NOW/c+yBOoF86ixh38wV3w+qYy6Gu7K7TfAiEAyZo9ZZQsrZ+7nAcG+VI74Cx5arKcyDoAf6+3e7jkQFc=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1895762,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf2T89CRA9TVsSAnZWagAA2KMP/1DNlvrXrxKGKO+98JQx\n9Waj/5sMktI1WfpDjK7BBaCU7WoAeW1tY9rbBID1Y1QqIR+Xi8j0Ago6Ic/e\naLh+Y8TRycTBZYquAdq1nqkfvlhaQZuxUtURvC3dCIQd5Wyvhh+KrNfsCs/R\nP+slzmY5dQCtpy6IwwzpV3+LPKgbjF00cm0UvyU9u+FLSfAv7L8iezEoWYxe\nMsltc2jaO0iyp7z2v0n/UCpoxshmqu5nfijJwKi9xSdbDZKrOClwrq/E+EM/\nJBgeApF3jOASVzYpvA9yM0IQc+84VoEjMbiefWvXccXuQVcr1FRUuUsATCdJ\nn4D9V0dzx/MK2gnnhUBsCtPIRQCK68n8xfuKT0mgxMxdns1wLGGKJzpoxPZX\n5p6zUwEWXkDzOOUPKL/GKkMiXn0+2kUwq5ddLxHrBQxmCyRCftf802y7sXgt\nMdogrbmGPvVB8QQxzmEgmuCctDlmp/7b4c/pQLAJ0Xih3A+HK0QIqF50FNWV\nwr3rCMz4R8RXDrK/7O///YcDDEqFMdEXnszP0t64UXaJK7Tt47MiNN+/0IMa\nQFFPBsDELsmSBz/QBxoqxOm2bXFRYEe26waius1aLIugClC7PoisfFjTKcrs\nWqHQ2jQdiAzPEcU7o53ipyZuKu2HUuZOwbai7C7XWVVHrVGonD2DBYu0It3b\n6CkJ\r\n=4fRq\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20201215.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20201215.1_1608073020892_0.8074084485142408","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20201217.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20201217.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20201217.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"849403acca6abc2b09117bd8771b787077dd945d","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20201217.1.tgz","fileCount":37,"integrity":"sha512-y5fYKZzcYJAr1avNfeuhdWG+UQPSNwkvGkLKI/i1W10gOGUf6uGU6rJOEPct8koPwKN76B5A9WMpCI/LNk2bBg==","signatures":[{"sig":"MEQCIFF8zmMGZkiA0vcfca7h6y1l+qNFYoTfr55vKGoaJMXSAiAYtjMPo21ObPA/oifvG2ldaqY+Jg9UA7Cx8FoFWGM/OA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1891848,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf2+NDCRA9TVsSAnZWagAA+a0P/1tSEe2VaI0aYgVUZZ2Z\nPMV9Upkdn8cDjddSnyxoMGoa+UMJ5Riid22lnU1yyyeIBdnG2noLyZUPADIu\nOOWy6AUG1sW/G5flTGGsxvpg6+o0irrUdUn0PzTbK/hMFg0S6Ri/J/JvHAkc\nhfeiVYMMd3Qozm2ISpkS4kYJmoRoaav74T7QaT21Cr2Io1XHr1IUvjMB6436\nbRyWpBI/Ffr+3/vbFNkehMIjnyV83aOOjOTxtcG4IjTs4oVC7as2Qs8vEahA\nXq5cIW9SH18VriSlxP6sav1pNhSGJhIzTHbqgS1dlcUNcryLu+JO6Ch4tK85\nEl5rQG8isDrkChan0Ff+iDZ1QUy5kWYBD5hb1jZinB+0qGLLZ6fCYSSluCJb\nNkMDBi2LkwlFVYwOpijdc3TgoqnNjnaFUe22cvkAeLa30xHp4KFiePpecBJn\nwpKXxU6X0Xd3bD8d/v6SvpC3HyneBe5o3h3YC695Rahr5JHrMHKFRFoYkjUO\nfKoGHZu8LKNWzVTY1IYrTZIRF1qcx68fhmOPqpVFIcDeFPLFwNZdJ99fozbn\nswtCr18WM9ofsBraoht/PkPKv7hYVLkzu4kvGUQmVG4OFNM2Qk1KITn1robo\n84w8TwrhxwffPCdzOWO9vPkDAs9IW9uhFQ+k8Ig91pzHgo0cjvx6id+qKxnW\nICoW\r\n=XTpF\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20201217.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20201217.1_1608246082717_0.10547980151644731","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210105.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210105.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210105.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ff42774f522146de842e831e78789e782faa401a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210105.1.tgz","fileCount":37,"integrity":"sha512-dRz6WM9gVsfR7TpEst3PO1llOKIT6TXw+Otw6elKiPxDXIxBqALF8b4ZiPpSn4lnW8OxFjV9tHgvHZe8B7L10A==","signatures":[{"sig":"MEYCIQCc26ispnVFIaNzFlArzO4udvhTvhWzBmChUWF3/K5ZYQIhAMfo/Tw02GNyAaH7BgrdjuO8D2rV7a/qTgZMGhlWQEhw","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1891867,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJf9O+eCRA9TVsSAnZWagAApjcP/3prKDRJbh9+eRgv2bHn\nAU2Q2vHkVdXR2K/LZ7xjxkSFgBoBfThSa0r1kmxSL4ajWlexX514ERaXdCTf\nvzXjnZmf2WE1AbJzSp2FY5J719337rOYj2LHDvDIFzbUP480QOocFgKgom5d\nkurQFVB0fBeUyGaZgVO1ttwsanwtSxNMEIV9GgrpWPP8i+Ki1xHGtbqRXLFn\noMbOduvlxB/R6FCv/2UPXsAyqxLbJ4d+cuITQOYvLYzSmFi00dz4YMk2LO0a\njENz/N4oI4J5mMcZoPQ0MmP0LAnaJ8JNIwNNxTsLuBpgNfnKUubchOEu0MHj\nWfJugaTruJhdwOCuAZ/Fxx7fFsaqzWiLlFtgV8Ig4TkstvLqA4yTDUaWMNjO\nKvtTT1iDyxv+of7cAFOMEdcwXkPu/Pmz+g/hoJarEYlxGQfxTh08olGKgQ26\nUUeBxbnAWl6Lu1pxyy42Tzlj8wrOGxHPc4Zb3YupcFJCdAShPdkYi/I7Ljys\nnqL6A1/pk0cYI/ZFuKfZcQuZ2YsVod4YOntVMB83L1Se8FIGea6+/kJGWP+M\nGfGD+IFWNEAYAuqnMbrVEl0qIcZLD53KOmaqdxEmELpsleCD5VcnBNrVUtxb\nRsX1vImYbWOx5rM2B0B+m+dv7VVYnEoxh9C1pIO1NeTItXjYcsvEIpEUIfxD\nrUgB\r\n=n30L\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210105.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210105.1_1609887646414_0.19346595708362613","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210115.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210115.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210115.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f4b1e09b07b40809247846f7d3a2070c5aa3de5a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210115.1.tgz","fileCount":37,"integrity":"sha512-F5a8wOY5wZYvhKJKC4npNIN8qvmSHmfaa7wli7xO9EVhRy7OTAOu9y+XfdsrUOCYux1mV7F0Rv3eiBZdqhzFrw==","signatures":[{"sig":"MEYCIQDc4RVO0s3KpS09W97wFIlIzjbIKCiU/a+LwEa6r9V2sAIhAOhLSjgEugwYj9wbk7MgxQVFJyfdILDMHEJLDSI0SBky","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1891883,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgAh3iCRA9TVsSAnZWagAAqwEQAKQYq0Xf1OFRsZl2oH0F\n0LnXF8rG19wiLdvGDWy1/IZOGflJOanfWQHcD7BrnbgdJg25d4HEV4PlDnyJ\nyT+SFExxp6Tf1LheuCTU6uct/Vtm2QnGAaV9ROMqQsTku5cECWrn8b2cthX/\n0b0Sj1Wr9tgEcknk7XDbG30rd9+sj+wFWN25J2Pgp7SICxebVOc8yFZSsDj4\nudJ2K51OO8QJVNOsus4KFb5ew/AXY2iLnHfxvdsqy1PeyczqK5ZdCs4Bu15E\nkdc6dIQI/+XN1pRQvuTIvtjaArq1X6SY0PxNqc+3BPv6l+2K79FTv4g8roDR\n5ZMRxCfSY0q6rj+cPvgYU3A2YPCR5hgL2lGVsyLPGtXFec4XgqVwEIiB8qtl\nJC+CM+MEpOZzRr/BlCrRAxuPOivNwXao6UgYsmAF97bEmHPGs2y5zRuNjhsg\nYVfyHuvZ2C/moJDacz/Rk8OjwIHhNB6SguH4qwsx8wXHVqMek4VBsqBpxEJa\nxkMPDaAPCj0wmVwO9KT0qi841Cy+xzljZesedG1mbDhx4B0iuWv7moSjBd8p\nLQlUOTtk4C4kizpwEIe9hz2hWk5MuIeiP6KmeQl8u4tF0Qkac/onKFSBBS/4\nMlVNoT43yVVp1KM7MDZJ9tZQMPBpOr45yYa8bfqmKDVWAYIV9kcCO9Spw46Z\nBQ3M\r\n=UvkQ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210115.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","karma-remap-istanbul":"^0.6.0","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210115.1_1610751457889_0.2555203367914012","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210122.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210122.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210122.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ab748891c1b98de2e80579a3b8a478691d68d033","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210122.1.tgz","fileCount":37,"integrity":"sha512-g0XllUmmq8qgkR/SRka/3R+5FU6ZKuasWWZWYUydSrNUOWGfbjo1oROOnRaT/b0tnd35+79a0ltFVz3mVH+duw==","signatures":[{"sig":"MEYCIQDkkRAiuFAUr/jNeEP2YVa20+24rXvg8BPCW26FkTalzQIhAMjSLoONvKxQoDrMt2LB6oOAaZK6nEFmn2w4t1zUIajU","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1891885,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgC1lgCRA9TVsSAnZWagAAe0EQAJNAQ6r2ng4FWgSJuyB4\nTddlLHaWW3k+RiIeC/oeyWFtKUorC4pwj6+GAMAQWtughROqgv5s/Rnf3/hs\nPIO7Eh+DrF1d5xmiLmxm8bkOby4Oc3168E2lDSJaEfhU19xbGCr5xG50TrHA\nXG4SBlXzXTeyhChkRrlnvIdVXIhmE06/SSJ34IWqt4p1KXAcSkpYnUmA+VKC\nx67skzsiO/NvlcYl4KqMW4P63hfsSjtL0UPbMujWZ/L+tWC71Y0rZdOj7WXm\nc2hiXPQjIXr7E7RRi54wN8V0p9Z2GShzFdj2zgzOrobzfTrm/5HlXbVYbtEr\nAnw4WBCmyDfH6nXEjbKACJrDeOvTJZEZbp5ZIHF/5PlOxKV5BPwNMwqldxCf\npKn3qQaiLgCf2CaqCi0NbsB7cs51KW3UuK+dNY2R8uGwp/N1eVdTrYJFZrJs\nffKTjWBFld++9iHYou2hFcVwCgMIOjeTGHRgHimemhuxuJHKVTb0HenFvymX\nD5L+JJHEadJQEDWN3+GKrS3EO01JWM6j/oeEuIVMcfRXhtSzSWf7jZisVlpT\ng+FkgeCd68bjRgjLwh8cgOIBQsOVKVBnEoMg0qJDvA+DnFYPBE96ffSkmK9J\neDxyLRmO9y6oClOLZKLNClM9s3kilwUX1MXlxj6/Ej0aFG74swFJHFdVghAr\nAoFD\r\n=WSi3\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210122.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.9","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210122.1_1611356511664_0.7992965265776482","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210126.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210126.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210126.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"e37a7d6666c0c232ac0ab0506de18e2df2c11a02","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210126.1.tgz","fileCount":39,"integrity":"sha512-HYO2y+/jB05EQOJPS0PIZecuNdN4V9kW2vm1+akcrWq5mCGU7YUQgvEJQc+t0MrP3ig9pGfFDA7DO36iRO4pzw==","signatures":[{"sig":"MEUCIDXqKTIFfPzYIE0BEiqpFzh2lnM3/muO1c/B4bqFH+u+AiEAxDLkCu5bpK0vSjilNqL7lsBMTVovfPUwSFYJjKJk8PM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951290,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgEJ3+CRA9TVsSAnZWagAAqnYP/2zNNSLCVR3qQLHaYI84\nP5O/rBmstWdbCQIGZeXQvc077XlRTeAa+VzTCkzZTdLd7WDJuXkcXOJxc1CK\ncULjhg4NtvNssuv3a17KJKvCuQVsb5qG+/n2kf40YT6q86KGjysWjWkLnoaw\nOKRlAVVDhAcar3NyLghTteRDWkApmKyX2dNOIynWUoIdTlvt31p+vneG78kT\nUON1gcNjdKwtZGrUQlCG35CYQeN4gsTVlpuzH6PLnFTb3jwc8ColOmqHSy8t\ngj2Iyf7hNmZpvnruQNPSr4i3jzn7kC/ODAJXC9svJsftKBd91v1KYvzy435R\nulWzIPLcucxyr66K+ZU5oDXBLclcz5FJkK2llg9KNUREaR4kjUvcLHxrX2dA\nw2UN7ZSAzawXl3mnahoUD6uaVdmNPQEJk0H470sy/60q4rMSKeJyBGm5xrqe\nFkzrycL8Gv9Foc/MNHYx9M+ekZTsgFGH4kSwwQQLuir4YY96EOQH03LLkHND\n+7rWAp40YFF3kq54tnSZuDezu8Y1UDvS2pAd7/B5HfcfrHutWVwJQOXw8F9U\nIzIQCUOdjFB67yWKLa2DZRAYKcULi9SvuSbqJ8qt3XefnLXg0xtiMmkSYcOV\n86ue75cIfktmjo31IsOirLn3hjPHJqQ23y13uyqQ3JcSwQ0ly2bTnnRasltz\nh5kX\r\n=XWKH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210126.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210126.1_1611701758252_0.6521624990190871","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210127.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210127.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210127.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"6dd2686ea715c11f1bf7808c4da1f390e4096589","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210127.1.tgz","fileCount":39,"integrity":"sha512-mVgfSWO/d+6pPhzGHNaGVIX7JTv5k+1dGUSXqeMnLiLHaAxy1C/xsQ9YGvFQgjynX+zTgxU9bc4sIyWtxp1tqQ==","signatures":[{"sig":"MEYCIQCOf2fVcCzbWcqr8MWWprktYP/5YGw0WAUIERCEyzj8UAIhANj1QWeOy7uAZxSGX15TEhGaogNSN5i6H3v7yr6hYBVV","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951242,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgEfASCRA9TVsSAnZWagAAsIsP/3acRrnEV5QO+liLt4xS\nm6b0owv3X3ARPaaRTpVdbMx25d9gOb4GOMgHGbXQ8VkCoZCRbGp3wEOQugJn\nq2htUk3IQqux3sQXwg3ohXZ86tWRfWDTE759HtKyaKL12tWFRzVKwyMzmLHU\nkfECSLSXW0hjzC6yye42CKZxcAyOFQZ1+47ceszsWuIkOmyaXmdfaF+M+LHV\nGG/gaIaLlWGHGdEWsiD2AdrfClmFRo7jPgjuAufYOLxsi0H07pSV4A8dFyi0\neUy0vdw61TRwdnyT/867jwGV4fMHaGh+yTqF2vKHlquO6Dm+DvlXmr0Quysa\nBfgeiOKFvjP6T/9AL/Ye3KJNVrRgD75Refno7e7kD86sRsrcniSI0Mx7NmBc\nIJhsohS6JMT2EjApv/P8U2BUctgqmN1rDy6vdhCIeAB6qGj5unwkI9Nk5Ol3\ngJcAYnUkB1UPrx5+qzecEN2Bd5AdMYxzqcH2/lXZS2tYi+B4Fgm2pkJkdLZc\n+2rAuDspwmGXjUUFyJ5R/qhIb/E8TuW/jF6F9IGv0WBnPFbmZZfy891a1MlT\nze4/MweclTs59yl0ojArD8N680wyvZEIMi50d2DXv/jcer2Ay4e1T22LHwgS\npM/lRfGsPExv7hL7b41fvxY9CheDHDBfs0yKHc35AQce5NTQs9djs81F5OvZ\nVHej\r\n=kpiS\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210127.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210127.1_1611788306340_0.7418798879595538","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210128.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210128.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210128.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a08b08b18b1e596368b56a3fb1241b5b00372f05","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210128.1.tgz","fileCount":39,"integrity":"sha512-hWeE+dKI01o6UhvbcCSmBGGyAPXXYKAE2cqN1iH1CFKJsbtnPcmy8rjhLsDI41ma9Sil7C1xucisWLHFfgsRwg==","signatures":[{"sig":"MEUCIQCmfTruD3Gc2gjQwKkwKT73TMzjuJ+38Y5wp1+eOkD7YAIgHpbfy89Y+nCECKEf6ms+8AJZNahGKXVtSJtAP/Cpnm8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951830,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgE0EACRA9TVsSAnZWagAAQp4QAJ4cnETlCznFKAM59RLX\nZf/f0tmCJCe5lVJGgHaJF3VWTSJa7kAstNafrrrHBDQcEcIRaMjDqy4ibkm1\nMu64XL43xx0XaIrDZSUnnEWtvalg7MQs7fGSjiu7ODZ7IIj2WbaPPqfd1Y6F\nCtwVFBxVrev3cHcl+Cd3cGSinFx4WwFp4Ewb3Z0iuBhIVxAfhIkNcXrNIuA+\nYpoqxybEJV62+TR642rCyBPlZNi6PeRU+D1tK8zBBq7S7FLIHQtWB7QxSQX9\n/d3iRgB+kYmsG5bOic2dqgGLC5AmZpbFV7GudbaRTpzpH1mI4xinTTrGpfbj\n/JA+zxnKVw1Alppi3JpMOic3gnD3/nvG9YYrWgYkAACK1D0Z8yRURdmnt8vN\n098tGH4OYF/bzVlMS57bdGGEUzlQbiltOfyWiLE6rNK90itAGuLXZdPp+Ph2\nsaBY3b38Hac7cVObgDmqA6NxV3qV0yrCiuITjQKAWbYmANU85Biy/hS89sxd\n4F0b0A4xjM7ph5qyFG2R2VWU8W3zhvlezywfXrx6n48HGF1C9lGRENP/ZfgY\nAb3Whyj19LRrYc+h6tHXN2Xixpnw2dX2qiHAIOIezx1kDxN9cFHXBn0sVXjV\niPh+Mwv+uOoz1bpDCTy9KxEqA19f3Q+XcZKQYpS0NrZ5selSP+DfE75JZDrG\neEAF\r\n=yuM5\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210128.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210128.1_1611874560347_0.11905382973400958","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210129.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210129.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210129.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"311b54e65a9db0aeda4bcac349247db77195b9ce","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210129.1.tgz","fileCount":39,"integrity":"sha512-rAMI5NY9TVKCPfl8BTYSZtKAaNuBGryQ7/EmgsTpjT5CoCYNs53xQi6YEYEysBhkiHexuG7iEZkvjfqWv0vszg==","signatures":[{"sig":"MEQCIHfAOcU1DXZDo7A1LY9BcFzpJOUfTmNekWFvgcIewLXxAiBxTGTr0B0HOqY3ymkhiowoYXNueM13PphqqAgzQZXswg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1957884,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgFJL9CRA9TVsSAnZWagAAfuYP/3bngodMAkHScwuBFoYP\nMsMMoNRiFCYFb28WQ0VOJe7QpFc8ZL3PEOp8aE++SCoGSSENkMqZl1upAx8e\nyje2hy0GjLZBoOL4YgbooKItFKL3/oXpAKMTbcxL5+wbeAFG/FnkvoAmbwlE\nsZjKWbvAKsDIzYNmxaNAfEO7D6DiZxnSoGaQcdT6x6+TxQ7JV7fHrOKrl5CD\ngDyOJpf8Quk4wZ5VSpY+TPrvFkw7TovXe+ZAmdkSlBFZ1mDNq8eETfSBjvMK\njHGe4uwkgMTZ5Y+DdLTpsAreD9/KrSh3mO0uvmQemxJSWvc7S7S8FQyVPmxk\nsGjrUYbUcB4hDsK+RXwvpycUBLtsuZE/3CcUpt9fE3wBVTxnEEkMarI/PVkf\nLKbf/ecYcwuZL769/3LUbpmpxa9PONeHRwQCgdKtplZI1jDMPQe+J40U+61r\n04yZloEulzfgC9VFfVuovz+xIqMzbYwyI9G+DgWA+RO4RWatFMWvTjwVPPrk\nBZgUE+T8oVbp+E8rzFUURjXvi1Ct2LhFmJuXODyu7nA8A50TOBTA7ot4KXoo\nE0OFOwmFNWvM6CJY2NeLsT/I3dzgGv7ovoCFd8D1JNzWGBm7xVn9fxvLK0KZ\nE180avujdtm9hIQCaoIXoQDNrOvXwpwi9wkPdUVCSiPQ+LA2yenEdpBsy6Cy\nPVBn\r\n=1V01\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/home/vsts/work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210129.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const created = await adminClient.createDataFeed(dataFeed);\n  /* To get the full datafeed object, you can call the get method and pass the id of the created datafeed\n   */\n  const result = await adminClient.getDataFeed(created.id);\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  const created = await adminClient.createDetectionConfig(anomalyConfig);\n\n  /* To get the full detection config object, you can call the get method and pass the id of the created detection config\n   */\n  const result = await adminClient.getDetectionConfig(created.id);\n  return result;\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  const created = await adminClient.createHook(hook);\n  /* To get the full hook object, you can call the get method and pass the id of the created hook\n   */\n  const result = await adminClient.getHook(created.id);\n  return result;\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  const created = await adminClient.createAlertConfig(anomalyAlertConfig);\n  /* To get the full alert config object, you can call the get method and pass the id of the created alert config\n   */\n  const result = await adminClient.getAlertConfig(created.id);\n  return result;\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210129.1_1611961084894_0.9233433614943327","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210201.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210201.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210201.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"4229ebd31937ea3a5c7b7c3973f3ee79586dbeb0","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210201.1.tgz","fileCount":39,"integrity":"sha512-NcFdQt5LJSBbexDyP3LBIKGRNthhzWD7f6NEGUS+tkUmuBwS8SYxm6n4IRzcvwRIRuXydBmH+f/MEUIBAFP6vQ==","signatures":[{"sig":"MEQCIC65wxlt2ix5zENCDY6b4WtE/593q0GixXCGIIlbHWYKAiAR/Qb9kA1LXeJ5Nc9V/oLcxcTHUbjR9IYt0lnRUiEupg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1958120,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgGIfQCRA9TVsSAnZWagAABhsP/25z0s4QpokhJqqgEvH+\nZyTeqJSlkE30Ouj+hepmbpqVxzVyTO8UfunwtSajBeuwNWzpfwlmNZvpEOO9\nExS5uKGWDWQYHImkVm9fuf6bNwBulRtYvihwOVPMd/uGLFR/KI7ywlMqZK7e\n/KT+Ar+Xt9YxceF5gGrLnHHssk4n563ggava01tdK0rapzXxDVxRrZVTF8SX\nEYndIVRucSr/dlqgfbU1wICketX8J4Mj6lguUwkxGqW4wTa4yQOR1UdJHGfu\nlp+5XlYzgpewdR/MjsP6c08Ii5SK686/0vR6bAL/fWdcNMAb5PIRzqDhPRcK\na0YEaarMfZbOdn8Wy1b6SV0h5PKV0wkT2TctqBFYFQi16HG3pqyxRzjIrCJA\nR+FFFPoX+I4+p3Zl0QHVZgA5wQP2U9tKIif+ke9B5uRZImugOTs2QvrCnBod\nqvXSHbg3sG/oZYPRRkhcWYmDmMBY4xwqZ0xYMtDGFDKexDBtheK5qpdqqeF0\nJJ/GT1ibjCcNEotWrfeG+M8pIek0NNpoaIEvLQ/PqbfkL9UF4mj/YXOdE2jx\nGlipM5gYSecNJH0zdeNRBrEcR09lg+BsBWV7QpIl+w39UDIkiu2KT6yma1nl\n4DdYv5SGCl8uFmotPJbV0O8kYLm4JtxJ4duBOX0RF1+ieTgRDEqyHYawDHSN\nKUfw\r\n=XNe6\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210201.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const created = await adminClient.createDataFeed(dataFeed);\n  /* To get the full datafeed object, you can call the get method and pass the id of the created datafeed\n   */\n  const result = await adminClient.getDataFeed(created.id);\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  const created = await adminClient.createDetectionConfig(anomalyConfig);\n\n  /* To get the full detection config object, you can call the get method and pass the id of the created detection config\n   */\n  const result = await adminClient.getDetectionConfig(created.id);\n  return result;\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  const created = await adminClient.createHook(hook);\n  /* To get the full hook object, you can call the get method and pass the id of the created hook\n   */\n  const result = await adminClient.getHook(created.id);\n  return result;\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  const created = await adminClient.createAlertConfig(anomalyAlertConfig);\n  /* To get the full alert config object, you can call the get method and pass the id of the created alert config\n   */\n  const result = await adminClient.getAlertConfig(created.id);\n  return result;\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210201.1_1612220367729_0.03134239690865637","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210203.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210203.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210203.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"87b4850a17714b8c1f8666381219e151c43779d4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210203.1.tgz","fileCount":39,"integrity":"sha512-+jzyKpGKud+h71d8CyHfLBso8FCIkARxY2xJOH/qsMrs3zfEFcnXP7DFhPLYsdOWD2LfPV2Re5S3yeWR+KOfNA==","signatures":[{"sig":"MEQCICjXhjxb+7nn/5H9GSZ1uqjCQ5T+083b+Wl3fQlgqmPrAiAvEQ5jfi2TD0UTo9HpdoghPr9RqULePj3FCdHGWsDemw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1964988,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgGypCCRA9TVsSAnZWagAA52sQAIL3+0eZMPnT9Z+f8J32\nE7NcExA2kMp+PHoH0tCS5JOyxUDzQtjLCJ7NawVYtxLOQdNuiVWzZbQqjDkr\n1rrArp3hSakTMNjC7E19XcUh8GGPB2v0BgMLSBxMe64BN3Ks4/eNATsg/l00\n9dsVaSJUJeYDLfUDB+Vk+2Hbv7QtFfMgdBdA7+HmgfnMNaCg07AUMj0UyR/m\nDm0CD79g7Z36ywoIo7W+ra+HkBIiAaytbS6rso4mP1MXPjRtLNxIr60LXbzR\niVrFjvegCinqGDl6N4d6+/cyhhVRpUhJCe/ffHaAKdaCreQApF/Tk4lL4WIQ\niNiNKtev1aGdeidlAyYJIL0qtE/Bd2AlQ4nupfS2rGczZo2UzXEQpCaPlBuh\n1BMl70R13xz4zYwdI4jvcQRDLbNkwfSIBJN9tx16eV37CWRS7lVr+58LLKX9\naRT58vNQeVyHHYtzTAIj+WLetj2W/eLVKv1GY0bMw2//g4ev0mz2jXoD/Bbp\nYwKIIRoN7C+H8Pv5C8XI5BdzHGwGI2U2JGSROQ6EqmNUOHz2iJqU+DRSS4EN\n8DQjVMLeQywIpZHIU5v0xy6dniwEwCHQdDEOAJgyr8JOQkSiczACOXHCA/dk\n3f38KF0QXBpeqGZ+gtF2B5UypJQlgTDdRC0bA9LoPsO/jXgV8f1TdITkmhni\nDeRA\r\n=nilG\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210203.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const created = await adminClient.createDataFeed(dataFeed);\n  /* To get the full datafeed object, you can call the get method and pass the id of the created datafeed\n   */\n  const result = await adminClient.getDataFeed(created.id);\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  const created = await adminClient.createDetectionConfig(anomalyConfig);\n\n  /* To get the full detection config object, you can call the get method and pass the id of the created detection config\n   */\n  const result = await adminClient.getDetectionConfig(created.id);\n  return result;\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  const created = await adminClient.createHook(hook);\n  /* To get the full hook object, you can call the get method and pass the id of the created hook\n   */\n  const result = await adminClient.getHook(created.id);\n  return result;\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  const created = await adminClient.createAlertConfig(anomalyAlertConfig);\n  /* To get the full alert config object, you can call the get method and pass the id of the created alert config\n   */\n  const result = await adminClient.getAlertConfig(created.id);\n  return result;\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210203.1_1612393025650_0.530383861475167","host":"s3://npm-registry-packages"},"//smokeTestConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]}},"1.0.0-alpha.20210204.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210204.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210204.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"b0656f858fc6f4bc8630f7b5871d2f0812945c57","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210204.1.tgz","fileCount":39,"integrity":"sha512-8hPwGigpmSqoo/3NrakDkKV2u3fKd4ChhufpU4Bo9pFIpeaNAZP61pOW38sOpagGrrRlb23Zi0fwwwXZrzH+fg==","signatures":[{"sig":"MEUCIQCXfsGsRGVAA8lAr6vCeTMoj7syZUd1AEnc7+2Vpm8/iwIgDTBeEt0+g0J1zOcCu58DtPde8/91ZcqL6s4urK0NbQw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1964985,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgHHuqCRA9TVsSAnZWagAAlGIP/2jpag+7YyuZAeUUQn9y\n15Qfq7SAWgT6UWOX+CmWTApzqBBANaXrxHoObTyRVycbMucQgyM0jdTy82lP\nd9asOkZ169wdda+5TJPxhNFRml+BjG5BdUksPoVf4nkMC9lf/vbS5CIQoAQG\nX0dMSD5JrbOxS1HmNUNm3+pH/7yV9G1tCOtJehOOmtyoKRwJ+DiWDr8MWBFJ\nGgWTNlGJC2WeJhGa9QuVsTilCj5Ta9kMvKksHEHSpuXa+gCPqmaoM8a6QU/U\n1Z57P5uMumjWVpZFrs0vdXgFhk+mESdcZ7zIr8kNhM/WcPg22ffqz/THf4kh\nOIb/VLmyYPvvrPf7Vaxr+MRmcKp8Kn0DvIAlGSHF7gAy63lYVcwkAnvPaisE\nlmzh8g4O5QSC9bWQrfTJTp2swy5GISzRqcXtBULCiT+97GvSnbY93AXQ5LTw\nIHDHf4CJPTu+UMlMl6qvch9hoAgUUvN67zUWOFK/MDlWA6RztbBNkebs87N2\nTk+NkBW74SUv4QqF0X3HzX4qAqENOa5vHYcuo3p6hYA7qwCNNBt6AkOdCOpc\nBTbRsd6AASh8YfZG+79Epe19mEpmhh14Ts7LnGnParyQXWwvmyUpD2Xe+IIL\n4NPnfCFMXT36A+ZrOcPWOc+MmdhmDQB66Tv95thvnyRtlUpy0RDv6DAZdGjV\n/XYr\r\n=GMsp\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210204.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const created = await adminClient.createDataFeed(dataFeed);\n  /* To get the full datafeed object, you can call the get method and pass the id of the created datafeed\n   */\n  const result = await adminClient.getDataFeed(created.id);\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  const created = await adminClient.createDetectionConfig(anomalyConfig);\n\n  /* To get the full detection config object, you can call the get method and pass the id of the created detection config\n   */\n  const result = await adminClient.getDetectionConfig(created.id);\n  return result;\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  const created = await adminClient.createHook(hook);\n  /* To get the full hook object, you can call the get method and pass the id of the created hook\n   */\n  const result = await adminClient.getHook(created.id);\n  return result;\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  const created = await adminClient.createAlertConfig(anomalyAlertConfig);\n  /* To get the full alert config object, you can call the get method and pass the id of the created alert config\n   */\n  const result = await adminClient.getAlertConfig(created.id);\n  return result;\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210204.1_1612479400308_0.7986473045254479","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210205.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210205.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210205.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"8c4e25e101a2e23a5226e5abf6a59a411eeab582","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210205.1.tgz","fileCount":39,"integrity":"sha512-6rpder/+dr6yd/wClQ6Tiukn8Aai2tDrHjpPBhC3a9+ouZKGRKRJcmZxG6qzzVq3BcEJEIxakILh1Gwsan7VSw==","signatures":[{"sig":"MEYCIQDgWWJG8lhghcqqVlxMCyd97fyfguTehQqCeeZ3jv7qdwIhAPDrMqJhJxH6DSPVgkYq9DariJqyAeLGDVdophGYt9cp","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1958978,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgHcyyCRA9TVsSAnZWagAAQwcP/iXKahN6sGezgFyIYITx\nnDi7xHdfjggb0Z4DCt/nkB04XISTnLvUeFzXDi4YUkIhCehva2dzgwgukFZQ\n8n8edPUtFJ9sQneXwQcuPMI5xLGVaPfEbSwOLRehSEbSIcdN+6XBkhhs+4jy\nLrvOAoB1Y6/5DIM2yRNrXb4Pszo4atwvfp0SjZzmzxCBQmvhCS3274gmWaeN\nEZ+dxXSWXZwZYSLwhvgik9uFbHdiscE8Trhh1Y+/CafiJq/1FiVj6pJGu4cO\nlNdVESdpbxaT8VYC0OeNoljMeliN6sjVmTJWoW79LbfFT2XPeReD74enGEZs\n/bsZSIFIFE8GL5k1PoTqN4McMrZ/XZJkcPSOAYeeqCBT4zOuFGmvZMpi8MhS\nnBzkFEryE6PdRiGodtXI9eYJAgYd4UIWxLxoMMUwWwlDbdd/Jyk+e4b3lTFA\nyiTUSkVEFKKa2VypzGGwHtLQ8iUsiSphcH7BBeG9NCQ/fE/sf/ckpfCBjTme\nnefnNcTyENqLGO1aMyyM8zPeXkA3hVhVs2GBqoeBZZuTfwIqJ8lVZhedAToI\nDDyAkZzKbv1aDZ4harTOG/Q8vUMEP2wr3k8ZsHiNrXcFcMoB9QSJjmtBtelY\nsTDVq1qheJsxS0ebtuDXTAf+k/oBc3vhuBlH1QaVg5MeDZ0T45uuHkcoQlSW\njB0Q\r\n=LTIB\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210205.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210205.1_1612565681477_0.14290392671298724","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210209.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210209.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210209.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"dbeef5be8ad8bf263c39c93db3332dc9f3a973b4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210209.1.tgz","fileCount":39,"integrity":"sha512-hUplRnyCv8JhVzgeyiWzuzQQGoWRcuQRbLzHLhvws6K6Qb7LQiuAeTeKov9JBnxQUh0uwzViBfyfy4rM5xMCAA==","signatures":[{"sig":"MEUCIQDgCcz7ttoM6wJ5fcG05gdueNUitFOsx9iseV0bzAPfuAIgE8E01MQxtDVK70WC6vbM1nLE2MhWGJQubcwGBAik2nQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1959692,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgIxKpCRA9TVsSAnZWagAA5csP/1c5Utakzvhyxx+NLpgA\np3szWim1YVlOfQCNpIZiOcbRWsMV5UFMIxMUrFt7b+sz+T2Kxi+hKnDCeNko\nIm22P3uzKmrT1avsbPp0gcBG0nSnor6QwX/q5fnn+aDcGgTA3rlNOIThHgdm\nmFIRZglGavyN5UqINCQL3smoGPsF5ZHTLyjql36jU9EGQitJfwTNc/dy0+3v\nURxK8cPPPirARvNVJ5ikmdO874J+/9EG1V88oOsNvPBfoBJizl0YL+9fQeVJ\n3WQFiKfbDDfdrxvprsMhaisriDo5Dw1fuBPN1Wcs3gJklYt0x538nOcJhP2s\nRCkifbLJDKzR99ALBtY2m13eS1iFfro43HS0T7qwGDufdkkhEt0hzuzf6yyv\nBD96NfvSlv2CexionYMCVA431GedIHpRk115mSbjDd0zU14BWbxV1vZz4o4s\n9eL5IG2Pl6HvoC2g+ma7wuf18pNN79Zji/Xuswm5oJF97A8kvmsNvbxzd4bS\nR/HAbZPoAhn0y5gjwEDmOQHt9r5KXm6thtR6jz2KFsMdYwhJygObbNSnQkGI\nj2DcxMx0Tmv9ZxzLfLs+5zDeTc4cQ+GuFQ7vOiBK3Bm+ZfvRjWJh8lPc5V3s\nvqVtIVksohbNhSOjNi/Om4gkmJ6/wDb4frlCsODaQUlc+otjJfRK8bBfKQuk\nLZEV\r\n=qLmt\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210209.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210209.1_1612911272912_0.6488917034172357","host":"s3://npm-registry-packages"}},"1.0.0-beta.3":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-beta.3","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-beta.3","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f37cbefcb596f2b5e013ac860da92cec9693ef93","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-beta.3.tgz","fileCount":39,"integrity":"sha512-7C1wodDLnLrdS7rmA/UoItoTAtpZdhkEoaxC7+j5l+LlrcWAe7K2JO1y5psVr5Pe8Y6cUGK4KfpgsAQAcSUDEw==","signatures":[{"sig":"MEUCICYrmOgCpyvRf54y54qhNqwstzmzwXkXe/EWWVrFFuNpAiEA+C0zup33JKBqfan8OTXVRINgV3np17GZX8qyw+RzOS8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1959667,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgIx0ICRA9TVsSAnZWagAAMpAQAKQlt4hSji7ew/m6GCdl\nljqGOyFDQQZztqnsUIQZk+kJitdVDCQugYxUptEsR5OBJMvmyS3Ly0JXo0Wv\nKYgnb0C+6/nEJlYX9FW6Rifd35iHWJGF2I1kZSc2RkdACPsLvhIK1dITXiyX\n9MXTLZZ9j1E1Vq5Hv0G382MAtf2CBdgpZJUR7iMLyU1ZL23sUVeKxbnSmae/\nGPdN0QElZqbImbIZRzGZUX+6GrWV6eLh1Hz4RB2uxixf90D6LYnNO2wqJ+wV\nkkP88oSl6l27VVGwPLjLaGYJIrYEm+KPIn8NMyeZTE+ZKBvgFDhsGjwtwwRD\n64iQuivPNUHPy3SMoH/CNKu+G7Uns2r2B8KpPYk0OCGzIGP9JV/m4VAXphZo\nUm8YH0+3t2+6GstdbDQiNGVbsvlTG0Qd9IGWMr3olSU61Q1yveAXvdpDgGWQ\nWsAsvkavHcYS3m2IhMuBFPNBfWmqUKjn6dNVUyjg/tRZz30Sc2zkGvFR+aRG\nIxybXbocazOBiG7I3wHFUzcbmM9+P5pd6T+4mUFTGOe8bmD9vsdqvuGYtHfl\nQcEyEGEo3VpwlxA/XHxC0PhkSSqDkJn4u/QGLoynz66lou37zCkYSpj75KKH\nlCmIWO/0od3kDkd7zlg3rLfF12c5PPoFXkfHZT3+rb5+EhjUlXbadNmqjbz7\n877O\r\n=R0oa\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-beta.3.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.10","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.1.3","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"1.0.0-preview.9"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-beta.3_1612913928434_0.5031039385116309","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210210.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210210.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210210.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f915b475f268d5dff8424f9824f76708d9cd31f0","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210210.1.tgz","fileCount":39,"integrity":"sha512-zcMmHvuqM0fMUbmtXfdDNoeyUhAVLGWHu4Rqt+cediAC/FtPX0Hu2nn2r0BCzd6cAIYMZQc2Dl3UwrpAG8u8vg==","signatures":[{"sig":"MEYCIQDl+MDqC17ob9lWgqboS2GtpgyGkKAV0zfkLwMOYLohgAIhAN1LJPGOOJTEo36KbOIy9FVOyFaU+vYpt+eJxA3AHwLY","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1959692,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgJGWICRA9TVsSAnZWagAA3h4P/2SCr1GPnHhbY/me4a74\nBl3+Gbb1sA4hdZB6bjZveaLLdo1Bs9zX+iTvNRUX2pNPkc/00ZGBjHZFfHXP\n2/raNIgy9ofMJWlDWAeM8yOkJ2IpfACfctjRPEJAVZi+qKTSg96duGcDuALC\n9YfAynwGMKiHZuzjNoa7S3i69o/A97/OZm+4KYsc+ttoX3TQPbPJcDFbdktm\n5RP1MWJunEK4ot1qnJ7izJ39zsM8Lk2LkTBqVzlJn6jy8Cb00hZ7u+gGDKdt\nWN4sxrJz13R/EP2ouCx0Yq5wKBj9BfjWnp4QlEeDMcyJcgbU9FCM94FgoQyX\n7oy9Mo2cPa8pVNY6MUvgrQ2ew8ifblguaQaC8RYf3Yh0n/uXAnGG8FDEXMim\nFN2YaziqL1oB37p8r1zDWMHHMk+aw+ReWBcgg6jU8n75rfci06YYjSUGrUVO\nOxU6bVoT6aRZ6zrasP4ZeDpd0DFX9/NOy2hf5cialU15ewSJTHoa0tD4336B\nAM+2q90KR4r1PglbfIrjQzA0XatbV2dOPfbLKYAg1V2b+0EEHBnaVfER1XnH\nFTvV4Fjxd3qnY0Um11rgVXYk9qxI9KGMSWNVels3t1KLiM2iRnvivBrsXFi7\n+8N4wtT3mFw2MjYqfgyBSVoa0g3OKr75NF3s+20TwXyOjr6UGpWGX2UqhqSd\n3wtX\r\n=+m4i\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210210.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.10","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210210.1_1612998023378_0.30821611670190574","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210217.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210217.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210217.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"fef9627274a8b406a74760f396bcd62445f1e76a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210217.1.tgz","fileCount":39,"integrity":"sha512-QXnhMGl6MQp1485ILh7TzgTvHxQ+vKU/PR0/5R1NRqLHmSU6g5qw5ovMqBocqimhSp1M2urMXOrispzqSzEXOg==","signatures":[{"sig":"MEUCIBF/lT0l4XidpcEVkvGDCmjbDYRod9+99IVASD/vVimCAiEAmjQ2hCIlITIT0KAFAQ1zK1f2bFuqLW0SrjLpba3OQZ8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1959723,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgLZ7GCRA9TVsSAnZWagAALpsP/A337ujCCSEOCZJyNlaP\ndxJyHKHo1VRe3f1CuwFJ5lE96nYFQUl+1fjhZWoG+bzpHBQAbtq+4vBFcuG3\nCR/JNzRLLzpO1BVCl08V/NnCI7Dy2qlcdUZrVits0OR8U5xXLXeyrXA2vgma\nB/yAOCw+tdDbeMczYq/4iXAm0c/D0u9mTi+fg8YocjMRKW1wJ7XjJK/KEzuR\nfmqTXvOP/CxxPCn4Rhbc2hK6zgeRb9JU3oshQVD0crbdaVnmOvewXtJOIyUG\nF/yxsRKv4eT+Y/RCvOPcAvybmSNkxb+8OGHfEGYU1YmlLHibw73dW0q04eqW\nhRXkE3Ovf5/lcqhx3vxnosWzIacJ49nL1ty1a7V5FXWypuJxRkx0BY31eutS\nME11Y5LsS5omzhllLr9UlIlsZvgoD4GwP5RdMlIX09q18SDr0CsAlpzKCm3Z\n1zm/7KsAam4c3LOFVa0UgDRsMP16QLZvHkw6FFgtF/iWdkxQH6gRo25S3L79\nbaFuOks5svLKvLmc1//INqEwdtam0LXuJP8mBxEeaibkeztv/VAhDC8uAHYG\n0j8uy018O6lfsAwRXg2bmUYM88/J3N/EL8rBNyQWd4MQTAdL11DU4pq6FHnr\nVCcZ/etZYGfls3NWTbHrMOEy2TIik+zNWPNK78clFN5rU36eSqGGHSU/Vv6n\n0UJf\r\n=IMAc\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210217.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://aka.ms/azsdk/js/metricsadvisor/docs) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.10","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.4","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210217.1_1613602501899_0.5474706268917731","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210219.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210219.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210219.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"b53aee52d149e6aa7248fdb746d6259679d5d832","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210219.1.tgz","fileCount":39,"integrity":"sha512-lMiuoaUBiFIwBV1PJyVpuzMGgiO755SjBuqkgYr29WRc0PIrecEF1QEiCLNJhe1YsULTkSCdSpq8E0DE0fRF7Q==","signatures":[{"sig":"MEUCIQD9gf1jYTQ283e1Vm/IlC5hLilbYtS1vg4jAISdGGevdwIgJBdLDLl6sc+uRv3AY+59v0k3Uu8CrczYrLhJugY78ac=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1959748,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgMENYCRA9TVsSAnZWagAAgJ4P/0+xddaqKwuE/C3gCUVM\n3ZAiLi+mpO8HDyQyuvANS+OTgJVo1palK/6Nuy0XaYZIbaig0qGXY8mLoURj\n8V7BRdMiQCj4nqwMQTfHEEz0YzGZLHZuWI+0Jir0XxCmrdWkvn25TYhdHJYn\n2EWCARCOQS2P199zHUzkRiIyedmFBmc62P3GxeTld/ypDU/XF4mFv8eeHmKm\nrlRe9UHn8q14/hR9J7finMYwpdgUeCsU0f2X4CgowmC34NyqA7xn7VDrMF+F\nwLgHb2OxloMWDkoQZ76PQL5xp/hIa7pzr8Tm66nkJ2ADnL+60/uAtnyRwzC1\n+qlMMWwlhIoWhpkvMUcv/lUxI1K6uaOW9Em5p1c4YO0BejeXvT+N2A7NVKAU\nGXtn8KEJApEmivOIV9eoq4PPAKiB62+F43hshS+tMqEpiSXwGku4CeTCRVAO\nFWlu9oie4GnsJpDt5o50f0oUKb3vPk2bvXKVcrb4WIS+Zh2jnqWxRTM8ixA/\nJfl0JrMbD6BZSPBb8tR7NwUNzfhDzEbYx252LWqIgA0b6JJoRcmEralYAayp\naunaGP36c3IT/O5mDJWGoKkepoyVeZDYgV8+zskeSrtiBPPvxcksNzzbznXt\nonaYQVSbcTEzgHFp0UwqnKJTRhL/FcHu4aVkjdxK7MXXUYhqFaGAMUKbcueg\nV7s8\r\n=Byb+\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210219.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.5","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210219.1_1613775703813_0.229249207977561","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210226.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210226.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210226.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"6dfd90d6b42ab293b4b3e97fc5b8dd0d32e3060a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210226.1.tgz","fileCount":39,"integrity":"sha512-NYpyJibMJEgiVYw0PnlffWrCnMTnHuzR85EysgZNP8o5Du0Qs4LR8kV+uwCSupE4N9DGpzxZqDipjuJPwUaGiQ==","signatures":[{"sig":"MEQCIG0+BZK+kT1rug64o1zBhZFC3FblpLrC+0NRECoc9afeAiAKF2I/N9CLUZy8mS1YHMeikC70rfxG1wcaXk+AZ1HYWA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1953619,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgOXxBCRA9TVsSAnZWagAAXNYQAKRZRVtHoJCQ6lEsFmW0\ncOziYSIqPo1r8cuFq7b9nol/Go+aWPlUOeoLC8Oq9qsS/XjkTj6tZ3tMmtic\n1qogXfNeVDTC2P9U3B4I8YzoFnFaPv3eSa2wU6HS3tTiwgqg9q1BgvCLT+cl\nJEvMpNdkKpcxZPcYQwvUhmcJqykCMJWFzuyi3pP/pnKRAyyC2xF9CCQJ8uv1\n3+he3Mu+Wm8p1epLyi49HlEzWtET2WR8T30c9vzHFHXL4r/2aJL2hsdS02MP\nz4Wz6+1wlMrCCOU09yABt6qfjpZInPg2pTWfqQcD2N3bluS4MQF2+Vy5FX5P\nEV4lIwx+03JYz5Mqc1gTiWj3EQqDarlFyFpgk/oK/yrdKORa+0wMdB+28jzq\n7lzIJDHf1GCH2ZdYxxD4VmcXW9dJsBIzZPmAwDGD5vogUOh/+am2q/R3II/J\nROA1iVtkCkUJhCzkmzKfaaZ3eJa74qpkEJ8yXJJY1jgU/6PJMYd2Q1eap2k5\nxzxpg8+sBRNivetUfeazjLJ0wEtpSC5ESp0W69CuCyAsa3UoK3MWqc02QXxu\n4jHSkhqdQxnxa4mUL3qxNZu4U9qaD/GOtKn4Bvurjcd2STaDwAU47ciLXnZ8\nUF7b0b0rqam/ALtQHlYhUhATHhPhr3PqtEZh1Dkbfj2yz3y2irT0H3kyWv/b\n2Tw6\r\n=4uDu\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210226.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Enable logs\n\nYou can set the following environment variable to see debug logs when using this library.\n\n- Getting debug logs from the Azure MetricsAdvisor client library\n\n```bash\nexport DEBUG=azure*\n```\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.5","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210226.1_1614380097315_0.8780918833438229","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210301.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210301.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210301.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"49d7f78a9061b07f403f9087145bbb869b5f5938","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210301.1.tgz","fileCount":39,"integrity":"sha512-la41J0RsDo2evIA9lDY1ld9Hmhtiznb4LNKi5KPVBKhvtVxkJICG5U9ivCrsK6rD6WraN1pg/qlt4RnbD9dgfg==","signatures":[{"sig":"MEYCIQD2dClKOPlwSf3/EETm4/vDzIPOSS8eRaPy25OT50oYggIhAP4MEU4NVdxXR+2Zis5jLVreohhinkuXfPH6rp43JaSe","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1953966,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgPXDwCRA9TVsSAnZWagAAaB8P/14hrNTm1iqW0T5yOEz1\n/oFdHPuqzrnlzdL8koZ7sy8i3ypsY9CtHPvytIElUAtiYZlIy6pq03YjGlXH\nBw12bqU5oucUtUsEuzjyzcJnSXo04nAtrtTWL5oi1yLtIsNmkxBnNBQLFM5L\nYGhKVBfAhDqBmdR9CzBQD62fp4RzqZnSDuNuFzaOAfa0Jgp+odh24M7US/Un\nRKzeAx1w44yhIwOo7l3iDp8Rrwm8PhBjRzTI8/vZKKMiEFzw3ZfOOtlpFNIv\n5NQKvRT+spDZ2bpOyMTnqddNChq5FgaB6O+hgsdLAi30mmUQRjd989L3hADY\nTRKhBbMBQkT9OgxnQr5jBQtZrKcMVp99gl9EZed3BI3L3lcoWqxKM67ypdkB\nQiB1vngu1r5BT5wSplDJ0M40/5Vr41PQesYa/H+F/FjRmbLYlqlemUn/JfxZ\n6HwMWOOiSEKkdRyIyWyZa1m/piuSP0mi2U0mx5+iH9Wv1SfzGmovZlPC9HeT\nV/Lrz8Xs0hPzGgGrEC9F9vJsE0+bZMdYtjncJ5SXUIG1tBsF18igJLsYiDv6\nBCiVmcW2MHBEYbiApIBZ+ZW15af1+B8gQmEO3DqjURTs/jgMDg4H3fvD/Lqj\n0ySU9EEAGzRE1B6pQrDkbqkfchgfJZfnyABc5ogofRsTNP/7y1C+aG893rFR\niUSk\r\n=jna3\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210301.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.15.5","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210301.1_1614639344240_0.5758001696808435","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210302.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210302.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210302.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f0445d663a7b2bb41b31e753500d7abe2f834cf7","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210302.1.tgz","fileCount":39,"integrity":"sha512-oUdJ3K+56dhIcjWhnpBuceeBVN6LQtFbKxQu2pJBggopI2008Yirn/QZOoBzLq2BE+g2uTcoPN3vg+E1ZqIAHw==","signatures":[{"sig":"MEUCIHZb15CSCIGTaznCywebq3Jnf4xjKLrDF92eQUHTwh7HAiEA/poVWizOLBCYnDt9crmEoG1bbrC/WlKAoiMZfOtsbv0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951087,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgPsLgCRA9TVsSAnZWagAAzcwP/0G+EYvwLvj4zwL3MaET\nUgV890UUK4B7oVt7Wraytk+lrixLoATAavFZQKXWvPvOMKaEmVhz/vi9/JXa\ni8U/xTPP/GhxtljxVppgo8sqbkq6Nqx0RfplR7YzgBswq2nWmkQfAp+AvlPq\n1Y1p2vk+CWG/VYqlRlj6yc3vMlPg4Z7Rfqw9LkncFikoJ3Z0bbi+HnL7D2KO\nVioOVxRFSfXG0RTIpMqfdSOPCPW/zYHGquVTZsy5GQ+T/5+oVWB1X13jcrFC\nj9DTLPI4RgtdqIkuKQh/KT8M95HgdkWrgyD/pwFdx+anSdqgmmX5+U9GqwAD\nHsEn2DoA5ilQAgZdpAvBrYsrhmFMtFxrXnjzrk9QDrQkxrZpNgzzM8+CmHf5\nKjV5D+Vh4QCC9C7DZx3u58I9LWG64yxRG7sGa+WkHPIRMxfmruwbOPsiAwBQ\nrh2LRu/iIFapitHAB1DPKiGuTBLk14p030KY0FVWTwLTQsIAHr40IrpvUYYg\nllrFMEzPAYoPZRvTalMSaBYyIEjtN6fDUSzyGte8er5XRl5pg9Bs6nRNWaRj\nMX4HHimbPVR4w+HMIcSMI4uPhj85KWeL7mn7iTeAAYryyDbjdGqAk2P0XA0t\n7Zug1w2LY1GHRv0tEAJgpGio5KEf5Sdr/Ypj8Zs/oaTxY1+2PjgzLQrC7reS\nljFS\r\n=Yf/s\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210302.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Form Recognizer by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210302.1_1614725855926_0.9736452484863056","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210303.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210303.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210303.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"0b78eb6d6ca6919b3b49e7a9524a8229bcd405f0","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210303.1.tgz","fileCount":39,"integrity":"sha512-dxqqsY6yXKg864JdPleqBhGvdEBipKdpkw5qSJ4ny80XNVc9fE8kBRaQziA4GERM5RWikrafs6rC8Q30DMnq4w==","signatures":[{"sig":"MEUCIQCzmwdUZgabLQN/tU0zRJqrcdvbRP7yPE+jjZHyHhXkGAIga0Se4QkxKvpKfUNo/N40E+MkLjg2A7MsQVDkE2+Hfr0=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951087,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgQBQWCRA9TVsSAnZWagAABEkP/2eoonAyBPKZQoHPUHPm\naEXh73nFfaYT8RwreaVam2OIu+eAkRhtbris7ijZSldjnOcRTKkM1NK7bBU2\no+uLIOyVLQ8bIe+KjoF7YIWEwyERq/2K55By1/5cxnO3qm+rcX2Q1UzuBJqz\nP4zFJly9r4pyLmHtZRFpdgjqds6rohT2XosmTg79t5xak4bK6QyEDfITcXLB\n23VQomPFIfdBP+Dsk2Dc2IyqdkH+SbxGcMJd7lnpG4fhEFtOVNbW6vwAJGhB\n1A0Cf1fRgNQ2cyqGatcIJwKCt7kv/AIXlzRrcxkOjk6gMtzupi/2T1LLg2u+\nwqHTvqsnPiSv2IYhKZ3W8Bz+nK2REKRAS/7mkntykvfrcqjE30sQrjIiNR/B\nuAzCUso+K08ry9QN6UtaI0IKvh8dhmIDLiFygGxPMacHfWmgSaMsAtPPBnph\nOZDr9cWuR6dr7TPElVBr+IOnWOV/pszl8DCmy7dUSctbBu7o7aQtOyjrkXQQ\nQlzjJeUUGRtELTpDZ0g26X9WDPW0cZ9X6GBsF8vXE5INTZvkh8Nt9Uj5qAi8\nQpGVCzJLHoTYh2iHbT77R4ESblfCca0kbT/ju2h+s3FDOYwxy93GyToIp3qg\naVAdp/LhP83fU5ignKa8IBQt4aTF0jypPWJhfrvY6sQqUCEdSq53gI0Ubd2o\nrfrk\r\n=p4Bv\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210303.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210303.1_1614812182166_0.72127825942023","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210304.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210304.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210304.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"5850bd3784f0f08c84e43fd3756795e71da8d339","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210304.1.tgz","fileCount":39,"integrity":"sha512-CqtV+D6ipubey76W4Z9WheeVs4jA/MXQtzc46TSU1W3HkYxXG4LLkrIoVbIkuU5+Zbgxf0rrxXErpWppmE3YSg==","signatures":[{"sig":"MEYCIQDky/EhZA1XtNs7JDJOTSrHVkv1d5luwWfFJ30nzaLm8QIhANX2HQjkcuKrQQim8AI7CahlM4NQLIVIkHwRw9l3qC0m","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951702,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgQWa2CRA9TVsSAnZWagAA2wEQAIwOgkDm57g8nYXbfvRP\nHiJ47WzkS/dABFNU26wHEPpA91eLdZDa3gj6gg6asLTQJcdCXvn5pckhEAXz\neXJt6KG7Qo/rJlCQZMMRE1LhuPCM22MaQLmMftDeCISPVahUiOSWE99F3Cqw\nMaEdbW3YD/lXqecdgTJv9sySoF3Akgwkp5wjpSh41+NyDL/groYxiGZVkSuz\n0ZoaRSddKQ9CgAm4D2VluNqhSWPCrDT132mFPKZ9mcJfdKWFYBs3w6rPon/0\nk0qtLFNkSBHsxqjJ5qjgSCmzs8O3S6Xip6JCtP+0UtqkRA0IXNNMBgiLwJeh\ni3CSuN0gosfqNEokHG+DwzMzIePoXp4yoh2LbIALBbgmI9CRHsmdg2i6iyZp\ncWz59lGDFiC5IZG9nUbTbCkiaJw/pAxIpotRxglcQBEMufEi6mYz1fSbatIl\ndSQQSXkai3/vX7Y1vTkFTrdQ1RVTF3gWWgXNmUc8b9pr8d0DR9dRlGhBUcJs\nXxPh5/zdqOKGKA80m5/c1RSoLjlOzNfAV61m7RJggpaWO8iUs7Wa9u35aYka\nh3ADDsqr5iL/0d7o/gh3I/qB1kjbV6C0gy8CP6d7NmS/THiEXZuDgG6UHPbu\nY5t0QVqxIDWXf551HTpC+Kv4+5bLWY0FeqggHxmGvoCyxlE9liXZJiFYewvS\nu6jd\r\n=pvNo\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210304.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"dev"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^5.1.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210304.1_1614898870111_0.7779665825463435","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210311.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210311.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210311.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f33c368f7ab4e268dfa0eaef6b3fec634da5138c","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210311.1.tgz","fileCount":39,"integrity":"sha512-glCdSqyNJahPD+IslKEgEc9WeZy+hjRFPE5x0xN0YYBvAszKubYWSd8xsFsdD5GZ7TH6umTtrI10AxV169hY+g==","signatures":[{"sig":"MEUCIQDxbs7FpC4AtuSVtYeseS7Q6VTUqcQULNTdFW/lUrReYgIgfCFylxqSCW9Mcd6zhVmRtwChGd0SHDIzrZNcGMAAEpE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951702,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgSqB/CRA9TVsSAnZWagAAqXAP/07ScuL3D8AqwHTWycN8\nBKv1qqATOt2t13sE5ofwx2FqKJG++asGesFXv2Yt0wc1TZVDKV/pj1KN6tq4\n6So10BVVPYMN/vK0xkyZ3egT9uZvr6KeqxqAB6rlqzFa8nIdN7p/VEC1ro2+\nEGmoEdFbv3SynOA+zKVSmxoHzXQnNPhAY6uwIHGeY3dmXo06fTd5ixghbS6c\nQV5U9iIN07Ke32mpG2rALlFMPs5UEoDYyH/QJXSVm/xYBoxx/N7gqklNEhSJ\nCnYD4rcOmyaluD0V2qeoiTBvm8RxVnSQkS6e/GGZ5kjoZXxCS8Znx8DSCgXM\noEWy8Sk+UWXSIKC+pFRm1WqXUskdPmI5tlUduShNA2wkNqvseU/Ow8f8XCZx\nEbzc5O0KS03oe8NLYVBHUvMyG23P6VLNyxxaqnQwYSviOBdNPWO9eiRtX/2R\nkQToe15Ai+XtkqPsOEKdR5PbLI/s+bR/j2CxLMyB15xu0N/gGWxtXmXXitR9\nsEHZMsfpkbW3ev8wNi/U8G88zKmarBHrdndI16kTd62itxwHSFDiKumTPmb5\nja6P9ZTAakDoDu59LF7NuT5/A82ElC3OrKsbhZSekX7nwWJtExffZirjMqHk\n7m5uYSZI4X9yTAKwn7ELoGYlHXWXA8autOoNanhGNm2axvwrpmJYJG2wfQf1\nmf58\r\n=0h7e\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210311.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"dev"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210311.1_1615503486513_0.7058236926420791","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210316.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210316.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210316.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"250f5cf74f6377e755496e647e4e4ab26a93671f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210316.1.tgz","fileCount":39,"integrity":"sha512-NTy/J8fiyxdHCJHA39+vMF+oyJ+08UBIrSRFfx42Cz5dIiuWlMP6HwQQJz3EbFJb42iGzKTT8/Fzahad1Lu8Dg==","signatures":[{"sig":"MEQCIExGmNs7Zy4hRo1uEVFjJ8Z9tYn89blN0DAelOVptA0iAiBbiW/3HAe3FaJsZKln1WW+N+SYTGzOdhcFD1lImlXEjA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1951729,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgUSpUCRA9TVsSAnZWagAAYlYP/jcPRbvCSIPMbLKE/FwM\nCwVG89hcRI92uRCjPaa17PhrbNwCZpVykb/LcHXiXruuEgoK8o5pfBe75oLD\nGdNtT0l81tElXnMc3JDDi0jzYKoXOBY6hLNJic19+N7L+IWv33PRNN7KA46/\nT4XIJOVgGMkBdQyxxJ3l+V8p2E25X/Fin/YMvNvUaSeagymM1xL8aaR190yD\ne/74JXjSNJB1o+6JNbSLUxc6huKyE5oJIQ3D8gH6ggvpgHV4ccz6rDcZ9J14\nMpU2KxEG5YFb5j7ZSZnzgFuaVaN1lWF1JJAuXNlY130otnSIm7fTF1SbmgN2\nrkO7Jj+LdUrgoIVZ8o/k4FbFpIsrlbAPtbeO3ug5DWS7fwfQ9CM1IzaS/XFj\ncZLKpGCaExjDduT4X2ETmMTZgHrgRvOCzPiEBgfYfwPH8OezzCFFWytuTUjH\n1p3k2O44rKraaWoiDX5PxDPzFa9oboIpS6D/X0GA0Hw5XJRnEsAjZu/382dA\notUo9JQeooG7KYHUZyBpbupzP1XAFtjF/tDRBijIQXkCh9NtoBj3UQsdsyN6\nU9r/HVSNjgeQNEp3EdSTXdUSeultIX2yra9J/puxEnvIf1TrPvX8+7Qn1X+j\n/fmFeODiFWygzDdlOTc9Y2mMKlH0Hts1hVQoc+/0CTRXfKiCUKGq/ugg66Dj\n0l8P\r\n=wmRU\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210316.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"4.1.2","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210316.1_1615931987574_0.12621334375072624","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210322.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210322.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210322.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"3afe8889fc8d492d6ab25085220a89822384b26f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210322.1.tgz","fileCount":39,"integrity":"sha512-uOPDJxUYR43EXIoa3gODJSRstfZltbeTgtNX85wkKidgDXqQvSMcgVUA5tSvuErBOG2ELtP+OOHdQTjenX6T/A==","signatures":[{"sig":"MEYCIQCBciYDcNdTqIohU9hj/Q2F2msNcVMBo5OgbIQO0WPaQAIhAIb6jvXNEz+Ghh3kgRtYnm/Tm8DTYoxDkZPUW/NOMlH/","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952472,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgWRPDCRA9TVsSAnZWagAAP5kP/RznUFntadwr1YMJXp27\n3FQrh2nsKBys6QlJiWNp4IUD/gv2aUR4M9Mn9FNfwcReuS//IcaUPfMsL6L+\nOUMHEYuoqxiHy3zEsUl7D8YyNqabjHwp6KdnJHrX8UqQeG4z8foAxPYRED3/\n1hJ+C9aayXeYzZ1zUeDlmWgcGUlDXjtONrIsFUDDPsWVAOTQVbNwtJGsk/7e\nONhcfNweiLEuGROdaUKL3+Y1cQQ6IVYPvdmahuKSOxUPlhtsIAS12PctDAWh\nxGcfQRvDc+xMQriLSS0rKfAZF710IcD9hgYZlXStpH3fI7qaNS+Ukh0GPUpc\nw29hGiVq8D22+xuiqo6xQuJ9wRO8nRdz9vB8Viwp7/DFHpzP+ox05YqCAadi\nb036T6cUpBykfiP2juFQREeqvlqU1E9tIS2vQpy+QF7UD7sVqQSYNNxl55op\n4gM5feuzK6DHRQcTjDxWOfEw5xfuOwWdXYeWYkRkQ9Rouxg5ZA3cW7orpPuL\nh40nmKy+Zv7K6zdVj1Dh4Dcaec/6A8DeIDoTWRL9xBjJsCjymKrLXt78in9q\n7k7IZgOeOPRQIkV2icTy91Vn0GkMZyO/Xqq6zCNOXJ25SXJoVfcXzmqwhz+7\nkkjPTrnLfgA6itgRtW7CsQMQ0A5Mf//iX8OERKi3JBZb6Fqcs0lql0/J2+ke\nyU3e\r\n=z2l6\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210322.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  dist-esm/test/internal/*.spec.js dist-esm/test/public/*.spec.js dist-esm/test/public/node/*.spec.js dist-esm/test/internal/node/*.spec.js","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^8.3.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210322.1_1616450498704_0.9233426618462013","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210323.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210323.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210323.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a06da554260db0ce6cd4076c13ff47327d873710","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210323.1.tgz","fileCount":39,"integrity":"sha512-NW8RZr+qe2aPYg9JJidAvGMNsuJBcc80BjgIYsJyl9ALowJZWCKd1OXsM3g84T25HPnA9AkVENegiLMKxwbK/w==","signatures":[{"sig":"MEYCIQDJnGeFZpAd+yZ3ghAteU5u1rqxd+ES1RjYxH7UsotUvwIhAKOHgNAmJwt79HCT/KNkIc+xsLz5oQWrHx/ByezAfLq6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952488,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgWmSUCRA9TVsSAnZWagAA+FUP/R/NSyEMfU/ApQ9emM7e\n8aBBJI5Kk1ayfYJiXG0rm+FGUPEzdqRF49c5iRYaPLRnAtnZb9RJq4oV9i9H\nhQr25J+OkuEowMw9b6MP/YAjoCvGzV6mezarLoLn7zJ+ZUQ4NuOUpgk1NK3r\nupqlHvMQ72c46IHrRyQu+GFpyeGyO/PihWyI1XqgGlLeC8/8WdSjfSFxoKmu\nPM0+zWyJAgqobCkAoJePxkoALVd578zppPzlIwoCv4KiKI8sJJsMykEC4njo\n1Sb2irYUgX7D6qT9ICoHqlNiSbGJUMIVTrJDK7o2PJUQVWu6zPqBTqQICULj\nFOBgNsdz27NPweTeGGarbTfxrshhl0Xd1KWQ3erKAL58xv179gyJ3uCGfJqj\npmZpCQQbwHnRPGJdfTEaaEM2CANd1tqZKz2ewWgqcPcoQQsXpB/YidnGQndD\nWQd79qXbHVFphW4pzCgdOalse8at42NikzUE3vo7bgOqmxk7O3V5TqTTJ9KP\nQNMH+A1YZXpsGk/1x/PC/TYgYGTObuqgxyhZvRcsc9Afpw73zZtw+b6JgIut\nu6HM1ColUoz7JpXx1eUHmKLIucSe//ei8jfQgzxOqKHAOX816xny8vqndHnW\nz+DS1b+8qGkAj1wDnKa9G5BoGtb82xxeODpW9QkPI65wKHuNTYIbqVq7wNy2\n6j/G\r\n=94j7\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210323.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.2.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@opentelemetry/api":"^0.10.2","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210323.1_1616536723874_0.8745347225425717","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210330.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210330.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210330.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"2220538d89f4bf3a0d099b45b44cc8ede26c40a4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210330.1.tgz","fileCount":39,"integrity":"sha512-Y/dHKLcncp/ve3MTV3B/m2HGMw8M0ckF2L5tzWIQ4xmudQK7CBydemNH0Ifm4ANgtgA5EGDGCxv3I+b+OCbctA==","signatures":[{"sig":"MEUCIHyrf4+RxsKHvJBZaSpZX7RpDOP+BzTmmrdIK1D/ZyG/AiEAyapb1LZ4QcBZhyAM1FW7oC7cXmDaOmg9X3NOF9VNUt4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952512,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgY56eCRA9TVsSAnZWagAA+AwP/0hIbdN7DK6KxRxZgg0y\nXnl+pR7B9YDQrJkvmNAQA/JgDsBlwAhoXOZYjcVlOsPnqZ/79d7lHqsMjbti\nHPDdexwQ43KJjZacb4rUwptgKnpNqLQEUA9F3fLGaAwKLCLnJem1ekfgCvo2\n3REp9Lq+1zadwN/Mk4ouAsiEyOJnG7X3STHM5KnQGBek1+b74JD9AHCrmwsN\n2VpjsfpnGR3rdjNeIKgcjzT1rjpO86rfczyuvKnOj5IQo+2ko3GZHDxK8a7G\nItzrrw45/Dfai9Ep4too+P2InueDKQRRYlsXtgLOfXG3lg9yqt8Tr8hh2tZX\nINmpUjHLF7OTldzV3AysprEnP9xMOv8zc55GUZT3biucLpYXUFQCMns4Pr5T\nOHu1tzO/TFpxElvmMPrGiqA0C3WOnuOR3KfoenfEbZY/RLtnY1DCxxcImITB\nXL7ZsMaDDlUwXDVOLpL5InJoDPI+1oLiVUUXEBITQ707NCvyc8hNiwUlb5DU\np78i5N9qEZnmA2q3OjY965TtLyynkqxVXF+VVIDA6zBW64VefkLOAalgvdag\nh7h4fFmhnQOphHgNHYPgopbpQD7dfarte9YLErKH7Ic1v4EwNqFS9BQA33oR\n0bNlDHZ8gh+OaKXgaLSsYLcvH9E5+/efWQYkBSVuX2kkVcU62GnuTFDjyu5X\nj3m7\r\n=f6SS\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210330.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0-alpha","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210330.1_1617141405965_0.16365490107705627","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210331.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210331.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210331.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a8c102d6f83d630b42af026eb917d5ef8b3a4f27","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210331.1.tgz","fileCount":39,"integrity":"sha512-mitOrmctR5gaiojundc+mRxB77+mWu7f/ex/ssY5zrgNqAaD4TRGNWVTnkgTT9hE2PvmAycAOjKnf9cAZJUqOA==","signatures":[{"sig":"MEUCIH4P2PijSSjqmA1zoMzO5QDQ3HbFggiju1fzFEGnqGZcAiEArsZLzE7F/R9+StP4RJxliKBKu35F93rgKk1ZtG51Edo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952506,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgZPDmCRA9TVsSAnZWagAADfgQAIz20zYGKWfj4kZG4+yL\n8YddvBOUV5YYpzj72pr8a0TdtaMBgV0zKis1Z7gKelsuiBJe1Mb8oVLwOtMs\ngDOmdhbogjFigUDibtM8+wTCbVW7eEn3PUqA2gTNPsUdSjUQfFnasGm0pXU5\nC7NwPaP3P+Y4vHgzzLuK2kUUCWQn5fpayoXg7b65247rqScml8ejlQLAMZ9A\n/KwftOI9DCONHVN1nADah2cWBju+ccgPix92aMKH+RKH2zY2nsUl4ugA8agM\nYrZBUqqPmWG2ALKxPMxW6pdtBXOOJmhx26QU4sOk51xiXhWl1RKW1oqs9UBe\nhvSYsuDPSQJOa3zIixNO+aB4EG/OwCkNLy8bRHfIIpSwJEUSaUbaI3s7lK9+\n6fM2WckA4A630MbU1buVl+bn0E7DRtRagKztHyLPKrJPCDrE0OfdXq628N0B\n0+MKTc2Wy2vvHF1sxcWxbt74Y6SBWqpUfIRUTIBcaD00zYI6l1CI5AnDcP/6\n0OQnPwSchajnEYr9Dq3qrGUo2Pz5k3aen7dFEoKR9tzJS+AM2jyXiyA7bA8B\ntAO0YbCfjnHw9tGnmSqcppoZ1pSON5P9fExgj45ewmo6wXEBr8sZc/NX/9dU\n4gZ9HgiV7VSkhTV2rpXPevG8Wx2YpUZXP7f12uAQdF8op8Q3is9JuVqp4cze\nUUqa\r\n=gZK/\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210331.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test test-browser temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210331.1_1617228005502_0.3329278758873748","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210407.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210407.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210407.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"cb9eef17ecfad803329eb661c1d8756c1fc59b05","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210407.1.tgz","fileCount":39,"integrity":"sha512-7Rv8DiLKqGgAAXxn1pz1xn/1x1hxXYQm5TrZi4piACra5QzYCIKf/NO3AdNF3rL1Y5r/UYODq8jVnIjbdBrJNw==","signatures":[{"sig":"MEUCIQDx2X09iQ+UP982TaxxNKeLvCL+EhK3oKoHhAfCKMCZgQIgONYBfnZXIeM3g7jFeIjlAWNYKy4Pg7wIgvxm982FAJs=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952503,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgbiy8CRA9TVsSAnZWagAARdoQAKOhzZj24BJPa7BTb/iV\niWwukh+BGqA3sZC873KTwWrAqFAPtwihv0OcEQ5D+6+JrT6KyM7TP+ts3SRU\nNkctmkqLv7auQg6GUcKCLyVLCxFcwfuPrFNDyyxxbzurb5te8nNkA+P2N4pw\nVsNfzvCg870PAh2Pz5fQdg9sw2Rw/mtMl0B5VQfj0SLQOB11NO7wcgolkYk8\nrbX/koDY5JwX2yFlbzKFEpSGRuOBMJRHzRAjCbmtPFyZOon1VXZuUAHEZAZE\nJ0heBX0N3SC00MosFNH6hM63xTLCWavM7WztFo5ehQR6toAZDxbL+ODGDxy4\nAMMrjqEkBs8u+aDSmImldE30nPsHlIKi21SBkJ4X9oZBa5kehkhOIN417jlf\nMlU2ltR9Nz4vGyTLo17HJnjxmrX3fP8LCvT7q2BZHrs75FQDG078foHlyc6D\nlePS0ihIoLxuNLND+fwp/bSqZmdIq+oDk7nHO+HCoYNOcahgYcdLbfCwtOq/\n+oAkJte7IuAfMiObz0dy4K/Qs04cEHs0bFcY5vwEUJuKDbDHE4LZRzD8JRg/\n0ToOmuuAm0N9skMR2zCWy4oBtMufih5zNpjV/QWAGDGum4T7HsVdVQEh+cMy\nq097/MV5jjDwkLYQkUV5VqmA5L/SN2kCI1SaLym1EuLZ3LmKMPaTM0wmZLLG\n8ljI\r\n=vuGV\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210407.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.11","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210407.1_1617833147490_0.581736168778517","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210427.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210427.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210427.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"91e302ba48b5850654ae1ce669b957a6d4ab8325","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210427.1.tgz","fileCount":39,"integrity":"sha512-Y0q6Ha3gkSzteMgUILOlNaYBV/lA8c/TyvhtZqivtQ124i3RB8+pJykPynjOCa3h/1YEYLaL9LySo3azZEkbpw==","signatures":[{"sig":"MEYCIQDRZVX0qGAyi+tnDC+CMMGK+DbXvJ3szuGd1Q4nYXha3QIhAOl+0lcPnivShBu+l4PuoTlMuNis3DEc5fr7pN5xzgNY","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952503,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiIhsCRA9TVsSAnZWagAAg4kQAIJDCKx4uB0yqrX5C015\nEEP/oSh4MC21GVg5SrovHSR0XO/okRKINxcC0I5i3Zel6StuopLIfbxOVWJd\niFmIbNvRH0pJxLm+WwMOZCnVeXXYgkGiaKhhf4Ec4BFM/PQX+1Bufnl5zXyr\nwGYmnFZHSFXalSNDpOf+/T9Ir6r934gzP4CYoQhDEjR/2io+v4+BNBSv8MIg\nTuSPplkg7PW20gS+UrLKAJ8rXhcKQMqD4nClOZAF+oNInAYXAQjGaDrJtwZ8\nkCQH0rL6IEA9ff17oReBPbNTuHnOaEzGxSzpmLPqTmbifyLiCU+RGYPyJ2WD\n8lOYRW1MQh6K4RCL5I19oorRdRoSRZ5mQQEPjAcKXVqbCPvMAOvhILEuFA/o\nxVKw8yL3VS6c9BMb2UfaSrkINYibUqwisXUbHyW+6m9V7aJ1tcEfAfSOW++2\n/Ie99xazZkKGFv4iVL9StAaAeyEVEwVnPUz5pI6OKtbHUlo7l44C8CsuZOtR\nRORV/4dg5KWT2iF1JNPcEgVokeiiEAvmq+vBkxZn1I1ycBWVQB6nyJdAAi6v\n2u8nb4pOzE+K14/8QOzVT3PtSqXNnt4I5+0FldXIKriMQa6MkvLr7xZyeX6s\nBh3rTj19xYtMTAInYSLrMH43xK2WC6hL+GDIstQ2y386eHttVdvk6kmW879A\nGyDL\r\n=jGFx\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210427.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"dev-tool samples prep && cd dist-samples && tsc -p .","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"npm run build:samples && dev-tool samples run samples/javascript/ && dev-tool samples run dist-samples/typescript/dist/dist-samples/typescript/src/","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.12","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"~1.3.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"]},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210427.1_1619560555792_0.28101149009138826","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210428.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210428.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210428.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"8fb2c43122e57e0dcd551bb48129c5a90e1b2b44","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210428.1.tgz","fileCount":39,"integrity":"sha512-aJkeOPj83ihKbDSgm+seFpjTd7Y4AuEynO3DbVa9ZcSiffVDhxtUkn4gP7FRfjvkupxsnjkfxvILqq9Is5dDMg==","signatures":[{"sig":"MEQCICQoJqK51kXX+jybvHFzRpMsHSM92AaISYeF3kkPBbHfAiBXip4GySjOipaqDF64sEy709n+KQkhKphmf+Wvec1jww==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":1952862,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgidpACRA9TVsSAnZWagAAgZ8P/3GNIiPoUJWyPrjv7+vI\n3G36FxVQbMiHXZvYrOOnuyAQvpeXhGoG+TnesveBLL6Z3bPOc9NAsOKtZhVB\nWlzFObfAKHW9AaNJZP0S/jbyjPYqaPqlY14tZ5JcO5BQmgboiIcRlx3oTjbi\nHvF66qrKTVZ6WsTJs20PviiAJDG8G78kdmushVhbzZI7sXS1BXLnsWoKcuO6\n9Q1U2kOVVBeHrITOY9WOiP6BpPIkQQnXpQAjlFJnLeagGJzgMu+QbarIrB0B\nGuftRPD/19JxqsP1f98qwQtiiTOiURcYKWGrpyarNlpXyIYrtv5lKMJSda5g\nZQe/oIW34v/72sbFVeekguMgUwkouzPBFpti+nNt0Z4L/qJpIcoQX6Bc+uS4\nwZF9Cx+IGxPv8nqsA7krrWKLXIjrcH2C4teIT9MWwBWtF4+SxKIzoZBiUVap\nXc5ZOUSKSdFEgnUsrqoqSs5KLqHFL6lv9AbUYDMeODE7CPTc9ZEI5vxcvcKh\nJ/v9mQ6+il8uxKE5Qj7Km5uADujmrOEmQO7MFkFRKOZXhQrXgq272MSj5SBc\nW1VvzWU1Y40LgbgD7MOM2QUCmndavlBndUGde2gClx7kZnvFkBwpLznwcaSV\n8qRI+4Xh5FkZzAktviGeZgv4p7muFpbESbmaWapVIqziYoAzC/r5FG/qMi5k\nRt1x\r\n=IdoO\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210428.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.12","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"~1.3.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210428.1_1619647039717_0.013574489234441378","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210429.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210429.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210429.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"c86057faa152ad0ea97c4885a65cf7eb253bc994","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210429.1.tgz","fileCount":39,"integrity":"sha512-QKVMaRTpQt2FacSBnqa6D0uq9YEVbAZX4EbBhmXVYfFnLXfBDeBYYDufIFLmUVwscz4Ql/R3Fr+B3j1ILKmrWw==","signatures":[{"sig":"MEYCIQDHxTo3z4PAYef6Xl/Qf1JTzG0I2t1PRBbGmFiruPHC0AIhALwrV9igQ3H+teUvxVvTeoTYysdZkDBGa0Svie1BCYub","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2090624,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgiywSCRA9TVsSAnZWagAAkrYP/0mavArIngChRccvFwDq\nYQRWv6Ono+2NCYBKruHepU36bc/nbzjuK93/84W41zgVZ8fW9+xfDsb0GKT+\nc9cfH+muFo8eK+d9Jauh2au5A13Shbwq3zr0P3EyrtrWY2h+IlF+hKK3dCXl\nVjO+3jELU3MnVsC64yNZuaoH9mcOAWtoWY6OrB1EbOL2O/N/FIrc5bXZ2eQb\n3oA8zAvEtvKDzdGVC0S6Sj02Hf8vrcko8ihByUtNDe8+DocBVqIKIyOhQ0Jg\nytVyGLy1YTLUYi6R1oBJx4jYNVZ+jcIcsCG8UlykNM2SlpGx61vFGz4aqPTV\n1GcE9XdQAyrMCxkMRC/yYvaKhQ8m2prHPvseBVSg6KBKVokKG859wQYaRwyJ\nrCUCovuEfWYIgr1WXr2wGDafPoIGD7eNF6s9RzoV74QZ6UBnISME0bZMOJ5F\nwrtsEwUgpUQJOtfd/R300C0rNaqpQ/THlrWAUdA9mqcfMwSRRHcfqHdGBAbk\nRCzGISaOWbKSYzmMkIZI0wYwq3A8Z78XqTkvhvSsHZ4tUI6yf2OL4AZcCLu/\nWvsDTSl8jEWxGg0dhwdMRKsmulHkTHuo+QIHZn20MAsusUNr0tDm7HOKsZoM\nuppZFH2dEtQil9ccmkNXsPOnHHYGUIpYBru3h0jXv1H/MLddR9F+DWWdQYuZ\nhtev\r\n=Vvdh\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210429.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.12","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"~1.3.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210429.1_1619733522385_0.7644209026739794","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210504.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210504.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210504.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"951a05bc7489452ecd5fcac433a05508a485bc22","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210504.1.tgz","fileCount":39,"integrity":"sha512-wvvk0QaeJgp5tvdVXlWqHUFzQ3mv83PQLSkRbLMnyl9ctOgWq0DJ1F76rzaNWyFNRBEprRB5OiENtrvb9AwwPw==","signatures":[{"sig":"MEYCIQD83pmTusnrOJ8xboIAIzTVjX1nQ7DYGJWc+zdRlaJRfgIhAIp9cu4aTPnD2F35ZrK54go/VZVwxU6ZVGrVeIEoYYAY","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2090624,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgkcNiCRA9TVsSAnZWagAAcp4P/0XqMIEpnJ7PZ+YYKOKH\nLlIyxljnYL2QCWsAdRSJLvmEhPMdbDrYfRYdUHuSyznJW/cCBQA4gNGN0syg\nuOzJFtlDiTYGOQc4OFce9pzggP9oymkHINO5V/44LSV3oy/a3tSSyzAWdfiq\nm5ZcwTDdjXLue0vCaCInufr9OSKHpR4tL7cWMSf0sBjKhQTwNFuSaMA01ni5\nBczRLBoB6Bhf7fjkC5mEUglLJDdLeQc/dHlg4B5B5Qd6PCBu5F9sj6zKqNXS\n2v5VvPMUwfHSKZuf24TRXaBRPPqBTs814ZPqHvGt4sF4m5I0OQ3MsdyMbQd2\naLnaLUqWFr+gk/6puliFSF34XUDcey6gGH2y1j7nVLTtx3nbRHm9y0d89z3Z\njN4h/SXdf+ZPngIhaL212FJZEYZWgOnYWkDBDgH7Okj8YHp7QSiHk0SZdWiH\nzAoAloBiwfPofdKKwqfmysGLWGyxUosv3T/VN8b6kFsD3odGDoZ8cOVgzW7C\n4oFmmSL43C+kI/2R+zIz7qaMs04V8cp/M4euk65lqCCiGmq2mon8cGf5NJgb\nJFRLoUvqmePHmx8UxdRhwK7PF5fDjU58vvJ2VSgUrW7CrdOHnxgWAaDjaOtw\n8xhL7k+hroL0PHbzPFnf7oi/vMs5vq/2xpcHge+V39fNK41la/vDKAMNLbLd\nAWsR\r\n=atko\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210504.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.12","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210504.1_1620165473898_0.009911905171392066","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210517.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210517.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210517.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"719cc1d9c93c733ff1a37b5a9f5c2c53f03b2eba","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210517.1.tgz","fileCount":39,"integrity":"sha512-zKMSRpAqLjIMEqpWfahgqPZJMW+EJ05i0Y2jdq8ABfIhNG3xOQCl6WDl0o38aFmgdDEIvyO/M7BEWPq9KtVSrA==","signatures":[{"sig":"MEYCIQDyB5F5lkQFXVZ8y2fi+E9VvbmdP24Yp4KWVV1gnRXKNwIhAOP4cBO2hlNzBF8mepYctelWNTsl2z6bUYwdgiorZ6+Q","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2090628,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgouZ6CRA9TVsSAnZWagAAMxcP/ikJH+m+nOAqtaffrv4R\nNvk9nXzvHo6qqXkDPxXOAO7Q3eOAxjCyoT3V3MEdmYntyA12JNVN99aCvLTl\nR95hmmOtY64AyhZPrn+dp3Tl2tmNATLYFpGGtCGhSKe/AhRilPZcMNO2LyDE\nymz8IQ/MEEeiPUXffOyljGFuYgUlFzFDUtEuN/L3ljIhCB7a082RLzYRlyaR\nE3Xjb3D8g60e6GPqg3fhIjvIN/2LhN8ftbBdFQAd51Ay/BCMM36n2R3/y6F9\nRRVizLhlqW7mHWTv72tCWu5iB2oN1r1O1kFXGVCgSHpB0k/c0VFUM0jLlN1b\nPiTWs6FD9tvf5NcserB5b23JICNcUHd/mDFyprIAgZXzGrgoOpU0R/C3265m\n73Yi25qlfK3X8cDdOtcKKOovBxbTH98R09rynIMz88+B6h8CvCRFsr8rCb1T\n1nGC1/T6dWMteeQw9M4od1KVaHUoIIZSMvZN1nzlM9m/SB0IYjwsV8FBzQwT\nkUIooJxRGEtn1Fn6Mz2mavbUo4N49MhuzOKTtfR+6rMoTSypjUjZ6pbkJ4Za\n9dw2z9CH5z6JLVN6wJtwjfxiK3wF7grpyKMQ7kvXYbSa43o4ohlvcIAay77+\nDbl7GESqdtrGivZGFG5BYmrrYpLFajwroh5IplN8Y6Oqi+R7FYzMOzRSCbUk\nq9Fv\r\n=7OKP\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210517.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.12","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.16.1","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.11"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210517.1_1621288570236_0.18243195860520078","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210518.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210518.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210518.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"4d37425d849d4945ab895c46461798cf59473e5a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210518.1.tgz","fileCount":39,"integrity":"sha512-xEiEJ0ljObX0sE/0SUgJekJDNkgQ3bounJ4J2Eaypz6EAgxt8oCxY+4HyruikyIS0cCi0HgzR+kCEXCvFrBpMQ==","signatures":[{"sig":"MEQCICLlpmDeKnwY2q8eCR4LXwKY5xYjCW2wTxyk/qLD7rOkAiAqbAURL1PrLkHzhZc/m5JG5j4DPsCVAxpSNe6LhpQ6Qg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2095895,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgpDhSCRA9TVsSAnZWagAA4c4QAJ96Zxrw9BO5LjRahiip\nVCavAr6ezvK9YLdyL/owQAeLllRQ1wcctTvIJdkANbX9XvAs9XrOogxNMX+r\nSir0qPS/4v9i2HXjoHmNcmTiErkTZeROn7TIUdP6OOSfa7MsV5IZnLL2G5WV\n7QEkOQUBmaATUnJ9ROeXve+PrR9JcLpeGJF6u3hQg9mVBW7dQtCdt55IGyPF\nBJTi9Lzj8k7yXqbwhWRUP3LTdJ3TLKdem/bRB7Qrkgl/ccpg5IHQLbdLVS05\nU8tpdo/jXbCxDE1wLFkodtnZNHX7eEyB8Rzw+dP0V5EZ1I4sbyUwj/x+e2rc\nwZMZRI8Qv3DK82cvo99L0xgxym+FvsQYVKTeU4lQdgnGgE+bprcuNy/Ha+Vm\n8PfVOuj0J1pSv+6SmTw9qZarC9R04CmjpKJJ3mHGVSaGV9nuvptteeDtK9Kv\nX6vyRXGrfdM/TaoEcXsbrgBDp8XUEcm5yPykKFsj5U2td5F2SBHykJkTIa08\nguvUBhvkIslcPAs+eJRwnsxL9OROmWixKAMwBCRkBqkjnvcDECkFzfOkvYfk\nnmWjbMacXxuN3GfWEjVBVLAWb/aZxxRPAIrvrNjl7KXuEBZij225LxX2jNmf\nzqOEbLhrHqv9XZtIu4H6j1oOn+6ge4lKxmVrhmekoXJoSJwnwE3KV9ldIe0r\nrX7Z\r\n=0BOF\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210518.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      }\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.11"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210518.1_1621375057649_0.22429496377550162","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210607.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210607.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210607.2","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ae91dcca18863d04ac6e18efcbbafd835c62b0b6","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210607.2.tgz","fileCount":39,"integrity":"sha512-qsdwRBkv5wvVXghylXsFLcVOsII3AsjIa5fn4kLvhXMteiX013zLOuqyxGUWLQUG9kgFezmh2Z3wKM3a39nECQ==","signatures":[{"sig":"MEYCIQCrKqkMb99DIk0Q88/vG2KNvURiI2XzoXPBEG7relQHUwIhAL6iffrmY0OLQQHT2Pvvdu5vH5OoNGDz3TGVsNlY8jC8","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2435891,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgvpXsCRA9TVsSAnZWagAAZzMP+gIj7fM89OzlpkdYYGGu\n0OXrPMgIBcqoCo3yHRLrxosPAyqiU1uPMIpZ2TUQ8drcG8ETi3oMeO/vXac4\naTL9LtQuO+5j13xP+8g7T52nHVLMzfzyHenvNwm2BW1wK5x+51tETogvcLMo\nh9B0Qpec+ansQHX4DbEWIK2CPfzt16B0GkaK2M4T90mO8PAyq18qDnzXiqGT\nP7r0SeifLAEKEBghvZVHsiyExbJMU259e4c/vCbBfwQCsSNCwTB7HJnALp2+\nylgtkTrI9jwjd+FkBmaVqsFuKdyE6PIvyADnmwQsE+94qnjRDqjnInW55l+x\nBguM611JVQLsV26NEanuzcF0AEFmReC+1B2L1x0k26aVwdmvofgr0sWGy7KZ\nl6qMiRsTrQpNo4KLW87uZHpF8a3FrbSBGApAzW02kTkDdAIKASdnePNYcJIU\n4KtOO46AB6PU3WlhWXmToR34iSzYE7XYRUK7WJMZ+fFgkMzzZEKMqVrSDGp4\n0gwrlUrhTGwnVbXzt+thGzgIqhUrnYoR9Z5kR+S8i+xZ5dlqg2NQAIVo+OXF\nHi3A94xreEyqHtpX5j0xYj8z0CWceNybNPlmIMJitCfL89mj5bAeU27kz2yO\n2z1CrdxRGhFQZFGdhMYtgzYnEsogM6zS8/wOuHq5YoTou+zo1vcfJTkI+Qcx\nLGeQ\r\n=7Wpg\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210607.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.11"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210607.2_1623102956015_0.30628649293071564","host":"s3://npm-registry-packages"}},"1.0.0-beta.4":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-beta.4","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-beta.4","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"f82b31db76e20417a04d2f1b57ede7d78d2e2e68","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-beta.4.tgz","fileCount":39,"integrity":"sha512-VFMF6hI1EGaP/ay0JYxbqVP6YVq/lrx0i4uVFUW/Jz2oojAipaTbPNFKpuFSkKj3hOgkYbZnRuK+Hd955150JQ==","signatures":[{"sig":"MEQCIEV65DAiEUUr1bCjpn6Y7mRKmcq4dLMVz68FjRZKhZ/LAiBBjEm56OP5WJug2cEgoBupunErtMjTX1yMvfUJeG+dCg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2435863,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgvtZzCRA9TVsSAnZWagAAaLgP/1cMfPkahtukdhpgkqU9\nKl4cXq9ofVwvpetzOsxB5FMbjiZWeAhJOLjXG8gz3zDMduquiS7gKh1Ao4tw\nAE8Fg8vARLoXabiY9hqSCZ04JFa1WbG0qJ8VPgdwrnX6emXqP60HRYaslacK\n1MskHlotQYDdHzqzOvuc45NYy5SFXNr7OhBmWH9udOFis4BjHX5KUx9De4fS\n0RY+XJ1eE80eRwBIOAiGaQDW+zcLvREUvBvLwCX0boqef6hGbcSICEwqnZFE\nu1C7dKCfCFJ6FdCPQge1FE3jDLxOEtfaBizTcl5rYIaWBju2ey/5tVgItAFH\n9ChY4yPdD3bE5a80uvLEfk1ieG5guv/EqddGRo7CGrJTq2YE5Q48WJH36b6a\nxY5LgcBmyk9hNmZQkYvvAozyGCOTozR59B8gU/9CX0s/1PTV8JO9BlVjIjQg\ndDowiJB5gWTQ5obSwK1oP5sUZP9F8qXWE9ntOGDHq07nv3EfVF8HYUGzj9n3\n3JUUtcDOJcgbQ9xcVFhoY0nniLGEKYo0vuAApREW3Pssk25K4v+4dSC17iLL\nOcTDHxgI2e13nnUszDUHvJs8v0Mf0/Z9aUgpvkF8PGZHfm1i+PP0CQIJUaHp\nlCSj1OScmODjLyDggCCyqrnMgaSmKqgBpZl5jnYyTmL9NyrqcA5DGw0Lm6sJ\nKjBZ\r\n=0fkD\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-beta.4.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.11"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-beta.4_1623119475563_0.6673761610118949","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210608.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210608.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210608.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"effd67b11302790fe8031db680e499ba9ae9ce1a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210608.1.tgz","fileCount":39,"integrity":"sha512-gG9AUwQiIy58olzGJPXC8X9U4ifE4LlgiDF9gSbfsni10jKY1x8CnS+VXO8oMyP2x6xfGVWNpOHwS29gkPAGsQ==","signatures":[{"sig":"MEQCIDgLxqOO/72ogch75xhhUMoNF7HhTaj2fNXJtKP6nHxoAiBcHgks82EtgcfSb48SNuJBcvt2TG4Lnsr8MxMLNOHy4Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2435891,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJgv+hKCRA9TVsSAnZWagAAPrIP/1v0EvJ1vLiK1SElIsHC\nU7bXvYGntpkeHjdDDLKRNGHW9Wm2e2S/dBwisbZ7lBrnZzfMRXB/BplgJ5E2\nP+JLaX9DyEb4/TUHqOa8eB+SjSbRic3ZmYTIWA4IifOdhGifHgcKtKPTqde9\nPm7jY8d0tcQbay87fqFoY5NY3jNb2duk54cwkvu1aFKfpA4EDS5l9w8VnFD1\nq60EqG8s6oJEtHs+NVqX3437UPqaiOAglA0yDha3Q5y17FZZ2Lk8v379sOQf\nVnldfcvs8klTLZCXS4A0X5ZGzTcps0//Nr+iTiT9zLHBPPW2M6EFtE0tK9Ys\njvPOSS+jsEYxTssjpLpT7zZU5cMuRRpkpmBU6A3PoUClX6PcPZR8UfTUyznF\nP5HiIX02HUq185FhR8dJ+GueS4KO6/w6bUmVRnpNCZxInUB2vJYqguH6V/RO\nGbvanb4iPjMkTbm2pnGJJOLl4HBmECNd4rGjmBYOeD/MeNB8TGZA2ml+nwfL\nm6brJyB9zeeMFYoSEcDLwanqPQH4pLBFk5kSr13aTAKweSsl87MsUSwt/h+R\n02EMkSbb7rysm4vDi962gqZMn7yQIc77Xo17D52QsKjiNOkizVMBELa7LLiP\nVBEJsZG52Ia++cXjVkTD2ZB9NNrCLoPoLBwHi0y6Al5HZ5NXvjgSEKW28EsD\nkB8l\r\n=oH8L\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor-1.0.0-alpha.20210608.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/master/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.0","dependencies":{"tslib":"^2.0.0","@azure/logger":"^1.0.0","@azure/core-lro":"^1.0.2","@azure/core-auth":"^1.3.0","@azure/core-http":"^1.2.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.11"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210608.1_1623189578111_0.9836658164238554","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210624.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210624.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210624.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"9d3471c679535c63ce1ce8593ba43e98159b61e8","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210624.1.tgz","fileCount":39,"integrity":"sha512-KA9J/J6C0c9SH0EVPE5T4P1gb/9O1pzSxNLMjbexNxNNwz/dgpl34VTYteuQ7hTCzXodiErTgy2K2ask6vFKag==","signatures":[{"sig":"MEQCIG8lcGrUSWhR/szjFIZ22WXTSskJ92HaBv8PnJbCqfIbAiBhBj3hUYo8PFYZlRcw244vXaFj1sK/qrfy0cjurhnLvg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2427218,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg1QGuCRA9TVsSAnZWagAAkkwP/RAH+tWNDTG3mZcBGQuD\n/sozQIsbUXtc/sgo5XDROO9FCOmLTcPMYa7G/vJigK+AJcPQo/KbPX5H86Dk\ncDY1KnJLbU4Qb9r4cvYf95iAE6ZoH7IbrPKXhPq9gUmG/B++ri2/R9eZriCJ\nxveQTJf6op+JD8XnpU4xYnD+6WchgkQyzPMWswf5hTIDOOdQmgYOSoOL5y81\nzwfUi9OOmOdDhxbYxGFJDoSgDHda64sw9CCbqNfKjch0BenQrHt9exVnh8UV\nzIFjhn7Q1f+4efl0OqcfqIhKrWNyQocmmhTAYbjg1MDIh9cvM81y6TykLSkC\nFibGesNKcEq0wb0u4yFYdleAOkyYkIfN5Lu6QcE/lFlwBFD/4m4v8UE8RjPd\normJKnUYBZ+6K0KPrX147fE0DFl0dKwswXLpz2zVm5fNeXojHukYoQGjYo6v\n6vwIydoUs/rY5gX93iaSZJs09g19ZqvmQA8jfNnj480qo7Y5DAThHWEVz0p0\nauzs19riF8WNHrK/TbJgzjTRLshady00PSXmlEa6N//3CUUmUXJbmVQ/T13T\ng1QTHSAhAZDNPqcSObk/Q/Y5q3Ww7bRFNwB1T3XG6+lHCj0Updwm+IlDx85i\nmrLPpuQIa1RZ4qPhw1FOnHRAPq7N/2UwAGacDmRJSWonBV6Kk9Xnpm11iDjT\nj5lu\r\n=FjfR\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210624.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### DataFeed\n\nA `DataFeed` is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA `Metric` is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `Incident`s are generated whenever any series within it has an `Anomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `Alert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a `Hook`.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomalies(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey.dimension} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0-alpha","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0-alpha","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210624.1_1624572334066_0.6511752667243083","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210625.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210625.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210625.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"1834cda7a95d39a91528ff0c66325d26ff0b6433","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210625.1.tgz","fileCount":39,"integrity":"sha512-y2w8H1xMv6KdMPUYzi8QbIhR/rsnudc6rIDMRwpMqipQq8RF+nZJ2imShETisPC9NzKka5U5Wx64DUT5fSzBYQ==","signatures":[{"sig":"MEUCIQCnNJ31knSXTB8idK2huU43c5jV0hwC5D0C9hMo5FzvLwIgPhRRwu3TwF4a5RggKmFHp3f1w5nmBs0UamAflC0GAdE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2436773,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg1lJsCRA9TVsSAnZWagAA1kEP/2H9mrU5wvbtnunB4nCL\nbQDxZZm3mepjrAOFxRUuHrEcjrb5CPJbfGYrl+D41aywmHFBuU9vrD5gBQlm\nWVKZwGlIyJTeJ2cJc1lVFq12+IFedbGBUGqpCbTTONyGHA9kkKcqzxTsDfq5\ng2JC65XZsQLZ6z+PPGcBUmgD+NeIzvNI/ghSj5URYiAVxja3RJEH4ggwBk/G\nakw7jbFrDw1lJrfgDmieGN+Kn1CWtUQCuw3XsiEFWBrk2p1bmJk+0HAAoXdb\nqb+vhqoq0Ox2KcEu5epxBm11HgvFHviaPwsCmonBidEONtDNhaeBGGtVKdAk\nHMrMO35z5PokLuALKbHijolC7+X4FxFfx3YJPr4v7wsazCjj1066cyj5lIEN\nXUbJAPScLsIkvL/i54Afj++mRbjAjmb2sHk6Q0pB01NhbxXlBNpb7s6ACRmj\n7uegT1YAIHI/d+BlQZdK40iFnLXhBfJQPkgMGu3wHZ5E63zzocEFXokjtM5E\nabIbAhZO8engdu/snbCnYsT6qZJms1/WEP0GgiMojJH8eY1LEWMpwEBTQ3J7\nSb5N/q04Y4p+hLDFS+o5Ujk0FZP2AMRQQy8Fkxjr8zowxdZayJzjCzOdJ1I0\npzGJzWQIZ17yFxBBJVVVY6WA2VOptaBT8omIZ7LcmfnNAz+LPI94JlugXCMa\nKlse\r\n=w+j5\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210625.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- Node.js version 8.x.x or higher\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0-alpha","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0-alpha","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210625.1_1624658539423_0.5179351457970736","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210628.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210628.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210628.2","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"072eecae636e2376b3911f61d6c27be593834ef5","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210628.2.tgz","fileCount":39,"integrity":"sha512-ozQk5EGeKWV6OYl+dvUlpFxCbNIu2EO+zN1iUFlyrmGKlF0O1J7BRSrBFrC1KcscRGFLZrlZObYFAf+v5uEq/w==","signatures":[{"sig":"MEYCIQDDy9zgss5gapRc+JGsChV8pNoZwjEIcyBp12JstdJu6gIhALlpFDGcCIJA40ExPyBNHCkcwl2+xS0O2yfZ0TLKJI7A","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2394044,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg2kX5CRA9TVsSAnZWagAAOpMP/0IlFLh8Du5/TD7UkDKj\nyRQI84n7LzRFipK914LVOl14saRjXNdGcVJ9/pZXobSJE86rn/2DaZ4aMIdK\nTPhu7FOKL2KdsjsUtjapSBY8snxoI0R3KY9ursfVlr6ZbPuCSG7U91yWBAFy\nbV39YNPWQ2ksAEoIHdFM1hgv/CoOL1b8wbFZOTQ1Lx0Cii+5BcgaQoFApF7p\nYdSdJPlei4ADmcPNxayDgu5SfbeiieYNaf0tUv0TpkUdGKNvmzLc5WqLKtKI\nvckXG0AY5EnSTaU6EcmV7ti3Zlf1PHMLrh63XPOA5y9WVyQpQu3nQcFUSxQu\ntibSaX/bM7AYtbyt3qZVs33mo9B9RSOyub6415xLWu7BbnJVlugA9Is7E9tp\ndUHFzoF5kffUb6q2nzpdpBVNSApSFw3JorUi3E+9YvXNw8+MnbC9dHeV66yZ\nIcK5EfYoU0qm4DjUifx3Tv5JHP5XCLJinOPIDPnDRZzQ6Y8wa/j+MlJeHs8/\nc/0JMxH2I7wJkyDrgd2/Ja5o7Ap7Ifu8NZrjpHktdarkMs0k4CZqCJoVwv/2\nEFKNPyXAD354Pxkl7NzlXX0EKSlc51cERMpllwh3F98WFqkaaOlSVhC/llYs\n1jZXcqN5dek7cetSkFwuPFJSzNcjH1B6ukI2kWjr0AhpqO7q6AAVoasTs1JV\nPAKt\r\n=dPbt\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210628.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=8.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0-alpha","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0-alpha","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^8.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210628.2_1624917496988_0.3543779452460596","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210629.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210629.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210629.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"4cb4130dd60cd66df211acf456f4ade037645732","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210629.1.tgz","fileCount":39,"integrity":"sha512-gKipO2DYVnch7yQMqYBIj53XZYU31lJU6qBubhX7lixVFk+5VHEssepQ4Buk/qbZNysKPwVOguKT6at86xUrOA==","signatures":[{"sig":"MEUCIHNiOn+/qHok29yORhQvWnf8vmowxD4jo7pXNkrLLTlxAiEA802kxGenbdiN+YLWpWn5FheQ4KEw4rf6CAuSUqqTViE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2394046,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg25g0CRA9TVsSAnZWagAASbwP/2KwkIW9e//P94Tvxje0\n/iQVARTgZaJSg2ilgbwCwZEnGlBgyq3+KEZH0WW/TyACSE4uhqYQ1azyqUWU\nHMh9pIX+DPdOcKZBKPwKB6A/F9LAgO5rJ0uf9TjY79Rg8Ts4liw5WJW8UYYM\nEJ+UhSphaUNUAwVSdyNkoPNIPLHgZW2mnmMdpeZ/5EBd/zQ/ggC5fqqNY9dL\nDQ49b2yx1PQjJz6iYqpGP1HOV6W2wN7zi6dr11nelGPIHT51l8GGeNzP8Pg5\nClqd1d6vYrzTEBDJjHF8EIRBtcfdD1Tny1niZSGc4KVJ0+aYjV0mHW/GOv/Q\neubG5L/uhhKgvybwW2qgM1Ol/UZDg3FllQCN5FujjiTWb3dIrEpGYv5VsaDs\nxaSdId1jYCT02GnmkSPSmLPQGAfaX7rKT0WfWDKHcgnDmePZjPR/ivUFNcl0\nM3fo5+eabtYZ1r8xPBQcSCGvtDNL323ppnpUUky9iutSoO2rABT1Jmpj3lDC\nwNIIWls1IiLI7zn9a3b2Wcf+XFe3s00l8mMTvLf2+5WOkaaqzB62BKOj9urb\nH2kj2GArokYNzG6r6ebNjjNow+PkpSagY+KwvNhkKhwGmEGvLHRHJpYvYx2v\nD341yYeHPeuooXhIrVljVMMnom15kXS9ssQsosld9eo3dEcOSiyDGW6M8GI5\nISGP\r\n=KhcG\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210629.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0-alpha","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0-alpha","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210629.1_1625004084110_0.7440961349988444","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210701.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210701.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210701.2","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"0ff053abc5081ff4c53765e3ec22ba62c6049602","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210701.2.tgz","fileCount":39,"integrity":"sha512-/UCaRNZQffiDrM5JwBCHWVNtvhf4NR6+ryZWuIwk3EzEcA9tRsYIefslWurtKBsLJ/rm0KG1RDAXrnPecY7Cww==","signatures":[{"sig":"MEQCIHnwTZHG8DyH3TBb/73yf9HMZHlPJYxs3+BsUWn041I6AiB1hx9c9rokGlrukfNM6v0VXKwF92rjODzi4ySZHjrNVw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2399585,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg3j7ICRA9TVsSAnZWagAAyJEP/jNZiVz/YcFVx2bsw2b6\no7+MG2EjzPukrm4IEIwJXPGzJ0FEyEBkwGK+F7dUQ0XGJthV9tIn7A4r0HOy\noOER/7WfuU7X4q8njLkwgQoSAZJIdzvISOPsrOP5yabHrDzCa8u1iVhS6hpQ\nPoUbocyYo1i32TPit/IA1mog45Cs4+E4pMZLR4Yp6vE/Se9fEFb60hg5CeBp\nZMtZEwDiHuRJGDsVGCgNV5nTqJI739in7asxcPXPu9heG0LSmI6V4yTyxsd1\nzKZSSMvrXmRAqo+c8Y8/3GhmFZ3gboXyyzcAr9CgB2lvkta/N/t0QyJ6BT/L\n0AAKEgaHYAtr2Z1v73PTMDSxbT2h6OGCgqNUoO3VMI3i+R/XPmIJKuChMp8E\n4/1YIl7EIBM7PA18XdpGh8VVQnBZ0yUqFEyNIQ/Jmfy+i8n04ADdYDP9NhQN\naeLCMY9ntU+rbwJcyH2fmMYYrZ5zMCf6szWSU2vwnNUqwvkxQsAiRxVPfN7q\nOR4pwc/FcNwrRu5vxPABriA+HDO8TUOOd4nc1xMrYT1RtVaq1VrIszsTe9Er\nN00AnCXbf02s8EYJCwWeEm6ImtSuWCN6LtP1G+XX5+SP6962mzmes4ej4SfC\nPKx1RJKABJhE/fhaZBSOoQ57JQZoSwy8GSVhEUmithC3bhV044D+fnfXzqGj\nQSkU\r\n=rVIa\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210701.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    adminEmails: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.12"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210701.2_1625177800292_0.32687707328746796","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210705.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210705.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210705.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ddd6a7ca3133b1773c4bac5d712a4e4a22c08696","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210705.1.tgz","fileCount":39,"integrity":"sha512-8sUmWxDC00Z+/EUl6CUrCetLuoF1DpWzlzHC2c9JKdsuDBflFt5pE91h+1V4iKrrmUivwQhvjdEFX7N4Oudopw==","signatures":[{"sig":"MEUCIQDsFo28/tP1dUkP7HYm2Y1vSex2CKHoyfm1u/aDpf9rTAIgCj+tf7XWm+Sv/v9m3fBbXydvqYgXaS4ItwnHrLEoO20=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407404,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg44AvCRA9TVsSAnZWagAAFoUP/087AiYvuiWLKWUDo/8T\natkooSNrEKaChkRBKSAXZmR9xkRGqUMWMu/NQvVBrWE/jxcnjcMReKxxGH5h\nrEUMICKzNHk4wDwtZ0DTj5Kk4ADpVDeCMHtcb4L3sVHcD2AtzF/3jcdU0HtD\nbjrpCvUnvb8/WIEdVB719WCVJtfzelWl3bsevDnMREo5pocPDZcuZp0eKH0b\nmaK8yXedZQpEcMgibyUI7n2Ueju88D90sFYGUL4A2TsIfLdCwqOjlVoJ4HY0\n86s4ugd1iK/Cz/b7zQg4ENUiOrqIdkv5FhuYbqrvfkAAA2GWOHtPmjzADZvk\n3jpYSA8vyOhncUrEP8b9dpx97g9KZza76EectdfTAh/dFhPNLhX3Zb3niBLj\nzDmkYcRXsGEHK80dyh0vjT1iG5ozBJlIy0sB8ftgKoJ9O/P04F/3lqcy4s7u\nam97KRo2B3v/XhDVlFSAsBkvLXNvNpya0kSzA1m386vVH3LC6sQ8E90DXfQn\nR37rycqktfOEHVCTJyYrRrYYxAtQcBPbWesOqH9TO9EVWIJyRVDF68QtfmWq\n0CoIQ+W1dCYH76ZHUlfHOcnbkhRVvk+IXUebWmyhwrgf+qJhfagzgXcCOlY+\niivVJf0oF9mCchBuXFZ1I2xPLBGFsiupN8aT3aD7dAn/m42vEgBh8KK7KgFI\nMULK\r\n=L81q\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210705.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\n[Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/) |\n[Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor) |\n[API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor) |\n[Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/) |\n[Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      dataSourceParameter: {\n        connectionString: sqlServerConnectionString,\n        query: sqlServerQuery\n      },\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.12"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210705.1_1625522222532_0.014112288094714431","host":"s3://npm-registry-packages"}},"1.0.0-alpha.20210706.3":{"name":"@azure/ai-metrics-advisor","version":"1.0.0-alpha.20210706.3","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0-alpha.20210706.3","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"4db02594a02f4fc466193b66cef27ccd0c798cfc","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0-alpha.20210706.3.tgz","fileCount":39,"integrity":"sha512-ASz7b3Zbe0gVAHlCb2IwxnQuPikXZ38MquIhaVHsIpVzSrX8XhVeqoGtqfm/3ds3LAqOc61GisSUF2mA64BVpA==","signatures":[{"sig":"MEQCIHHSX2HAEQj/C9JYXl6mWmbEKtFBLuE+J+aJfTsLC4moAiAOQe6cpoNfMq0YBE4k7RNq9tA+aQYpa6rmjmP0JhccwQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2406980,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5NNVCRA9TVsSAnZWagAAscYP/0XRBxrFPTy2ijFoRoch\nZP2fPrvfAFqd9le3ZEFxonuHIzL30y2ZuLq/TaqC1YxRzlqPg7oHzt371LYn\n+d04eWp4kJ5Xhd2E9zUnPqG1lmLQQlL0XVMYceDm45A3VRZtAI/qkEnRQv/s\nTM6VIOVbDplyZV126VGl+yTSyr0Be/TR5iZqihaJ2pxGUV6RScw01PZJxy97\nMUlKLovk7ldGdsi+9uYRBLIqvvnwxZvK5fusIw9ZpPS0J0w8wVZTptkveGab\nxu2fJVXKCGliynWCAXW0SSNLd8/55epJg/8JHFplUA/lJ0ZNu0JlITiEkDO0\nPFEg7RZx5LFrxKF1JxIe7A9W6iVZKm46GYgdcHwcyCYM6N7kUHUkOhcXZlcm\n/Zf3HLXUGEDaN5cGyvuPCNmB//Kh8hrQHGLBV/UduOAmsnvfGi6JLuNfcrqk\nwondaQ94loxt+EsiozNSy3RgjgzTwDyoVAAH8jdoipXazAVy5EplDJeHY73U\nWCOoxFSJTEadV0/SMEcNqC89tdUBqqiN/9BosaVqz9T0/Vxa19aNr0U+tCrQ\neOnuIFruH6IJ6ugC3aRkyiWpOvbVDQJOXYrvdEXtwK8rI/OjN3hNekymH/gQ\nccLnVCEYoAPeoOAhbt5Cny4DUVYDsGQFdHNHzPpgdnqYJYXTXB6KBVQ1HQMM\nt95q\r\n=CSGk\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0-alpha.20210706.3.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.12"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0-alpha.20210706.3_1625609044922_0.1431550911014523","host":"s3://npm-registry-packages"}},"1.0.0":{"name":"@azure/ai-metrics-advisor","version":"1.0.0","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.0","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"64875f3d2712d381cde5290026f3efa5869cb3c8","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.0.tgz","fileCount":39,"integrity":"sha512-5V8oTpcEGNRIFGEC80hJncx6cHXQOmbGAh78QDn28/uSbIAAa6S9v1iSgHuB/C3p9/n60WfkYeO8ROmksCuxWg==","signatures":[{"sig":"MEUCIFMubtbB7NaUlm+CDBknoAQOGiEWj7dbcFTZ5qtanWtXAiEAwW8XC+vr1ln/jowOo2Cn3FUNkAiM8DjSzdJFo2AE0Eg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2406945,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5ORgCRA9TVsSAnZWagAAfFoP/1ZrEqAXslWwDkKqT3tX\nRi2hY6OaF+olr5vNbAfuv9Z3PsJl1/InBRo04xmYnBaRxUMp9s02ZAfETm6E\nWqyzm8F0dfUpqTZAMedmGbwwiC1SDHrnW1gyz0DU9YQk59ywUVz1QeURwZff\nTzaWVeZnpoyZshbo1xERZq3QPy3Zml8awxMmeMkSwHksJqr/1c2Kw3NuqN7+\nIfekeEWIj6F4nk6hcDa/2FoKtXj+i0UUc1tvCHlKzTYyTd77UswdWNTOy95N\nmkhHXbIPSWk6MC8fi4DGcrF7Vt9e82DOHxiqZAPlaB8Y7O3w5iXkjhOXucR8\nriQiu31NqL1exA3dthcPjaRLDG2PA1xw1qnyE4h1BKOrkOxPoNdc9n1jHf6q\nSeEnvBtQ8TtcmXsQvuxK8kzezSOhWgiKcN8nODm9CpE2IsKsm26oEDrJboOn\nWguQVDtuokkfm7e5L6gZoQ4UINBtfU2BYw9+WiFz99xGfaBPmKsQfw9KCKRS\nCqVmE25E1+G/5xBurxF47PGHwJWBcJwoXpS22U5ll2nl9icjt3UzqIkcoOaU\nqOyVscQqLaRrg+AglCFJpUVqIvnLoC7g5mzFTt+Y7amwxvsezNlVtLxKnRYA\nIoe1rYyRXwYOeRQDlez6b5eEWC926UIDNBh4uNDdvFkFN2DU7m6YIcxX61Bk\nioK2\r\n=vNvd\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.0.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.12"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.0_1625613407682_0.34134720603791946","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210707.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210707.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210707.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"c877c544ac0ae2929656d9efa572c1041e9d21b4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210707.1.tgz","fileCount":39,"integrity":"sha512-5v+nSTSedc5NE9lO+OjpkWvl9DyBgg6iAkDW9XkEo7hVUWsARpI11U3+XR088wCOqrOIYrg+9MufW0C5dgxHew==","signatures":[{"sig":"MEUCIHzCwxNmbZ1Qzo+dFXm1nIE8It/uhIVSrKuIZaQ+eV59AiEAq6RpjxijSjtN/nSpo2jlM40AboL1u0VZ7D/0GKDuyZU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407080,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg5iTMCRA9TVsSAnZWagAAVlQP/0eyzouFChoXlHOwHdBT\nP49FeDDefeOzKybqAzBcsRMYHRbGyzlAVFQgIvPrZ7bKePrnX4rTXyy1RMbl\n4pWgvFTvUqmNjEOY2APnAIcDMBkNqAdZuh94gQ/+v64R/daAJ3T/EHxfKqVA\npJoOE7LR+NCQHutjEK6PZjaCb/Euq9vn1w9afiqMF5NbXQb6T1zBl3VUtcpM\nNozzW/L5fXwpK7hu4W+a7crtYF/jH6tdiVcZxnQwqXrd4yL6nrzY6C0T52l3\n68HR75ttDr8ug+a0iQ4jtIESOFBdbB4Vz1qe7jWW/zp8kXl31v2k8T/CWjMh\nL9y/P5CyrrnMGWgrPKnYi4zbUMMVkGsRUft8+r9kGO9iHdwZngbKSmpA2cJ0\n9dFkndB9yJdvvf34i8olD1NzrR3MlqebRefgK4I3RzxIQvFOe/KWn3DXmCIZ\nxe02LLJjb13qDegTKpTLN2AkiB83IIrsoxpn+6AAMSJaOyygsaWqUb4rrDjQ\nbnshQgA1WdNmdt3D95OXlF788qToU8fEJ6fTO6GFBvf9mNH8FWRzufpybObc\npYLZ0PtsdmjPMKv5FmxosVgK4Oksx9Idxi/WUzfBgQFnCjK5aPS+0QsxQ+xe\n+TkBELl2Qu0XGJVSCrHlR/6/GTH6eDKSKxKjbj/KwGrDU5NGxF2fTBxoFSNE\n1jOK\r\n=wZD4\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210707.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.12"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210707.1_1625695435974_0.8083687144489149","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210715.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210715.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210715.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"2cacdb375dc4ced7dde8b6be9d1ed87a795daba7","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210715.1.tgz","fileCount":39,"integrity":"sha512-DBBMuoTSFvZWw+PvJhEIU/D86KeS9ubduOR1iaeJ2kLztWCYBaTASmQvlTlEnamkJqLrOPAo1xguoMGwLUNQXA==","signatures":[{"sig":"MEUCIG6e9kCl+/kgivFQYBe6sOJ4fn+TTIHuHjby/Mkti4g4AiEAiswQrDS4iHBNDmUXuBOho9wmddfUOMdXmS1xHnZX8m4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407076,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg8LDUCRA9TVsSAnZWagAA9gMP/jzMyOSfVHJMiAh5Yc5h\nA5N39iU2WzUC+66lNMmPBh0RUVb5S2yBlNIhVUoAaWR6JdgvFG28ASYcenLr\nsVZRYOEfuHz5E+qLTQB6evPWClp9P8R3miik0Uc9ajos1Q647UnpR03Z9kIQ\nx7q8VM0VLgSOShWZVqqTmeGVj+ewK/kfdIr95WxshWOu2BjKXEvCSBADca0b\n1vZ+Rc29J7wLbGhSGf4ksZyOtmeqaS9Q10tNvUM2JCBWsk923bx5zWuB0KpQ\nawnvgbXRu3twi49e8xJ94AI85MaFoONCEOQWJqHVN4txCF48nAl0QQcrzpXI\nYXakzcr4JcJsiVYSL6qKS1Sja/gfHI080RL20ef6R0pj2pFNzn5x5q4Zs10w\n36lf9b7ihQ4jRky9eU+0cIj0yo4kpKThpfafiUWld5zr8zI3oUX18Q2KkSFl\nOKRuePhZjzfc3IiKEzp75PCHKcon/0lD/N7RvdLZlCRIY9jieSuMR5coJxH9\nNLUVUNckPHMhI/MbYUEfVkOkeLkPhkmvaIltk/Za/4SuP/VOLDwCMJT0dW33\nboCP+YnA5nxpb2qGgF69/tx4oM6EQda2UH+2Oy5Zf4UxxvwbepqEINNHWl8p\nOkRNs+Uzrw0nBpmZLkWdKpWqHq3RyH0wzC5ypGLH53T+c9HxG6SpMdNNJjpy\nj+0B\r\n=s4sD\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210715.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.3","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0-alpha"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210715.1_1626386644561_0.6375182823925531","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210716.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210716.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210716.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"e4c1d80c201b4e89a92d30f664327533300d743f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210716.1.tgz","fileCount":39,"integrity":"sha512-J978Q1me2CPve8TuMmMyvoGHbu/coSxHAWPYlOESrM4fVSxOuquj50Sz8JmS3uyF8fLvJQpL8ckdNW5/+g90Hw==","signatures":[{"sig":"MEYCIQCdWOmZ1w2XhdFqsABsH/yYkW7S/OhLKm3N8DPk5m5ViQIhAN3MTPeYGuin+ZN7HLS1KxUTJIO6Y0Smwb6NInyDlt5b","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407080,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg8gErCRA9TVsSAnZWagAAqucP/jz/gwkt2CdglJAvF7Rz\n29tHA2gbf3EHlIE8KxoD/goMTZ5NE1CGTjZWXDUffNioktfFbDkbF75bSFKh\nHajIaZdyJCYP1Oq20gqObSZwe3Stx07BWE97xte0A5GQhgjhDYYLRr7cgooT\nZXMDF6kCuqjPfOxUznGibWoJAzx36wDBgt+XlnIGUviX6WHWwExzpySEO8A9\nuDxqJgQZUAf8TnHo+ppYUqbK2onL60udwHBGeUV2sSOWpK2noHyCV83GN0ea\nYF5tESChFz/S5seaSX3IG1BK/QFN4EPX9QWEXdrZtxldhcYHpjEdKxm/db6f\nfVfJu2DaD1qfqBjgVXSvow9xC/MOT0WeoO0efcj7m9O6/3NAjyuKR44Qwzo0\ndBAWePYdsn1o2xgY2uB3sqsW8H8xnTpe2Bay/kOU+VPjPBIlf13s1GevmbrM\n9sNt6f8Shqea1FE9CTA3o0uESlWRYCtmnqSq5jq8iGAzt+iEXC1kYrXMAfB7\nEX2YvUJ6A3+q03LMreBvLXCYQkQR1/J2auDkZD0iWYgMtSZpW6/RL3OPjo2R\npsnXxI7hfcNVoVP1I3uA4L3vEakI9oOgAUCL/b99Uvza/pmBLjBpbbnKFgwU\ne+Jkj+fc2lQBUP1yYgdUNLf9u6aWKWg7pe0eS4dX4fpPvlINrsjdbseT0Dos\npFei\r\n=J5mq\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210716.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.13","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.3","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.0.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210716.1_1626472746949_0.6267431287122136","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210804.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210804.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210804.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"12be7187312e4be7ced718c59642109c3e923af4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210804.1.tgz","fileCount":39,"integrity":"sha512-DJk7VNh6hNr98Zjmh9Ah33wC0fqAUwnrLjjlCahmpjgMWydsmZByZNlxWbXWY4+cTOhURUpf+nYSM6NB5xwrnA==","signatures":[{"sig":"MEUCIHfg3AqLB8UqWNw47SbPcTYfVNxCL2a0ZXgga6jNOPeMAiEA/OLwsqDRX4n3vWgVTyklwzjCrx4BkqHZXPxuo2ecCGk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407086,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhCw+YCRA9TVsSAnZWagAAnjgP/Rp4z+GY957Y8kGkL1wd\nwP8YMGvE5hh1TAuA0BNDhF9niO0TyWxsauNTAMyIYC7nS+mkKL3s+I5YolvG\nA7dnxNwpaRdmaJtQNEOe3aV/s5G93Kh3D+Gdq6Vhwdm8MjaG/BMawTvT5yyH\nLbnIYuJj36NU9B8vksRbcggHKjUS6/1d6T3MgczhWrWJyxz9d2v9RDOxPY+U\n2nP8HEjAV8ns8/6p6Go8GCC/8SOYvcriNrxVHgcIBHd2xWIsHluz21IPuRdO\nAJ2bIlEODwBgrsedf9I/LhCYM4RuT2gtLkaWrxeaUy19ZSIg8fovP63bYmR2\nWzuM78nAmnG50D5RQaiIJ0UwHV8ZHBlBiF0waIsF1hF0XhQrhqNycmeUbTU5\no1C10HDUpvkP5aw/zFwpZgooLmY0tGkd7JRTuK7h4YSyvs8cqJNVW3vre6jk\nLlhHWGAbBnrqJ/PozirSSj3QMrg0Y8bcmQkT+6Urjl+vvJo0AG+LBHyRP3zL\nHjYoTCFKjRpuA76fWOF2jKWHK5Byuk1gzUlpeDesSfjBzF6NbIHDge78sZVv\nDaHZsxW6vI17Jk/S77/bAYCkg8ZWTsSpzp463dAN5xGAt49+Dnrwajeaq8GD\nfwU8zdjLcL6KgOrq4jng0jqf+1vkkad1c1mBNMTGLpyGvGISFEUWX12e6lKA\nTs7w\r\n=0FgO\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210804.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.14","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.4","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0-alpha","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210804.1_1628114840351_0.025430835631362614","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210806.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210806.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210806.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"db1747b7ff9133cef6b2931e2d74c42ce4bba1af","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210806.1.tgz","fileCount":39,"integrity":"sha512-2Ykqo5TIvm+7jt+yxz96A3gcT5LKG2EHW1NXfbBrXUA0i7Wh1S2rw2m4gdOJ3vyusthp7356r4os8OrkuxH1/Q==","signatures":[{"sig":"MEUCICThMlpXRHFTEForqLRhHscSzGMS9vHcYW1yxFLRIfApAiEAwrCQvAS/Sha834iI60KWgRct3SuPdQ+tcNA+Gnv/NSg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407080,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhDbH5CRA9TVsSAnZWagAAh18P+gLR6+x8kRJQHssAFKR6\nI6/deE15S7fn5YTXyEkX8eltyDVk6I30guHAcmJU6Xt+Lkg9AJIeE6jCXYtO\n/F/zgL9k0Dl19kTDkRyHBDU6aDXjC829M356+rgYc5bE+V4RQrtVQmXJzCJh\nKGbaFUmloa9K/Z6kEqTPGrYydnCee/KVvgQCc7V7voy4vEOVitj8XMQmNfPF\n2lUCjPdVGHJhuiq22pgAjcrT/JBzsCZO6hy0AF75SrnPPvlKceWwSUa1uZGN\nBqM/fWCr/8TG6yf4gSYnuZDefx7ZSnIWeWtVjweBFfp01L5W5OHnUTlu5JeF\n0DakumX2MTB+0zPKriwFvwC0q77oxOkMf20Bf1YpP6+HvucQqkTHqWMmzZ5u\nANwX+kUPualLxoSwSjuX9RWblwe42SdSIwCgnjcSB/CfjCcYfrHHroEIcwL4\nwFl2hEmJh29giFqw+GpLB9adP/4f5rFdhQhnHeEBFaYDqCXII9Yxpse7rVCg\nf51QtmvEPuF/WFOhAo7WmYOTX9B2JcuxQAkBanyBmhPxVZBxoGuPm7UA2bOa\nltnDcBfKB0nksbKJu1CnzzkT3PILMlGm/MQHSqugac+9/95ymmC70z5M8SMw\nGSde9jAqPYdDJqH+KPdumlR9Q365/dihT/n9S28GJDaC8UkkTWmfAE4UF1N0\nbZUg\r\n=HE6+\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210806.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.14","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.4","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":"^1.0.0-alpha","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":"^1.0.0-alpha","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":"^3.0.0-alpha"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210806.1_1628287481623_0.4864990256873287","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210816.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210816.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210816.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"7e89f24f47d37b5c6f1735c92c74e5d8615e710d","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210816.1.tgz","fileCount":39,"integrity":"sha512-33W7ZfWIm5bB4/YaygUsHwCrdT9A+NsdfUd3SMliNgtPB2X5Jb2CuP66zt/oMg7W3qmDHwu40g6sDyt1EOuwmQ==","signatures":[{"sig":"MEYCIQC2uiOcCDt+OdQDcpcdfigJbzYnyNy9ps+ba01Eg0/fsQIhAJy4Zt3b3Gftb0L8uHoILKOCcA44784mgWWvdVkHRhGC","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407122,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhGuIECRA9TVsSAnZWagAAKfoQAKT+iQ+6A2KMd89bbzV/\nrdpJqImxzLyDtmiEI7/Hex5eIEhnYEeoJn5Z1cX+vCmD0Hsx70jiJdr/Hhy5\n4+H75sagRm5nco+zXbrNt/aYQkKRItJyxICzh5HXrkyuf6GGBqRwKfe0NMhD\n4Gj1BwYQ7d65yKNA1KFEHBSFi0SKYktpd7cVsIZ17Vz2IUx/7uY3hyhF4yEW\n08KMbgDdBYjHyqYmx766MaqWltVZgln89kbWhiZI9bVOs5HrEK4cZoW2j5Ch\nhX1leOkTox2g3K7iWhTcJKPTZ5hmG2AZalSkcEXag1PhAdUUR18tAKSzCqZT\nAwlpvh/MYf/q8eJLYFj9OpA2xESkt9uRNQpit5gB43SzYWT1TOKcKlnARRJu\nAGUEFPOA1uGQd5C9aMK7AMbXsf/yQZqSk7VjWEq/4j7ueFVhRLda7MAYACoU\nh6n3MJvT5mdY3KScrJ8rgXkh1l7B9XgQFqyW0w62YSuhT7cMzAAt86IHz41w\nvdvVeePdEZXUGh9EatECd/iH03ICiWlqorCfGT9mQJnGVLJek0MiJRkVnd+D\ncvU8Dto6w3FJIht3QUDpvt4VNuvNAMUzL37KeiIuBjaJQGYGNFPVSL9qaM3p\nHEuQYlElvu1Nn8MQYbRRGRJ9GAE1WfE+h2S3PnxjAbS2AXm3FA4yS16fKNvK\nX/u9\r\n=vLe1\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210816.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","prebuild":"npm run clean","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.14","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.5","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure/test-utils-recorder":">=1.0.0-alpha <1.0.0-alphb","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210816.1_1629151748061_0.17894844441273605","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210826.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210826.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210826.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"29ff3c954bc43b9392a2782de258174b77ac2117","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210826.1.tgz","fileCount":39,"integrity":"sha512-xq7MsdUaXIGOoVew1hnywgH0AIQzfLQT34uZcSEwKU2aFT/HskzypyamOezs0MpuIDhx0vrC4bKReF/gIxCg0w==","signatures":[{"sig":"MEQCIAjxQ562rRTsPrNkaq0+ysfrJCLEOaOMAOzk2jN0kqqeAiAQifrOI9ji56w3haDlUD+dsm9Y4hhNhb9SrXg4PF2r/Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407106,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhKBFSCRA9TVsSAnZWagAAtwMP/1T0JTpMZBjPun+uCW0P\nTRQjL/SXa6Xuw5/RtMvC98GFoF3vIgr1c5ZJ7Utvt3w9fHeHLviXbVuQrx5e\nDNl2LOmtSRxd6Nf4c+4vw92xI+wJkGYH2avYXv6cP2d66TjHgXWX4sFY91oE\nYioiNQ5meBsgkZNaSNupPFbSlkfolgaz2bjOT4UbRhkcs8bFlFzgysuHdan+\nCUtbBex3v+HZDgjq3KaszNWLPRAPlWjsz9nKoGdOhOGrlEnbsTc7u/bI+IS6\nWNsG6Af7qWSfoWql0Pc4aBIZjrrdDiEF3MYUt3duN0DNs975bgB7DbJkaQSx\nUCt0s/g9XcsqhZrbqIXII7ZMqbzS01lA9M2XPBK2fowaMEABOR2AX6/WynRe\nuUamiijCED/CLeYvDOLl6E+uxQ267/D1vUWuufpRkAo+O2y9PI3XZgxKZ1YU\npY2vnGcoiUUZrRjapdNk6h9s8Q3pxnDpWJO6G8oF0x9k0pbJV0oNnSSdo261\nA6YXifeQj4B7q2yTa7SbSWnFinbiT11MBSRwNY0EC3E8pFxxSfKuY7ORr7ni\ny+9mfsfg5CQH/jQ89Vh32/89ntEuESldym0gA2SnOeBOJ97pKN2APGdKFExK\nWwHAvjHurJQdHFspJIB7KCPVi7YNn/bg08Ph8QzPboEF+GPHWr8kNieZUmpc\nqKIk\r\n=MrA0\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210826.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.14","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.5","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure-tools/test-recorder":">=1.0.0-alpha <1.0.0-alphb","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210826.1_1630015826183_0.45009951257637115","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210901.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210901.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210901.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a694d3ee28aea166e176e161011443ce23d09917","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210901.1.tgz","fileCount":39,"integrity":"sha512-GMB2RPPDy0BrDNh3raoho5sgCLxtFhJsk1doWVVjh0QOXC2+ILzbcQexIA8zzc69QG04VXC+11VRXhWz3mD3RA==","signatures":[{"sig":"MEUCIQD6X4ai3D0Z6v91IdP+IMPMBN1o3Pxed9vNk2WDII3N5wIgBTgyLn54GoQIy5WMrsAR8wJLoe+sYBZt02K3Lo7wgzo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407086,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhL/fKCRA9TVsSAnZWagAAAioQAIBmyxUgSmBwAv2G+tyy\nOmAg/q7IXg2NBtBVXgG4ASOrGelCxOcEFWLnynyFApfg3KCCQBTF+/jlHZg0\nVTbyymZ2/U5jkOkGfL1AAFA5Wv7NlENU7zY8nCt6RepdQPYarEHXyAa2cqI3\nNr1DzgVVOq9rPQqgSlKFboN8TJMEvu7lcB9Mo+1CWPqEtCcRNFGcai3NCotE\nSShizHqSyqTAl7rch2cdlakveEF1UKRwDSzoft2CDBd9kI1ZnO/okVDhWqxV\n8wQHtB0tqoQ74egNkqP9NVLiNJkAkMjvC8wQrTnUeViZDReQNlAStYwDYWvW\nFW8uA0LjuHfKDgPa9DVfWsuE/iq7LwQHApyZhib/Og4Srs1/NbZrXtYDkXHi\neGKiGdzIIEmM33cNqKqH8Ddg1WP+eqIQxGj4V6DNODa7EjHu1YgjcfewqoiO\ncj6Co5bXmd4n5TJfnewT+OkPPGNbRh4IwwpeK22MGq8VmUPh1Ztj5HBuMVj9\n7s+bndNk5F/47pBukgHAdVzPqqL+UTQqzpVLhCakxkW1VLtZWTMNHyM60/E/\nrCGOi9Mo3zrtYTBcYE+vMHJHXk74jjT44dstWsF9kDVeaJLGqATKAEsXRg0d\nlI8eC0ABL0uS6E56YDvU0XI/nk7gtKAQv7kp2TQ72/QzUBV8q6IDzxQTCV3p\nEc4A\r\n=8ae7\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210901.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.15","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.6","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^9.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210901.1_1630533578396_0.2576546305334415","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210913.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210913.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210913.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"41612b2103cd47581ef71798e72a64adb20cb1db","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210913.1.tgz","fileCount":39,"integrity":"sha512-F46sngyN3gmmKTOw2T5FIzaa6RCzj/DkusKskcU8ZHrgunQGJKZSTNx9W26SNTvjbYd4ylfs2Bi8vkAAIoyEfg==","signatures":[{"sig":"MEQCIE5bBsKeh/tgXFJ9VXRqfyct9u+WdJ8YrcXdeEhkyIZuAiBq8ag6/nHaVcym+OoZLY4IG36AOwzuBKg2xqdK/gvJgQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407087,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhP8m6CRA9TVsSAnZWagAAEwIP/A2bNkWsUY1uoa07SaA5\nqAQVOk6yl330mhMpdTEqem4CvAzpBR/BaX99kjCDBjQN/I7bkw2sGMlTN9Nq\nLyiKh6oGdm2tR/WBjVFbFTdIjfGJnFsGU5F/QXoAOmNX6i85jWehq9eJSrw9\npeeWWE824BBGKI0dBV5NdKdtqvWLaxsLkoD3RalGXue2WxIev27DWeC8I4q6\nsb31JOsVDJCoBYr3JhBvtyztWibo1P5hIu5vHTNKvekS3ByLy6Z19t3leTop\nEhLboT08tAJjFwQJaClZOxEpiUft7Lu+ETMvrgtQ7ERtrxgGjdj07r5qiXiv\njhUkRxN4WCbOZ2jaiqCjsXLVONT22a/O1biyh2EPuDYmuELFHStfnUsl3FZ+\n3lkEUsWCDMphqwghGae9+xdomLkbyJ0T9h9TeN7+g9NSfYPMFMuDsKWBisks\nayqbH0EIGRLLFBjoK52SkHaIqg0eX0KhaqI3WASpGS7cJPUIGD1TL7Woifqp\nJM5DYJRZ+6euLhfepSFvgZk7AGNj32FA2cXYeCcJaQlmtHCaxHUSwpZyOuK+\nZv1I23NVdaB1F36dNLuw+Q/mO7IZHrsFyEfEUo+0CDHacNvMVOV/j52fmXTL\n+K1zf8/OBqe6lLYYG7bbebtnb5Z8dtY/X2m4H7ldPMV2GlPYb2cupayo5tCo\nMDUY\r\n=WsLY\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210913.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.15","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.17.6","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.7.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210913.1_1631570362748_0.9851360616888489","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20210930.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20210930.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20210930.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"43a5c04af64723ce9a83c66ec42dcb87510e2ef0","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20210930.1.tgz","fileCount":39,"integrity":"sha512-MjOMBuXaoCraGWHuOSwTAbVuZlXmLC0SsxQv2GObortDynSEs2iwfxG4E8LJVNxE3gHD35BOG3HidLHL5Oj/4g==","signatures":[{"sig":"MEYCIQCTlhxElgbwxWt4rgfG5uGB08n1+CS5P1rhYWG6xnIoRwIhAMDoDzZuWadFiXReV5S4zlmRRlQXOp0Un1wC90Wjxwsc","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407091},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20210930.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","build:autorest":"autorest ./swagger/README.md --typescript --version=3.0.6267","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.15","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.18.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20210930.1_1633039137921_0.6122835636419741","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20211101.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20211101.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20211101.2","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"9705097fed6a4150ab892932615d1bab65e1d15b","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20211101.2.tgz","fileCount":39,"integrity":"sha512-Aj0dse+QzRxdqdQqcea737rhjRVjxEuGu25/W0NW4uZS0fTTS53ECNbhmzp1xstTSBR/fdtYmqj89msLp3nXxw==","signatures":[{"sig":"MEYCIQCYQBpJkMsV7+tbO5P/twLk9XHjTffZH3dHKtI8THCvBwIhANWZVUqYpxO3dUd/YP35NnsGkWvPhiAz1BaxVBbbX1qb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407073},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211101.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.15","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.18.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^1.1.0","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20211101.2_1635804635491_0.19296877352930064","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20211116.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20211116.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20211116.1","maintainers":[{"name":"southpolesteve","email":"southpolesteve@gmail.com"},{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"070f2228c97a35f9952070900a98101e4b4f67fc","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20211116.1.tgz","fileCount":39,"integrity":"sha512-HLPk7fyQPnLV3TQQ5d7mVkrr5RjlUq2Z40nNQyxvbaiFuYFzC1th6OJPCq7ntOHHrqIgvhhVzLoZvi0i9Oykew==","signatures":[{"sig":"MEQCIEG4RIM4NuL9bt2d/AWWLAqcaM9Vavy6Kmy1sL2/utM5AiAifUqfAYsmm6MyNsrG+FzopYlUPwjEpLmqXNAf1bBuWw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407073,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhlDmaCRA9TVsSAnZWagAAmnsP/iRllSDmHS5hXWueyEIA\n03Y5EI5c6sSQcNESHajAZ0DqshSst2tLhmLZ6P0Iw2wy4Ou121UgdqgWYUwX\nBPo0/0WWYaToYz3Qgmn2Gms4k9V1oBUjawp2P5wvkhWtXvIzZ08vnTptj9b0\ninZLA4qBX+zQLQrvBss1lt3LwCYUmjgFQjCKXlBMxynrjmzv1gKjhqZ0YwzU\nF6cea/IUef0OaX2E4v/8YvdOa0+Q3iQ+2moaX81llVqpCoBvA1QCPOpEcfmb\niQlFSLQ0/4DSpBPfnQhIbATYgAgupx1pSnuOKT/vUd1OW5XOr0RbKLLHZTl+\nLI2ccDX3dEoy/x/sajWefcxW8EViUYmjJaV3wiIrxzw72VHz6UJ3TgzlXPj0\nYm6gBNoOVYunOxcFY1nYi9M524hc+mw5HqyVB0HeTW8r64EWKmavAAm1Zjbm\ntCrl/CfUnJ97KlDfDPvV3rIR+0wFJwSw8ReCk4zhVeKkmmXWv7cQajgc+7Z6\ndIgldpnpyXMCxY/Pot6sb3cYM1/0eudPlUvX6SWeUmxscBiBryFehv9l87ow\n/QqlOB5WMK+MShD6KAtf3qMYBDnRP8MIePYOIhusRYLQYnmDqKUio+Gsj5HT\ns3P5jqJvqbJhEGB7ifkKY1E9qnQPxpCvPr5nGozJg9UuBu7z79v38/UZbdiM\nRWHk\r\n=1Ky+\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211116.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data, and provides a set of APIs web-based workspace for data ingestion, anomaly detection, and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names:\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. You can find this in the web portal for Metrics Advisor, in **API keys** on the left navigation menu. The url of your web portal can be found in the **Overview** section of your resource in the [Azure Portal][azure_portal].\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key, or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary querying interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us market.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series, and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within it has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact, and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\"\n    },\n    granularity: {\n      granularityType: \"Daily\"\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\"\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\"\n        }\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" }\n      ],\n      timestampColumn: null\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\"\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\"\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"]\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1\n        }\n      }\n    },\n    description: \"Detection configuration description\"\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\"\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    }\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\"\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" }\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true\n        }\n      }\n    ],\n    hookIds,\n    description: \"Alerting config description\"\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"6.14.15","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"14.18.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20211116.1_1637104026309_0.006556277997040949","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20211208.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20211208.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20211208.1","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"d1d980fac74626a70832a68ad58aae36ea0ee288","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20211208.1.tgz","fileCount":39,"integrity":"sha512-610gdjB79UoFkJLfrBYcMTHh41kbvpeHt0Fn65F9TIOGwWbpEGP7ByqPr4TfiRgyzElqP8jTRx9t57iQNJIFYA==","signatures":[{"sig":"MEQCIDkw/4nxEqHeWlCJAbouTUquvdvP8NnAe+b5mpinixebAiAtRbQC3nuykwSfG7rJoHpTIYoj0re6Q69MhY+c2B3iTw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407059,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhsT90CRA9TVsSAnZWagAAry4P/3bAzUc9E45hJVTjQko0\nOy5RLKPtOvPzrDUjCJfCOjU2N2H2SdsUYaa1y7FPS8LMs6vJjXEoHALc5pBc\nsFPJ1sJRI06r+OTe/rBJ2K+HRnOuS1Riqz05XbnCiYyCGN/W2r7a3qgqeigq\nT/krg/83PGu8hmmpK+NU7KARB9AwDTjd+Yb/69LIuakntvxsMlpLJh74fONC\nsQWHpp38FgqgKfyM1MGFSF5eaEojim+Ykaj2fdixX+cykIwfEPM53DkRIw7c\nKCAJpG+J6VGp/JbDCPRR9xRU+s7Jx+zZqwPQnpd7bvTZKqTLe4wly6WVSdZW\nCQiMuZJILWROInhYFL8fWCe4L+mxD7+oV3//Yli3RoL5TKGZqje+3FMSMD2V\nbhQgZO5WKjgeQEAu0u/gKfesCAqsTTL8JjRIS68J+o5nd/cH/LyOU5I5IlZ8\nLoeWnafvq7VcSKTlisQh2NxNa8OO8bjAInoc1R1zFSjZM6rgAR6Ob6iL0j0S\nTi6Ml3jmpIpOv40LoJytYre+VnKhnxLPfaFfba6d8iM7H1eNRoBXJepmt1hr\nRyow5UllMYtxM5M9HEfOdPTjPrv2H5Qtytof/EgwDS5+9osjyBeGEOZI6Baq\nU85myRIZFgt0I8sMnwRBN8DfGUtguNoxPdQzZ9aWzouiPRWsx6a9AYmdm6Rz\npj8R\r\n=t5Ph\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211208.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"docs":"typedoc --excludePrivate --excludeNotExported --excludeExternals --stripInternal --mode file --out ./dist/docs ./src","lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211208.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-610gdjB79UoFkJLfrBYcMTHh41kbvpeHt0Fn65F9TIOGwWbpEGP7ByqPr4TfiRgyzElqP8jTRx9t57iQNJIFYA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^14.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","typedoc":"0.15.2","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^1.18.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20211208.1_1639006068009_0.35323772541698495","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20211214.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20211214.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20211214.2","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"26294b94fe8c433c4e11517ae5bc3eeae3a16b9a","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20211214.2.tgz","fileCount":39,"integrity":"sha512-oJzWneEkIOCHLmRz0bp1QNtfy5sc6qMP4jYg6hOjsC86AY6E+ioqhKf2U75cX/daP0suGhSimCZbGQYOcu+nOA==","signatures":[{"sig":"MEYCIQDD+Mi7UgYTad8T1H2Nu2Z9x/bHCROt2zdbKZ7WBtz9FwIhAIoA034xj8tdTzxK8Cx/dSZdSHl/bYwSiUuCIGdEozni","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2406901,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuSEJCRA9TVsSAnZWagAAUgYP/Rg95pu4q1YdYMzltdD1\nnzfFaxe8CJ4AHMmvS33hWAJ5HuMu371vgzAbtNJAQRyWxUIpc/6YT91m0E7G\nt8wF0bkqaa0J+rySrnVfTlr9DNTVcE4wMyNL9CX9IId8n/PSbT3Jcoiuek6p\nQ1xebiL35i1KIH0u6xsPnzfGnh+i5gR24NL/hlGcrKt0Iek14lTMfy/ZQq4f\naVlt5fhaBV/DFhhVwU5zrP0GMeifScidOU+kG7iDLoH0yoKBBPcUXG7qnnHX\n+eFInpgrLKOtjZLhW5hP10SNlDoRRBtTtWcwt8wmJMuVG59f5R3AhpSGuGmo\n/nLCwYCgQuSh13vVlp2t9tVfEsiIWzcig0E7pYgTkkngK7r2TQf81wMbHsz9\n1HvG0zVFsonE/o0O02aRyEBmHIB9OfV2rLSRUuCYL0kHkIZlcA2nA4jcx60n\nuw1FQSsfG/eWL5PCCE7p8+AgBTmvHwt9PVi/3YiiBo/+LRHUBR/La6Kb+ee7\nf0TA8ZO11b9gN24LAMgz4hsVaogmM1aqLep1GMrElz+R4aInL5TQHDuOP6th\nu6p0xk4rdJJHzXgbLi2RWzqwtzHlipsayfSN4i4DSx+AC6J5BqUF6KOKYnxX\n1lzUWJAmZp01gc0xx6idLLsFwMUNUXA5elvhcbERkY65j3QrndqcQMqbw9H+\n8En/\r\n=vJFH\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211214.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211214.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-oJzWneEkIOCHLmRz0bp1QNtfy5sc6qMP4jYg6hOjsC86AY6E+ioqhKf2U75cX/daP0suGhSimCZbGQYOcu+nOA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","prettier":"^1.16.4","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20211214.2_1639522568873_0.5318681581650022","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20211221.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20211221.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20211221.2","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"19eeff75b93069a57705084921609df02294c0b2","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20211221.2.tgz","fileCount":39,"integrity":"sha512-hsl794LWIBamEL0gFpNuOoS4xD603d3n6nhbQeyFwibQ8sakElcCYgQwOBnqD1h3S1hg227p9pJ2VkHpdPHUFw==","signatures":[{"sig":"MEYCIQDAfsRIMsOpvWfyj+EvabXwzTKUr9Vsa1O66VyE/t+uVQIhALPYggUBiYgPoUWAdwPErdoU5jZkR453zQvoemYk1x16","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407830,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhwlv/CRA9TVsSAnZWagAA4scP/jaqZzqeSplITDS/Y1QW\nAwCBn9yQ/BXDh62VYfRmlxgKsCjm+KQ5n6yzz4UmRd3NvmEU7CmUWDNadS9e\nUZ0nnhrC3/5iT+OSr9AG/Pjze2Ug647ru8zDgt9e07oUBX9qHS6y3qgJGCp2\nQmxYSfp5HdrheP2MbGCP26maUoELQYrGhX0I0vbbcRVx8DZ2HnTlchwsZSKV\nVlKXdW0fG2/GYT6soJbSUgN3ud/EhgkGNTOCfEdano17HWrothe2E0l5/EjA\ncTFfj0WzzMrHzHMwlTlGKcxLT3nNzR4Lh5OcmDp6qQ84I45Cc0tnf5iYnTfB\n0lhZ6SX/ntlLG3f1nrhO9KOTlp89sQb4QP0bi7xkstJehBaBvNfl0lT8Sbvo\neoC2oxS706ibiayHGZLbvg8F31usu3AKdHgE61vZwUe483lLped4wKkjSK3w\nunWg/HjAvF2bDpZYL6AI1RIpLG3XuJumDNMXgt4Eee3mpJ6DvcxiGjyy+F3y\nkY05MP4lg9klBIJPRPxzA7T7SnvGdyA6P39dBXrN/jJjyA6S0HCy+0U+1SvV\naz/YFPregGao8FGKs1PhQVabovUZywNTqflkRRXlzl/SNto+o0nsZbmXDaUM\nchHt/ZgPQYMw/kxEWpYLYkji/FJh5EijEOaqtfp/2JsyhQPUowzVdCQGVBzw\n7QaY\r\n=qe/E\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211221.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20211221.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-hsl794LWIBamEL0gFpNuOoS4xD603d3n6nhbQeyFwibQ8sakElcCYgQwOBnqD1h3S1hg227p9pJ2VkHpdPHUFw==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20211221.2_1640127487611_0.8991509692025472","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220106.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220106.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220106.1","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a369bfd92115e61bb343b3bf472903540152a811","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220106.1.tgz","fileCount":39,"integrity":"sha512-NXSz0n4ZEYvfE8IVF/wMzmxFbnVaQETAfCT3B0z6Sr209BW98smTOHqBO8CWHhlXp2otMcKAquUNF4U91Uz78w==","signatures":[{"sig":"MEUCIEMscloH0WYYL5cGbZI0iC6pjw3P5zLaEtprE0EQW/Y/AiEAmJsNXN/59HoUHGpCLFAA2DzD6wzmDO0A/HNobFduoTo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2407885,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh13RFCRA9TVsSAnZWagAAZdUP/RjeYcUJLjXTZv4OqkzD\nadQUobvt7crVcFfHCBFnDipWzavd5NSoluZ6S+UoV+iPjzu4AazYMXnS5mUq\nVJczKIgaR6llcvFtGsvH8R696HLk38BTjLkzV99eT6qFc6O1KyKgCk++GmMS\n3RkE90ivoMGapu8lYJWTeZmEnikpE9YP7GG5nsG3HhZrXm+0xC3KmTSyXv9L\npJTekbBKooJT1FbEbi55C7wWTq1pQYvteMV/kZE9ped2kPxi/27wmSkHMLiQ\nsz4tA5S5XI93FqEloM2p7iZJfVVPoE7R8gt+VvuaXCFW52gD+RXVXOXKXTl1\n3ARPO+mgl/Mza4XHOhtny2sjr3wvX/KXMdsWZN5dqVVMTKZ+7MFo1Q+cHt4E\nUKr3FzAUfmt2b8oC6rHpd9lHrG/pUYmblpuh8rsSe87w1onMuR2Rc9FnKJhK\nc4k3EhjrB5LHNTUt0Wd1jiBuWABjJRe7tDmXXK4Xxg5Ybntff5ETAPeOmn6C\njyqLZAFs1XYvDUW2XZQDZaS9wNKoxklMHa0hZlaaK2PfvdlQ6TkPth42DnwD\nqKNem5qviYNj3N3AywiHZUMflskki3tJPV2dSysOOrKZFbCO4ejn0+0gc/8/\nvT9Cljr8pmOBUOnkSYfU/bD6RdwReMq1mIl20ukzz0zOKzg+s3b2+mP2gXuF\nzvQG\r\n=Te75\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220106.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220106.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-NXSz0n4ZEYvfE8IVF/wMzmxFbnVaQETAfCT3B0z6Sr209BW98smTOHqBO8CWHhlXp2otMcKAquUNF4U91Uz78w==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220106.1_1641509957032_0.42812160512191477","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220112.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220112.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220112.1","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"94d836d96b8edb124305a78e1440928c2131ee8d","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220112.1.tgz","fileCount":39,"integrity":"sha512-73jIV9hdgN3URYoZjsYUgosboA29aHe/tofW/hQARfezukLdr65XOm/8eWlfotHVYgEM9UfrsUUNMCOrKdZhZg==","signatures":[{"sig":"MEUCIQCg3iuGsZdfBk5TLNxL5LnioWVhDjDW7pN+X99zyIvrMgIgXPhhsvYqr1oCDeP7YfHiKBGdUMlfITs15psCpGd8LNk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2408207,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh31zLCRA9TVsSAnZWagAAAnEP/3V/7MduJpftuPnqbEhb\nDN2VmE4gASHyJmtAPbRiwb72x/vAyZ/YX4WZLUrX7wZOeoPT2eKcO0WclaC8\njRilxz62LKSupeKxONJ0nnkm25gaOCF3jmugMqR9t4nebhd5W+5Iyz8buyyW\nOa6QK2lS2iIwqR3K3wA6FhLIZF1qjTrDptHKurX4ApercJTGI1bhwXs6SrQP\n2xAJjKrBeub1ZtsYopKCMx1RTIehikv0TkopSi5UGnBYZbF4/KH0IkAzdab3\nFsCl/fTzGOxSTxrhxf1IO6fC/DBFhjtD0NnTUm2HzbN5lT3rR41KMAUaiTbt\nnMUq4Ne1khw04R5VsnK2CMKNzzpJvTLoH3hHIr68KndZ2/lSW3DVKX0xhnUx\nJz8FSTva/f6dZDhgsg7u9dQ4DgG4aFX1YHJN+KQ/1ZfPsPQVQEdGvlBcaY4C\nhNMTpY/pFETYmWwQQrqUdHwjzKUBRwTJ+R7SsgFDXcWLq2t7IFwtoPbq07ZT\ntGP1nPAWgyTnHRpMLEvE8FPghS0VkBOGT1sYN6UvqfLWTDvdR7u/iuyHl+Oi\nhDVxC6t1HPbHSAE7Qh0QV3YIKByYDAdKqrHuFVM7Z3YylBpSr531mcW71jsj\n+GKlo1zMYh2lkEFve2whanTZ5z0+RkPsBjYayVz5i05O8lDzXomOW6oLvDv3\ngCSA\r\n=5ihK\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220112.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220112.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-73jIV9hdgN3URYoZjsYUgosboA29aHe/tofW/hQARfezukLdr65XOm/8eWlfotHVYgEM9UfrsUUNMCOrKdZhZg==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-http":"^2.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220112.1_1642028235489_0.2891515532489457","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220120.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220120.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220120.1","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"c4d5df5a6d4e251c57e53b74392623b0f3f2327e","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220120.1.tgz","fileCount":37,"integrity":"sha512-fANwRjBnr+hYP8PO7o+PThXDm5lMjodxXPvSiGzoYlXz+hsv6Vnx8cXibq9PKBc5bBaeec1oLuJCgA2CPNExog==","signatures":[{"sig":"MEUCIQCrqhkfcnIK2qgvfS46PVKoISVszKNxb2LJC856A2Z/CQIgM4II8bMczPvifm4iKGc1Pbyjxo9d0W3LEpAu3jDbVgA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2334472,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh6elnCRA9TVsSAnZWagAAR9YP+wYvotnJX484PFv4DtYs\nSy0EGe0V3l6LnfgU9MeJeVofgPLIGFav0eT721MxNv5YpyahlaDvOW8sn6yz\nQPpKhzWORyzHnEGk32SL3wxZDBN/s97Ar3cG442wh+yQjTNSLwGvKGNZVucC\nREuJvXZEOENbRJKoJYeWyXiBBg7M2T6fH6aDdCb+DafVOhvtR4BqGlGcolnA\nyB5F0lK2hnaHaazUMMb0eHzeF/9evptltRpSs7foELfvBbJNqfZzCFx+9i5e\ndALsHBqxouFiU1Z6Uy1Grr3oLkm9Sn4pob9yfE/RhzK6n3i5jENqoBSZhN2S\nxevrZuqlQOd+LElijHjRJZK+EAiQU87SZwDbxa+t1EcveogMKu/CMzTbW4Zn\n11Autlji8h4eT9miXtwCRGAt0WzXRNk+og0/qhTqAF4jUJPbKqNPcd3xDR9z\n4VR6kLjJqeosYhWBzVXr33ouYZ0lqpK/MCEBTmpABgXRwQ1xAJXGaUP1fj9B\n5RpsYeBV7hhhiNrtqPE9HH6pEu9GBxY/3uskQRq7citDfqh+Q+oZT3sKcOsB\nP8ZOoLMPTZtBi5lDXXJ59lrSlvawNeAUCaiG4RqW2qOIubuxb0sj6LCRKd8I\nrB17MRUQ8KLYAV6+AKB4IeKfki/lPxn4rUTvo5i6wsG8046LkEgoJX6OKYxi\ny1AM\r\n=smh2\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220120.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && rollup -c 2>&1 && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1","build:test":"tsc -p . && rollup -c 2>&1","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220120.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-fANwRjBnr+hYP8PO7o+PThXDm5lMjodxXPvSiGzoYlXz+hsv6Vnx8cXibq9PKBc5bBaeec1oLuJCgA2CPNExog==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","rollup":"^1.16.3","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220120.1_1642719591496_0.22033821946379728","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220128.3":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220128.3","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220128.3","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"c132928c215b79f471b29c9621b9f86c4420f948","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220128.3.tgz","fileCount":37,"integrity":"sha512-551MhhXVFF1N37dXxjWNvS3uOXWBx2BGMKkYyCd11R4Kx90C4hYmMa95fM49hL8GvRRSYZQm4hC08G4C6YRKNA==","signatures":[{"sig":"MEUCIBX153vUqrKqBP9RTcWXZGVVsg/Tpwe0eHmxTmCjwFpwAiEA1QXQLVCev5AWS70str+PDNNxXCcIDeHCDrCftn6ny5A=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2334555,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh9HolCRA9TVsSAnZWagAABmUP/Ahsri/jMks35FN0ajL2\nBO9MfoWSq6Oku9xLmJadRS35VgUtg+yhn6h7jiZOSyBXbJobdxaCn1f37oGb\nM6lXNMpZTXy856MdECFl3g/mZm6RZnDkPteuL+Rvt6RHSgRQJl1qtFTxjiRz\nASSneZYc1K/62ilyHGth2drcgVsDmkOziieJP+fDIs4m3gupAKUlj7/HzMu2\n/sBWR/ef2k176JVBLIkauj2vJYXRZUXgruCGmjcbWfnRO6v7ea2o0PPOhTfV\nHKVFdF8rtfhf5GsMI7WSuVyLMyTUhcGgt6fA3841MBs42D6RwOiu758b2yIO\nNZ13L0OzKui3hufRwVsoW6/ODLzBQRyJ0E0lpjd6xFBGP8XZc0TDasvWOtA4\nuy4UCsTW2jHgQhGk5snq4RKSKj/mYCvKB6rzbvFTCmFAAwkpGQzHuIBT/qF+\nE/I7h1wdvEv5kNzqnPVpOMtjXt9yt5BWGL09jnfgXhLFieMuc0CY9tTwcNsS\nyW6ypUCIHxJPYEOBl5DK6VZCCIrMyEj0OireEFOhP/XbQhTgSI5mSdrhV7gZ\n8AIC1xh1T5zFRdyfAsTmpjNvG/7kY4m6n3Qpo4peB1YfyYqwXXcegHDibBnu\nDTczYKCUD4BrJY2MDWs+aEFGIEVJjgcTTSw8kTJwYX426N5uv1G+1MZRIoO1\nKIbw\r\n=RWDt\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220128.3.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220128.3.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-551MhhXVFF1N37dXxjWNvS3uOXWBx2BGMKkYyCd11R4Kx90C4hYmMa95fM49hL8GvRRSYZQm4hC08G4C6YRKNA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220128.3_1643412004958_0.0028201856412599646","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220131.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220131.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220131.2","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ce9530637a7df3a7faab8f91fb18d5e39f8aee35","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220131.2.tgz","fileCount":37,"integrity":"sha512-Ok57rTqGOcPw/v8VtTM5uZQKrVLJsiHhlEPKsQrCwNEnGAoNghvbWred4NvOV3SZgKN1lyiQ8XvOKFV7Tf9G8Q==","signatures":[{"sig":"MEUCIB3vYirTBa5kjS2CR8tZ3foAcXTdasx6Bj5YAb+6SZrMAiEAzycvsCtQGDHJrqBgXWm+wPqNBTqCNBSK9N1rEWLSKRQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2335141,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh+GloCRA9TVsSAnZWagAA0loP/2oxZ8YP7sscq48kWEay\npVoR2g4IoB9t8r6DLtQKKj/QH0BTh6GxXtqRk4YvomE6mkMxwaOop0Ms9Z+3\njtay6UF3ZHa6X+3fqNO5WGOP/JlWTBpLcRu8XvFfmu7puIqAjiUM9Ly8VvzP\n0e5AQ/qpQdhebX/RDcy6wEp/wrgAXzgRvyKk5ZB1YHr7pNoWf0HEHLYQs6fI\ntoPfVblqG+UAL0m9dYt5Y1Jvo4W9z+1gm98Cs71H2dl27ztvH20xaBz6D1p4\ncr+DeIZMgJRHuCT38Zcx8gsjsKcRWLWDwME8gBTSACsrYvOimUfRroTmX9yI\nhVjzB7SOMXTXnDjziuyilmQbk+4H66Z9hvjGBC+G326BEXU+kgFmHaipiKY9\nRXuxIXzMhJ1IRXLMhExeuUDLElrGSEcavSivqY+gteBGrVVP5SxH7D2jESfg\nFKb/vjbGcxhN3VxB7B+VY5NPO9E4fO+RE+VqigRpsU8qSJUFLKjhCMjIY1YU\nPc343iP1RDwXZE/Uj9RhKXyk3HXpj+kFxTv8hBJZKWpz4RUowLFtGvuh8NpV\nlcOEcFXXEhutAv9YlCCpnkCDoHMQf0npdInCAdZzmstmihN8Y29nrGJyp1Z/\nwxg/2/wBpOL3at5eJj+6Q82eTWFWELTJKcttgEDNG6xy3/BgKsS2holphhyy\nzo9a\r\n=519C\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220131.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220131.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-Ok57rTqGOcPw/v8VtTM5uZQKrVLJsiHhlEPKsQrCwNEnGAoNghvbWred4NvOV3SZgKN1lyiQ8XvOKFV7Tf9G8Q==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220131.2_1643669864731_0.42487263581338097","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220211.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220211.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220211.1","maintainers":[{"name":"christopheranderson","email":"chrande@outlook.com"},{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"33d973460e01f2750ff76e25dbd0f18e77a81708","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220211.1.tgz","fileCount":37,"integrity":"sha512-doL3c2DIzFgv2E5JolHi71RM344kD3Wem6dT0X2wfLyMMN9jCeBaE73j1QYVUg90exDXWt+1nExa54gXM8PosA==","signatures":[{"sig":"MEUCIGoLtTRx7JwYtNW5meuBlsiRmF8D7wVjtF6oYCDJOsvUAiEAmJA0wiNHUKkP1jYqdndUHoGNxz3H5bSLJsE73aHUh8w=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2335037,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiBuo7CRA9TVsSAnZWagAAoeAP/A7t1vN7RTYs7CZjDVap\nLA47gqRp/bPGG9iP0qdulYb9pVhG3+aS/ubid3L55Oaue5b3J97AZn7tBpLd\nFbO1fZDgJihylrcEnD7siGSJODJ7rqI4nlgM3+ph3ZVp8rmLhXTqw/vhUdI9\nR8+SDXdtXfVhb+FvX2vaXnm2Akt4b+oClT5p75ecPQDhN70pBLWyazZHp64B\nQ5WJyZXKNVqR0HbT5cVTq7WjtRr2igDDfLPJJhamK6psrWj7WOTMhwxsrV+j\nUZOD/OiCiQyciS4a0jAbiukYkDhxugxHy5fYvUkIWiswJ76z6X0fiE1m3kiG\n2aFvTl9Ufm8jjb1PtoNGUR3xVu2dDciCu1cTmUsvAVu1TlcH0yJP9VXlFyE2\nhvS3VBcvMW3lJUWfKPJUZ1qIojN3845xeO969H2r5BFBeUoLMLws8Zt/Kz9a\nSX0zc4dtDuUas/O+4s1si5PWM1GmRbqb2e3IDx+UJL6PIpfiVvkCUoUf6Wyv\n79Pe5QuTgksYI6bGy5RReWVlqGM5473CGQ2dkv2SWQhq987wz9umcXeWEHQU\nkh87UX+qoU6Ygw7A+SuPeIVE5agGVhC3ZPONXZEuqALESXZVevf5goeDjHXH\nJyDEVWuxM1LOl26IR0bjxIsyJHapM8umLt3464Oobawo2nq9SnEuQ9skNtud\n17ty\r\n=DZVb\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220211.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220211.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-doL3c2DIzFgv2E5JolHi71RM344kD3Wem6dT0X2wfLyMMN9jCeBaE73j1QYVUg90exDXWt+1nExa54gXM8PosA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.1.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.13.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220211.1_1644620347802_0.10660935087255918","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220307.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220307.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220307.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a0e6a675ab0766aedf164cbfcc1d2c44e18307dc","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220307.1.tgz","fileCount":37,"integrity":"sha512-NRphyAag4jx7ObKMa8S1wgxphBKjECdY3sDQEbO9vWDpWM6Hz6ABVpLffIxQENNmJfcduNingXvF1DIltir7AA==","signatures":[{"sig":"MEUCIQDDccJF2brSgqPvzA4Aj7WYIh87CLCUvb9GHQ1bVMOkjgIgSuO73reqMzMW+lGFmglMsad15k700RYTtKZw8ZuhoEY=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2387074,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiJo7VACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrltQ/+Nm5UxgX4FsPc6jff4c9ot/tyYgX44wHpXeCGRDiICu+UL5as\r\nMVb4Q99KWqZE4zUvO3htpV3S+yRX2JJMgx1L2lNsUMoB8BBwBoMLuTNgNvV3\r\nQBHII6TBqhIv9HJEuVO4f5rOw6H6QLTsAlUz4Jqn+wN7BNUHwKTMkn+ueYdX\r\nHxAQX3afWAP2AvhNwtq/UzSgnlpKneNlyRdYn8HLlud3A5tk2STg4vVMnUG7\r\nVD+RvHCC6tN/Da4QV3tyf77w8QQoKZP8jRs6g6a7cM8u+hYvgH82O9lJcZtH\r\nfwZBbQ+Ec2um4Xdk6D5KWeI3czgblN0BVHvZbMWGnrmRHCr45DX0gFnHV4Th\r\nAN87xDtcYJpec1whsQ+xL3nwoGi7/LZD7m/m9P3YejpANzbt6qLA/vCHpoo9\r\n4POWesIJGsfcupCefVuDpU5Cpb1Uu6bUYI3J2V7JOeqCJ9plmM/fRSG3iDND\r\nVWTXd+EE1mlGhCpHbOc0s536ZJu1isEhRH9z7+6Iwzo7xmLApYth9eZu71j+\r\nfRGhQ9ifKKywMXUjEbQuVtBMybXb6rhGOiCYW0cIc45AHTpeB4hKJWEC5pUT\r\ncjD8aMMayJLpLL8bapvEOpUFT5kB3ouQJn+T0jcvcYEihkEkxnSyRLmCgNL1\r\n4PkYvfRAr7n25qzPAllwRbFi4PbONJHAgdk=\r\n=yDPK\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220307.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220307.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-NRphyAag4jx7ObKMa8S1wgxphBKjECdY3sDQEbO9vWDpWM6Hz6ABVpLffIxQENNmJfcduNingXvF1DIltir7AA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.3.1","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220307.1_1646694101274_0.08196121963581526","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220315.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220315.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220315.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"60797307760fb310374ebddbc1a0c79385e714b3","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220315.1.tgz","fileCount":37,"integrity":"sha512-4n/dfSO6I8zVMUSpxRGtArsMbJB9Mwfzvmlh6ntH26sWVU+KrtqqMXCaFmx8CPleJpmoNp4fMoP4jmEsjSDa0w==","signatures":[{"sig":"MEQCIA209fOjPJLReg/lBVQle6bxCDVtP5rHXqCT2VjzlVScAiBDOtY3l93+z6cQmFKTo+3uFXzTQN2pr/gzsMIbTGtr/A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2335037,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiMQ27ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp3AQ/7Bfw0DH9JRiVEzOzpmManX9Ao3YrTuMNcbO+pOJKeT8CfsWV6\r\nHSlJ++6Tfn9ycdFl44gB5nZs9h4pzlLdCVvSK6x5i8zEodtD6KtuT02hh7k9\r\n3TJEAyBFeTzSvxgAwiZDPNJ2hmJZbWY+HAa/LTgzCO6t8rRYprbw6tyJjNPc\r\nxx8Pe/Uh2pb13SNVpSMVMwSZyQjoJoncwkIld5t8lbNGJkOEFombOpnslujO\r\n8T8adPUMsXysMQjgENIE1+OcbWttQQ1s+MyVq8j2IoP0suyk1ZPpHePf5pXu\r\n4HcDzA9FE1pu70YCO5GuDgsGvUiy6Kr3yHK1VddM+pfHzk2GjR04NDBuarVs\r\nEPNjALQFndt++t7UwgsPWqSLYI3XBMiY6ajcrxg4TVNqUhAtldjZJrjfL+lw\r\ntT2wIbkAwTJyY0cSUssdvLTkbR9aXu3367d40Nm+IByFZJodUPTREcunYuSr\r\nQHhccdNBbB5xFDQ2jUPn50RMPopaEQ7Sj6GRP6V+P8gFAca+F7k1CfwUHRjf\r\ndlDFzpmGLuN1J41Se0EIMyI3I4Pm7YPIbVm4rWfnb4EP6ozgz6Kt8azlhlxc\r\nrc7eMNEPaqLjlpeU2i1rrhzUuV443d3X4jTvSThwXbc0aPFev+whCBVxq6qW\r\nB1vk18gtH4wVoXgrFZnqeTPDP2kb0V4ioso=\r\n=Ct6n\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220315.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220315.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-4n/dfSO6I8zVMUSpxRGtArsMbJB9Mwfzvmlh6ntH26sWVU+KrtqqMXCaFmx8CPleJpmoNp4fMoP4jmEsjSDa0w==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.3.1","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220315.1_1647381946872_0.4963857286932085","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220321.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220321.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220321.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"cffafb02999fd21331c16ea0912e432b33f97d2f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220321.1.tgz","fileCount":37,"integrity":"sha512-GyVelV+JqTvwCJwmC/9zsX42rt5f6Bya2QOI92dnMakXPZqEPQdxFZLYXMsjJ8WW6FeuKVwGV8bgPemQw3GQiQ==","signatures":[{"sig":"MEUCIEqh0wLe+9pWJFEmm1lhcAsZnrpHJQlRPcD2vyj2wPsNAiEAtheDUvC5uapjdxysRBxmpHIOKAhjuUZSyPu0Tz5cKLM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2387074,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiOPx4ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrWZg//eIk+WpwvbuICOcVJA3vxE8lCIXp1AFNn/L9sUJq4DLj0ALNE\r\neFmaQRykuTXacTz11En3/us9yvwUoONC7/FibTJL9gKjz9mTVU9sD2itaG9H\r\ni+MAg8Z6psOu1ZkDTfJq4F5l8z7+yZaaVPG0xmQsCYLu4tb99YuRgqdV0YBd\r\nLTHQNXKkBPQ3QmF3pwewM327rahI6Do0jUEVkJHUcHiwTe8//DRBvBt0+d1D\r\nhEv/XRvY+sLlloDXBOzfSLn2rkTKKw2Ig6dCFLHs6hJ/lj+L+stK+pAmtVIW\r\nHb0lOTI0UIIYUoUO7Fjp7mIuBzmxskfxl3sJueVV4j8jVVLVyQuTCNAskB/8\r\npjqOD6SgOAPOE9XesaU56JFtF+NVOB5rN8eIuUrx67QO6kTxph83ab3jUi6/\r\n1xpNeAv0FaN7nXdIrB0Jw5ROaWN7lXHeVFl1o43AiCCXvfzysuvScmlBRr2I\r\nsWEgL3KH7u2uToIovtKW6TpNeuS2L+wKcsPKtkcqI866Csx+8t8eT5Z/7q0u\r\ni/WhhDAEYAER4WZCO0V3meWBIKNxIJrju3XoFiCYFp8NxQDgQKcSs58chDDU\r\nKTbvBx79MYq7VqTpTSPQLaVeznewPfb9h8K5DA+j1FDVfkPRRzHAUqhFckrO\r\npDrBQ5kZ/nUeo56qkKOqFlwdwnf77bySNNY=\r\n=PENR\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220321.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220321.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-GyVelV+JqTvwCJwmC/9zsX42rt5f6Bya2QOI92dnMakXPZqEPQdxFZLYXMsjJ8WW6FeuKVwGV8bgPemQw3GQiQ==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220321.1_1647901816788_0.693908786391642","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220330.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220330.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220330.2","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"88005479950998a9e66c6f469a79f9156ef11509","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220330.2.tgz","fileCount":37,"integrity":"sha512-2YsoDG67/FvCQ5wYaRLpFnZdA0B5tswgYgBDL2wZ7Vjqhp6k+4ssVZ0VfERSh3e76NiRk267GYn61ooZHcMoMg==","signatures":[{"sig":"MEQCHxXHob9N5wmLGQ2xHr9kHJ9i0j19qgi2PBg6rVXp3YMCIQCSF0VeoC56jQt7Qw1Jm9mF36jgY6NaLJM75Kh3tLgYmw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2336114,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiRNMIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmolmRAAgCkeYMa2TfyIZSiPFJX5zmcQWcgzt2i3dprLw9Z1Xjdcz+Yx\r\nw0QDUy3Ra+MS016fjYj5sSu/crn9HxuiyCH2TGcWzuUPoW1tcSnOBZhgriNy\r\nYFR+/xVdhZLN7V1UOwiMHTgnivnObz8KFi9tCTr32NtdO1HFhz7wbFN17bDI\r\nzhw28Mc2dGMaphOgbHTXRjnplKHFi8mARqGhabZAlAMdVdaxMbCk1iCmWSuM\r\nW1WMTqs4NLDAKsDjDILCcNykcOGPHnXaUAldDdrdyVvAaEx23lpTJwHE2zBh\r\nhLq4486bovjgJDZeEbwrZWMNV72T0btJ+U+/dUEXlIrrCQ/NI7blz4vPxbUQ\r\nEZjoU3EYCdrjZnxiIYwhwftkNV05yiy1u7HugN+ULME8khQaQ8jNnoZhjn1r\r\niwcmNskZ2df8Xycdd3bIviHqlD85XVkg2OAqD8cRyipc/suOmHlveojmgUXJ\r\nOejNZNkl5RCajXgaoGaVe8KKhxfDkOQD84c600fojdLwBmuvGGLq7oloAmZT\r\n9Uy+cNUv0RbMn6PxlSCfxvnvpQklWvgzF3ZzZ++a9gn49jHuIyPWv8DAKqqy\r\nHiBiRyG/mJkk0j+fHtK2IALAJpYR0/NSWAtHqoz8u224ANud5qyxIr8ZIAIY\r\npmLeN43hhbX5vUu4mV6KE3iuKRBql9/Yo/w=\r\n=fNK7\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220330.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220330.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-2YsoDG67/FvCQ5wYaRLpFnZdA0B5tswgYgBDL2wZ7Vjqhp6k+4ssVZ0VfERSh3e76NiRk267GYn61ooZHcMoMg==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":">=1.2.0-alpha <1.2.0-alphb","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220330.2_1648677640573_0.5525065533109719","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220401.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220401.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220401.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"9ae7db858bd9dc12f0775beeab5769ad56fb62bc","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220401.1.tgz","fileCount":37,"integrity":"sha512-/NiVR6Ygdd9e2BF1WbQz4juH2TqUDV4o/411edMKWxCBu41KNn06JIGfhiGCpnlUrpjNIVC11/rHJkEU+WSpJA==","signatures":[{"sig":"MEQCIBX2nLQWV4hJu5bnSKmLE9Yvu0CnOmS8wBxUOuNW3rYCAiBrMsT2djW8PerCGopepQE5FISBmkRVo26l514XESB5DA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388110,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiR3rOACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpZ5g/+PGxnNXBd+4TNYL/AyXvJmM+alLYHd5903aD+d0wEkFTTzdXQ\r\nDW+auFTCFBkJJpeCS0ewMLjEj59JKphhb+588QfOMfnonDGnCYhonDF5YWEp\r\nHWXRxOZG8Ayb0Jhz19AqG/FQN2Iqa4O9q8uoNxzqT0bwlPk/spTpQm86yVVm\r\nagFyUFhpTSfdUCNDJWKwgscj15hh9AkX1fr/DtQN0PqWZcsS1tvzCHRUsc9C\r\nCF8I+/amnQRIJ1K94H2jtPkxYFpARykP3SGqcIwoJIQ3F8qAFHhLiE4wfMwV\r\noLygiL40zAwg3FlVTVMYjO9kmLzbFOui2Tm7Rnsknlq4jDU5IwE+5oZzNQbn\r\nP4ZdtbqHeViuPw5KOSEUTeGofhbgQujVg2i3Y9GHeXajZpjY9LzBKsPmE43A\r\nfQ2eRLUR2llp3gSHmh/mJ1vFSQyxPLo1NJHcTOsHR+8X6yMBO0f5tqHdag3D\r\nN8WRrq4MOxTD5KuBMQGce6X1IAXSkyJkMwxTnEk2Mmup80DwfQwgfIarr33K\r\nuWSiTiMnEK9jBLJFmn0q0qW9nsJFi1UeWIrOLY4w5LBKHLBRotfBvUpU00aC\r\nGpC2Npuyn7dYDQnD+h4BR5ohqeR9iG3iUeWOaaQL7lQE+ltfSTjTu0boAF5G\r\nsBZlDgJ2+F4CFvzHiNCo2BMJ8TBjhsr6twk=\r\n=v22T\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220401.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220401.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-/NiVR6Ygdd9e2BF1WbQz4juH2TqUDV4o/411edMKWxCBu41KNn06JIGfhiGCpnlUrpjNIVC11/rHJkEU+WSpJA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":">=1.2.0-alpha <1.2.0-alphb","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220401.1_1648851662155_0.4199579074811641","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220406.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220406.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220406.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"9d7cd6ebf49535db77b2ed122acec73c48d251c2","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220406.1.tgz","fileCount":37,"integrity":"sha512-a7ssgCdnVfJx2gFPcgu5AZapeFrmycg9y87zgesIbrHIoRhRVrspVViwPmhq8elSyvT8sxDJNhRnkkDxAIlrgw==","signatures":[{"sig":"MEUCIQD53EvWBmr9nc/PcMo9o3Ove5ktbDXfyWl5BjYiHmyXyQIgWSHEYKllYskjjS/W+kSv9p6uzWzGOtuOLMSkFe7gNYU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2336114,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTg1XACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpDbw//esx+oqWMRdjssFm70wBzm5LJREDWyNvc5wdI8efN6CkCwNfw\r\na6+xUudJVe7/zmZZTu416T7aFRASOE83uGyJcXNMRbobivx60xowK3vP8fkx\r\nCKr9ueKpzOllP3CuZxIJTUpr7VbrC4DaTkkxiXzoI2J4PwFyZaepl0tcEO68\r\nwSbMc5XsaEWI6Gu7L8yY2dVcO8jcHyv5DhPLkDZ5lX9lD1Nhcc22zWgfa6sZ\r\nUvCEQsq/OOKKKsy/QgmL+6KgEjJOYU4eLO4Zx9PNC+a58eWXmPPszB1HyKtZ\r\nhsbH26eavAOjECeuVQ3emrS6CL7e4Q53/pXuLmzA/ZIBBAy+Ff7XrXYJdkF+\r\nuqaB/Z8QcwgIipcFy5gaufKzrsSAH+GW9qK1xROET5DxvrNbKae8+QOrwd5F\r\nQ+Ky+RKU6AGG0P4ekh88JUtOEVA9gb7kHhU+3Wa5z20Lfx88R1B4jXsYoAvI\r\nXNoNsh8KtjgmM3fkxVxUXJf38Vz8K0mb7cLo4Mlwed22LIXf6S2I1eimZntM\r\nqnmoTWUQsi9IqF9/zjxjOZ8ZDgeACLqeXJTDuCZFbw6OBkDPal1dNCuX/w1C\r\ndBmBT4ccRM7qKDRdvwkZ5oI0il8U/vFTkU1ym7DTlcGB8EU8L9GdVRlYSMep\r\nZATA4/H1x/g2IVh39BfpCvkbjIftppgcD1s=\r\n=PT0E\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220406.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220406.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-a7ssgCdnVfJx2gFPcgu5AZapeFrmycg9y87zgesIbrHIoRhRVrspVViwPmhq8elSyvT8sxDJNhRnkkDxAIlrgw==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":">=1.2.0-alpha <1.2.0-alphb","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220406.1_1649282390861_0.5314327557609773","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220407.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220407.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220407.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"353329df56078f6590e0fcf7c2be0733f44e8373","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220407.1.tgz","fileCount":37,"integrity":"sha512-8wm1slBZL4kwPBgzRYxOOZC/4FPOMMqGpOc0iO8gesRC8NIMaB927Jwr5pLrZP+hLZbPXiO/2O8vGbdmDLq+OA==","signatures":[{"sig":"MEQCIB8AbddMoQfmZCMxdhvafNxuth53zk9DbwTY1eT1emzQAiB+0Ncm1xmK3LCSPLfZGj2056yJfaxSrcEN3BPR6w6SQA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388110,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiT19GACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoZXg//TkxHH5sUYOkVPKSSrr5gmepCbvWbsvHIZsQ2KUJ59lbD7YT6\r\n+aOpMljvhklzhRe/NR3YhehpEsbAq1N3XNJBs+ZIkkRPUPg3LO4zoh2RQiRp\r\n+usyWrhoh5H8RXadbgxXzQkSClWuZqpe8we1xUODePkLXCXIfQYyuPkfK+Jw\r\namrMOFkHRtf5DYXuhuk47y7Lxt7vl5uraQe3cIXBXbCXHPEX3GdGvo+yiTcJ\r\nNWiuuW8k98ksZseSEcP4rIE5Tz0bgpgWE6Ob81ksO0myfZUfrSCCkyLMQRV6\r\n8y8np9e1jXF9Nnm2ZhvTmIfRW16BcD2uL52cJXxib8IBMpePH5fvtN0cBGbX\r\n9hVvu196/w5MKi9KDmiWsbELu3rD76w6pnqxm1aaajanuDSri1q0yhtqYd8o\r\nA9IXqmiPGp7FUPjJTIwdTtffsac84fq6PtEaVoHlasUNDiHitqKUUj2zc/4Z\r\nJ68Cd7NgF636SIspaCVI0jxyjaSJyOEVZyTDSnBEXtpTgDoJwdlwtMPPsEXS\r\nvgX3XDZoGBpNX2hvIdHnQD65rZalVjU2C8YPYnMmBEfMn3DwwBcgFp02iVwg\r\n9u7HVZ5/vtRi0p78hL3pOrIxJBmcczHImTXKo/I0dEofX8c4rMtwkAT4G27v\r\nnxEoAB4gHmkHDe6Sc6VnqsT/F8K9Ur4rvS8=\r\n=n8cj\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220407.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220407.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-8wm1slBZL4kwPBgzRYxOOZC/4FPOMMqGpOc0iO8gesRC8NIMaB927Jwr5pLrZP+hLZbPXiO/2O8vGbdmDLq+OA==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":">=1.2.0-alpha <1.2.0-alphb","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220407.1_1649368902720_0.9283917805443735","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220408.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220408.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220408.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"9347a0cd36d0f2d0745770947c44badfd0216d5b","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220408.1.tgz","fileCount":37,"integrity":"sha512-5IIUurQUJ78IEukbNjmDS5EBhRMw7aB/4D+Sy1u9ALR6nqXC9Gs/DcOPtIlUfY20psawGfFcvtXFMmVx7W/B2g==","signatures":[{"sig":"MEUCIQCvPu9et0g98uMYH4P9RccFbqV9pPzHLscjTu89LcKhWQIgArWlf9uySwHdKo49G775e6rFoxz/aQE87hpIQubpgXM=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388090,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiULGGACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr4hw//WEMR2wBCBYT2JwNbM3KDiUJjWjHt5RCHA2dv8Ay0tagtwW6/\r\nx+dcxKGnn6g9GnBamHsle7FN6RiAiuxzO4ntiOugvAD2LnUX0EeJ4NdEISfM\r\na6TPLhBK92Al0HPxSX/NtMkn1rb+2JF1xqvXqTvNH/+G0Qjv6bwi+Auak+6Q\r\n1t/RSUU1+8rmeiLkF5JGFNYwpMuiK+yvkiu5NP2uLv+BLX0k4YRADUqtkoJ7\r\nyr6CBofkbACd0EuRzkiTMNqIVFgdTgm2R17YlVy5UYPlg35Vnrl64WILqlQj\r\nC6l+FHaTsd0lnAxws7OTBj57o6drSXHS8CpiOf9Y7OB12RCEFTlnhmX3ERnB\r\nfq5cDiG656wKBlmeVtZEQP65VwS2fuB27/GNGAOE2FL44EsCYFxmy6d/FekT\r\nBiaJdl4YJsvceMnQSftT/PZZ1EJcrFJpWk/va6pxngldaNlI35xbOJAFt3rR\r\n9Bz3ENp4Lt87Ia2sbjdkHgm/IygmMF+xxUcC7NfKRdVya9X36egCVT5Y6r/f\r\nWIAA1xyFvvlEFkUm1eqXxU1n0sHL6pm112D6cH8lzpzFhscJKDM709gAQ6BM\r\n/qRIxgHsgEP1xu4UHjes8s9um63AAqb93FgyGE4xB6kArvFscbt/UGHDqucv\r\nzHXw/T7Gcv7n0eovN5f81UQ9ChLuB4ki0ws=\r\n=ryHJ\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220408.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220408.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-5IIUurQUJ78IEukbNjmDS5EBhRMw7aB/4D+Sy1u9ALR6nqXC9Gs/DcOPtIlUfY20psawGfFcvtXFMmVx7W/B2g==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220408.1_1649455493863_0.09283659951679257","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220419.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220419.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220419.2","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"d04b7d00d39f1938ddfd8f6fdeff940b40170e71","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220419.2.tgz","fileCount":37,"integrity":"sha512-h+5wDV+letfB096EEHvTfK0aDge3RdW/5aEdz0bMlF7hZoznhiU1iRy4L/9bgqxBgu74jh54BzLWQgKDZViw1A==","signatures":[{"sig":"MEQCIFyozTYJrmTCk0NerPQk4wZdf539+2F/xtilXBhWf8B3AiAzOtL8ORLv4DAAOQryHWfD/DzNksf2AqIsDCtg2XcQRA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388340,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiXzHmACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpWEBAAgmy8BVS0LeoYSsY+VbTjhhQWywGuVlIv1bIJLm521oGq15uh\r\nec+MKnZACeB16Aq92AeGS8lUSKOqgyLr3VDIphdbsHnSlHYAkLHBDS1MV9pM\r\nVl4L5h2UkpNYkkd2hm8JASbE32rHe96bGhV8vdc4MbDQY/SK+HplV+/XjkFO\r\n+o+7pfx5t3tmviuhdUVRWGiqs1Yeo6Jj5XJHuc1/S5uIfjp/Wk4L5im0zdyF\r\n6r2TkFHiK3W1ZcPHpm7sgcHv4ijJnM3LeIU3D5qKaOq9qWJU20PyImkW7qoi\r\nr79uiv+X8DQgSIuRdIwRkSJvr17tM0ltbrw27Iuf9L9kXmmtB1MCK0Ex+nn4\r\nY5tmLozQGklzKgwoVRJQYF2Ec6x/bOgMzNTVzOG4y6Uh2Ha8xvgwRZ8tlHj+\r\nDq044LQCsYbLpMxTCmPl73yIKvXol8j/vx06khAiYFaZ9V+8OJcS9DbO9XLn\r\nGJVVK9RqxN/UyFGbh994+0fgeiMNU3TCpCj9qad7LzIz3f8aPPK/PifdHBsD\r\n9jPV1NgR+X9/nuJiLz5O6IKHhEr5aBcXyDXgY3+HygVMdRyw2+K3OhfbD9q0\r\njXpaB1DB+frOthpGUqJoeqm++dyYEgwydq8udnuCDhzWbx8pr7z2SANy1x9Y\r\nC65Ry17x06y3wNKdSp5Ue4xSwHnmYlIHSes=\r\n=hORl\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220419.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220419.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-h+5wDV+letfB096EEHvTfK0aDge3RdW/5aEdz0bMlF7hZoznhiU1iRy4L/9bgqxBgu74jh54BzLWQgKDZViw1A==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220419.2_1650405862266_0.3283571721939207","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220421.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220421.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220421.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"d95dbdc3d1a645c339f2049f5b6fcadb358ec2ce","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220421.1.tgz","fileCount":37,"integrity":"sha512-N1eNTPf0DonmKrc7rudOFwsKLLIUhsNp0opZwCMWCU1idGDSa/KVKcZW9BgZm817CioEoLHhQ2ENh6QIolnixQ==","signatures":[{"sig":"MEYCIQDAFLH70oemOcuFwYcgSJKOMpvZQSdHBMMc5yUZf/ehTwIhAI8j6NH+tjJZnloZ8Z1xVpxfbbzwSAQKIHADXD9zJiT3","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388339,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiYdUTACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrFfxAAoYwJtWRGljNI1gotHTdGrPZvRVUBwe9YjuTnpiDX4PdFQlL0\r\nj8jfNW0ihiQ60tztHrxN3DiNUas77e3/CXkFkylCmjRAHjywGMOsoScKGjW1\r\nKuAxxhECYnScloedl1QHbghJdCC8l7fk3bgsSqPOEGb4QA+CuFz1VDFazpKa\r\noLtFfG6SDzpwv4Zx2KSoUeosoAf+ykaQoi1KfSe7h17WR+AdtKp4ka5A+oAH\r\nkkwaBqMn9CeJI8mBYejVvCYNw8BRMrKFkuallCAlirCc1ehJc26T0KfIhCFh\r\nXdlhcjiGNIsxAfluE9Aw6gAt/d04ESZX34TlQh6buX3EVarEsbEPDlIlRhys\r\nrvHerKdz76CdFdaQWDRzB44CNsjGu2GYBjGYxJ6YYQKNrrT7P1oZ6rAPvtvd\r\ntpcnmC8dc82nXzDQvhy8HAjRlesJBjU6xu04P8CTYGHi15W1h2ZYIbR97S5G\r\n7zADLn4uQ4frggAz0t0tJUZNovyLCgyJdZvNEG531IuGg912WtRgFpgR9S7B\r\nRDZI5xcxk9ZJx3gEcdZEm4sqRhj7SUreeBnKQIRL3sgZF4f56vJP67WJuFPV\r\nos8vSc0Oc+g0s60/w23w2FZnRuhGO35xX6hHp8LWt5Q/CCuxnlj4Qu7Iljda\r\nE0GFl7bTvY3cPMeVbpPd45ITkO/qGFSE0lY=\r\n=mZn+\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220421.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220421.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-N1eNTPf0DonmKrc7rudOFwsKLLIUhsNp0opZwCMWCU1idGDSa/KVKcZW9BgZm817CioEoLHhQ2ENh6QIolnixQ==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.2.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220421.1_1650578707073_0.025896828444253783","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220426.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220426.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":"Microsoft Corporation","license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220426.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"55474def072881b2f1873e40bfb84460a7296208","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220426.1.tgz","fileCount":37,"integrity":"sha512-xRaQSdwolMJm0enQz4n7BVei3RlyN/51TRaRHvJ/vQiJp6Heqj2lFB1qKyE21b+LfV/NPzD2LNZGcHgJXtlI7w==","signatures":[{"sig":"MEUCIQDV5mUYph/69XEAWjVSfwQ9XEergDS6Cgp3WZign3d13wIgVGjBtwMpQWW2ybdzUrjYXWzalBA4xZyEaGsPS/YTNaI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2388339,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiaGtHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmrlpw//Q35gZ3AEMZO5GyuGhx1/XYs6S7YEo4RuiwyFCzenIgyVX37T\r\njKWAob2fXUXDMiNAuEKH7eAPGK+ET74gRrhtCXlyRdL4W6w4twyMqk8jAos3\r\nNx265xSbZVZFajXWKZLITYvvVIiAfx15Y6X8F3pj/aNaNbTrs7OGn27doaLR\r\nZtVUuQUOYptbZkULPkQl+sZcmCJreJkBEscshXOEAv07cwbmBdjCo0lPmbZE\r\nolzeGREkTwK/DgXThbnqw01mTAMCbePxSxHU8UeLRbryOTauZZ4se3D2jHLE\r\nz2J0LEhguKDGkjbMI7yNB5WOQEfPYb8CTnirfiJ/hbsql5x1t2BwUHNFp9J7\r\n4vFKcxeU/B+NVyR3Vu8iXZiuWQK2HeMmX5AQmeMjT2WbLzxMr2ojTiUHY4+d\r\nCaeW6WasmwyOshHIbcxe1RpvETvyyClKEyIENK8nUcROCsOC6+HvMT1SRbvI\r\nkrEAfPX9/LKC7+2EeT9HMVjdIjFp9O2Lzk0m/kko4aSJ9lmqcWlMvqWLl1F+\r\n+Rb2pz9AJ1402yFgi1mwe44k3041GnMPx8Oihbg2Y0kLUGn6ETfyjRU0I0FM\r\n53fquHyVDN/5HLl1mSKqdGFSTUgWKktQSs6X3oVcbr853q4f5QPwacjalAiV\r\nPyCc9vfCQ9HIdq3UBe01woFKg9HbJN5rtfs=\r\n=ZKqy\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220426.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220426.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-xRaQSdwolMJm0enQz4n7BVei3RlyN/51TRaRHvJ/vQiJp6Heqj2lFB1qKyE21b+LfV/NPzD2LNZGcHgJXtlI7w==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":"github:Azure/azure-sdk-for-js","_npmVersion":"8.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.14.2","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220426.1_1651010374738_0.6611434857051395","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220517.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220517.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220517.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"13f00239b7f7b9b736df263c3c3afab6e73219b4","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220517.1.tgz","fileCount":36,"integrity":"sha512-cskV6yOk2gUibEZ5WfgpKBrO9j/DSuJnR+H9h4e4Kuu0ZYii2mswtiDNDJTHkDWOF8geExtBQwNUZoWWP52BEw==","signatures":[{"sig":"MEUCIArNHbpbSzZRRhKHCNSNLuf60bI+j4nNe91UO8yr3+dcAiEA3BvPIkR/9AkQyH9JFkwsRFSgZbNl4qA4U2fC6ptmVeQ=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380664,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJihBr2ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo36BAAhVv0jkdmF4wkFzsHMqALR5csr4PTAK3IBVidh84MYyr0WoEd\r\nSSR8NoyUSDqIGHl4E9k9IjTBumn5uvwEt9nO0RSkvu91jVvUbcn0NLEyGiwD\r\nGSukuoQL1y9KkneRWG3IxfcLBCzYLMQXZEFmF/1nX39qQ2PpL+9Hg4jOWhdQ\r\n7QQj/+G+Jb6Rf9OviELOYYX2tRDN+djg+zorefD+iS1XOpYiTfEB+UiRgT21\r\nxmh2ZKLczNLZkJxoveGtJvgXlkOxuMmDBTFa7ysg31owOVfD8Tn+LChKX2JZ\r\nCeuHuDAMmMZYD1MsGj1I7adF32bszOdSjLbJR1/EJnpoVp+KrkwxwbMrj1na\r\nXsP34k6PEkrNUfvTftzuFmG4Ze/N3DQvezortlwYTTJ/a2wHiuGyuvqdeMdC\r\nKKxsHIdSjBJv4oRiCQpWZVJ+nxsYpmzMokjOR53iv5GXuRqQxXqRxolbFKJU\r\n7dMM/1Tg/zqNJAD5JCwlNcMevBsxlngSi1phwUv1Z+mgMmywUuddj5PSCGlw\r\n8JJ8cBWeQl5tSJ/uBbiBRJjMHQFwPIYkpW9Sm6FXuOB1Jw3pzEvRPqlJgwN4\r\nLC4VmpMJ8NLzhyt/QGAFy/8nXtoiW+1IETJk2gdBvoVG8phM6S6NDZ2dFo8t\r\nxVkQAScL2Zgxai1hVfR5cO37uijfRSVKe5c=\r\n=9vZh\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220517.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220517.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-cskV6yOk2gUibEZ5WfgpKBrO9j/DSuJnR+H9h4e4Kuu0ZYii2mswtiDNDJTHkDWOF8geExtBQwNUZoWWP52BEw==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.5.5","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.15.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^7.15.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220517.1_1652824822295_0.24448870261057265","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220520.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220520.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220520.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"75bfa75f1035e258626ab3fc43f0b4cdf0002ecb","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220520.1.tgz","fileCount":36,"integrity":"sha512-hW6qO9EQ2mCLS36EyeKWOlBhTvm3tDQH3AB4gbOuROQbIGz3NTiMEMlkQxkKNd090etxEuAdMEOVjnpukaNHNQ==","signatures":[{"sig":"MEUCIC0f+NQNX+i9/j9TXJ6WC6Z2ZOXf1bO79IN4GTpfGIMpAiEAyO5HGhUmZmrv/o7WO5szRsiOd6Xy9y1U59hntboGMso=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380663,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiiA6sACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrFrRAAlaj2tQmeHblXEyUu1clDo7q4UZrrSAFBRto6tEmBsyIUvW2H\r\nLEUOPaHSwL+KQpwpVm92CcMeUf3prJRMORsLafd3Veb8UP07IBZHWgaU9dCX\r\nBbW9wX90mGTP6PsEmS3KdBdEudLZMWnBMFAVfAgJcwMYjmRKRXkiZrvawBdr\r\n3yCUgVb/0nqDLaO/FDy8X2A+e/HLU3BRAMq7T+R7GUg6dnZwhwz048Elxc3F\r\n0o8Fsq4KojEUqNEzBsK7qkk059MpFtpzDYobIfAtJP/VJnTvGGP5YWRTrOT4\r\nLyo7jgd2G7SikUYaOfrc8yyFY18ZDeF94qc1mmy+U0HJsJ1OluvjAOIq1R+j\r\nKy5QgxLk0FiMJZwMV2J5MEtr5uIxF4+Lcsj7fYdlMxRZajSBO8dPOiRtpOr0\r\niztXYrI+EkDHo5Gz91bIdrYeI2RB4n93IG2j+sWZAPPzNNv7kCOkUguYfxPh\r\nswfpmvEUej6EIwWwdHOo+9nvKeqZ7+S/iUtY5d16mGynFbxVRCquMNz4W/oh\r\nZ74vKpEUSE1+9YF0Z692jFzVPoP9GwWOcyD9p1lRq7k0I7MU5Qct63IjeugO\r\n7Y1+boK55Kf8rTMhif9cIboBSQJG7Z9E2m5v+fTNSlQOc95fYv1jOWJwt5Vy\r\naJQ20GjyQ7MvY3OCqJGb1EJf5cvbi91Nblg=\r\n=2UAT\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220520.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nimport { DefaultAzureCredential } from \"@azure/identity\";\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nimport { setLogLevel } from \"@azure/logger\";\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json src test --ext .ts","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json src test --ext .ts --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220520.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-hW6qO9EQ2mCLS36EyeKWOlBhTvm3tDQH3AB4gbOuROQbIGz3NTiMEMlkQxkKNd090etxEuAdMEOVjnpukaNHNQ==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.5.5","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.15.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220520.1_1653083819938_0.12121574726624718","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220524.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220524.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220524.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"5d54c1e5cc6c981ddf7c4508b40ccd54d0a26236","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220524.1.tgz","fileCount":36,"integrity":"sha512-cJkl/hlWPUk2x16kwvCA3WQahdWB4MICsP8cHVXePWvoD/1m4Mqa5+FA6cqty4RLFz9JGDh7S0IeJcPzvxAVrg==","signatures":[{"sig":"MEUCIQCINUirHrPLqPtp6MwWADFELtSRXlG+DpvPhijpmR5D6gIgZI72V7d2xVTdY1A1zFOpBKdUfhCIrupkgeo7G6kPiM4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380725,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJijVYuACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmphyxAAhS5Vnkejxml/S6owlYcWLl9H0DrPXQHtcQaTqep+ubIJFWav\r\nGqjgIS8CD2tC5bFcLmhWB6bZLOrBDjtoB9SL4HWehVD42Ru5vk44QGenXoh2\r\nFwI7fluWlIm4bnc1Ei8XlHHFIVheKBQVFECyh16cZKe2s/pvUzTCer1f/JvT\r\nEbmAGEZj4k1Tr0s4QtVNPYC/ZwN2R4SFQQI25M6muOEkooDEkArVO3CObV9D\r\nHsW4MOsiCvotYfgRIJCklmPl1HCuIjBO4+atWDe2HVFopkzpnNiZppS7Dlo0\r\nLMKyOWqnJD6aw5M6vqvgtlRsjszwRhbxYMi8JJzzEfQReRjrMJHL845d+NXN\r\nlzV/2Qr2ssG0HKe3CzdWykJc4rnrEOPzEzICRdnNuLP87qSH+doCQwFV86yZ\r\nSdf0ZY7vMi1Dcnx5IltSCkTzW5oj7oyYIA+sxgosVwaAqGLXjj2PlY1EQeqo\r\nlD7Ow6Ni1uIf5Hj2IFIQsohkaPQ+DRuziIF0F7GEgiiLL2L74bh9+HjefQpo\r\noIlC660doOUvF4g485Rj0oCOrN2nJAOEalWSZSR8UNbPoofhrkXg/cKzcshy\r\noSCfaM6TdMpzg955u1lMnsTySux0Fxq8Cb3k7wAtjposwuekRXyl80Hunr5J\r\nLF8+j+2L89TdA5p+yo5f26tH4ZiR/WLRcBg=\r\n=o2xC\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220524.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://nodejs.org/about/releases/)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220524.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-cJkl/hlWPUk2x16kwvCA3WQahdWB4MICsP8cHVXePWvoD/1m4Mqa5+FA6cqty4RLFz9JGDh7S0IeJcPzvxAVrg==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.5.5","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.15.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220524.1_1653429806347_0.20725862492730718","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220919.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220919.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220919.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"7b065f04656ae4a34695399a57b3d9cbe28fd59b","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220919.1.tgz","fileCount":36,"integrity":"sha512-D3YhdGlTGmKsQ0FZ3U4M0Yd0z5h7HxCeMkeW94N989psryDZ71I3Yd7UVflrEAPNeaoQLq4dYfvqc0hML0qK5Q==","signatures":[{"sig":"MEQCICUenZYxKp5ZD/z6AKKjV4huwIl2v4Ekpbkr/5KsFjnGAiAhGgmG3/t5o/ZJuGIURDqSi/I2z9CtHaC/0j4uETxyOg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380741,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjKOjSACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp8+w/6A3KFYx6/Yr0t9UQu7J5q9vgyk1+BEb9Isk3bXxcCs6iHqUBj\r\netBHTEju3AaQq7F6IT3ee9RpHt7HwT3a2swBA/1b38LnB0eOr8LxBto6PVrJ\r\nVonTu7i/oEWJ0F6vkK6lNbXmHNhLr2MsFI+pRWpwPnpDY3c4FyNBY1N5frm8\r\noi7Y0wgJQr/8tyIkqYiLlx1Pd9SC8NjD6ErUyY3A98CGDj0aN89PGKBdhi+n\r\nZQUzo32iZiVS75zwNbixvezxPI2zs42PlSA9x0nm0NstLJXt/yD7HnY5mexV\r\nW0xjFskXbfYpV6Y17mRW6wbEQJjCjNhAPabP1cp6URBHRfi+YBx2CaP1QGu6\r\nrZzydSp7iE9Ad+qreKmd6KBix9VV0QWzwkyP7uXd9dY2f8hbckni+/LTQHeH\r\nMzpiD5lWGEcE7f9Npui3JOKyQ/7ck5xMQbMAMRReIpq3gzIcuA6waA0Odk3N\r\nwAhHbjjynePO2GYS11p+9dCAgaGFlVZHFA1m2bWegNThWskSuCujSq4z9M2n\r\neF0WdrjbvrrvUuiX3etR6klNkSTOtZFXp+mHv6XJfBCn/+cSuQf1xLh5EEFP\r\ng1pP8Fz6d/ETuXeuD5zkxvRrCDZZB1zyHfV9ofG3pmyiZWxtJ9PMtX3OanYq\r\nPxnN8FVvKUqpawMyqZF3/oHH4GWE4Okrs1U=\r\n=qjvr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220919.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220919.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-D3YhdGlTGmKsQ0FZ3U4M0Yd0z5h7HxCeMkeW94N989psryDZ71I3Yd7UVflrEAPNeaoQLq4dYfvqc0hML0qK5Q==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.15.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.17.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"7.18.11","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220919.1_1663625426164_0.4501766964901004","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20220926.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20220926.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20220926.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"cba256f2c77405cf7b3b5d4ca109a1fcf4f62832","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20220926.1.tgz","fileCount":36,"integrity":"sha512-XtARzPIrod/ivxs+EugBgc0LqSiwECCO++M4wad/vtYn44Z0S/AdxqS0mNecejg+SHJmAVVXyhvIly3dano3QQ==","signatures":[{"sig":"MEQCIC0S7Q/F8qemALogAWAvi3AzRz/knCBLpteWoJgsppLPAiAd3uNeFPjBnxPqeSK/X4xFsVLMQX1hXOFaUntjHwH99g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380741,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjMiEMACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqyig/+Nle0IwQ5aFdBs/ugZ+Du5lfdkhQPjDWI4c7ydJua9VUr2YNp\r\nSTBcZ7Z6CZ0CKg2CLw0/PL3QMtFXn1KQupo2ydJ3Vy3rQO3SMne1ClaGQr/l\r\nXhy+Z/ON1M+XUIM7mF6ujeYvcdsyDh66XyrLyGp+IgZ+d7hrQA19fMYymR2E\r\nv/5okfcMOD734Y3uCVVavCCkQ638TN96NUSB5Ydq70ZDRraaj2/fElAYyofV\r\nnjaaPqeXHwLUDEBVWqXOeJYcejuK4b2uTX6KObfOJit6DADmwEbjk1kikFS7\r\ntNRWzjGv5RJHvbguHsG28cfGlOww42AhZSn1mFGoC5m5JVNv69DTexnaNpQP\r\n+Am4tmFM17DnngXyz846XWUUOpzP5vn9jETXU27SOGVW5w1/kP2V3NPW1Kga\r\n0xCiPQucWuYN5N6Fcj8Jd5qU4/5xMZ42nzjgMdMvFjvz3tqWuuh49r6YwakO\r\nvzJrzHiDM5RPQ5lH8UqaZPSMJ/mJb43FfIFWaY7Q4V3medrey5dZBZXwUYHd\r\nyR7EivP25gMtz+P7usOhMIcGiW3bm8tzPQay7HkjFl7kwXXKqfrAzRO2Smrx\r\nUhGZVoC3xFjR6TTbgNTcbm9DADtWLiBylBfl9uWt22CrivVmCk9e/N2jq1Z5\r\nxq+7azqUOk1rBwRViB4sC5grGpbuMeyPCb4=\r\n=ab0b\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220926.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=12.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20220926.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-XtARzPIrod/ivxs+EugBgc0LqSiwECCO++M4wad/vtYn44Z0S/AdxqS0mNecejg+SHJmAVVXyhvIly3dano3QQ==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.15.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.17.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^12.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20220926.1_1664229643838_0.8275544630107807","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20221014.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20221014.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20221014.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"ef6347070904a3607fb2a13659c43396b9b00d36","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20221014.1.tgz","fileCount":36,"integrity":"sha512-5lFaRiNs+zqmUsmBjNvwzvn/NaP4UE5jaFZ/woOrYuAPr3rMgtFba/12sG0IN6hMZV37+2onIxlLT4jhv8RZLw==","signatures":[{"sig":"MEYCIQCuSxQ7uhgQSaNNpxTVbbARPB0/AAXcizWvAbhezAkaEQIhAL7WbxUn7RtzwhRky5WPLR0EmX6bt+jrLp3tHi9SJyUy","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2380741,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjSdybACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrlKhAAjktzm3xPQeCKjLjAszmxwSJLkm5JLGyUNKaL5P2X4MZIZJdJ\r\nxQ5Sp9qJrCOlNU0Nu6MgKBo+LP4GyCuK9h/okTPaW9K0aPl5KpEjuKaMqLrj\r\nas2vc9iJbXTRzu6h18qmitRtIk7HJlikifqm/I05D3mIog0yRftptUwmBnsS\r\ntkbhZA8eaW8imuJTj/4U5bklvjI3Jt7ndqiHz+gEyjcy9hk7ddmH0BXJx6oY\r\n5te68BktkqQ2TsprWQYp8Jc7ZjS83qRBFEMjJwXcgkxFjlamMWKiRAuOCj5G\r\nWeAa4bUgLEfB2PAaXiiD+DaKg0uuPcUs97lW1xQbE2FKQYNi4HR4TzOyKibq\r\nmRG+KP1neJbXDxeU9UuUyWRGCG+TSnBFswBYRmDCxbC03dXnoNfGOrXzGkWe\r\neFwufjvYenmeIhszn8xEyz4BbavkXCoqWmoFeZd8g3BBNveOU3EpU+4jLjQ0\r\n6cnGc+3k1OGwBOl60wb5gfh4ODCnkyaN3WqwT/ET3fQLvq42kpUSK4i4PvOI\r\nqG+Pl7jH87f0JSDSqOCGjMDAtAuM82y/V+9hMTgO8j6phM73IP8XrUmWfNkw\r\nyKjXgzYyjFIre+m0L3rmV+s0AC2yCM1w2v73Kv+bec3NktG7j9IMY+VfOFRL\r\nHUUrwilgx5BxewALmpEK+tseFzpmDMwPVTo=\r\n=6vP7\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221014.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221014.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-5lFaRiNs+zqmUsmBjNvwzvn/NaP4UE5jaFZ/woOrYuAPr3rMgtFba/12sG0IN6hMZV37+2onIxlLT4jhv8RZLw==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.15.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"1.0.0-preview.13","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20221014.1_1665784987573_0.8088277758208291","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20221018.2":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20221018.2","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20221018.2","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"c25c609ad0e80910a7f5fb17bb83cc1924a42371","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20221018.2.tgz","fileCount":36,"integrity":"sha512-kwU6ZOCHg/u7DUydmZqvrB5R3VdHc0+Z/ZQRZiK+iroUpD7Za2TQg+V0XdFVB66pZzkqi0xMx+F5KfN64s4iIw==","signatures":[{"sig":"MEYCIQCM2EQv6VE2JjBxdcL7em8q9eDc9C9s6lR9gsykMZltXgIhALujGETf1Mc+Zk23VjNxh7g5BU3M7tJtWN45GFuoo0c6","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2349685,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjTydxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqh5BAAg9ALdmFdES/yIXnehpM0RZ7iMS0YHGqfGLLRSQNcSBAFyy4o\r\nORZBBGQIlG/wyX8WhZvakOgRrqjUeGJdVv9a5FaYrPKyC5nJbKkfMJSZLIvA\r\nesD/VIJfMpof+JTa13h+JTteeZiU6zkz4+8M9/8OPHKP6mZKx3wB3wUvcJpw\r\n95gPISmpf6DHjwTZXdCfsBaEpEjCH9onDWxvhELqrlom0wUJU4ajfdK8Dy+/\r\nnZKrvettDCLwHFxo7hj0pHJwO5x7tgBaQ50hdZMEhdgaQEk/NBTNpYrUnplK\r\n0soo6A4X+L9Dg3IKgshU2Y8xJ79HWaa9i2pQpdEbj8f4kjE+0KhCmiIUOMzk\r\nV4E8YpUDAflDHNukrTVa3G1ZmcTiXgeI8eIARL00tNpVZd7UvUhITxzOEGeo\r\n37hWIi1hOY/3UOPXs2VdymcAse+rIzILQ/b2KEA+jnPszEWiiIpXYRV7WcFs\r\n76fz91ES/Ee7T2WWsb4toGWkw98jRUQmdsL8oZAeZGPXObrOmjNxHQPe/3ve\r\nBYhQcWytJaMfqZH01rI6q50u2P360ckm9hPzwEUP8IaHKGQjoup0VXETiAqd\r\nVsZPNlDuzyDJsqTlfspXZCXjXHU7qNhYVld2brWrmXSGvbyKa1aySuBYgyGW\r\nGgrAKEuZkWZfTtw+Xx+DRN6n5hRuslynjY8=\r\n=SVde\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221018.2.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221018.2.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-kwU6ZOCHg/u7DUydmZqvrB5R3VdHc0+Z/ZQRZiK+iroUpD7Za2TQg+V0XdFVB66pZzkqi0xMx+F5KfN64s4iIw==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.15.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.17.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.6.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20221018.2_1666131825547_0.6715243337001455","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20221107.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20221107.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20221107.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"a676730329221550b612f1b39a7911b5570e8c9f","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20221107.1.tgz","fileCount":36,"integrity":"sha512-ApbODKYlvoB4r7KCIGkpkp178ELn+nzEskxsANXNc7fokU2+sOzsu5LhYgKJiuONO3C+AmyBfNdodkzv/F5Rng==","signatures":[{"sig":"MEQCIHJ/khBXH8k5nrbGeMZFGMg0PWG02BIbI3g7u/5Z4fNYAiB0BVXl0V4rXmSXxbXn86DqYJk+9pNroZWZQK9K/vEh9w==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2349685,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjaY8YACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoWYw//e4K4w8eOcUwujQmbs+BNWucXkxR/8qzfHoGEhscgSQf9HmqA\r\nqMlr1NuBkAhD0lA6zGkSVEuxzOBTIIlL9EbHXIWaIeKCZbkpRwwkpJhbqWpQ\r\nFMnLqZFgxKRZlYBDXLCAJ2Er2LnBSuwnSw0Q8ifSZyHDaLuCgjYQxi+rPOej\r\nccqLirttisw2nk+wErkuUQok7D+a5JNR0Wz7XlxN26TW4ehmXPDujjQTSOSZ\r\nD/jG+7mu+al9CJ4k60pECdc5b2NuQhSm9hUFsDw7uO8b65qFtK3eDfW2Rg9J\r\n9tsCZumQtOH7cLXCE9YcAPJO08ohjSnVHN6QxXBd2mJrXhlHCaipbC+byRLo\r\nE8Zf66dqXfSOdN8j8MyOIpNk7nWU1Kzd9aDYjGGGkff/dI+HEXi2dfx/Z3ke\r\nap/oXN8SXBmpwb9mt+FYQinn6DBvLRpv5JQH4Bl0QjqH0Y+4k+HRvV1xxreV\r\nB08rS0Q8vod+cPEfQgQOEY+dqMHdK5v0YW9UsQyY2udnBIdUmDMQLSz3bgec\r\n78zJvcwm2Pn6zF1lsFwPupSdxbXlBLTNs5foWdGyqoxE7Bw5Jhu1uk8Z+XwN\r\nUmrKDgOYWUGA6uFkpCr9CDrtDb+vhxSQGX/pj344JkjgDbVdVjhn4d6nXkzT\r\nVDHJtoOUjjxVq+TKkA9/JSgGho+mL3ZIyS4=\r\n=bM6U\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221107.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20221107.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-ApbODKYlvoB4r7KCIGkpkp178ELn+nzEskxsANXNc7fokU2+sOzsu5LhYgKJiuONO3C+AmyBfNdodkzv/F5Rng==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.19.2","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.18.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^8.2.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.8.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20221107.1_1667862296220_0.22003342540209236","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20230127.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20230127.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20230127.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"96fd84850f12c4a9cd161252c7070fea0811f9cc","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20230127.1.tgz","fileCount":36,"integrity":"sha512-sPDc274eTqQNrMDveVjBDqe7R/nYFIzsinbA9MT1MECVcHf1kQpXF5kDcQvdkrtWa70bg1UGsf113F8wsN9b4Q==","signatures":[{"sig":"MEQCIERb7Wc/F6R6+s8bac25GgqL2Y3XyLYEdyWiMZ5DiJVxAiBrW+gWa/Et7g6p2mrBwju01/ai8gQVIqVS3S1D13Tlkw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2349686,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj1FjIACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmre1A/+IULOw/tMmiP8cTn1iOAo1p2bOKSZC23K9eruK5MqjVRgW2RJ\r\nyuKf33LgKhM2pUS0EhMqbz1PkN4dVcz/QOEjwP73T5hzYrogc5Gfw1Zcc1Fj\r\nYwvSm6c+jNw3daGz3OXK6oLPbmBdrncz77HyFN2/euuCgDEIL3ICbXfLJnfE\r\nqRBNfJMn3Th0kh3TQOU/CI9JeOcqHz6NaY+VV6UfLNe9Ne+1/PBTHY6Jq9cM\r\nBOBC3FsaaZo18svueeS/OiPquZ7c9PetzFBrWIcCY16tMZSKIZjqAQBxbM5P\r\n1mKY1hL6oV3XiUxepkDbS0gPQbfg4KifsHAQIpPy/EovfCtFmSaI+awaVxQ8\r\ndn25Q7oxpGqo3ezhYw2Y9uesP6+Gbd948weaA8V99ODsjJ2qjU+4mDn2Jy2O\r\nisYfvcqgUjnsK5HbaZwdsFtBH/sL9WlyXlOVlY9uMVOB8GYH0RB5FyGHMXs8\r\nSO/fof64i8LugSqvgZd2aaweYLONxrfKiuAQz5phmaIr9Wyw1ADm1eYVG3VY\r\nwc1zB2+TJxra8bGio4KXsow1ACKMHy/YjnkRZXPNlOw7vGsYGVFx4wgUAAd0\r\n7lkNnWZegqCBftNO5IjU9bJHB1XeebBmnW2K8Ph8c/xmcd2UOqKLq9VvqFC3\r\nVuj9Wf/WiMpvjQGF6W58OOlEPqdKkga+g/c=\r\n=Zqf8\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230127.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230127.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-sPDc274eTqQNrMDveVjBDqe7R/nYFIzsinbA9MT1MECVcHf1kQpXF5kDcQvdkrtWa70bg1UGsf113F8wsN9b4Q==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"8.19.3","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"16.19.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^16.0.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.8.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","karma-ie-launcher":"^1.0.0","source-map-support":"^0.5.9","karma-edge-launcher":"^0.4.2","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20230127.1_1674860744720_0.8110934891473613","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20230306.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20230306.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20230306.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"54acad44e2a2243ddbafc7bf79e70a90c2272073","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20230306.1.tgz","fileCount":36,"integrity":"sha512-eL3cayWM9QuaFpHv9dOs/yk6b5wkf9MPivzWOhHUABy594oGmG1E6apQnQJb+4rZi2ldebUB9DTqLvng26RnpQ==","signatures":[{"sig":"MEQCIBRbfp1V1O2CUjtVVI0xwptE4HTeoeSdCbk4o3ZUrwJ+AiAe/yvYhRdPNOmzwGcjBB7eicAWxenPs5UiVW1KRv1wxQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2349614,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkBnYfACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoPHw/+L2Nam/geuISO/Ya2S541J1q1CCfZdM3qCvE56KQ3PJoG0rvj\r\nPmu+AhZDQ7jtgXXqsvdW7eNbsmbBPzWbG9UIDNKKGQ9rCynUPiH3qaQT8yQ+\r\nJ+MUNLPOFmLs7ERwLnYwzODalHcKW6tgDsSoOoeZH/hD+jw8324waz7B0mUd\r\nyvrWRn2SHlMZ7MSISGxYnLy6Umo50gWSSNhGJ7d5jj71YvDPzwQNQ/OLfNu8\r\n7QFB55aFqgm8n77NVcZKl6786vi/Zl3IvZf9Fx+SNXGg+Qwt1tFYGnwcJBPZ\r\nmGBD1wt8fxEqdPGDF+rtQKWhSu6Gk11+yDdUGoWjnltx7KWY8kWl3P9QEUyk\r\nsetxbbeXS/z+84UF/dkrDyer84wgMdTODRn56viO7x0o9sqM9HE7KVN2OObe\r\nMO0rmEqls/YH46xCNcMZNU2/3N0xT1xSeSNTZHmUYzGMYWATLnOvaNl/M3yo\r\n/tiyfLviGEG3dYjTEKFQLFVxTp9QGxjj9ysLhDPiwl9FePZBoJg3gEM8LSsw\r\nc3isHzt/sfQcrrT6/y/xSKzyUjFSVadJj7v6oNYj/GzV1zUEWo7GSPqS4Zg5\r\nlEPFJ0dZo/NuQfcA7BZhr13gDPw9mGqymerm3ALSg9ajhJIFjhrh06hHAV4d\r\n+PdoMLP0ryIqIHE6QewQRw0OmFf+ML7biMs=\r\n=qeYt\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230306.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230306.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-eL3cayWM9QuaFpHv9dOs/yk6b5wkf9MPivzWOhHUABy594oGmG1E6apQnQJb+4rZi2ldebUB9DTqLvng26RnpQ==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"9.3.1","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"18.14.1","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^16.0.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~4.8.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","source-map-support":"^0.5.9","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20230306.1_1678145055687_0.9847202764550715","host":"s3://npm-registry-packages"}},"1.0.1-alpha.20230419.1":{"name":"@azure/ai-metrics-advisor","version":"1.0.1-alpha.20230419.1","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"author":{"name":"Microsoft Corporation"},"license":"MIT","_id":"@azure/ai-metrics-advisor@1.0.1-alpha.20230419.1","maintainers":[{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"}],"homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"dist":{"shasum":"7c24bd44472faebb93a56faa0fe2fe800dc7714b","tarball":"https://registry.npmjs.org/@azure/ai-metrics-advisor/-/ai-metrics-advisor-1.0.1-alpha.20230419.1.tgz","fileCount":36,"integrity":"sha512-N7oNqMlUdSZgW/QFoP273FUpV39ikicBFomfsSp1cUQTpL+j0MDkLcDwSnXzrYnjdzDdKiCYXGolAairubIHGg==","signatures":[{"sig":"MEYCIQDJiJ83Mew5fyhMr2Tx39dY4Eh+fRVmOlPaM2gMDuX1uAIhAKodiksYXMGZe5vUq4VAWEhxbXMczoU9fITxal/4URXf","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2359302,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQGUyACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrqNA/+Nbt2hI3MX3+jEMV0BB9YpMcM5ryjuaBL3DBEugjKXArdzDLy\r\n2T/WiPXYp3yAfoHfOKc1Dljjh/FAjcw59SZPk/GWrPfoSIUJc9VCbkOhlZ7Y\r\nAXBD4T42hhx/NkR0R/dxpO6zCh83MrRQyEvwRD6tB+S/QxBJhW5N0oOlwYF+\r\nF4cgalm5yQXn7ybjTb44IQ/7MQWgAXq4PGAwUPR2xYnxmHfIhtp1xZ3i0r4q\r\no2WbhOIiDaIjWZMoMzq7STXjMPux6D0kPtv/yzwM5VKdpcGaPlH1RAqpUYeZ\r\nIbCTJdhcUYdMne5Od/UXtWHymT+fS7NHHZ4H8PG9KYccFJEaJt6FOkRMjLoz\r\nasq59xXMkNrSCnYfziWD1SAwTqjqCtWDDt2+jb6Abn+RluwVQPQaaH1D6Kk4\r\nMCwYRstxKmKhEJRD76jC30vJBib/jtEF4JVaNiSGxIWK6GLmlr+trvyXkSkm\r\nt0IpYYpKWJOYLct0F2kjTrua4ciLaw9oNsmaNbJzkDXb0oa1lR6aJin8R3rp\r\nIZGgOk8EHzV30o25gw3pFiPlzbK7kPxCjmuSwAg27PkxdDZP3W6SxUKX8OwT\r\njKXWGgkJane9DKM+b/zCnvIYNUmaEIevhISTmT/8+twyv+0PTGcV0fqR+9LB\r\ndO8zAcvcCNvS7W/CdwmPK9fv/aGjDJODEu0=\r\n=CDiD\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./dist/index.js","_from":"file:/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230419.1.tgz","types":"./types/ai-metrics-advisor.d.ts","module":"./dist-esm/src/index.js","readme":"# Azure Metrics Advisor client library for JavaScript\n\nMetrics Advisor is a part of Azure Cognitive Services that uses AI to perform data monitoring and anomaly detection in time series data. The service automates the process of applying models to your data and provides a set of web-based APIs for data ingestion, anomaly detection and diagnostics - without needing to know machine learning. Use Metrics Advisor to:\n\n- Analyze multi-dimensional data from multiple data sources\n- Identify and correlate anomalies\n- Configure and fine-tune the anomaly detection model used on your data\n- Diagnose anomalies and help with root cause analysis.\n\nKey links:\n\n- [Source code](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/metricsadvisor/ai-metrics-advisor/)\n- [Package (NPM)](https://www.npmjs.com/package/@azure/ai-metrics-advisor)\n- [API reference documentation](https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor)\n- [Product documentation](https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/)\n- [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\n\n## Getting started\n\n### Currently supported environments\n\n- [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)\n- Latest versions of Safari, Chrome, Edge, and Firefox.\n\nSee our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.\n\n### Prerequisites\n\n- An [Azure subscription][azure_sub].\n- An existing [Cognitive Services][cognitive_resource] or Metrics Advisor resource. If you need to create the resource, you can use the [Azure Portal][azure_portal] or [Azure CLI][azure_cli].\n\nIf you use the Azure CLI, replace `<your-resource-group-name>` and `<your-resource-name>` with your own unique names. You can also provide the pricing tier (or sku) `<sku level>` and an Azure location `<location>`\n\n```bash\naz cognitiveservices account create --kind MetricsAdvisor --resource-group <your-resource-group-name> --name <your-resource-name> --sku <sku level> --location <location>\n```\n\n- Existing data sources with time series metric data with the [required data schema][data_schema_requirements]. You can find the settings and requirements for [connecting different types of data sources][connect_sources_metrics_advisor] to Azure Metrics Advisor.\n- After this, [set up datafeeds to onboard data][onboard_data_feed]\n\n### Install the `@azure/ai-metrics-advisor` package\n\nInstall the Azure Metrics Advisor client library for JavaScript with `npm`:\n\n```bash\nnpm install @azure/ai-metrics-advisor\n```\n\n### Create and authenticate `MetricsAdvisorClient` or `MetricsAdvisorAdministrationClient`\n\nTo create a client object to access the Metrics Advisor API, you will need the `endpoint` of your Metrics Advisor resource and a `credential`. The Metrics Advisor clients use a Metrics Advisor key credential to authenticate.\n\nYou can find the endpoint for your Metrics Advisor resource either in the [Azure Portal][azure_portal] or by using the [Azure CLI][azure_cli] snippet below:\n\n```bash\naz cognitiveservices account show --name <your-resource-name> --resource-group <your-resource-group-name> --query \"endpoint\"\n```\n\n#### Using Subscription Key and API Key\n\nYou will need two keys to authenticate the client:\n\n- The subscription key to your Metrics Advisor resource. You can find this in the **Keys and Endpoint** section of your resource in the [Azure Portal][azure_portal].\n- The API key for your Metrics Advisor instance. Get the web portal url for Metrics Advisor from the **Overview** section of your resource in the [Azure Portal][azure_portal]. After logging into the web portal for Metrics Advisor, click on **API keys** on the left navigation menu to find the API key.\n\nUse the [Azure Portal][azure_portal] to browse to your Metrics Advisor resource and retrieve an subscription key or use the [Azure CLI][azure_cli] snippet below:\n\n```PowerShell\naz cognitiveservices account keys list --resource-group <your-resource-group-name> --name <your-resource-name>\n```\n\nIn addition, you will also need the per-user api key from your Metrics Advisor web portal.\n\nOnce you have the two keys and the endpoint, you can use the `MetricsAdvisorKeyCredential` class to authenticate the clients as follows:\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nconst credential = new MetricsAdvisorKeyCredential(\"<subscription Key>\", \"<API key>\");\n\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n#### Using Azure Service Directory\n\nAPI key authorization is used in most of the examples, but you can also authenticate the client with Azure Active Directory using the Azure Identity library. To use the DefaultAzureCredential provider shown below or other credential providers provided with the Azure SDK, please install the @azure/identity package:\n\n```\nnpm install @azure/identity\n```\n\nTo authenticate using a service principal, you will also need to register an AAD application and grant access to Metrics Advisor by assigning the \"Cognitive Services User\" role to your service principal (note: other roles such as \"Owner\" will not grant the necessary permissions, only \"Cognitive Services User\" will suffice to run the examples and the sample code).\n\nSet the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.\nWe also support Authentication by Azure Active Directoty Credential. You will need the Azure Tenant ID, Azure Client ID and Azure Client Secret as environment variables.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorClient,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\nconst { DefaultAzureCredential } = require(\"@azure/identity\");\nconst credential = new DefaultAzureCredential();\nconst client = new MetricsAdvisorClient(\"<endpoint>\", credential);\nconst adminClient = new MetricsAdvisorAdministrationClient(\"<endpoint>\", credential);\n```\n\n## Key concepts\n\n### MetricsAdvisorClient\n\n`MetricsAdvisorClient` is the primary query interface for developers using the Metrics Advisor client library. It provides asynchronous methods to access a specific use of Metrics Advisor, such as listing incidents, retrive root causes of incidents, retrieving original time series data and time series data enriched by the service.\n\n### MetricsAdvisorAdministrationClient\n\n`MetricsAdvisorAdministrationClient` is the interface responsible for managing entities in the Metrics Advisor resources, such as managing data feeds, anomaly detection configurations, anomaly alerting configurations.\n\n### Data Feed\n\nA data feed is what Metrics Advisor ingests from your data source, such as Cosmos DB or a SQL server. A data feed contains rows of:\n\n- timestamps\n- zero or more dimensions\n- one or more measures\n\n### Metric\n\nA metric is a quantifiable measure that is used to monitor and assess the status of a specific business process. It can be a combination of multiple time series values divided into dimensions. For example a web health metric might contain dimensions for user count and the en-us locale.\n\n### AnomalyDetectionConfiguration\n\n`AnomalyDetectionConfiguration` is required for every time series and determines whether a point in the time series is an anomaly.\n\n### Anomaly & Incident\n\nAfter a detection configuration is applied to metrics, `AnomalyIncident`s are generated whenever any series within has an `DataPointAnomaly`.\n\n### Alert\n\nYou can configure which anomalies should trigger an `AnomalyAlert`. You can set multiple alerts with different settings. For example, you could create an alert for anomalies with lower business impact and another for more important alerts.\n\n### Hook\n\nMetrics Advisor lets you create and subscribe to real-time alerts. These alerts are sent over the internet, using a notification hook.\n\nPlease refer to [the Metrics Advisory Glossary][metrics_advisor_glossary] documentation page for a comprehensive list of concepts.\n\n## Examples\n\nThe following section provides several JavaScript code snippets illustrating common patterns used in the Metrics Advisor client libraries.\n\n- [Add a data feed from a sample data source](#add-a-data-feed-from-a-sample-data-source \"Add a data feed from a sample or data source\")\n- [Check ingestion status](#check-ingestion-status \"Check ingestion status\")\n- [Configure anomaly detection configuration](#configure-anomaly-detection-configuration \"Configure anomaly detection configuration\")\n- [Add hooks for receiving anomaly alerts](#add-hooks-for-receiving-anomaly-alerts \"Add hooks for receiving anomaly alerts\")\n- [Configure alert configuration](#configure-alert-configuration \"Configure alert configuration\")\n- [Query anomaly detection results](#query-anomaly-detection-results \"Query anomaly detection results\")\n\n### Add a data feed from a sample data source\n\nMetrics Advisor supports connecting different types of data sources. Here is a sample to ingest data from SQL Server.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const sqlServerConnectionString =\n    process.env[\"METRICS_ADVISOR_SQL_SERVER_CONNECTION_STRING\"] ||\n    \"<connection string to SQL Server>\";\n  const sqlServerQuery =\n    process.env[\"METRICS_ADVISOR_AZURE_SQL_SERVER_QUERY\"] || \"<SQL Server query to retrive data>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const created = await createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery);\n  console.log(`Data feed created: ${created.id}`);\n}\n\nasync function createDataFeed(adminClient, sqlServerConnectionString, sqlServerQuery) {\n  console.log(\"Creating Datafeed...\");\n  const dataFeed = {\n    name: \"test_datafeed_\" + new Date().getTime().toString(),\n    source: {\n      dataSourceType: \"SqlServer\",\n      connectionString: sqlServerConnectionString,\n      query: sqlServerQuery,\n      authenticationType: \"Basic\",\n    },\n    granularity: {\n      granularityType: \"Daily\",\n    },\n    schema: {\n      metrics: [\n        {\n          name: \"revenue\",\n          displayName: \"revenue\",\n          description: \"Metric1 description\",\n        },\n        {\n          name: \"cost\",\n          displayName: \"cost\",\n          description: \"Metric2 description\",\n        },\n      ],\n      dimensions: [\n        { name: \"city\", displayName: \"city display\" },\n        { name: \"category\", displayName: \"category display\" },\n      ],\n      timestampColumn: null,\n    },\n    ingestionSettings: {\n      ingestionStartTime: new Date(Date.UTC(2020, 5, 1)),\n      ingestionStartOffsetInSeconds: 0,\n      dataSourceRequestConcurrency: -1,\n      ingestionRetryDelayInSeconds: -1,\n      stopRetryAfterInSeconds: -1,\n    },\n    rollupSettings: {\n      rollupType: \"AutoRollup\",\n      rollupMethod: \"Sum\",\n      rollupIdentificationValue: \"__CUSTOM_SUM__\",\n    },\n    missingDataPointFillSettings: {\n      fillType: \"SmartFilling\",\n    },\n    accessMode: \"Private\",\n    admins: [\"xyz@example.com\"],\n  };\n  const result = await adminClient.createDataFeed(dataFeed);\n\n  return result;\n}\n```\n\n### Check ingestion status\n\nAfter we start the data ingestion, we can check the ingestion status.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const dataFeedId = process.env[\"METRICS_DATAFEED_ID\"] || \"<data feed id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  await checkIngestionStatus(\n    adminClient,\n    dataFeedId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n}\n\nasync function checkIngestionStatus(adminClient, datafeedId, startTime, endTime) {\n  // This shows how to use for-await-of syntax to list status\n  console.log(\"Checking ingestion status...\");\n  const iterator = adminClient.listDataFeedIngestionStatus(datafeedId, startTime, endTime);\n  for await (const status of iterator) {\n    console.log(`  [${status.timestamp}] ${status.status} - ${status.message}`);\n  }\n}\n```\n\n### Configure anomaly detection configuration\n\nWe need an anomaly detection configuration to determine whether a point in the time series is an anomaly.\nWhile a default detection configuration is automatically applied to each metric, you can tune the detection modes used on your data by creating a customized anomaly detection configuration.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const metricId = process.env[\"METRICS_ADVISOR_METRIC_ID\"] || \"<metric id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n\n  const detectionConfig = await configureAnomalyDetectionConfiguration(adminClient, metricId);\n  console.log(`Detection configuration created: ${detectionConfig.id}`);\n}\n\nasync function configureAnomalyDetectionConfiguration(adminClient, metricId) {\n  console.log(`Creating an anomaly detection configuration on metric '${metricId}'...`);\n  const anomalyConfig = {\n    name: \"test_detection_configuration\" + new Date().getTime().toString(),\n    metricId,\n    wholeSeriesDetectionCondition: {\n      smartDetectionCondition: {\n        sensitivity: 100,\n        anomalyDetectorDirection: \"Both\",\n        suppressCondition: {\n          minNumber: 1,\n          minRatio: 1,\n        },\n      },\n    },\n    description: \"Detection configuration description\",\n  };\n  return await adminClient.createDetectionConfig(anomalyConfig);\n}\n```\n\n### Add hooks for receiving anomaly alerts\n\nWe use hooks subscribe to real-time alerts. In this example, we create a webhook for the Metrics Advisor service to POST the alert to.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const hook = await createWebhookHook(adminClient);\n  console.log(`Webhook hook created: ${hook.id}`);\n}\n\nasync function createWebhookHook(adminClient) {\n  console.log(\"Creating a webhook hook\");\n  const hook = {\n    hookType: \"Webhook\",\n    name: \"web hook \" + new Date().getTime().toString(),\n    description: \"description\",\n    hookParameter: {\n      endpoint: \"https://example.com/handleAlerts\",\n      username: \"username\",\n      password: \"password\",\n      // certificateKey: \"certificate key\",\n      // certificatePassword: \"certificate password\"\n    },\n  };\n\n  return await adminClient.createHook(hook);\n}\n```\n\n### Configure alert configuration\n\nThen let's configure in which conditions an alert needs to be triggered and which hooks to send the alert.\n\n```javascript\nconst {\n  MetricsAdvisorKeyCredential,\n  MetricsAdvisorAdministrationClient,\n} = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const detectionConfigId = process.env[\"METRICS_ADVISOR_DETECTION_CONFIG_ID\"] || \"<detection id>\";\n  const hookId = process.env[\"METRICS_ADVISOR_HOOK_ID\"] || \"<hook id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const adminClient = new MetricsAdvisorAdministrationClient(endpoint, credential);\n  const alertConfig = await configureAlertConfiguration(adminClient, detectionConfigId, [hookId]);\n  console.log(`Alert configuration created: ${alertConfig.id}`);\n}\n\nasync function configureAlertConfiguration(adminClient, detectionConfigId, hookIds) {\n  console.log(\"Creating a new alerting configuration...\");\n  const anomalyAlertConfig = {\n    name: \"test_alert_config_\" + new Date().getTime().toString(),\n    crossMetricsOperator: \"AND\",\n    metricAlertConfigurations: [\n      {\n        detectionConfigurationId: detectionConfigId,\n        alertScope: {\n          scopeType: \"All\",\n        },\n        alertConditions: {\n          severityCondition: { minAlertSeverity: \"Medium\", maxAlertSeverity: \"High\" },\n        },\n        snoozeCondition: {\n          autoSnooze: 0,\n          snoozeScope: \"Metric\",\n          onlyForSuccessive: true,\n        },\n      },\n    ],\n    hookIds,\n    description: \"Alerting config description\",\n  };\n  return await adminClient.createAlertConfig(anomalyAlertConfig);\n}\n```\n\n### Query anomaly detection results\n\nWe can query the alerts and anomalies.\n\n```javascript\nconst { MetricsAdvisorKeyCredential, MetricsAdvisorClient } = require(\"@azure/ai-metrics-advisor\");\n\nasync function main() {\n  // You will need to set these environment variables or edit the following values\n  const endpoint = process.env[\"METRICS_ADVISOR_ENDPOINT\"] || \"<service endpoint>\";\n  const subscriptionKey = process.env[\"METRICS_ADVISOR_SUBSCRIPTION_KEY\"] || \"<subscription key>\";\n  const apiKey = process.env[\"METRICS_ADVISOR_API_KEY\"] || \"<api key>\";\n  const alertConfigId = process.env[\"METRICS_ADVISOR_ALERT_CONFIG_ID\"] || \"<alert config id>\";\n  const credential = new MetricsAdvisorKeyCredential(subscriptionKey, apiKey);\n\n  const client = new MetricsAdvisorClient(endpoint, credential);\n\n  const alerts = await queryAlerts(\n    client,\n    alertConfigId,\n    new Date(Date.UTC(2020, 8, 1)),\n    new Date(Date.UTC(2020, 8, 12))\n  );\n\n  if (alerts.length > 1) {\n    // query anomalies using an alert id.\n    await queryAnomaliesByAlert(client, alerts[0]);\n  } else {\n    console.log(\"No alerts during the time period\");\n  }\n}\n\nasync function queryAlerts(client, alertConfigId, startTime, endTime) {\n  let alerts = [];\n  const iterator = client.listAlerts(alertConfigId, startTime, endTime, \"AnomalyTime\");\n  for await (const alert of iterator) {\n    alerts.push(alert);\n  }\n\n  return alerts;\n}\n\nasync function queryAnomaliesByAlert(client, alert) {\n  console.log(\n    `Listing anomalies for alert configuration '${alert.alertConfigId}' and alert '${alert.id}'`\n  );\n  const iterator = client.listAnomaliesForAlert(alert);\n  for await (const anomaly of iterator) {\n    console.log(\n      `  Anomaly ${anomaly.severity} ${anomaly.status} ${anomaly.seriesKey} ${anomaly.timestamp}`\n    );\n  }\n}\n```\n\n## Troubleshooting\n\n### Logging\n\nEnabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:\n\n```javascript\nconst { setLogLevel } = require(\"@azure/logger\");\n\nsetLogLevel(\"info\");\n```\n\nFor more detailed instructions on how to enable logs, you can look at the [@azure/logger package docs](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/core/logger).\n\n## Next steps\n\nPlease take a look at the\n[samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/samples)\ndirectory for detailed examples on how to use this library.\n\n## Contributing\n\nIf you'd like to contribute to this library, please read the [contributing guide](https://github.com/Azure/azure-sdk-for-js/blob/main/CONTRIBUTING.md) to learn more about how to build and test \\\nthe code.\n\n## Related projects\n\n- [Microsoft Azure SDK for Javascript](https://github.com/Azure/azure-sdk-for-js)\n\n![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fmetricsadvisor%2Fai-metrics-advisor%2FREADME.png)\n\n[azure_cli]: https://docs.microsoft.com/cli/azure\n[azure_sub]: https://azure.microsoft.com/free/\n[cognitive_resource]: https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account\n[azure_portal]: https://portal.azure.com\n[azure_identity]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity\n[register_aad_app]: https://docs.microsoft.com/azure/cognitive-services/authentication#assign-a-role-to-a-service-principal\n[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential\n[metrics_advisor_glossary]: https://docs.microsoft.com/azure/cognitive-services/metrics-advisor/glossary\n[onboard_data_feed]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data\n[data_schema_requirements]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/how-tos/onboard-your-data#data-schema-requirements-and-configuration\n[connect_sources_metrics_advisor]: https://docs.microsoft.com/azure/applied-ai-services/metrics-advisor/data-feeds-from-different-sources\n","browser":{},"engines":{"node":">=14.0.0"},"scripts":{"lint":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js","pack":"npm pack 2>&1","test":"npm run build:test && npm run unit-test && npm run integration-test","audit":"node ../../../common/scripts/rush-audit.js && rimraf node_modules package-lock.json && npm i --package-lock-only 2>&1 && npm audit","build":"npm run clean && tsc -p . && dev-tool run bundle && api-extractor run --local","clean":"rimraf dist dist-esm dist-browser dist-test dist-test temp types *.tgz *.log","format":"prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","lint:fix":"eslint package.json api-extractor.json README.md src test --ext .ts,.javascript,.js --fix --fix-type [problem,suggestion]","test:node":"npm run build:test && npm run unit-test:node && npm run integration-test:node","unit-test":"npm run unit-test:node && npm run unit-test:browser","build:node":"tsc -p . && dev-tool run bundle","build:test":"tsc -p . && dev-tool run bundle","extract-api":"tsc -p . && api-extractor run --local","check-format":"prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"test/**/*.ts\" \"samples-dev/**/*.ts\" \"*.{js,json}\"","test:browser":"npm run build:test && npm run unit-test:browser && npm run integration-test:browser","build:browser":"tsc -p . && dev-tool run bundle","build:samples":"echo Obsolete.","unit-test:node":"mocha -r esm --require ts-node/register --reporter ../../../common/tools/mocha-multi-reporter.js --timeout 120000 --full-trace \"test/{,!(browser)/**/}*.spec.ts\"","execute:samples":"dev-tool samples run samples-dev","generate:client":"autorest --typescript ./swagger/README.md","integration-test":"npm run integration-test:node && npm run integration-test:browser","unit-test:browser":"karma start --single-run","integration-test:node":"nyc mocha -r esm --require source-map-support/register --reporter ../../../common/tools/mocha-multi-reporter.js --full-trace -t 300000  \"dist-esm/test/internal/*.spec.js\" \"dist-esm/test/public/*.spec.js\" \"dist-esm/test/public/node/*.spec.js\" \"dist-esm/test/internal/node/*.spec.js\"","integration-test:browser":"karma start --single-run"},"_npmUser":{"name":"azure-sdk","email":"azure-sdk-npmjs@microsoft.com"},"prettier":"@azure/eslint-plugin-azure-sdk/prettier.json","sdk-type":"client","_resolved":"/mnt/vss/_work/1/packages/azure-ai-metrics-advisor/azure-ai-metrics-advisor-1.0.1-alpha.20230419.1.tgz","//metadata":{"constantPaths":[{"path":"src/generated/generatedClientContext.ts","prefix":"packageVersion"},{"path":"src/constants.ts","prefix":"SDK_VERSION"},{"path":"swagger/README.md","prefix":"package-version"}]},"_integrity":"sha512-N7oNqMlUdSZgW/QFoP273FUpV39ikicBFomfsSp1cUQTpL+j0MDkLcDwSnXzrYnjdzDdKiCYXGolAairubIHGg==","deprecated":"This service has been deprecated and will be fully retired. For more information see https://azure.microsoft.com/en-us/updates?id=ai-services-metrics-advisor-will-be-retired-on-1-october-2026","repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"_npmVersion":"9.5.0","autoPublish":false,"description":"An isomorphic client library for the Azure Metrics Advisor service.","directories":{},"sideEffects":false,"_nodeVersion":"18.15.0","dependencies":{"tslib":"^2.2.0","@azure/logger":"^1.0.0","@azure/core-lro":"^2.2.0","@azure/core-auth":"^1.3.0","@azure/core-client":"^1.0.0","@azure/core-paging":"^1.1.1","@azure/core-tracing":"^1.0.0","@azure/core-http-compat":"^1.2.0","@azure/core-rest-pipeline":"^1.1.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^15.0.0","chai":"^4.2.0","karma":"^6.2.0","mocha":"^7.1.1","sinon":"^9.0.2","dotenv":"^16.0.0","eslint":"^8.0.0","rimraf":"^3.0.0","ts-node":"^10.0.0","prettier":"^2.5.1","cross-env":"^7.0.2","typescript":"~5.0.0","@types/chai":"^4.1.6","@types/node":"^14.0.0","karma-mocha":"^2.0.1","@types/mocha":"^7.0.2","@types/sinon":"^9.0.4","karma-coverage":"^2.0.0","@azure/dev-tool":">=1.0.0-alpha <1.0.0-alphb","@azure/identity":"^2.0.1","chai-as-promised":"^7.1.1","@azure/test-utils":">=1.0.0-alpha <1.0.0-alphb","source-map-support":"^0.5.9","karma-junit-reporter":"^2.0.1","karma-mocha-reporter":"^2.2.5","mocha-junit-reporter":"^2.0.0","karma-chrome-launcher":"^3.0.0","karma-env-preprocessor":"^0.1.1","karma-firefox-launcher":"^1.1.0","karma-sourcemap-loader":"^0.3.8","karma-json-preprocessor":"^0.3.3","@microsoft/api-extractor":"^7.31.1","@azure-tools/test-recorder":"^1.0.0","karma-json-to-file-reporter":"^1.0.1","@azure/eslint-plugin-azure-sdk":">=3.0.0-alpha <3.0.0-alphb"},"//sampleConfiguration":{"skip":["alertingConfig.js","dataFeed.js","detectionConfig.js","hooks.js","incidentsAndAlerts.js","ingestionStatus.js","metricFeedback.js","metricQueries.js","quickstart.js","seriesData.js"],"apiRefLink":"https://docs.microsoft.com/javascript/api/@azure/ai-metrics-advisor/","skipFolder":false,"productName":"Azure Metrics Advisor","productSlugs":["azure","azure-cognitive-services","azure-metrics-advisor"],"disableDocsMs":false,"requiredResources":{"Azure Cognitive Services account":"https://docs.microsoft.com/azure/cognitive-services/cognitive-services-apis-create-account"}},"_npmOperationalInternal":{"tmp":"tmp/ai-metrics-advisor_1.0.1-alpha.20230419.1_1681941810227_0.4527807215791515","host":"s3://npm-registry-packages"}}},"time":{"created":"2020-10-06T23:22:29.017Z","modified":"2026-03-19T19:46:00.371Z","1.0.0-alpha.20201006.1":"2020-10-06T23:22:29.420Z","1.0.0-beta.1":"2020-10-07T21:26:26.869Z","1.0.0-beta.2":"2020-11-11T01:23:03.596Z","1.0.0-alpha.20201211.1":"2020-12-11T22:59:57.935Z","1.0.0-alpha.20201214.1":"2020-12-14T23:01:37.163Z","1.0.0-alpha.20201215.1":"2020-12-15T22:57:01.068Z","1.0.0-alpha.20201217.1":"2020-12-17T23:01:22.995Z","1.0.0-alpha.20210105.1":"2021-01-05T23:00:46.650Z","1.0.0-alpha.20210115.1":"2021-01-15T22:57:38.056Z","1.0.0-alpha.20210122.1":"2021-01-22T23:01:51.882Z","1.0.0-alpha.20210126.1":"2021-01-26T22:55:58.448Z","1.0.0-alpha.20210127.1":"2021-01-27T22:58:26.543Z","1.0.0-alpha.20210128.1":"2021-01-28T22:56:00.541Z","1.0.0-alpha.20210129.1":"2021-01-29T22:58:05.094Z","1.0.0-alpha.20210201.1":"2021-02-01T22:59:27.943Z","1.0.0-alpha.20210203.1":"2021-02-03T22:57:05.837Z","1.0.0-alpha.20210204.1":"2021-02-04T22:56:40.690Z","1.0.0-alpha.20210205.1":"2021-02-05T22:54:41.672Z","1.0.0-alpha.20210209.1":"2021-02-09T22:54:33.500Z","1.0.0-beta.3":"2021-02-09T23:38:48.637Z","1.0.0-alpha.20210210.1":"2021-02-10T23:00:23.619Z","1.0.0-alpha.20210217.1":"2021-02-17T22:55:02.167Z","1.0.0-alpha.20210219.1":"2021-02-19T23:01:43.975Z","1.0.0-alpha.20210226.1":"2021-02-26T22:54:57.504Z","1.0.0-alpha.20210301.1":"2021-03-01T22:55:44.345Z","1.0.0-alpha.20210302.1":"2021-03-02T22:57:36.146Z","1.0.0-alpha.20210303.1":"2021-03-03T22:56:22.336Z","1.0.0-alpha.20210304.1":"2021-03-04T23:01:10.268Z","1.0.0-alpha.20210311.1":"2021-03-11T22:58:06.734Z","1.0.0-alpha.20210316.1":"2021-03-16T21:59:47.773Z","1.0.0-alpha.20210322.1":"2021-03-22T22:01:38.947Z","1.0.0-alpha.20210323.1":"2021-03-23T21:58:44.046Z","1.0.0-alpha.20210330.1":"2021-03-30T21:56:46.194Z","1.0.0-alpha.20210331.1":"2021-03-31T22:00:05.763Z","1.0.0-alpha.20210407.1":"2021-04-07T22:05:47.694Z","1.0.0-alpha.20210427.1":"2021-04-27T21:55:55.970Z","1.0.0-alpha.20210428.1":"2021-04-28T21:57:19.999Z","1.0.0-alpha.20210429.1":"2021-04-29T21:58:42.566Z","1.0.0-alpha.20210504.1":"2021-05-04T21:57:54.072Z","1.0.0-alpha.20210517.1":"2021-05-17T21:56:10.349Z","1.0.0-alpha.20210518.1":"2021-05-18T21:57:37.839Z","1.0.0-alpha.20210607.2":"2021-06-07T21:55:56.216Z","1.0.0-beta.4":"2021-06-08T02:31:15.780Z","1.0.0-alpha.20210608.1":"2021-06-08T21:59:38.293Z","1.0.0-alpha.20210624.1":"2021-06-24T22:05:34.361Z","1.0.0-alpha.20210625.1":"2021-06-25T22:02:19.652Z","1.0.0-alpha.20210628.2":"2021-06-28T21:58:17.194Z","1.0.0-alpha.20210629.1":"2021-06-29T22:01:24.293Z","1.0.0-alpha.20210701.2":"2021-07-01T22:16:40.463Z","1.0.0-alpha.20210705.1":"2021-07-05T21:57:02.741Z","1.0.0-alpha.20210706.3":"2021-07-06T22:04:05.107Z","1.0.0":"2021-07-06T23:16:47.900Z","1.0.1-alpha.20210707.1":"2021-07-07T22:03:56.136Z","1.0.1-alpha.20210715.1":"2021-07-15T22:04:04.751Z","1.0.1-alpha.20210716.1":"2021-07-16T21:59:07.111Z","1.0.1-alpha.20210804.1":"2021-08-04T22:07:20.569Z","1.0.1-alpha.20210806.1":"2021-08-06T22:04:41.840Z","1.0.1-alpha.20210816.1":"2021-08-16T22:09:08.310Z","1.0.1-alpha.20210826.1":"2021-08-26T22:10:26.356Z","1.0.1-alpha.20210901.1":"2021-09-01T21:59:38.833Z","1.0.1-alpha.20210913.1":"2021-09-13T21:59:22.931Z","1.0.1-alpha.20210930.1":"2021-09-30T21:58:58.150Z","1.0.1-alpha.20211101.2":"2021-11-01T22:10:35.685Z","1.0.1-alpha.20211116.1":"2021-11-16T23:07:06.487Z","1.0.1-alpha.20211208.1":"2021-12-08T23:27:48.144Z","1.0.1-alpha.20211214.2":"2021-12-14T22:56:09.172Z","1.0.1-alpha.20211221.2":"2021-12-21T22:58:07.836Z","1.0.1-alpha.20220106.1":"2022-01-06T22:59:17.257Z","1.0.1-alpha.20220112.1":"2022-01-12T22:57:15.736Z","1.0.1-alpha.20220120.1":"2022-01-20T22:59:51.738Z","1.0.1-alpha.20220128.3":"2022-01-28T23:20:05.206Z","1.0.1-alpha.20220131.2":"2022-01-31T22:57:44.932Z","1.0.1-alpha.20220211.1":"2022-02-11T22:59:07.933Z","1.0.1-alpha.20220307.1":"2022-03-07T23:01:41.478Z","1.0.1-alpha.20220315.1":"2022-03-15T22:05:47.085Z","1.0.1-alpha.20220321.1":"2022-03-21T22:30:16.945Z","1.0.1-alpha.20220330.2":"2022-03-30T22:00:40.806Z","1.0.1-alpha.20220401.1":"2022-04-01T22:21:02.373Z","1.0.1-alpha.20220406.1":"2022-04-06T21:59:51.247Z","1.0.1-alpha.20220407.1":"2022-04-07T22:01:42.959Z","1.0.1-alpha.20220408.1":"2022-04-08T22:04:54.050Z","1.0.1-alpha.20220419.2":"2022-04-19T22:04:22.467Z","1.0.1-alpha.20220421.1":"2022-04-21T22:05:07.299Z","1.0.1-alpha.20220426.1":"2022-04-26T21:59:35.007Z","1.0.1-alpha.20220517.1":"2022-05-17T22:00:22.549Z","1.0.1-alpha.20220520.1":"2022-05-20T21:57:00.210Z","1.0.1-alpha.20220524.1":"2022-05-24T22:03:26.553Z","1.0.1-alpha.20220919.1":"2022-09-19T22:10:26.362Z","1.0.1-alpha.20220926.1":"2022-09-26T22:00:44.064Z","1.0.1-alpha.20221014.1":"2022-10-14T22:03:07.772Z","1.0.1-alpha.20221018.2":"2022-10-18T22:23:45.777Z","1.0.1-alpha.20221107.1":"2022-11-07T23:04:56.415Z","1.0.1-alpha.20230127.1":"2023-01-27T23:05:44.948Z","1.0.1-alpha.20230306.1":"2023-03-06T23:24:15.872Z","1.0.1-alpha.20230419.1":"2023-04-19T22:03:30.494Z"},"bugs":{"url":"https://github.com/Azure/azure-sdk-for-js/issues"},"author":{"name":"Microsoft Corporation"},"license":"MIT","homepage":"https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/metricsadvisor/ai-metrics-advisor/README.md","keywords":["node","azure","typescript","browser","isomorphic","cloud"],"repository":{"url":"git+https://github.com/Azure/azure-sdk-for-js.git","type":"git"},"description":"An isomorphic client library for the Azure Metrics Advisor service.","maintainers":[{"email":"azure-sdk-npmjs@microsoft.com","name":"azure-sdk"},{"email":"npmjs@microsoft.com","name":"microsoft1es"},{"email":"microsoft-oss-publishing@microsoft.com","name":"microsoft-oss-releases"}],"readme":"","readmeFilename":""}