Skip to content

Instantly share code, notes, and snippets.

@pjh
Created October 14, 2020 01:07
Show Gist options
  • Save pjh/604c34b342d0560f6b20abce7c28e08b to your computer and use it in GitHub Desktop.
Save pjh/604c34b342d0560f6b20abce7c28e08b to your computer and use it in GitHub Desktop.
# NOTE: remove $LOGGINGAGENT_INSTALLER_DIR = 'C:\flb-installers' up above
# NOTE: Call DownloadAndInstall-LoggingAgent, then Configure-LoggingAgentServices
# NOTE: make 'v0.10.3' a constant
# NOTE: does $LOGGINGEXPORTER_SERVICE need its failure parameters set like LOGGINGAGENT_SERVICE?
# Installs the logging agent according to https://docs.fluentbit.io/manual/installation/windows#
# Also installs fluent bit stackdriver exporter
function DownloadAndInstall-LoggingAgent {
if (IsLoggingAgentInstalled) {
# Note: we should reinstall the agent if $REDO_STEPS is true
# here, but we don't know how to run the installer without it prompting
# when logging agent is already installed. We dumped the strings in the
# installer binary and searched for flags to do this but found nothing. Oh
# well.
Log-Output ("Skip: Fluentbit logging agent is already installed")
return
}
if (ShouldWrite-File $LOGGINGAGENT_ROOT\td-agent-bit-${LOGGINGAGENT_VERSION}-win64) {
$install_dir = 'C:\flb-installers'
New-Item $install_dir -ItemType 'directory' -Force | Out-Null
$url = ("https://storage.googleapis.com/gke-release/winnode/fluentbit/td-agent-bit-${LOGGINGAGENT_VERSION}-win64.zip")
MustDownload-File -OutFile $install_dir\td.zip -URLs $url
cd $install_dir
Expand-Archive td.zip
mv .\td\td-agent-bit-${LOGGINGAGENT_VERSION}-win64\ $LOGGINGAGENT_ROOT
cd C:\
Remove-Item -Force -Recurse $install_dir
}
# Download fluent bit exporter
if (ShouldWrite-File $LOGGINGEXPORTER_ROOT\flb-exporter.exe) {
MustDownload-File `
-OutFile $LOGGINGEXPORTER_ROOT\flb-exporter.exe `
-URLs 'https://storage.googleapis.com/gke-release/winnode/fluentbit-exporter/v0.10.3/flb-exporter-v0.10.3.exe'
}
}
function Configure-LoggingAgentServices {
cd $LOGGINGAGENT_ROOT
Log-Output 'Creating service: ${LOGGINGAGENT_SERVICE}'
sc.exe create $LOGGINGAGENT_SERVICE binpath= "${LOGGINGAGENT_ROOT}\bin\fluent-bit.exe -c \fluent-bit\conf\fluent-bit.conf"
sc.exe failure $LOGGINGAGENT_SERVICE reset= 30 actions= restart/5000
sc.exe query $LOGGINGAGENT_SERVICE
Log-Output 'Creating service: ${LOGGINGEXPORTER_SERVICE}'
sc.exe create $LOGGINGEXPORTER_SERVICE binpath= "${LOGGINGEXPORTER_ROOT}\flb-exporter.exe --kubernetes-separator=_ --stackdriver-resource-model=k8s --enable-pod-label-discovery --logtostderr --winsvc --pod-label-dot-replacement=_"
sc.exe query $LOGGINGEXPORTER_SERVICE
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment