WIP(telegraf): autogenerate output plugin docs, refactor.
parent
edbaf358ec
commit
d5ce256b20
|
@ -17,3 +17,5 @@ node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
tmp
|
tmp
|
||||||
content/telegraf/v1/input-plugins
|
content/telegraf/v1/input-plugins
|
||||||
|
content/telegraf/v1/output-plugins
|
||||||
|
|
||||||
|
|
|
@ -3,38 +3,23 @@
|
||||||
# Determine the root project directory
|
# Determine the root project directory
|
||||||
ROOT_DIR=$(git rev-parse --show-toplevel)
|
ROOT_DIR=$(git rev-parse --show-toplevel)
|
||||||
|
|
||||||
# Clone an external repository
|
# If the Telegraf repo isn't already cloned in ./external, clone it
|
||||||
git clone https://github.com/influxdata/telegraf.git "$ROOT_DIR/external/telegraf"
|
|
||||||
|
|
||||||
|
if [ ! -d "$ROOT_DIR/external/telegraf" ]; then
|
||||||
|
git clone https://github.com/influxdata/telegraf.git "$ROOT_DIR/external/telegraf"
|
||||||
|
fi
|
||||||
# Update the external repository
|
# Update the external repository
|
||||||
cd "$ROOT_DIR/external/telegraf"
|
cd "$ROOT_DIR/external/telegraf"
|
||||||
git pull origin master
|
git pull origin master
|
||||||
|
|
||||||
# Function to create a Hugo page
|
# Function to create a Hugo page
|
||||||
create_page() {
|
create_page() {
|
||||||
local plugin_dir=$1
|
local dest_dir=$1
|
||||||
local dest_dir=$2
|
|
||||||
local dest_file="$dest_dir/_index.md"
|
local dest_file="$dest_dir/_index.md"
|
||||||
local parent=$3
|
local content=$2
|
||||||
|
|
||||||
# Check if the plugin directory exists
|
mkdir -p "$dest_dir"
|
||||||
if [ -d "$plugin_dir" ]; then
|
echo "$content" > "$dest_file"
|
||||||
mkdir -p "$dest_dir"
|
|
||||||
# Use a heredoc to write the frontmatter to the destination file
|
|
||||||
cat <<EOF > "$dest_file"
|
|
||||||
---
|
|
||||||
description: "Telegraf plugin for collecting metrics from $plugin_dir"
|
|
||||||
menu:
|
|
||||||
telegraf_v1_ref:
|
|
||||||
parent: $parent
|
|
||||||
name: $(basename "$plugin_dir")
|
|
||||||
tags: [$(basename "$plugin_dir")]
|
|
||||||
---
|
|
||||||
|
|
||||||
EOF
|
|
||||||
else
|
|
||||||
echo "Plugin directory not found: $plugin_dir"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to copy README.md content to _index.md
|
# Function to copy README.md content to _index.md
|
||||||
|
@ -56,7 +41,7 @@ copy_readme() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy the README.md content to _index.md
|
# Copy the README.md content to _index.md
|
||||||
cat $src_readme >> $dest_file
|
cat "$src_readme" >> "$dest_file"
|
||||||
echo "Copied $src_readme to $dest_file"
|
echo "Copied $src_readme to $dest_file"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,39 +54,72 @@ semaphore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Limit the number of concurrent processes
|
# Limit the number of concurrent processes
|
||||||
MAX_CONCURRENT=10
|
MAX_CONCURRENT=5
|
||||||
|
|
||||||
build() {
|
# Function to generate frontmatter for input plugins
|
||||||
# For each plugin in external/telegraf/plugins/inputs,
|
input_plugin_frontmatter() {
|
||||||
# copy the README.md file to content.
|
local plugin_name=$1
|
||||||
local input_plugins_dir="$ROOT_DIR/content/telegraf/v1/input-plugins"
|
|
||||||
cat <<EOF > "$input_plugins_dir/_index.md"
|
cat <<EOF
|
||||||
---
|
---
|
||||||
title: "Telegraf Input Plugins"
|
description: "Telegraf plugin for collecting metrics from $plugin_name"
|
||||||
description: "Telegraf input plugins collect metrics from the system, services, and third-party APIs."
|
|
||||||
menu:
|
menu:
|
||||||
telegraf_v1_ref:
|
telegraf_v1_ref:
|
||||||
name: Input Plugins
|
parent: input_plugins_reference
|
||||||
identifier: input-plugins
|
name: $plugin_name
|
||||||
weight: 10
|
identifier: "$plugin_name-input-plugin"
|
||||||
tags: [input-plugins]
|
tags: [$plugin_name, "input-plugins", "configuration"]
|
||||||
|
related:
|
||||||
|
- /telegraf/v1/configure_plugins/
|
||||||
---
|
---
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
for plugin_dir in "$ROOT_DIR/external/telegraf/plugins/inputs"/*; do
|
# Function to generate frontmatter for output plugins
|
||||||
|
output_plugin_frontmatter() {
|
||||||
|
local plugin_name=$1
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
---
|
||||||
|
description: "Telegraf plugin for sending metrics to $plugin_name"
|
||||||
|
menu:
|
||||||
|
telegraf_v1_ref:
|
||||||
|
parent: output_plugins_reference
|
||||||
|
name: $plugin_name
|
||||||
|
identifier: "$plugin_name-output-plugin"
|
||||||
|
tags: [$plugin_name, "output-plugins", "configuration"]
|
||||||
|
related:
|
||||||
|
- /telegraf/v1/configure_plugins/
|
||||||
|
---
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build function to create pages and copy README.md files
|
||||||
|
build() {
|
||||||
|
local src_dir=$1
|
||||||
|
local dest_dir=$2
|
||||||
|
local frontmatter_func=$3
|
||||||
|
local main_frontmatter=$4
|
||||||
|
|
||||||
|
# Create the main index file for plugins
|
||||||
|
echo "$main_frontmatter" > "$dest_dir/_index.md"
|
||||||
|
|
||||||
|
for plugin_dir in "$src_dir"/*; do
|
||||||
|
# If the directory name is "all", then skip it
|
||||||
|
if [ "$(basename "$plugin_dir")" == "all" ]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
local plugin_name=$(basename "$plugin_dir")
|
||||||
|
local plugin_dest_dir=$dest_dir/$plugin_name
|
||||||
if [ -d "$plugin_dir" ]; then
|
if [ -d "$plugin_dir" ]; then
|
||||||
# If the directory name is "all", then skip it
|
|
||||||
if [ "$(basename "$plugin_dir")" == "all" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
local plugin_name=$(basename "$plugin_dir")
|
|
||||||
local dest_dir=$input_plugins_dir/$plugin_name
|
|
||||||
semaphore "$MAX_CONCURRENT"
|
semaphore "$MAX_CONCURRENT"
|
||||||
(
|
(
|
||||||
create_page "$plugin_dir" "$dest_dir" "Input Plugins"
|
local frontmatter=$($frontmatter_func "$plugin_name")
|
||||||
copy_readme "$plugin_dir" "$dest_dir"
|
create_page "$plugin_dest_dir" "$frontmatter"
|
||||||
) &
|
copy_readme "$plugin_dir" "$plugin_dest_dir"
|
||||||
|
) &
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -109,4 +127,54 @@ EOF
|
||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
build
|
# Configuration for input plugins
|
||||||
|
SRC_DIR_INPUT="$ROOT_DIR/external/telegraf/plugins/inputs"
|
||||||
|
DEST_DIR_INPUT="$ROOT_DIR/content/telegraf/v1/input-plugins"
|
||||||
|
FRONTMATTER_FUNC_INPUT="input_plugin_frontmatter"
|
||||||
|
MAIN_FRONTMATTER_INPUT=$(cat <<EOF
|
||||||
|
---
|
||||||
|
title: "Telegraf Input Plugins"
|
||||||
|
description: "Telegraf input plugins collect metrics from the system, services, and third-party APIs."
|
||||||
|
menu:
|
||||||
|
telegraf_v1_ref:
|
||||||
|
name: Input plugins
|
||||||
|
identifier: input_plugins_reference
|
||||||
|
weight: 10
|
||||||
|
tags: [input-plugins]
|
||||||
|
---
|
||||||
|
|
||||||
|
Telegraf input plugins collect metrics from the system, services, and third-party APIs.
|
||||||
|
|
||||||
|
{{< children >}}
|
||||||
|
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the build function for input plugins
|
||||||
|
build "$SRC_DIR_INPUT" "$DEST_DIR_INPUT" "$FRONTMATTER_FUNC_INPUT" "$MAIN_FRONTMATTER_INPUT"
|
||||||
|
|
||||||
|
# Configuration for output plugins
|
||||||
|
SRC_DIR_OUTPUT="$ROOT_DIR/external/telegraf/plugins/outputs"
|
||||||
|
DEST_DIR_OUTPUT="$ROOT_DIR/content/telegraf/v1/output-plugins"
|
||||||
|
FRONTMATTER_FUNC_OUTPUT="output_plugin_frontmatter"
|
||||||
|
MAIN_FRONTMATTER_OUTPUT=$(cat <<EOF
|
||||||
|
---
|
||||||
|
title: "Telegraf Output Plugins"
|
||||||
|
description: "Telegraf output plugins send metrics to various destinations."
|
||||||
|
menu:
|
||||||
|
telegraf_v1_ref:
|
||||||
|
name: Output plugins
|
||||||
|
identifier: output_plugins_reference
|
||||||
|
weight: 20
|
||||||
|
tags: [output-plugins]
|
||||||
|
---
|
||||||
|
|
||||||
|
Telegraf output plugins send metrics to various destinations.
|
||||||
|
|
||||||
|
{{< children >}}
|
||||||
|
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the build function for output plugins
|
||||||
|
build "$SRC_DIR_OUTPUT" "$DEST_DIR_OUTPUT" "$FRONTMATTER_FUNC_OUTPUT" "$MAIN_FRONTMATTER_OUTPUT"
|
Loading…
Reference in New Issue