Scripts

Virtyx scripts are a powerful feature allowing you to monitor, diagnose, and fix all the software in your stack. Scripts can collect custom metrics that are then monitored and alerted from. A script can also simply collect information and display the results to you. Scripts can also be used to resolve problems.

Create a Script

To create a new script, go the Scripts page in Virtyx.

From there, click New Script. A script can have the following runtimes:

  1. sh for Unix shells
  2. powershell on Windows systems
  3. cmd.exe on Windows systems

If you want to use another runtime (Python, Node.js, etc), please contact us.

Run a Script

To simply execute a script once on an agent or agents, click on the script you want from the Scripts page, and then click “Run…”. Select the Agent(s) you want the script to run on. The results will appear below, as well as any error that occured.

If there is an error, the first thing you should do is try to run the script as a standalone script on the same machine. You can use the Virtyx Shell for that, or SSH or remote into the box using other tools. Once on the machine, create a script that is exactly the same as the script in Virtyx. Try running it and check the result. For example:

sh ./my-test-script.sh

Note: The agent may be running the script as a different user than your default user. Try running the script as Admin or Root as well.

Once the script runs correctly, you can edit the script in Virtyx to be the same.

Run a script as Task

To execute a script on a scheduled basis you need to create a Task. Tasks can be created for an Agent or Group. The Script task executes under the name hermes. When monitoring for errors, hermes.error is the metric name for any script that is having an error.

When using a script to collect metrics, the script itself can emit error metrics of any kind. However, if the script itself has an error (syntax error, bad exit, unhandled exception), then hermes reports that under hermes.error.

Collecting Metrics from a Script

Script output can be parsed as metrics allowing the collection of custom metrics. This can often be easier and quicker than creating your own custom plugin. A script output will be parsed for any metrics and if any are found, they will be stored. The raw result is stored if there are no metrics found. To record custom metrics the output should be:

metric.name.here|numeric_value_here|{"tag":"name"}
metric.name.one|40
metric.name.two|100
metric.name.three|0
metric.name.four|3.14159|{"hostname":"my-computer.local"}

The format is metric.name with no spaces, followed by the pipe | character, followed by the metric value. Metric values are always numbers. Lastly, an optional | can be placed followed by tags. These tags can be used later to filter metrics.