Skip to content

Commit

Permalink
Add telegraf enabled/disabled info in TelegrafMetricsSentCount (#1121)
Browse files Browse the repository at this point in the history
* Add telegraf enabled/disabled info in telegrafmetricssentcount

* Setting the env var before starting telegraf

* Add the telemetry only for windows

---------

Co-authored-by: Janvi Jatakia (from Dev Box) <[email protected]>
  • Loading branch information
jatakiajanvi12 and Janvi Jatakia (from Dev Box) authored Nov 27, 2023
1 parent 8300e19 commit 60a2f75
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
18 changes: 9 additions & 9 deletions kubernetes/windows/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,15 @@ function Get-ContainerRuntime {

function Start-Fluent-Telegraf {

Set-ProcessAndMachineEnvVariables "TELEMETRY_CUSTOM_PROM_MONITOR_PODS" "false"
# run prometheus custom config parser
Write-Host "**********Running config parser for custom prometheus scraping**********"
ruby /opt/amalogswindows/scripts/ruby/tomlparser-prom-customconfig.rb

Set-EnvironmentVariablesFromFile "/opt/amalogswindows/scripts/powershell/setpromenv.txt"

Write-Host "**********End running config parser for custom prometheus scraping**********"

$containerRuntime = Get-ContainerRuntime

if (![string]::IsNullOrEmpty($containerRuntime) -and [string]$containerRuntime.StartsWith('docker') -eq $false) {
Expand Down Expand Up @@ -690,15 +699,6 @@ function Start-Telegraf {
Write-Host "**********Setting default environment variables for telegraf prometheus plugin..."
.\setdefaulttelegrafenvvariables.ps1

Set-ProcessAndMachineEnvVariables "TELEMETRY_CUSTOM_PROM_MONITOR_PODS" "false"
# run prometheus custom config parser
Write-Host "**********Running config parser for custom prometheus scraping**********"
ruby /opt/amalogswindows/scripts/ruby/tomlparser-prom-customconfig.rb

Set-EnvironmentVariablesFromFile "/opt/amalogswindows/scripts/powershell/setpromenv.txt"

Write-Host "**********End running config parser for custom prometheus scraping**********"

$monitorKubernetesPods = [System.Environment]::GetEnvironmentVariable('TELEMETRY_CUSTOM_PROM_MONITOR_PODS')
if (![string]::IsNullOrEmpty($monitorKubernetesPods) -and $monitorKubernetesPods.ToLower() -eq 'true') {
# Set required environment variable for telegraf prometheus plugin to run properly
Expand Down
20 changes: 19 additions & 1 deletion source/plugins/go/src/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,12 @@ func SendContainerLogPluginMetrics(telemetryPushIntervalProperty string) {
TelemetryClient.Track(logLatencyMetric)
}
}
TelemetryClient.Track(appinsights.NewMetricTelemetry(metricNameNumberofTelegrafMetricsSentSuccessfully, telegrafMetricsSentCount))
telegrafEnabled := make(map[string]string)
osType := os.Getenv("OS_TYPE")
if osType != "" && strings.EqualFold(osType, "windows") {
telegrafEnabled["IsTelegrafEnabled"] = os.Getenv("TELEMETRY_CUSTOM_PROM_MONITOR_PODS") // If TELEMETRY_CUSTOM_PROM_MONITOR_PODS, then telegraf is enabled
}
SendMetric(metricNameNumberofTelegrafMetricsSentSuccessfully, telegrafMetricsSentCount, telegrafEnabled)
if telegrafMetricsSendErrorCount > 0.0 {
TelemetryClient.Track(appinsights.NewMetricTelemetry(metricNameNumberofSendErrorsTelegrafMetrics, telegrafMetricsSendErrorCount))
}
Expand Down Expand Up @@ -309,6 +314,19 @@ func SendEvent(eventName string, dimensions map[string]string) {
TelemetryClient.Track(event)
}

// SendMetric sends a metric to App Insights
func SendMetric(metricName string, metricValue float64, dimensions map[string]string) {
Log("Sending Metric : %s\n", metricName)
metric := appinsights.NewMetricTelemetry(metricName, metricValue)

// add any extra Properties
for k, v := range dimensions {
metric.Properties[k] = v
}

TelemetryClient.Track(metric)
}

// SendException send an event to the configured app insights instance
func SendException(err interface{}) {
if TelemetryClient != nil {
Expand Down

0 comments on commit 60a2f75

Please sign in to comment.