Bootstrap FreeKB - ELK (Elastic Search, Logstash, Kibana) - Create Elastic Synthetics Project using NodeJS
ELK (Elastic Search, Logstash, Kibana) - Create Elastic Synthetics Project using NodeJS


ELK is the abbreviation for (Elastic Search, Logstash, Kibana) which is a system that parses log data from one or more systems and displays the log data in a web console, used for Observability, Alerting, Logging, and Monitoring.

NodeJS can be used to interact with ELK Kibana Synthetics. If you have not yet installed @elastic/synthetics in NodeJS, check out my article Install Elastic Synthetics in NodeJS.

The npx @elastic/synthetics init command can be used to create a new project. In this example, I'm creating a project named my-project in the present working directory. 

~]$ npx @elastic/synthetics init my-project
> Initializing Synthetics project in 'my-project'

 

Or, you can include the full path to the directory.

~]$ npx @elastic/synthetics init /tmp/my-project
> Initializing Synthetics project in 'my-project'

 

Enter your Elastic Kibana URL or Cloud ID and press enter.

✔ Enter Elastic Kibana URL or Cloud ID · ELK-Acme-Prod:abc123==
Generate API key from Kibana https://abc123.us-east-1.aws.elastic-cloud.com:443/app/synthetics/settings/api-keys

 

Enter your API Key and press enter.

abc123.us-east-1.aws.elastic-cloud.com:443/app/synthetics/settings/api-keys
✔ What is your API key · xyz987

 

Select the location where you want to run your monitors.

? Select the locations where you want to run monitors …  (Use <space> to select, <return> to submit)
✔ japan
✔ india
✔ singapore
✔ australia_east
✔ united_kingdom
✔ germany
✔ canada_east
✔ brazil
✔ us_east
✔ us_west
✔ my-private-location (private)

✔ Select the locations where you want to run monitors · my-private-location (private)

 

Select the default schedule.

? Set default schedule in minutes for all monitors … 
  1
  3
  5
▸ 10
  15
  20
  30
  60
  120
✔ Set default schedule in minutes for all monitors · 10

 

Give your project an ID.

✔ Choose project id to logically group monitors · my-project-id

 

Select a space.

✔ Choose the target Kibana space · default

 

And if all goes well, the project should be created.

> Setting up project using NPM...
Wrote to /tmp/elk/package.json:

{
  "name": "my-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


> Installing @elastic/synthetics library...
added 143 packages, and audited 144 packages in 16s

14 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
> Writing my-project/synthetics.config.ts.
> Writing my-project/journeys/advanced-example-helpers.ts.
> Writing my-project/journeys/example.journey.ts.
> Writing my-project/lightweight/heartbeat.yml.
> Writing my-project/journeys/advanced-example.journey.ts.
> Writing my-project/README.md.
> Writing my-project/.github/workflows/run-synthetics.yml.
> Writing my-project/package.json.

All set, you can run below commands inside: /tmp/elk/my-project:

  Run synthetic tests: npm run test

  Push monitors to Kibana: SYNTHETICS_API_KEY=<value> npm run push

  Configure API Key via `SYNTHETICS_API_KEY` env variable or --auth CLI flag.

Visit https://www.elastic.co/guide/en/observability/current/synthetic-run-tests.html to learn more.

 

In your present working directory, there should be a directory for the project you created (my-project in this example).

~]$ ls -l
total 88
drwxrwsr-x.   6 john.doe john.doe   4096 Jul  3 23:20 my-project
drwxrwsr-x. 130 john.doe john.doe  12288 Jul  3 22:53 node_modules
-rw-rw-r--.   1 john.doe john.doe     64 Jul  3 22:53 package.json
-rw-rw-r--.   1 john.doe john.doe  66553 Jul  3 22:53 package-lock.json

 

And in the directory should be a few files and subdirectories.

]$ ls -l my-project/
total 104
drwxrwsr-x.   2 john.doe john.doe  4096 Jul  3 23:20 journeys
drwxrwsr-x.   2 john.doe john.doe  4096 Jul  3 23:20 lightweight
drwxrwsr-x. 130 john.doe john.doe 12288 Jul  3 23:20 node_modules
-rw-rw-r--.   1 john.doe john.doe   333 Jul  3 23:20 package.json
-rw-rw-r--.   1 john.doe john.doe 66656 Jul  3 23:20 package-lock.json
-rw-rw-r--.   1 john.doe john.doe  1323 Jul  3 23:20 README.md
-rw-rw-r--.   1 john.doe john.doe   813 Jul  3 23:20 synthetics.config.ts

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter b8d8fb in the box below so that we can be sure you are a human.