Skip to content

Commit 190e51b

Browse files
Improve machine stats for Unix documentation (#191)
* Added more detail on the different ways to run machine stats, and the use cases for each * Small grammar tweaks, removed uneccessary lines from example scripts * Updated docs in tidal offline to link to instructions, rather than duplicating them * Added instructions for uploading results file to TMP * Fixed header type for 'creating the hosts file' section * Removed unneccessary backticks * Updated offline docs * Added parent 'Run machine stats' header to MS4U sections in machine_stats and tidal_offline
1 parent fe46157 commit 190e51b

File tree

2 files changed

+106
-28
lines changed

2 files changed

+106
-28
lines changed

pages/tidal tools/machine_stats.md

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ gather facts in a cross-platform way.
9999
Prior to the steps on syncing your Unix/Linux machines, be sure to have the below
100100
dependencies setup:
101101

102-
- To get started you will need to have Tidal Tools installed. You can check out
102+
- If you want to upload the results of running Machine Stats to the Tidal Migrations Platform, you will need to be on a server which is connected to the internet and has Tidal Tools installed. You can check out
103103
[Getting Started with Tidal Tools](tidal-tools.html) guide on how to install
104104
it.
105105
- You need to install **Python 3.6+** on your local workstation (control node)
@@ -109,12 +109,12 @@ dependencies setup:
109109
documentation](https://github.com/tidalmigrations/machine_stats/blob/master/unix/README.md)
110110
for installation instructions.
111111

112-
### Running the Script
112+
### Creating the Hosts File
113113

114-
1. Create a `hosts` file in the current directory.
114+
1. Create a file named `hosts` in the current directory.
115115

116116
2. Add connection strings in the form of `ssh-user@ip-address` or
117-
`ssh-user@domain` to the `hosts` file one per line If the `ssh-user@` part
117+
`ssh-user@domain` to the `hosts` file, one per line. If the `ssh-user@` part
118118
is omitted, then the current user name is used.
119119

120120
3. If you need to use a custom SSH identity file for some particular host,
@@ -124,11 +124,59 @@ dependencies setup:
124124
[email protected] ansible_ssh_private_key_file=path/to/key-file.pem
125125
```
126126
127-
4. Execute `machine-stats` and pipe its output to Tidal Tools:
127+
### Execute Machine Stats Manually
128+
129+
Execute `machine-stats` in your current working directory, and save the result to a `json` file of your choice.
130+
131+
This is useful for performing a test run to ensure you have Machine Stats set up correctly, or for saving the results of a single invocation when running Machine Stats on an offline server.
132+
133+
$ machine-stats > <path-to-result-file>
134+
135+
On an online server with `tidal tools` installed, you can upload this result file to Tidal Migrations Platform with the following command.
136+
137+
$ tidal sync servers <path-to-result-file>
138+
139+
### Run Machine Stats
140+
141+
Now that you have created a hosts file, you have two options for how to run Machine Stats depending on your needs. For example, you could use Machine Stats to capture data points on your inventory and send its output to your Tidal workspace. Alternatively, You can use Machine Stats to capture statistics on a host for a period of time. The following 2 sections will guide you through both scenarios.
142+
143+
#### Pipe Machine Stats Output to Tidal Migrations Platform
144+
145+
Execute `machine-stats` and pipe its output to Tidal Tools:
128146
129-
```
130147
$ machine-stats | tidal sync servers
131-
```
148+
149+
This approach is useful when you want to take a snapshot of your infrastructure and upload it directly to the Tidal Migrations Platform in one command. Since we're uploading the result immediately, this approach will only work on a server which has `tidal tools` installed and which is connected to the internet.
150+
151+
#### Run Machine Stats on a Cron Job
152+
153+
By leveraging cron, you can run Machines Stats on a schedule to gather data over a period of time. This is useful if you want to gather utilization data, for example recording the CPU utilization of your machines over a set period.
154+
155+
Since we're not piping the result to Tidal Migrations Platform, and are instead saving the result files locally, this approach can be used on an offline server.
156+
157+
First, create a script for cron to execute, like the one below. Replace `<path-to-hosts-file>` and `<path-to-results-directory>` with the correct values. Ensure you use full paths, not relative paths. Save this script with a name like `run-machine-stats.sh`.
158+
159+
#!/bin/bash
160+
161+
timestamp_start=$(date +%T)
162+
machine-stats <path-to-hosts-file> > <path-to-results-directory>/result-${timestamp_start}.json
163+
164+
Make the script executable by anyone, so that cron can execute it.
165+
166+
$ chmod +x <full-path-to-working-directory>/run-machine-stats.sh
167+
168+
Next, open a crontab with `crontab -e`. Copy the following into your crontab.
169+
170+
PATH=<full-path>
171+
*/5 * * * * bash <full-path-to-working-directory>/run-machine-stats.sh
172+
173+
You can get the value for `<full-path>` by running `echo $PATH`.
174+
175+
The `*/5` means that cron will execute this script every 5 minutes. You can customize this to set the sampling interval of your choosing.
176+
177+
Your results should appear in the existing `<path-to-results-directory>` that you specified in the `run-machine-stats.sh` script. Each result filename will contain a timestamp of when the invocation occurred.
178+
179+
### Technical Documentation
132180
133181
For more details on configuration and usage, please check Machine Stats for
134182
Unix-like systems [technical
@@ -138,7 +186,7 @@ documentation](https://github.com/tidalmigrations/machine_stats/blob/master/unix
138186
139187
### Introduction
140188
141-
Machine Stat for Hypervisors is built ontop of [libvirt](https://libvirt.org)
189+
Machine Stats for Hypervisors is built on top of [libvirt](https://libvirt.org)
142190
and it gathers facts from virtual machines within a QEMU/KVM environment.
143191
144192
### Requirements and Dependencies

pages/tidal tools/tidal_offline.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,33 +131,63 @@ You should receive confirmation that the upload has completed and can navigate t
131131

132132
## Gather Machine Stats (For Unix-Like Systems)
133133

134-
Follow [these instructions](#machine-stats-for-unix-like-systems) to install Machine Stats on an offline instance.
134+
### Installation
135135

136-
In your offline instance, create a `hosts` file in the current directory.
136+
Follow [the steps outlined above](#machine-stats-for-unix-like-systems) to install Machine Stats on an offline server.
137137

138-
Add connection strings in the form of `ssh-user@ip-address` or
139-
`ssh-user@domain` to the `hosts` file one per line If the `ssh-user@` part
140-
is omitted, then the current user name is used.
138+
### Creating the Hosts File
141139

142-
If you need to use a custom SSH identity file for some particular host,
143-
provide it as the following:
140+
1. Create a file named `hosts` in the current directory.
144141

145-
```
146-
my-user@example.com ansible_ssh_private_key_file=path/to/key-file.pem
147-
```
142+
2. Add connection strings in the form of `ssh-user@ip-address` or
143+
`ssh-user@domain` to the `hosts` file, one per line. If the `ssh-user@` part
144+
is omitted, then the current user name is used.
148145

149-
Execute `machine-stats` and save the result to a file of your choice:
146+
3. If you need to use a custom SSH identity file for some particular host,
147+
provide it as the following:
150148

151-
```
152-
$ machine-stats > result.json
153-
```
149+
```
150+
[email protected] ansible_ssh_private_key_file=path/to/key-file.pem
151+
```
154152
155-
Now, transfer the result.json file to your server with internet access.
153+
### Run Machine Stats
156154
157-
From here you can use
155+
Now that you have created a hosts file, you have two options for how to run Machine Stats depending on your needs. For example, you could use Machine Stats to capture data points on your inventory, and then send the result from an online server to your Tidal workspace. Alternatively, You can use Machine Stats to capture statistics on a host for a period of time. The following 2 sections will guide you through both scenarios.
158156
159-
```
160-
tidal sync servers result.json
161-
```
157+
#### Execute Machine Stats Manually
158+
159+
Execute `machine-stats` in your current working directory, and save the result to a `json` file of your choice.
160+
161+
This is useful for performing a test run to ensure you have Machine Stats set up correctly, or for taking a single snapshot of your machines to then upload from your online server to Tidal Migrations Platform.
162+
163+
$ machine-stats > <path-to-result-file>
164+
165+
On an online server with `tidal tools` installed, you can upload this result file to Tidal Migrations Platform with the following command.
166+
167+
$ tidal sync servers <path-to-result-file>
168+
169+
#### Run Machine Stats on a Cron Job
170+
171+
By leveraging cron, you can run Machines Stats on a schedule to gather data over a period of time. This is useful if you want to gather utilization data, for example recording the CPU utilization of your machines over a set period.
172+
173+
First, create a script for cron to execute, like the one below. Replace `<path-to-hosts-file>` and `<path-to-results-directory>` with the correct values. Ensure you use full paths, not relative paths. Save this script with a name like `run-machine-stats.sh`.
174+
175+
#!/bin/bash
176+
177+
timestamp_start=$(date +%T)
178+
machine-stats <path-to-hosts-file> > <path-to-results-directory>/result-${timestamp_start}.json
179+
180+
Make the script executable by anyone, so that cron can execute it.
181+
182+
$ chmod +x <full-path-to-working-directory>/run-machine-stats.sh
183+
184+
Next, open a crontab with `crontab -e`. Copy the following into your crontab.
185+
186+
PATH=<full-path>
187+
*/5 * * * * bash <full-path-to-working-directory>/run-machine-stats.sh
188+
189+
You can get the value for `<full-path>` by running `echo $PATH`.
190+
191+
The `*/5` means that cron will execute this script every 5 minutes. You can customize this to set the sampling interval of your choosing.
162192
163-
This sends the results to the Tidal Migrations API. Tidal Tools should confirm to you that the results were successfully uploaded. You should see the Job in the Discovery section, and your updated Server inventory in the Tidal Migrations Platform.
193+
Your results should appear in the existing `<path-to-results-directory>` that you specified in the `run-machine-stats.sh` script. Each result filename will contain a timestamp of when the invocation occurred.

0 commit comments

Comments
 (0)