Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splunkenterprisereceiver add health metric (#36695) #36695

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
22 changes: 22 additions & 0 deletions .chloggen/changes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'
atoulme marked this conversation as resolved.
Show resolved Hide resolved

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'splunkenterprisereceiver'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Added a new `splunk.health` metric."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36695]

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
15 changes: 15 additions & 0 deletions receiver/splunkenterprisereceiver/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ Size in bytes on disk of this index *Note:** Must be pointed at specific indexer
| ---- | ----------- | ------ |
| splunk.index.name | The name of the index reporting a specific KPI | Any Str |

### splunk.health

The status ('red', 'yellow', or 'green') of the Splunk server. Health of 'red' produces a 0 while all other colors produce a 1.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| {status} | Gauge | Int |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| splunk.feature | The Feature name from the Splunk Health Introspection Endpoint | Any Str |
| splunk.feature.health | The Health (in color form) of a Splunk Feature from the Splunk Health Introspection Endpoint | Any Str |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure you need that? you already get the status via the value right?


### splunk.indexer.throughput

Gauge tracking average bytes per second throughput of indexer. *Note:** Must be pointed at specific indexer `endpoint` and gathers metrics from only that indexer.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ all_set:
enabled: true
splunk.data.indexes.extended.total.size:
enabled: true
splunk.health:
enabled: true
splunk.indexer.avg.rate:
enabled: true
splunk.indexer.cpu.time:
Expand Down Expand Up @@ -101,6 +103,8 @@ none_set:
enabled: false
splunk.data.indexes.extended.total.size:
enabled: false
splunk.health:
enabled: false
splunk.indexer.avg.rate:
enabled: false
splunk.indexer.cpu.time:
Expand Down
14 changes: 14 additions & 0 deletions receiver/splunkenterprisereceiver/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ attributes:
splunk.searchartifacts.cache.type:
description: The search artifacts cache type
type: string
splunk.feature:
description: The Feature name from the Splunk Health Introspection Endpoint
type: string
splunk.feature.health:
description: The Health (in color form) of a Splunk Feature from the Splunk Health Introspection Endpoint
type: string

metrics:
splunk.license.index.usage:
Expand Down Expand Up @@ -345,6 +351,14 @@ metrics:
aggregation_temporality: cumulative
value_type: int
attributes: [splunk.host]
#`services/server/health/splunkd/details`
splunk.health:
enabled: false
description: The status ('red', 'yellow', or 'green') of the Splunk server. Health of 'red' produces a 0 while all other colors produce a 1.
unit: "{status}"
gauge:
value_type: int
attributes: [splunk.feature, splunk.feature.health]

tests:
config:
57 changes: 55 additions & 2 deletions receiver/splunkenterprisereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (s *splunkScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
s.scrapeIndexerAvgRate,
s.scrapeKVStoreStatus,
s.scrapeSearchArtifacts,
s.scrapeHealth,
}
errChan := make(chan error, len(metricScrapes))

Expand Down Expand Up @@ -1075,12 +1076,12 @@ func unmarshallSearchReq(res *http.Response, sr *searchResponse) error {

body, err := io.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("Failed to read response: %w", err)
return fmt.Errorf("failed to read response: %w", err)
}

err = xml.Unmarshal(body, &sr)
if err != nil {
return fmt.Errorf("Failed to unmarshall response: %w", err)
return fmt.Errorf("failed to unmarshall response: %w", err)
}

return nil
Expand Down Expand Up @@ -1733,3 +1734,55 @@ func (s *splunkScraper) scrapeSearchArtifacts(ctx context.Context, now pcommon.T
}
}
}

// Scrape Health Introspection Endpoint
func (s *splunkScraper) scrapeHealth(ctx context.Context, now pcommon.Timestamp, errs chan error) {
if !s.conf.MetricsBuilderConfig.Metrics.SplunkHealth.Enabled {
return
}

ctx = context.WithValue(ctx, endpointType("type"), typeCm)

ept := apiDict[`SplunkHealth`]
var ha HealthArtifacts

req, err := s.splunkClient.createAPIRequest(ctx, ept)
if err != nil {
errs <- err
return
}

res, err := s.splunkClient.makeRequest(req)
if err != nil {
errs <- err
return
}
defer res.Body.Close()

if err := json.NewDecoder(res.Body).Decode(&ha); err != nil {
errs <- err
return
}

s.settings.Logger.Debug(fmt.Sprintf("Features: %s", ha.Entries))
for _, details := range ha.Entries {
s.traverseHealthDetailFeatures(details.Content, now)
}
}

func (s *splunkScraper) traverseHealthDetailFeatures(details HealthDetails, now pcommon.Timestamp) {
if details.Features == nil {
return
}

for k, feature := range details.Features {
if feature.Health != "red" {
s.settings.Logger.Debug(feature.Health)
s.mb.RecordSplunkHealthDataPoint(now, 1, k, feature.Health)
} else {
s.settings.Logger.Debug(feature.Health)
s.mb.RecordSplunkHealthDataPoint(now, 0, k, feature.Health)
}
s.traverseHealthDetailFeatures(feature, now)
}
}
15 changes: 15 additions & 0 deletions receiver/splunkenterprisereceiver/search_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var apiDict = map[string]string{
`SplunkIntrospectionQueues`: `/services/server/introspection/queues?output_mode=json&count=-1`,
`SplunkKVStoreStatus`: `/services/kvstore/status?output_mode=json`,
`SplunkDispatchArtifacts`: `/services/server/status/dispatch-artifacts?output_mode=json&count=-1`,
`SplunkHealth`: `/services/server/health/splunkd/details?output_mode=json`,
}

type searchResponse struct {
Expand Down Expand Up @@ -156,3 +157,17 @@ type DispatchArtifactContent struct {
StatusCacheSize string `json:"cached_job_status_status_csv_size_mb"`
CacheTotalEntries string `json:"cached_job_status_total_entries"`
}

// '/services/server/health/splunkd/details
type HealthArtifacts struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type HealthArtifacts struct {
type healthArtifacts struct {

limit your exported API to the minimum to avoid dependencies down the road using your internal structs.

Entries []HealthArtifactEntry `json:"entry"`
}

type HealthArtifactEntry struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type HealthArtifactEntry struct {
type healthArtifactEntry struct {

Content HealthDetails `json:"content"`
}

type HealthDetails struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type HealthDetails struct {
type healthDetails struct {

Health string `json:"health"`
Features map[string]HealthDetails `json:"features,omitempty"`
}
Loading