chore: Fix linter findings for revive:max-public-structs in plugins/inputs/[t-z]* and rest (#15879)
This commit is contained in:
parent
714989aba2
commit
8d282ab03a
|
|
@ -19,23 +19,23 @@ import (
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type TomcatStatus struct {
|
type tomcatStatus struct {
|
||||||
TomcatJvm TomcatJvm `xml:"jvm"`
|
TomcatJvm tomcatJvm `xml:"jvm"`
|
||||||
TomcatConnectors []TomcatConnector `xml:"connector"`
|
TomcatConnectors []tomcatConnector `xml:"connector"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TomcatJvm struct {
|
type tomcatJvm struct {
|
||||||
JvmMemory JvmMemoryStat `xml:"memory"`
|
JvmMemory jvmMemoryStat `xml:"memory"`
|
||||||
JvmMemoryPools []JvmMemoryPoolStat `xml:"memorypool"`
|
JvmMemoryPools []jvmMemoryPoolStat `xml:"memorypool"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JvmMemoryStat struct {
|
type jvmMemoryStat struct {
|
||||||
Free int64 `xml:"free,attr"`
|
Free int64 `xml:"free,attr"`
|
||||||
Total int64 `xml:"total,attr"`
|
Total int64 `xml:"total,attr"`
|
||||||
Max int64 `xml:"max,attr"`
|
Max int64 `xml:"max,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type JvmMemoryPoolStat struct {
|
type jvmMemoryPoolStat struct {
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
Type string `xml:"type,attr"`
|
Type string `xml:"type,attr"`
|
||||||
UsageInit int64 `xml:"usageInit,attr"`
|
UsageInit int64 `xml:"usageInit,attr"`
|
||||||
|
|
@ -44,18 +44,18 @@ type JvmMemoryPoolStat struct {
|
||||||
UsageUsed int64 `xml:"usageUsed,attr"`
|
UsageUsed int64 `xml:"usageUsed,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TomcatConnector struct {
|
type tomcatConnector struct {
|
||||||
Name string `xml:"name,attr"`
|
Name string `xml:"name,attr"`
|
||||||
ThreadInfo ThreadInfo `xml:"threadInfo"`
|
ThreadInfo threadInfo `xml:"threadInfo"`
|
||||||
RequestInfo RequestInfo `xml:"requestInfo"`
|
RequestInfo requestInfo `xml:"requestInfo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ThreadInfo struct {
|
type threadInfo struct {
|
||||||
MaxThreads int64 `xml:"maxThreads,attr"`
|
MaxThreads int64 `xml:"maxThreads,attr"`
|
||||||
CurrentThreadCount int64 `xml:"currentThreadCount,attr"`
|
CurrentThreadCount int64 `xml:"currentThreadCount,attr"`
|
||||||
CurrentThreadsBusy int64 `xml:"currentThreadsBusy,attr"`
|
CurrentThreadsBusy int64 `xml:"currentThreadsBusy,attr"`
|
||||||
}
|
}
|
||||||
type RequestInfo struct {
|
type requestInfo struct {
|
||||||
MaxTime int `xml:"maxTime,attr"`
|
MaxTime int `xml:"maxTime,attr"`
|
||||||
ProcessingTime int `xml:"processingTime,attr"`
|
ProcessingTime int `xml:"processingTime,attr"`
|
||||||
RequestCount int `xml:"requestCount,attr"`
|
RequestCount int `xml:"requestCount,attr"`
|
||||||
|
|
@ -112,7 +112,7 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
|
||||||
resp.StatusCode, s.URL)
|
resp.StatusCode, s.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
var status TomcatStatus
|
var status tomcatStatus
|
||||||
if err := xml.NewDecoder(resp.Body).Decode(&status); err != nil {
|
if err := xml.NewDecoder(resp.Body).Decode(&status); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,35 +70,35 @@ func (e *newEventError) Error() string {
|
||||||
return e.s
|
return e.s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (awh *ArtifactoryWebhook) NewEvent(data []byte, et, ed string) (Event, error) {
|
func (awh *ArtifactoryWebhook) NewEvent(data []byte, et, ed string) (event, error) {
|
||||||
awh.log.Debugf("New %v domain %v event received", ed, et)
|
awh.log.Debugf("New %v domain %v event received", ed, et)
|
||||||
switch ed {
|
switch ed {
|
||||||
case "artifact":
|
case "artifact":
|
||||||
if et == "deployed" || et == "deleted" {
|
if et == "deployed" || et == "deleted" {
|
||||||
return generateEvent(data, &ArtifactDeploymentOrDeletedEvent{})
|
return generateEvent(data, &artifactDeploymentOrDeletedEvent{})
|
||||||
} else if et == "moved" || et == "copied" {
|
} else if et == "moved" || et == "copied" {
|
||||||
return generateEvent(data, &ArtifactMovedOrCopiedEvent{})
|
return generateEvent(data, &artifactMovedOrCopiedEvent{})
|
||||||
} else {
|
} else {
|
||||||
return nil, &newEventError{"Not a recognized event type"}
|
return nil, &newEventError{"Not a recognized event type"}
|
||||||
}
|
}
|
||||||
case "artifact_property":
|
case "artifact_property":
|
||||||
return generateEvent(data, &ArtifactPropertiesEvent{})
|
return generateEvent(data, &artifactPropertiesEvent{})
|
||||||
case "docker":
|
case "docker":
|
||||||
return generateEvent(data, &DockerEvent{})
|
return generateEvent(data, &dockerEvent{})
|
||||||
case "build":
|
case "build":
|
||||||
return generateEvent(data, &BuildEvent{})
|
return generateEvent(data, &buildEvent{})
|
||||||
case "release_bundle":
|
case "release_bundle":
|
||||||
return generateEvent(data, &ReleaseBundleEvent{})
|
return generateEvent(data, &releaseBundleEvent{})
|
||||||
case "distribution":
|
case "distribution":
|
||||||
return generateEvent(data, &DistributionEvent{})
|
return generateEvent(data, &distributionEvent{})
|
||||||
case "destination":
|
case "destination":
|
||||||
return generateEvent(data, &DestinationEvent{})
|
return generateEvent(data, &destinationEvent{})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, &newEventError{"Not a recognized event type"}
|
return nil, &newEventError{"Not a recognized event type"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateEvent(data []byte, event Event) (Event, error) {
|
func generateEvent(data []byte, event event) (event, error) {
|
||||||
err := json.Unmarshal(data, event)
|
err := json.Unmarshal(data, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -10,16 +10,11 @@ import (
|
||||||
|
|
||||||
const meas = "artifactory_webhooks"
|
const meas = "artifactory_webhooks"
|
||||||
|
|
||||||
type CommonFields struct {
|
type event interface {
|
||||||
Domain string `json:"domain"`
|
|
||||||
Event string `json:"event_type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Event interface {
|
|
||||||
NewMetric() telegraf.Metric
|
NewMetric() telegraf.Metric
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactDeploymentOrDeletedEvent struct {
|
type artifactDeploymentOrDeletedEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
@ -31,7 +26,7 @@ type ArtifactDeploymentOrDeletedEvent struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArtifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
|
func (e artifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -47,7 +42,7 @@ func (e ArtifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactMovedOrCopiedEvent struct {
|
type artifactMovedOrCopiedEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
@ -60,7 +55,7 @@ type ArtifactMovedOrCopiedEvent struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArtifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
|
func (e artifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -77,7 +72,7 @@ func (e ArtifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtifactPropertiesEvent struct {
|
type artifactPropertiesEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
@ -90,7 +85,7 @@ type ArtifactPropertiesEvent struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ArtifactPropertiesEvent) NewMetric() telegraf.Metric {
|
func (e artifactPropertiesEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -107,7 +102,7 @@ func (e ArtifactPropertiesEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type DockerEvent struct {
|
type dockerEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
@ -125,7 +120,7 @@ type DockerEvent struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e DockerEvent) NewMetric() telegraf.Metric {
|
func (e dockerEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -144,7 +139,7 @@ func (e DockerEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type BuildEvent struct {
|
type buildEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Data struct {
|
Data struct {
|
||||||
|
|
@ -154,7 +149,7 @@ type BuildEvent struct {
|
||||||
} `json:"data"`
|
} `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e BuildEvent) NewMetric() telegraf.Metric {
|
func (e buildEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -168,7 +163,7 @@ func (e BuildEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReleaseBundleEvent struct {
|
type releaseBundleEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination"`
|
||||||
|
|
@ -180,7 +175,7 @@ type ReleaseBundleEvent struct {
|
||||||
JpdOrigin string `json:"jpd_origin"`
|
JpdOrigin string `json:"jpd_origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ReleaseBundleEvent) NewMetric() telegraf.Metric {
|
func (e releaseBundleEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -196,7 +191,7 @@ func (e ReleaseBundleEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type DistributionEvent struct {
|
type distributionEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination"`
|
||||||
|
|
@ -214,7 +209,7 @@ type DistributionEvent struct {
|
||||||
OriginURL string `json:"jpd_origin"`
|
OriginURL string `json:"jpd_origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e DistributionEvent) NewMetric() telegraf.Metric {
|
func (e distributionEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
@ -232,7 +227,7 @@ func (e DistributionEvent) NewMetric() telegraf.Metric {
|
||||||
return metric.New(meas, t, f, time.Now())
|
return metric.New(meas, t, f, time.Now())
|
||||||
}
|
}
|
||||||
|
|
||||||
type DestinationEvent struct {
|
type destinationEvent struct {
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Event string `json:"event_type"`
|
Event string `json:"event_type"`
|
||||||
Destination string `json:"destination"`
|
Destination string `json:"destination"`
|
||||||
|
|
@ -244,7 +239,7 @@ type DestinationEvent struct {
|
||||||
OriginURL string `json:"jpd_origin"`
|
OriginURL string `json:"jpd_origin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e DestinationEvent) NewMetric() telegraf.Metric {
|
func (e destinationEvent) NewMetric() telegraf.Metric {
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"domain": e.Domain,
|
"domain": e.Domain,
|
||||||
"event_type": e.Event,
|
"event_type": e.Event,
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateEvent(data []byte, event Event) (Event, error) {
|
func generateEvent(data []byte, event event) (event, error) {
|
||||||
err := json.Unmarshal(data, event)
|
err := json.Unmarshal(data, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -80,53 +80,53 @@ func (e *newEventError) Error() string {
|
||||||
return e.s
|
return e.s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gh *GithubWebhook) NewEvent(data []byte, name string) (Event, error) {
|
func (gh *GithubWebhook) NewEvent(data []byte, name string) (event, error) {
|
||||||
gh.log.Debugf("New %v event received", name)
|
gh.log.Debugf("New %v event received", name)
|
||||||
switch name {
|
switch name {
|
||||||
case "commit_comment":
|
case "commit_comment":
|
||||||
return generateEvent(data, &CommitCommentEvent{})
|
return generateEvent(data, &commitCommentEvent{})
|
||||||
case "create":
|
case "create":
|
||||||
return generateEvent(data, &CreateEvent{})
|
return generateEvent(data, &createEvent{})
|
||||||
case "delete":
|
case "delete":
|
||||||
return generateEvent(data, &DeleteEvent{})
|
return generateEvent(data, &deleteEvent{})
|
||||||
case "deployment":
|
case "deployment":
|
||||||
return generateEvent(data, &DeploymentEvent{})
|
return generateEvent(data, &deploymentEvent{})
|
||||||
case "deployment_status":
|
case "deployment_status":
|
||||||
return generateEvent(data, &DeploymentStatusEvent{})
|
return generateEvent(data, &deploymentStatusEvent{})
|
||||||
case "fork":
|
case "fork":
|
||||||
return generateEvent(data, &ForkEvent{})
|
return generateEvent(data, &forkEvent{})
|
||||||
case "gollum":
|
case "gollum":
|
||||||
return generateEvent(data, &GollumEvent{})
|
return generateEvent(data, &gollumEvent{})
|
||||||
case "issue_comment":
|
case "issue_comment":
|
||||||
return generateEvent(data, &IssueCommentEvent{})
|
return generateEvent(data, &issueCommentEvent{})
|
||||||
case "issues":
|
case "issues":
|
||||||
return generateEvent(data, &IssuesEvent{})
|
return generateEvent(data, &issuesEvent{})
|
||||||
case "member":
|
case "member":
|
||||||
return generateEvent(data, &MemberEvent{})
|
return generateEvent(data, &memberEvent{})
|
||||||
case "membership":
|
case "membership":
|
||||||
return generateEvent(data, &MembershipEvent{})
|
return generateEvent(data, &membershipEvent{})
|
||||||
case "page_build":
|
case "page_build":
|
||||||
return generateEvent(data, &PageBuildEvent{})
|
return generateEvent(data, &pageBuildEvent{})
|
||||||
case "ping":
|
case "ping":
|
||||||
return nil, nil
|
return nil, nil
|
||||||
case "public":
|
case "public":
|
||||||
return generateEvent(data, &PublicEvent{})
|
return generateEvent(data, &publicEvent{})
|
||||||
case "pull_request":
|
case "pull_request":
|
||||||
return generateEvent(data, &PullRequestEvent{})
|
return generateEvent(data, &pullRequestEvent{})
|
||||||
case "pull_request_review_comment":
|
case "pull_request_review_comment":
|
||||||
return generateEvent(data, &PullRequestReviewCommentEvent{})
|
return generateEvent(data, &pullRequestReviewCommentEvent{})
|
||||||
case "push":
|
case "push":
|
||||||
return generateEvent(data, &PushEvent{})
|
return generateEvent(data, &pushEvent{})
|
||||||
case "release":
|
case "release":
|
||||||
return generateEvent(data, &ReleaseEvent{})
|
return generateEvent(data, &releaseEvent{})
|
||||||
case "repository":
|
case "repository":
|
||||||
return generateEvent(data, &RepositoryEvent{})
|
return generateEvent(data, &repositoryEvent{})
|
||||||
case "status":
|
case "status":
|
||||||
return generateEvent(data, &StatusEvent{})
|
return generateEvent(data, &statusEvent{})
|
||||||
case "team_add":
|
case "team_add":
|
||||||
return generateEvent(data, &TeamAddEvent{})
|
return generateEvent(data, &teamAddEvent{})
|
||||||
case "watch":
|
case "watch":
|
||||||
return generateEvent(data, &WatchEvent{})
|
return generateEvent(data, &watchEvent{})
|
||||||
}
|
}
|
||||||
return nil, &newEventError{"Not a recognized event type"}
|
return nil, &newEventError{"Not a recognized event type"}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ import (
|
||||||
|
|
||||||
const meas = "github_webhooks"
|
const meas = "github_webhooks"
|
||||||
|
|
||||||
type Event interface {
|
type event interface {
|
||||||
NewMetric() telegraf.Metric
|
NewMetric() telegraf.Metric
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type repository struct {
|
||||||
Repository string `json:"full_name"`
|
Repository string `json:"full_name"`
|
||||||
Private bool `json:"private"`
|
Private bool `json:"private"`
|
||||||
Stars int `json:"stargazers_count"`
|
Stars int `json:"stargazers_count"`
|
||||||
|
|
@ -22,44 +22,44 @@ type Repository struct {
|
||||||
Issues int `json:"open_issues_count"`
|
Issues int `json:"open_issues_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Sender struct {
|
type sender struct {
|
||||||
User string `json:"login"`
|
User string `json:"login"`
|
||||||
Admin bool `json:"site_admin"`
|
Admin bool `json:"site_admin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitComment struct {
|
type commitComment struct {
|
||||||
Commit string `json:"commit_id"`
|
Commit string `json:"commit_id"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deployment struct {
|
type deployment struct {
|
||||||
Commit string `json:"sha"`
|
Commit string `json:"sha"`
|
||||||
Task string `json:"task"`
|
Task string `json:"task"`
|
||||||
Environment string `json:"environment"`
|
Environment string `json:"environment"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Page struct {
|
type page struct {
|
||||||
Name string `json:"page_name"`
|
Name string `json:"page_name"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Issue struct {
|
type issue struct {
|
||||||
Number int `json:"number"`
|
Number int `json:"number"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Comments int `json:"comments"`
|
Comments int `json:"comments"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IssueComment struct {
|
type issueComment struct {
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Team struct {
|
type team struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullRequest struct {
|
type pullRequest struct {
|
||||||
Number int `json:"number"`
|
Number int `json:"number"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
|
@ -70,27 +70,27 @@ type PullRequest struct {
|
||||||
ChangedFiles int `json:"changed_files"`
|
ChangedFiles int `json:"changed_files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullRequestReviewComment struct {
|
type pullRequestReviewComment struct {
|
||||||
File string `json:"path"`
|
File string `json:"path"`
|
||||||
Comment string `json:"body"`
|
Comment string `json:"body"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Release struct {
|
type release struct {
|
||||||
TagName string `json:"tag_name"`
|
TagName string `json:"tag_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeploymentStatus struct {
|
type deploymentStatus struct {
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommitCommentEvent struct {
|
type commitCommentEvent struct {
|
||||||
Comment CommitComment `json:"comment"`
|
Comment commitComment `json:"comment"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s CommitCommentEvent) NewMetric() telegraf.Metric {
|
func (s commitCommentEvent) NewMetric() telegraf.Metric {
|
||||||
event := "commit_comment"
|
event := "commit_comment"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -110,14 +110,14 @@ func (s CommitCommentEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateEvent struct {
|
type createEvent struct {
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
RefType string `json:"ref_type"`
|
RefType string `json:"ref_type"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s CreateEvent) NewMetric() telegraf.Metric {
|
func (s createEvent) NewMetric() telegraf.Metric {
|
||||||
event := "create"
|
event := "create"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -137,14 +137,14 @@ func (s CreateEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeleteEvent struct {
|
type deleteEvent struct {
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
RefType string `json:"ref_type"`
|
RefType string `json:"ref_type"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s DeleteEvent) NewMetric() telegraf.Metric {
|
func (s deleteEvent) NewMetric() telegraf.Metric {
|
||||||
event := "delete"
|
event := "delete"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -164,13 +164,13 @@ func (s DeleteEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeploymentEvent struct {
|
type deploymentEvent struct {
|
||||||
Deployment Deployment `json:"deployment"`
|
Deployment deployment `json:"deployment"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s DeploymentEvent) NewMetric() telegraf.Metric {
|
func (s deploymentEvent) NewMetric() telegraf.Metric {
|
||||||
event := "deployment"
|
event := "deployment"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -192,14 +192,14 @@ func (s DeploymentEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeploymentStatusEvent struct {
|
type deploymentStatusEvent struct {
|
||||||
Deployment Deployment `json:"deployment"`
|
Deployment deployment `json:"deployment"`
|
||||||
DeploymentStatus DeploymentStatus `json:"deployment_status"`
|
DeploymentStatus deploymentStatus `json:"deployment_status"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s DeploymentStatusEvent) NewMetric() telegraf.Metric {
|
func (s deploymentStatusEvent) NewMetric() telegraf.Metric {
|
||||||
event := "delete"
|
event := "delete"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -223,13 +223,13 @@ func (s DeploymentStatusEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type ForkEvent struct {
|
type forkEvent struct {
|
||||||
Forkee Repository `json:"forkee"`
|
Forkee repository `json:"forkee"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ForkEvent) NewMetric() telegraf.Metric {
|
func (s forkEvent) NewMetric() telegraf.Metric {
|
||||||
event := "fork"
|
event := "fork"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -248,14 +248,14 @@ func (s ForkEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type GollumEvent struct {
|
type gollumEvent struct {
|
||||||
Pages []Page `json:"pages"`
|
Pages []page `json:"pages"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// REVIEW: Going to be lazy and not deal with the pages.
|
// REVIEW: Going to be lazy and not deal with the pages.
|
||||||
func (s GollumEvent) NewMetric() telegraf.Metric {
|
func (s gollumEvent) NewMetric() telegraf.Metric {
|
||||||
event := "gollum"
|
event := "gollum"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -273,14 +273,14 @@ func (s GollumEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type IssueCommentEvent struct {
|
type issueCommentEvent struct {
|
||||||
Issue Issue `json:"issue"`
|
Issue issue `json:"issue"`
|
||||||
Comment IssueComment `json:"comment"`
|
Comment issueComment `json:"comment"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s IssueCommentEvent) NewMetric() telegraf.Metric {
|
func (s issueCommentEvent) NewMetric() telegraf.Metric {
|
||||||
event := "issue_comment"
|
event := "issue_comment"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -302,14 +302,14 @@ func (s IssueCommentEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type IssuesEvent struct {
|
type issuesEvent struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Issue Issue `json:"issue"`
|
Issue issue `json:"issue"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s IssuesEvent) NewMetric() telegraf.Metric {
|
func (s issuesEvent) NewMetric() telegraf.Metric {
|
||||||
event := "issue"
|
event := "issue"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -331,13 +331,13 @@ func (s IssuesEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberEvent struct {
|
type memberEvent struct {
|
||||||
Member Sender `json:"member"`
|
Member sender `json:"member"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s MemberEvent) NewMetric() telegraf.Metric {
|
func (s memberEvent) NewMetric() telegraf.Metric {
|
||||||
event := "member"
|
event := "member"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -357,14 +357,14 @@ func (s MemberEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type MembershipEvent struct {
|
type membershipEvent struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
Member Sender `json:"member"`
|
Member sender `json:"member"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
Team Team `json:"team"`
|
Team team `json:"team"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s MembershipEvent) NewMetric() telegraf.Metric {
|
func (s membershipEvent) NewMetric() telegraf.Metric {
|
||||||
event := "membership"
|
event := "membership"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -380,12 +380,12 @@ func (s MembershipEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageBuildEvent struct {
|
type pageBuildEvent struct {
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PageBuildEvent) NewMetric() telegraf.Metric {
|
func (s pageBuildEvent) NewMetric() telegraf.Metric {
|
||||||
event := "page_build"
|
event := "page_build"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -403,12 +403,12 @@ func (s PageBuildEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublicEvent struct {
|
type publicEvent struct {
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PublicEvent) NewMetric() telegraf.Metric {
|
func (s publicEvent) NewMetric() telegraf.Metric {
|
||||||
event := "public"
|
event := "public"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -426,14 +426,14 @@ func (s PublicEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullRequestEvent struct {
|
type pullRequestEvent struct {
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
PullRequest PullRequest `json:"pull_request"`
|
PullRequest pullRequest `json:"pull_request"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PullRequestEvent) NewMetric() telegraf.Metric {
|
func (s pullRequestEvent) NewMetric() telegraf.Metric {
|
||||||
event := "pull_request"
|
event := "pull_request"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -460,14 +460,14 @@ func (s PullRequestEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullRequestReviewCommentEvent struct {
|
type pullRequestReviewCommentEvent struct {
|
||||||
Comment PullRequestReviewComment `json:"comment"`
|
Comment pullRequestReviewComment `json:"comment"`
|
||||||
PullRequest PullRequest `json:"pull_request"`
|
PullRequest pullRequest `json:"pull_request"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PullRequestReviewCommentEvent) NewMetric() telegraf.Metric {
|
func (s pullRequestReviewCommentEvent) NewMetric() telegraf.Metric {
|
||||||
event := "pull_request_review_comment"
|
event := "pull_request_review_comment"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -495,15 +495,15 @@ func (s PullRequestReviewCommentEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type PushEvent struct {
|
type pushEvent struct {
|
||||||
Ref string `json:"ref"`
|
Ref string `json:"ref"`
|
||||||
Before string `json:"before"`
|
Before string `json:"before"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PushEvent) NewMetric() telegraf.Metric {
|
func (s pushEvent) NewMetric() telegraf.Metric {
|
||||||
event := "push"
|
event := "push"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -524,13 +524,13 @@ func (s PushEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type ReleaseEvent struct {
|
type releaseEvent struct {
|
||||||
Release Release `json:"release"`
|
Release release `json:"release"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s ReleaseEvent) NewMetric() telegraf.Metric {
|
func (s releaseEvent) NewMetric() telegraf.Metric {
|
||||||
event := "release"
|
event := "release"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -549,12 +549,12 @@ func (s ReleaseEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type RepositoryEvent struct {
|
type repositoryEvent struct {
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s RepositoryEvent) NewMetric() telegraf.Metric {
|
func (s repositoryEvent) NewMetric() telegraf.Metric {
|
||||||
event := "repository"
|
event := "repository"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -572,14 +572,14 @@ func (s RepositoryEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusEvent struct {
|
type statusEvent struct {
|
||||||
Commit string `json:"sha"`
|
Commit string `json:"sha"`
|
||||||
State string `json:"state"`
|
State string `json:"state"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StatusEvent) NewMetric() telegraf.Metric {
|
func (s statusEvent) NewMetric() telegraf.Metric {
|
||||||
event := "status"
|
event := "status"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -599,13 +599,13 @@ func (s StatusEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type TeamAddEvent struct {
|
type teamAddEvent struct {
|
||||||
Team Team `json:"team"`
|
Team team `json:"team"`
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s TeamAddEvent) NewMetric() telegraf.Metric {
|
func (s teamAddEvent) NewMetric() telegraf.Metric {
|
||||||
event := "team_add"
|
event := "team_add"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
@ -624,12 +624,12 @@ func (s TeamAddEvent) NewMetric() telegraf.Metric {
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type WatchEvent struct {
|
type watchEvent struct {
|
||||||
Repository Repository `json:"repository"`
|
Repository repository `json:"repository"`
|
||||||
Sender Sender `json:"sender"`
|
Sender sender `json:"sender"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s WatchEvent) NewMetric() telegraf.Metric {
|
func (s watchEvent) NewMetric() telegraf.Metric {
|
||||||
event := "delete"
|
event := "delete"
|
||||||
t := map[string]string{
|
t := map[string]string{
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ func (rb *RollbarWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dummyEvent := &DummyEvent{}
|
dummyEvent := &dummyEvent{}
|
||||||
err = json.Unmarshal(data, dummyEvent)
|
err = json.Unmarshal(data, dummyEvent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
@ -59,7 +59,7 @@ func (rb *RollbarWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateEvent(event Event, data []byte) (Event, error) {
|
func generateEvent(event event, data []byte) (event, error) {
|
||||||
err := json.Unmarshal(data, event)
|
err := json.Unmarshal(data, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -67,14 +67,14 @@ func generateEvent(event Event, data []byte) (Event, error) {
|
||||||
return event, nil
|
return event, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEvent(dummyEvent *DummyEvent, data []byte) (Event, error) {
|
func NewEvent(dummyEvent *dummyEvent, data []byte) (event, error) {
|
||||||
switch dummyEvent.EventName {
|
switch dummyEvent.EventName {
|
||||||
case "new_item":
|
case "new_item":
|
||||||
return generateEvent(&NewItem{}, data)
|
return generateEvent(&newItem{}, data)
|
||||||
case "occurrence":
|
case "occurrence":
|
||||||
return generateEvent(&Occurrence{}, data)
|
return generateEvent(&occurrence{}, data)
|
||||||
case "deploy":
|
case "deploy":
|
||||||
return generateEvent(&Deploy{}, data)
|
return generateEvent(&deploy{}, data)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("Not implemented type: " + dummyEvent.EventName)
|
return nil, errors.New("Not implemented type: " + dummyEvent.EventName)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,37 +2,37 @@ package rollbar
|
||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type Event interface {
|
type event interface {
|
||||||
Tags() map[string]string
|
Tags() map[string]string
|
||||||
Fields() map[string]interface{}
|
Fields() map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DummyEvent struct {
|
type dummyEvent struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewItemDataItemLastOccurrence struct {
|
type newItemDataItemLastOccurrence struct {
|
||||||
Language string `json:"language"`
|
Language string `json:"language"`
|
||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewItemDataItem struct {
|
type newItemDataItem struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Environment string `json:"environment"`
|
Environment string `json:"environment"`
|
||||||
ProjectID int `json:"project_id"`
|
ProjectID int `json:"project_id"`
|
||||||
LastOccurrence NewItemDataItemLastOccurrence `json:"last_occurrence"`
|
LastOccurrence newItemDataItemLastOccurrence `json:"last_occurrence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewItemData struct {
|
type newItemData struct {
|
||||||
Item NewItemDataItem `json:"item"`
|
Item newItemDataItem `json:"item"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NewItem struct {
|
type newItem struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Data NewItemData `json:"data"`
|
Data newItemData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ni *NewItem) Tags() map[string]string {
|
func (ni *newItem) Tags() map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"event": ni.EventName,
|
"event": ni.EventName,
|
||||||
"environment": ni.Data.Item.Environment,
|
"environment": ni.Data.Item.Environment,
|
||||||
|
|
@ -42,34 +42,34 @@ func (ni *NewItem) Tags() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ni *NewItem) Fields() map[string]interface{} {
|
func (ni *newItem) Fields() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"id": ni.Data.Item.ID,
|
"id": ni.Data.Item.ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type OccurrenceDataOccurrence struct {
|
type occurrenceDataOccurrence struct {
|
||||||
Language string `json:"language"`
|
Language string `json:"language"`
|
||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OccurrenceDataItem struct {
|
type occurrenceDataItem struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Environment string `json:"environment"`
|
Environment string `json:"environment"`
|
||||||
ProjectID int `json:"project_id"`
|
ProjectID int `json:"project_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OccurrenceData struct {
|
type occurrenceData struct {
|
||||||
Item OccurrenceDataItem `json:"item"`
|
Item occurrenceDataItem `json:"item"`
|
||||||
Occurrence OccurrenceDataOccurrence `json:"occurrence"`
|
Occurrence occurrenceDataOccurrence `json:"occurrence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Occurrence struct {
|
type occurrence struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Data OccurrenceData `json:"data"`
|
Data occurrenceData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Occurrence) Tags() map[string]string {
|
func (o *occurrence) Tags() map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"event": o.EventName,
|
"event": o.EventName,
|
||||||
"environment": o.Data.Item.Environment,
|
"environment": o.Data.Item.Environment,
|
||||||
|
|
@ -79,28 +79,28 @@ func (o *Occurrence) Tags() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Occurrence) Fields() map[string]interface{} {
|
func (o *occurrence) Fields() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"id": o.Data.Item.ID,
|
"id": o.Data.Item.ID,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeployDataDeploy struct {
|
type deployDataDeploy struct {
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Environment string `json:"environment"`
|
Environment string `json:"environment"`
|
||||||
ProjectID int `json:"project_id"`
|
ProjectID int `json:"project_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DeployData struct {
|
type deployData struct {
|
||||||
Deploy DeployDataDeploy `json:"deploy"`
|
Deploy deployDataDeploy `json:"deploy"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Deploy struct {
|
type deploy struct {
|
||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Data DeployData `json:"data"`
|
Data deployData `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ni *Deploy) Tags() map[string]string {
|
func (ni *deploy) Tags() map[string]string {
|
||||||
return map[string]string{
|
return map[string]string{
|
||||||
"event": ni.EventName,
|
"event": ni.EventName,
|
||||||
"environment": ni.Data.Deploy.Environment,
|
"environment": ni.Data.Deploy.Environment,
|
||||||
|
|
@ -108,7 +108,7 @@ func (ni *Deploy) Tags() map[string]string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ni *Deploy) Fields() map[string]interface{} {
|
func (ni *deploy) Fields() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"id": ni.Data.Deploy.ID,
|
"id": ni.Data.Deploy.ID,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,23 +10,23 @@ package win_eventlog
|
||||||
// More info on schema, if there will be need to add more:
|
// More info on schema, if there will be need to add more:
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/wes/eventschema-elements
|
// https://docs.microsoft.com/en-us/windows/win32/wes/eventschema-elements
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Source Provider `xml:"System>Provider"`
|
Source provider `xml:"System>Provider"`
|
||||||
EventID int `xml:"System>EventID"`
|
EventID int `xml:"System>EventID"`
|
||||||
Version int `xml:"System>Version"`
|
Version int `xml:"System>Version"`
|
||||||
Level int `xml:"System>Level"`
|
Level int `xml:"System>Level"`
|
||||||
Task int `xml:"System>Task"`
|
Task int `xml:"System>Task"`
|
||||||
Opcode int `xml:"System>Opcode"`
|
Opcode int `xml:"System>Opcode"`
|
||||||
Keywords string `xml:"System>Keywords"`
|
Keywords string `xml:"System>Keywords"`
|
||||||
TimeCreated TimeCreated `xml:"System>TimeCreated"`
|
TimeCreated timeCreated `xml:"System>TimeCreated"`
|
||||||
EventRecordID int `xml:"System>EventRecordID"`
|
EventRecordID int `xml:"System>EventRecordID"`
|
||||||
Correlation Correlation `xml:"System>Correlation"`
|
Correlation correlation `xml:"System>Correlation"`
|
||||||
Execution Execution `xml:"System>Execution"`
|
Execution execution `xml:"System>Execution"`
|
||||||
Channel string `xml:"System>Channel"`
|
Channel string `xml:"System>Channel"`
|
||||||
Computer string `xml:"System>Computer"`
|
Computer string `xml:"System>Computer"`
|
||||||
Security Security `xml:"System>Security"`
|
Security security `xml:"System>Security"`
|
||||||
UserData UserData `xml:"UserData"`
|
UserData userData `xml:"UserData"`
|
||||||
EventData EventData `xml:"EventData"`
|
EventData eventData `xml:"EventData"`
|
||||||
RenderingInfo *RenderingInfo `xml:"RenderingInfo"`
|
RenderingInfo *renderingInfo `xml:"RenderingInfo"`
|
||||||
|
|
||||||
Message string
|
Message string
|
||||||
LevelText string
|
LevelText string
|
||||||
|
|
@ -34,47 +34,47 @@ type Event struct {
|
||||||
OpcodeText string
|
OpcodeText string
|
||||||
}
|
}
|
||||||
|
|
||||||
// UserData Application-provided XML data
|
// userData Application-provided XML data
|
||||||
type UserData struct {
|
type userData struct {
|
||||||
InnerXML []byte `xml:",innerxml"`
|
InnerXML []byte `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EventData Application-provided XML data
|
// eventData Application-provided XML data
|
||||||
type EventData struct {
|
type eventData struct {
|
||||||
InnerXML []byte `xml:",innerxml"`
|
InnerXML []byte `xml:",innerxml"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provider is the Event provider information
|
// provider is the Event provider information
|
||||||
type Provider struct {
|
type provider struct {
|
||||||
Name string `xml:"Name,attr"`
|
Name string `xml:"Name,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Correlation is used for the event grouping
|
// correlation is used for the event grouping
|
||||||
type Correlation struct {
|
type correlation struct {
|
||||||
ActivityID string `xml:"ActivityID,attr"`
|
ActivityID string `xml:"ActivityID,attr"`
|
||||||
RelatedActivityID string `xml:"RelatedActivityID,attr"`
|
RelatedActivityID string `xml:"RelatedActivityID,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execution Info for Event
|
// execution Info for Event
|
||||||
type Execution struct {
|
type execution struct {
|
||||||
ProcessID uint32 `xml:"ProcessID,attr"`
|
ProcessID uint32 `xml:"ProcessID,attr"`
|
||||||
ThreadID uint32 `xml:"ThreadID,attr"`
|
ThreadID uint32 `xml:"ThreadID,attr"`
|
||||||
ProcessName string
|
ProcessName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Security Data for Event
|
// security Data for Event
|
||||||
type Security struct {
|
type security struct {
|
||||||
UserID string `xml:"UserID,attr"`
|
UserID string `xml:"UserID,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeCreated field for Event
|
// timeCreated field for Event
|
||||||
type TimeCreated struct {
|
type timeCreated struct {
|
||||||
SystemTime string `xml:"SystemTime,attr"`
|
SystemTime string `xml:"SystemTime,attr"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderingInfo is provided for events forwarded by Windows Event Collector
|
// renderingInfo is provided for events forwarded by Windows Event Collector
|
||||||
// see https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtformatmessage#parameters
|
// see https://learn.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtformatmessage#parameters
|
||||||
type RenderingInfo struct {
|
type renderingInfo struct {
|
||||||
Message string `xml:"Message"`
|
Message string `xml:"Message"`
|
||||||
Level string `xml:"Level"`
|
Level string `xml:"Level"`
|
||||||
Task string `xml:"Task"`
|
Task string `xml:"Task"`
|
||||||
|
|
|
||||||
|
|
@ -299,7 +299,7 @@ func init() {
|
||||||
// function PdhAddEnglishCounter instead. hQuery is the query handle, which has been fetched by PdhOpenQuery.
|
// function PdhAddEnglishCounter instead. hQuery is the query handle, which has been fetched by PdhOpenQuery.
|
||||||
// szFullCounterPath is a full, internationalized counter path (this will differ per Windows language version).
|
// szFullCounterPath is a full, internationalized counter path (this will differ per Windows language version).
|
||||||
// dwUserData is a 'user-defined value', which becomes part of the counter information. To retrieve this value
|
// dwUserData is a 'user-defined value', which becomes part of the counter information. To retrieve this value
|
||||||
// later, call PdhGetCounterInfo() and access dwQueryUserData of the PdhCounterInfo structure.
|
// later, call PdhGetCounterInfo() and access dwQueryUserData of the pdhCounterInfo structure.
|
||||||
//
|
//
|
||||||
// Examples of szFullCounterPath (in an English version of Windows):
|
// Examples of szFullCounterPath (in an English version of Windows):
|
||||||
//
|
//
|
||||||
|
|
@ -435,7 +435,7 @@ func PdhCollectQueryDataWithTime(hQuery pdhQueryHandle) (uint32, time.Time) {
|
||||||
|
|
||||||
// PdhGetFormattedCounterValueDouble formats the given hCounter using a 'double'. The result is set into the specialized union struct pValue.
|
// PdhGetFormattedCounterValueDouble formats the given hCounter using a 'double'. The result is set into the specialized union struct pValue.
|
||||||
// This function does not directly translate to a Windows counterpart due to union specialization tricks.
|
// This function does not directly translate to a Windows counterpart due to union specialization tricks.
|
||||||
func PdhGetFormattedCounterValueDouble(hCounter pdhCounterHandle, lpdwType *uint32, pValue *PdhFmtCountervalueDouble) uint32 {
|
func PdhGetFormattedCounterValueDouble(hCounter pdhCounterHandle, lpdwType *uint32, pValue *pdhFmtCountervalueDouble) uint32 {
|
||||||
ret, _, _ := pdhGetFormattedCounterValue.Call(
|
ret, _, _ := pdhGetFormattedCounterValue.Call(
|
||||||
uintptr(hCounter),
|
uintptr(hCounter),
|
||||||
uintptr(PdhFmtDouble|PdhFmtNocap100),
|
uintptr(PdhFmtDouble|PdhFmtNocap100),
|
||||||
|
|
@ -446,7 +446,7 @@ func PdhGetFormattedCounterValueDouble(hCounter pdhCounterHandle, lpdwType *uint
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhGetFormattedCounterArrayDouble returns an array of formatted counter values. Use this function when you want to format the counter values of a
|
// PdhGetFormattedCounterArrayDouble returns an array of formatted counter values. Use this function when you want to format the counter values of a
|
||||||
// counter that contains a wildcard character for the instance name. The itemBuffer must a slice of type PdhFmtCountervalueItemDouble.
|
// counter that contains a wildcard character for the instance name. The itemBuffer must a slice of type pdhFmtCountervalueItemDouble.
|
||||||
// An example of how this function can be used:
|
// An example of how this function can be used:
|
||||||
//
|
//
|
||||||
// okPath := "\\Process(*)\\% Processor Time" // notice the wildcard * character
|
// okPath := "\\Process(*)\\% Processor Time" // notice the wildcard * character
|
||||||
|
|
@ -497,7 +497,7 @@ func PdhGetFormattedCounterArrayDouble(hCounter pdhCounterHandle, lpdwBufferSize
|
||||||
// szDataSource is a null terminated string that specifies the name of the log file from which to
|
// szDataSource is a null terminated string that specifies the name of the log file from which to
|
||||||
// retrieve the performance data. If 0, performance data is collected from a real-time data source.
|
// retrieve the performance data. If 0, performance data is collected from a real-time data source.
|
||||||
// dwUserData is a user-defined value to associate with this query. To retrieve the user data later,
|
// dwUserData is a user-defined value to associate with this query. To retrieve the user data later,
|
||||||
// call PdhGetCounterInfo and access dwQueryUserData of the PdhCounterInfo structure. phQuery is
|
// call PdhGetCounterInfo and access dwQueryUserData of the pdhCounterInfo structure. phQuery is
|
||||||
// the handle to the query, and must be used in subsequent calls. This function returns a PDH_
|
// the handle to the query, and must be used in subsequent calls. This function returns a PDH_
|
||||||
// constant error code, or ErrorSuccess if the call succeeded.
|
// constant error code, or ErrorSuccess if the call succeeded.
|
||||||
func PdhOpenQuery(szDataSource uintptr, dwUserData uintptr, phQuery *pdhQueryHandle) uint32 {
|
func PdhOpenQuery(szDataSource uintptr, dwUserData uintptr, phQuery *pdhQueryHandle) uint32 {
|
||||||
|
|
@ -587,7 +587,7 @@ func PdhFormatError(msgID uint32) string {
|
||||||
// If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.
|
// If the specified size on input is greater than zero but less than the required size, you should not rely on the returned size to reallocate the buffer.
|
||||||
//
|
//
|
||||||
// lpBuffer [out]
|
// lpBuffer [out]
|
||||||
// Caller-allocated buffer that receives a PdhCounterInfo structure.
|
// Caller-allocated buffer that receives a pdhCounterInfo structure.
|
||||||
// The structure is variable-length, because the string data is appended to the end of the fixed-format portion of the structure.
|
// The structure is variable-length, because the string data is appended to the end of the fixed-format portion of the structure.
|
||||||
// This is done so that all data is returned in a single buffer allocated by the caller. Set to NULL if pdwBufferSize is zero.
|
// This is done so that all data is returned in a single buffer allocated by the caller. Set to NULL if pdwBufferSize is zero.
|
||||||
func PdhGetCounterInfo(hCounter pdhCounterHandle, bRetrieveExplainText int, pdwBufferSize *uint32, lpBuffer *byte) uint32 {
|
func PdhGetCounterInfo(hCounter pdhCounterHandle, bRetrieveExplainText int, pdwBufferSize *uint32, lpBuffer *byte) uint32 {
|
||||||
|
|
@ -602,7 +602,7 @@ func PdhGetCounterInfo(hCounter pdhCounterHandle, bRetrieveExplainText int, pdwB
|
||||||
|
|
||||||
// PdhGetRawCounterValue returns the current raw value of the counter.
|
// PdhGetRawCounterValue returns the current raw value of the counter.
|
||||||
// If the specified counter instance does not exist, this function will return ErrorSuccess
|
// If the specified counter instance does not exist, this function will return ErrorSuccess
|
||||||
// and the CStatus member of the PdhRawCounter structure will contain PdhCstatusNoInstance.
|
// and the CStatus member of the pdhRawCounter structure will contain PdhCstatusNoInstance.
|
||||||
//
|
//
|
||||||
// hCounter [in]
|
// hCounter [in]
|
||||||
// Handle of the counter from which to retrieve the current raw value. The PdhAddCounter function returns this handle.
|
// Handle of the counter from which to retrieve the current raw value. The PdhAddCounter function returns this handle.
|
||||||
|
|
@ -612,8 +612,8 @@ func PdhGetCounterInfo(hCounter pdhCounterHandle, bRetrieveExplainText int, pdwB
|
||||||
// This parameter is optional.
|
// This parameter is optional.
|
||||||
//
|
//
|
||||||
// pValue [out]
|
// pValue [out]
|
||||||
// A PdhRawCounter structure that receives the counter value.
|
// A pdhRawCounter structure that receives the counter value.
|
||||||
func PdhGetRawCounterValue(hCounter pdhCounterHandle, lpdwType *uint32, pValue *PdhRawCounter) uint32 {
|
func PdhGetRawCounterValue(hCounter pdhCounterHandle, lpdwType *uint32, pValue *pdhRawCounter) uint32 {
|
||||||
ret, _, _ := pdhGetRawCounterValue.Call(
|
ret, _, _ := pdhGetRawCounterValue.Call(
|
||||||
uintptr(hCounter),
|
uintptr(hCounter),
|
||||||
uintptr(unsafe.Pointer(lpdwType)), //nolint:gosec // G103: Valid use of unsafe call to pass lpdwType
|
uintptr(unsafe.Pointer(lpdwType)), //nolint:gosec // G103: Valid use of unsafe call to pass lpdwType
|
||||||
|
|
@ -636,7 +636,7 @@ func PdhGetRawCounterValue(hCounter pdhCounterHandle, lpdwType *uint32, pValue *
|
||||||
// Number of raw counter values in the ItemBuffer buffer.
|
// Number of raw counter values in the ItemBuffer buffer.
|
||||||
//
|
//
|
||||||
// ItemBuffer
|
// ItemBuffer
|
||||||
// Caller-allocated buffer that receives the array of PdhRawCounterItem structures; the structures contain the raw instance counter values.
|
// Caller-allocated buffer that receives the array of pdhRawCounterItem structures; the structures contain the raw instance counter values.
|
||||||
// Set to NULL if lpdwBufferSize is zero.
|
// Set to NULL if lpdwBufferSize is zero.
|
||||||
func PdhGetRawCounterArray(hCounter pdhCounterHandle, lpdwBufferSize *uint32, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
|
func PdhGetRawCounterArray(hCounter pdhCounterHandle, lpdwBufferSize *uint32, lpdwBufferCount *uint32, itemBuffer *byte) uint32 {
|
||||||
ret, _, _ := pdhGetRawCounterArrayW.Call(
|
ret, _, _ := pdhGetRawCounterArrayW.Call(
|
||||||
|
|
|
||||||
|
|
@ -32,49 +32,35 @@
|
||||||
|
|
||||||
package win_perf_counters
|
package win_perf_counters
|
||||||
|
|
||||||
// PdhFmtCountervalueDouble is a union specialization for double values
|
// pdhFmtCountervalueDouble is a union specialization for double values
|
||||||
type PdhFmtCountervalueDouble struct {
|
type pdhFmtCountervalueDouble struct {
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
padding [4]byte
|
padding [4]byte
|
||||||
DoubleValue float64
|
DoubleValue float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
|
// pdhFmtCountervalueLong is a union specialization for long values
|
||||||
type PdhFmtCountervalueLarge struct {
|
type pdhFmtCountervalueLong struct {
|
||||||
CStatus uint32
|
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
|
||||||
LargeValue int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueLong is a union specialization for long values
|
|
||||||
type PdhFmtCountervalueLong struct {
|
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
LongValue int32
|
LongValue int32
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
padding [4]byte //nolint:unused // Memory reservation
|
||||||
}
|
}
|
||||||
|
|
||||||
type PdhFmtCountervalueItemDouble struct {
|
type pdhFmtCountervalueItemDouble struct {
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
padding [4]byte //nolint:unused // Memory reservation
|
||||||
FmtValue PdhFmtCountervalueDouble
|
FmtValue pdhFmtCountervalueDouble
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
|
// pdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
|
||||||
type PdhFmtCountervalueItemLarge struct {
|
|
||||||
SzName *uint16 // pointer to a string
|
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
|
||||||
FmtValue PdhFmtCountervalueLarge
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
|
|
||||||
type PdhFmtCountervalueItemLong struct {
|
type PdhFmtCountervalueItemLong struct {
|
||||||
SzName *uint16 // pointer to a string
|
SzName *uint16 // pointer to a string
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
padding [4]byte //nolint:unused // Memory reservation
|
||||||
FmtValue PdhFmtCountervalueLong
|
FmtValue pdhFmtCountervalueLong
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
// pdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
||||||
type PdhCounterInfo struct {
|
type pdhCounterInfo struct {
|
||||||
//Size of the structure, including the appended strings, in bytes.
|
//Size of the structure, including the appended strings, in bytes.
|
||||||
DwLength uint32
|
DwLength uint32
|
||||||
//Counter type. For a list of counter types, see the Counter Types section of the
|
//Counter type. For a list of counter types, see the Counter Types section of the
|
||||||
|
|
@ -122,9 +108,9 @@ type PdhCounterInfo struct {
|
||||||
DataBuffer [1]uint32 // pointer to an extra space
|
DataBuffer [1]uint32 // pointer to an extra space
|
||||||
}
|
}
|
||||||
|
|
||||||
// The PdhRawCounter structure returns the data as it was collected from the counter provider. No translation, formatting,
|
// The pdhRawCounter structure returns the data as it was collected from the counter provider. No translation, formatting,
|
||||||
// or other interpretation is performed on the data
|
// or other interpretation is performed on the data
|
||||||
type PdhRawCounter struct {
|
type pdhRawCounter struct {
|
||||||
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
||||||
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
|
|
@ -139,9 +125,9 @@ type PdhRawCounter struct {
|
||||||
MultiCount uint32
|
MultiCount uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type PdhRawCounterItem struct {
|
type pdhRawCounterItem struct {
|
||||||
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
//A PdhRawCounter structure that contains the raw counter value of the instance
|
//A pdhRawCounter structure that contains the raw counter value of the instance
|
||||||
RawValue PdhRawCounter
|
RawValue pdhRawCounter
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,45 +32,20 @@
|
||||||
|
|
||||||
package win_perf_counters
|
package win_perf_counters
|
||||||
|
|
||||||
// PdhFmtCountervalueDouble is a union specialization for double values
|
// pdhFmtCountervalueDouble is a union specialization for double values
|
||||||
type PdhFmtCountervalueDouble struct {
|
type pdhFmtCountervalueDouble struct {
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
DoubleValue float64
|
DoubleValue float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
|
// pdhFmtCountervalueItemDouble is a union specialization for double values, used by PdhGetFormattedCounterArrayDouble
|
||||||
type PdhFmtCountervalueLarge struct {
|
type pdhFmtCountervalueItemDouble struct {
|
||||||
CStatus uint32
|
|
||||||
LargeValue int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueLong is a union specialization for long values
|
|
||||||
type PdhFmtCountervalueLong struct {
|
|
||||||
CStatus uint32
|
|
||||||
LongValue int32
|
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueItemDouble is a union specialization for double values, used by PdhGetFormattedCounterArrayDouble
|
|
||||||
type PdhFmtCountervalueItemDouble struct {
|
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
FmtValue PdhFmtCountervalueDouble
|
FmtValue pdhFmtCountervalueDouble
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
|
// pdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
||||||
type PdhFmtCountervalueItemLarge struct {
|
type pdhCounterInfo struct {
|
||||||
SzName *uint16 // pointer to a string
|
|
||||||
FmtValue PdhFmtCountervalueLarge
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
|
|
||||||
type PdhFmtCountervalueItemLong struct {
|
|
||||||
SzName *uint16 // pointer to a string
|
|
||||||
FmtValue PdhFmtCountervalueLong
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
|
||||||
type PdhCounterInfo struct {
|
|
||||||
//Size of the structure, including the appended strings, in bytes.
|
//Size of the structure, including the appended strings, in bytes.
|
||||||
DwLength uint32
|
DwLength uint32
|
||||||
//Counter type. For a list of counter types,
|
//Counter type. For a list of counter types,
|
||||||
|
|
@ -115,9 +90,9 @@ type PdhCounterInfo struct {
|
||||||
DataBuffer [1]uint32 // pointer to an extra space
|
DataBuffer [1]uint32 // pointer to an extra space
|
||||||
}
|
}
|
||||||
|
|
||||||
// The PdhRawCounter structure returns the data as it was collected from the counter provider.
|
// The pdhRawCounter structure returns the data as it was collected from the counter provider.
|
||||||
// No translation, formatting, or other interpretation is performed on the data
|
// No translation, formatting, or other interpretation is performed on the data
|
||||||
type PdhRawCounter struct {
|
type pdhRawCounter struct {
|
||||||
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
||||||
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
|
|
@ -132,9 +107,9 @@ type PdhRawCounter struct {
|
||||||
MultiCount uint32
|
MultiCount uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type PdhRawCounterItem struct {
|
type pdhRawCounterItem struct {
|
||||||
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
//A PdhRawCounter structure that contains the raw counter value of the instance
|
//A pdhRawCounter structure that contains the raw counter value of the instance
|
||||||
RawValue PdhRawCounter
|
RawValue pdhRawCounter
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,44 +32,19 @@
|
||||||
|
|
||||||
package win_perf_counters
|
package win_perf_counters
|
||||||
|
|
||||||
// PdhFmtCountervalueDouble is a union specialization for double values
|
// pdhFmtCountervalueDouble is a union specialization for double values
|
||||||
type PdhFmtCountervalueDouble struct {
|
type pdhFmtCountervalueDouble struct {
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
DoubleValue float64
|
DoubleValue float64
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueLarge is a union specialization for 64-bit integer values
|
type pdhFmtCountervalueItemDouble struct {
|
||||||
type PdhFmtCountervalueLarge struct {
|
|
||||||
CStatus uint32
|
|
||||||
LargeValue int64
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueLong is a union specialization for long values
|
|
||||||
type PdhFmtCountervalueLong struct {
|
|
||||||
CStatus uint32
|
|
||||||
LongValue int32
|
|
||||||
padding [4]byte //nolint:unused // Memory reservation
|
|
||||||
}
|
|
||||||
|
|
||||||
type PdhFmtCountervalueItemDouble struct {
|
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
FmtValue PdhFmtCountervalueDouble
|
FmtValue pdhFmtCountervalueDouble
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLarge is a union specialization for 'large' values, used by PdhGetFormattedCounterArrayLarge()
|
// pdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
||||||
type PdhFmtCountervalueItemLarge struct {
|
type pdhCounterInfo struct {
|
||||||
SzName *uint16 // pointer to a string
|
|
||||||
FmtValue PdhFmtCountervalueLarge
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhFmtCountervalueItemLong is a union specialization for long values, used by PdhGetFormattedCounterArrayLong()
|
|
||||||
type PdhFmtCountervalueItemLong struct {
|
|
||||||
SzName *uint16 // pointer to a string
|
|
||||||
FmtValue PdhFmtCountervalueLong
|
|
||||||
}
|
|
||||||
|
|
||||||
// PdhCounterInfo structure contains information describing the properties of a counter. This information also includes the counter path.
|
|
||||||
type PdhCounterInfo struct {
|
|
||||||
//Size of the structure, including the appended strings, in bytes.
|
//Size of the structure, including the appended strings, in bytes.
|
||||||
DwLength uint32
|
DwLength uint32
|
||||||
//Counter type. For a list of counter types, see the Counter Types section
|
//Counter type. For a list of counter types, see the Counter Types section
|
||||||
|
|
@ -115,9 +90,9 @@ type PdhCounterInfo struct {
|
||||||
DataBuffer [1]uint32 // pointer to an extra space
|
DataBuffer [1]uint32 // pointer to an extra space
|
||||||
}
|
}
|
||||||
|
|
||||||
// The PdhRawCounter structure returns the data as it was collected from the counter provider.
|
// The pdhRawCounter structure returns the data as it was collected from the counter provider.
|
||||||
// No translation, formatting, or other interpretation is performed on the data.
|
// No translation, formatting, or other interpretation is performed on the data.
|
||||||
type PdhRawCounter struct {
|
type pdhRawCounter struct {
|
||||||
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
// Counter status that indicates if the counter value is valid. Check this member before using the data in a calculation or displaying its value.
|
||||||
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
// For a list of possible values, see https://docs.microsoft.com/windows/desktop/PerfCtrs/checking-pdh-interface-return-values
|
||||||
CStatus uint32
|
CStatus uint32
|
||||||
|
|
@ -132,9 +107,9 @@ type PdhRawCounter struct {
|
||||||
MultiCount uint32
|
MultiCount uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type PdhRawCounterItem struct {
|
type pdhRawCounterItem struct {
|
||||||
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
// Pointer to a null-terminated string that specifies the instance name of the counter. The string is appended to the end of this structure.
|
||||||
SzName *uint16
|
SzName *uint16
|
||||||
//A PdhRawCounter structure that contains the raw counter value of the instance
|
//A pdhRawCounter structure that contains the raw counter value of the instance
|
||||||
RawValue PdhRawCounter
|
RawValue pdhRawCounter
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ const initialBufferSize = uint32(1024) // 1kB
|
||||||
|
|
||||||
var errBufferLimitReached = errors.New("buffer limit reached")
|
var errBufferLimitReached = errors.New("buffer limit reached")
|
||||||
|
|
||||||
// CounterValue is abstraction for PdhFmtCountervalueItemDouble
|
// counterValue is abstraction for pdhFmtCountervalueItemDouble
|
||||||
type CounterValue struct {
|
type counterValue struct {
|
||||||
InstanceName string
|
InstanceName string
|
||||||
Value interface{}
|
Value interface{}
|
||||||
}
|
}
|
||||||
|
|
@ -33,8 +33,8 @@ type PerformanceQuery interface {
|
||||||
ExpandWildCardPath(counterPath string) ([]string, error)
|
ExpandWildCardPath(counterPath string) ([]string, error)
|
||||||
GetFormattedCounterValueDouble(hCounter pdhCounterHandle) (float64, error)
|
GetFormattedCounterValueDouble(hCounter pdhCounterHandle) (float64, error)
|
||||||
GetRawCounterValue(hCounter pdhCounterHandle) (int64, error)
|
GetRawCounterValue(hCounter pdhCounterHandle) (int64, error)
|
||||||
GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]CounterValue, error)
|
GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]counterValue, error)
|
||||||
GetRawCounterArray(hCounter pdhCounterHandle) ([]CounterValue, error)
|
GetRawCounterArray(hCounter pdhCounterHandle) ([]counterValue, error)
|
||||||
CollectData() error
|
CollectData() error
|
||||||
CollectDataWithTime() (time.Time, error)
|
CollectDataWithTime() (time.Time, error)
|
||||||
IsVistaOrNewer() bool
|
IsVistaOrNewer() bool
|
||||||
|
|
@ -44,38 +44,38 @@ type PerformanceQueryCreator interface {
|
||||||
NewPerformanceQuery(string, uint32) PerformanceQuery
|
NewPerformanceQuery(string, uint32) PerformanceQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
// PdhError represents error returned from Performance Counters API
|
// pdhError represents error returned from Performance Counters API
|
||||||
type PdhError struct {
|
type pdhError struct {
|
||||||
ErrorCode uint32
|
ErrorCode uint32
|
||||||
errorText string
|
errorText string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PdhError) Error() string {
|
func (m *pdhError) Error() string {
|
||||||
return m.errorText
|
return m.errorText
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPdhError(code uint32) error {
|
func NewPdhError(code uint32) error {
|
||||||
return &PdhError{
|
return &pdhError{
|
||||||
ErrorCode: code,
|
ErrorCode: code,
|
||||||
errorText: PdhFormatError(code),
|
errorText: PdhFormatError(code),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PerformanceQueryImpl is implementation of PerformanceQuery interface, which calls phd.dll functions
|
// performanceQueryImpl is implementation of PerformanceQuery interface, which calls phd.dll functions
|
||||||
type PerformanceQueryImpl struct {
|
type performanceQueryImpl struct {
|
||||||
maxBufferSize uint32
|
maxBufferSize uint32
|
||||||
query pdhQueryHandle
|
query pdhQueryHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
type PerformanceQueryCreatorImpl struct{}
|
type performanceQueryCreatorImpl struct{}
|
||||||
|
|
||||||
func (m PerformanceQueryCreatorImpl) NewPerformanceQuery(_ string, maxBufferSize uint32) PerformanceQuery {
|
func (m performanceQueryCreatorImpl) NewPerformanceQuery(_ string, maxBufferSize uint32) PerformanceQuery {
|
||||||
return &PerformanceQueryImpl{maxBufferSize: maxBufferSize}
|
return &performanceQueryImpl{maxBufferSize: maxBufferSize}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open creates a new counterPath that is used to manage the collection of performance data.
|
// Open creates a new counterPath that is used to manage the collection of performance data.
|
||||||
// It returns counterPath handle used for subsequent calls for adding counters and querying data
|
// It returns counterPath handle used for subsequent calls for adding counters and querying data
|
||||||
func (m *PerformanceQueryImpl) Open() error {
|
func (m *performanceQueryImpl) Open() error {
|
||||||
if m.query != 0 {
|
if m.query != 0 {
|
||||||
err := m.Close()
|
err := m.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -92,7 +92,7 @@ func (m *PerformanceQueryImpl) Open() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close closes the counterPath, releases associated counter handles and frees resources
|
// Close closes the counterPath, releases associated counter handles and frees resources
|
||||||
func (m *PerformanceQueryImpl) Close() error {
|
func (m *performanceQueryImpl) Close() error {
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return errors.New("uninitialized query")
|
return errors.New("uninitialized query")
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +104,7 @@ func (m *PerformanceQueryImpl) Close() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) AddCounterToQuery(counterPath string) (pdhCounterHandle, error) {
|
func (m *performanceQueryImpl) AddCounterToQuery(counterPath string) (pdhCounterHandle, error) {
|
||||||
var counterHandle pdhCounterHandle
|
var counterHandle pdhCounterHandle
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return 0, errors.New("uninitialized query")
|
return 0, errors.New("uninitialized query")
|
||||||
|
|
@ -116,7 +116,7 @@ func (m *PerformanceQueryImpl) AddCounterToQuery(counterPath string) (pdhCounter
|
||||||
return counterHandle, nil
|
return counterHandle, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) AddEnglishCounterToQuery(counterPath string) (pdhCounterHandle, error) {
|
func (m *performanceQueryImpl) AddEnglishCounterToQuery(counterPath string) (pdhCounterHandle, error) {
|
||||||
var counterHandle pdhCounterHandle
|
var counterHandle pdhCounterHandle
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return 0, errors.New("uninitialized query")
|
return 0, errors.New("uninitialized query")
|
||||||
|
|
@ -128,7 +128,7 @@ func (m *PerformanceQueryImpl) AddEnglishCounterToQuery(counterPath string) (pdh
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCounterPath return counter information for given handle
|
// GetCounterPath return counter information for given handle
|
||||||
func (m *PerformanceQueryImpl) GetCounterPath(counterHandle pdhCounterHandle) (string, error) {
|
func (m *performanceQueryImpl) GetCounterPath(counterHandle pdhCounterHandle) (string, error) {
|
||||||
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
||||||
buf := make([]byte, buflen)
|
buf := make([]byte, buflen)
|
||||||
|
|
||||||
|
|
@ -136,7 +136,7 @@ func (m *PerformanceQueryImpl) GetCounterPath(counterHandle pdhCounterHandle) (s
|
||||||
size := buflen
|
size := buflen
|
||||||
ret := PdhGetCounterInfo(counterHandle, 0, &size, &buf[0])
|
ret := PdhGetCounterInfo(counterHandle, 0, &size, &buf[0])
|
||||||
if ret == ErrorSuccess {
|
if ret == ErrorSuccess {
|
||||||
ci := (*PdhCounterInfo)(unsafe.Pointer(&buf[0])) //nolint:gosec // G103: Valid use of unsafe call to create PDH_COUNTER_INFO
|
ci := (*pdhCounterInfo)(unsafe.Pointer(&buf[0])) //nolint:gosec // G103: Valid use of unsafe call to create PDH_COUNTER_INFO
|
||||||
return UTF16PtrToString(ci.SzFullPath), nil
|
return UTF16PtrToString(ci.SzFullPath), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,7 +155,7 @@ func (m *PerformanceQueryImpl) GetCounterPath(counterHandle pdhCounterHandle) (s
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExpandWildCardPath examines local computer and returns those counter paths that match the given counter path which contains wildcard characters.
|
// ExpandWildCardPath examines local computer and returns those counter paths that match the given counter path which contains wildcard characters.
|
||||||
func (m *PerformanceQueryImpl) ExpandWildCardPath(counterPath string) ([]string, error) {
|
func (m *performanceQueryImpl) ExpandWildCardPath(counterPath string) ([]string, error) {
|
||||||
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
||||||
buf := make([]uint16, buflen)
|
buf := make([]uint16, buflen)
|
||||||
|
|
||||||
|
|
@ -181,9 +181,9 @@ func (m *PerformanceQueryImpl) ExpandWildCardPath(counterPath string) ([]string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFormattedCounterValueDouble computes a displayable value for the specified counter
|
// GetFormattedCounterValueDouble computes a displayable value for the specified counter
|
||||||
func (m *PerformanceQueryImpl) GetFormattedCounterValueDouble(hCounter pdhCounterHandle) (float64, error) {
|
func (m *performanceQueryImpl) GetFormattedCounterValueDouble(hCounter pdhCounterHandle) (float64, error) {
|
||||||
var counterType uint32
|
var counterType uint32
|
||||||
var value PdhFmtCountervalueDouble
|
var value pdhFmtCountervalueDouble
|
||||||
|
|
||||||
if ret := PdhGetFormattedCounterValueDouble(hCounter, &counterType, &value); ret != ErrorSuccess {
|
if ret := PdhGetFormattedCounterValueDouble(hCounter, &counterType, &value); ret != ErrorSuccess {
|
||||||
return 0, NewPdhError(ret)
|
return 0, NewPdhError(ret)
|
||||||
|
|
@ -194,7 +194,7 @@ func (m *PerformanceQueryImpl) GetFormattedCounterValueDouble(hCounter pdhCounte
|
||||||
return 0, NewPdhError(value.CStatus)
|
return 0, NewPdhError(value.CStatus)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]CounterValue, error) {
|
func (m *performanceQueryImpl) GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]counterValue, error) {
|
||||||
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
||||||
buf := make([]byte, buflen)
|
buf := make([]byte, buflen)
|
||||||
|
|
||||||
|
|
@ -204,11 +204,11 @@ func (m *PerformanceQueryImpl) GetFormattedCounterArrayDouble(hCounter pdhCounte
|
||||||
ret := PdhGetFormattedCounterArrayDouble(hCounter, &size, &itemCount, &buf[0])
|
ret := PdhGetFormattedCounterArrayDouble(hCounter, &size, &itemCount, &buf[0])
|
||||||
if ret == ErrorSuccess {
|
if ret == ErrorSuccess {
|
||||||
//nolint:gosec // G103: Valid use of unsafe call to create PDH_FMT_COUNTERVALUE_ITEM_DOUBLE
|
//nolint:gosec // G103: Valid use of unsafe call to create PDH_FMT_COUNTERVALUE_ITEM_DOUBLE
|
||||||
items := (*[1 << 20]PdhFmtCountervalueItemDouble)(unsafe.Pointer(&buf[0]))[:itemCount]
|
items := (*[1 << 20]pdhFmtCountervalueItemDouble)(unsafe.Pointer(&buf[0]))[:itemCount]
|
||||||
values := make([]CounterValue, 0, itemCount)
|
values := make([]counterValue, 0, itemCount)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.FmtValue.CStatus == PdhCstatusValidData || item.FmtValue.CStatus == PdhCstatusNewData {
|
if item.FmtValue.CStatus == PdhCstatusValidData || item.FmtValue.CStatus == PdhCstatusNewData {
|
||||||
val := CounterValue{UTF16PtrToString(item.SzName), item.FmtValue.DoubleValue}
|
val := counterValue{UTF16PtrToString(item.SzName), item.FmtValue.DoubleValue}
|
||||||
values = append(values, val)
|
values = append(values, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -229,7 +229,7 @@ func (m *PerformanceQueryImpl) GetFormattedCounterArrayDouble(hCounter pdhCounte
|
||||||
return nil, errBufferLimitReached
|
return nil, errBufferLimitReached
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) GetRawCounterArray(hCounter pdhCounterHandle) ([]CounterValue, error) {
|
func (m *performanceQueryImpl) GetRawCounterArray(hCounter pdhCounterHandle) ([]counterValue, error) {
|
||||||
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
for buflen := initialBufferSize; buflen <= m.maxBufferSize; buflen *= 2 {
|
||||||
buf := make([]byte, buflen)
|
buf := make([]byte, buflen)
|
||||||
|
|
||||||
|
|
@ -239,11 +239,11 @@ func (m *PerformanceQueryImpl) GetRawCounterArray(hCounter pdhCounterHandle) ([]
|
||||||
ret := PdhGetRawCounterArray(hCounter, &size, &itemCount, &buf[0])
|
ret := PdhGetRawCounterArray(hCounter, &size, &itemCount, &buf[0])
|
||||||
if ret == ErrorSuccess {
|
if ret == ErrorSuccess {
|
||||||
//nolint:gosec // G103: Valid use of unsafe call to create PDH_RAW_COUNTER_ITEM
|
//nolint:gosec // G103: Valid use of unsafe call to create PDH_RAW_COUNTER_ITEM
|
||||||
items := (*[1 << 20]PdhRawCounterItem)(unsafe.Pointer(&buf[0]))[:itemCount]
|
items := (*[1 << 20]pdhRawCounterItem)(unsafe.Pointer(&buf[0]))[:itemCount]
|
||||||
values := make([]CounterValue, 0, itemCount)
|
values := make([]counterValue, 0, itemCount)
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
if item.RawValue.CStatus == PdhCstatusValidData || item.RawValue.CStatus == PdhCstatusNewData {
|
if item.RawValue.CStatus == PdhCstatusValidData || item.RawValue.CStatus == PdhCstatusNewData {
|
||||||
val := CounterValue{UTF16PtrToString(item.SzName), item.RawValue.FirstValue}
|
val := counterValue{UTF16PtrToString(item.SzName), item.RawValue.FirstValue}
|
||||||
values = append(values, val)
|
values = append(values, val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -264,7 +264,7 @@ func (m *PerformanceQueryImpl) GetRawCounterArray(hCounter pdhCounterHandle) ([]
|
||||||
return nil, errBufferLimitReached
|
return nil, errBufferLimitReached
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) CollectData() error {
|
func (m *performanceQueryImpl) CollectData() error {
|
||||||
var ret uint32
|
var ret uint32
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return errors.New("uninitialized query")
|
return errors.New("uninitialized query")
|
||||||
|
|
@ -276,7 +276,7 @@ func (m *PerformanceQueryImpl) CollectData() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) CollectDataWithTime() (time.Time, error) {
|
func (m *performanceQueryImpl) CollectDataWithTime() (time.Time, error) {
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return time.Now(), errors.New("uninitialized query")
|
return time.Now(), errors.New("uninitialized query")
|
||||||
}
|
}
|
||||||
|
|
@ -287,17 +287,17 @@ func (m *PerformanceQueryImpl) CollectDataWithTime() (time.Time, error) {
|
||||||
return mtime, nil
|
return mtime, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) IsVistaOrNewer() bool {
|
func (m *performanceQueryImpl) IsVistaOrNewer() bool {
|
||||||
return PdhAddEnglishCounterSupported()
|
return PdhAddEnglishCounterSupported()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *PerformanceQueryImpl) GetRawCounterValue(hCounter pdhCounterHandle) (int64, error) {
|
func (m *performanceQueryImpl) GetRawCounterValue(hCounter pdhCounterHandle) (int64, error) {
|
||||||
if m.query == 0 {
|
if m.query == 0 {
|
||||||
return 0, errors.New("uninitialised query")
|
return 0, errors.New("uninitialised query")
|
||||||
}
|
}
|
||||||
|
|
||||||
var counterType uint32
|
var counterType uint32
|
||||||
var value PdhRawCounter
|
var value pdhRawCounter
|
||||||
var ret uint32
|
var ret uint32
|
||||||
|
|
||||||
if ret = PdhGetRawCounterValue(hCounter, &counterType, &value); ret == ErrorSuccess {
|
if ret = PdhGetRawCounterValue(hCounter, &counterType, &value); ret == ErrorSuccess {
|
||||||
|
|
|
||||||
|
|
@ -399,7 +399,7 @@ func (m *WinPerfCounters) ParseConfig() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *WinPerfCounters) checkError(err error) error {
|
func (m *WinPerfCounters) checkError(err error) error {
|
||||||
var pdhErr *PdhError
|
var pdhErr *pdhError
|
||||||
if errors.As(err, &pdhErr) {
|
if errors.As(err, &pdhErr) {
|
||||||
for _, ignoredErrors := range m.IgnoredErrors {
|
for _, ignoredErrors := range m.IgnoredErrors {
|
||||||
if PDHErrors[pdhErr.ErrorCode] == ignoredErrors {
|
if PDHErrors[pdhErr.ErrorCode] == ignoredErrors {
|
||||||
|
|
@ -491,7 +491,7 @@ func (m *WinPerfCounters) gatherComputerCounters(hostCounterInfo *hostCountersIn
|
||||||
}
|
}
|
||||||
addCounterMeasurement(metric, metric.instance, value, collectedFields)
|
addCounterMeasurement(metric, metric.instance, value, collectedFields)
|
||||||
} else {
|
} else {
|
||||||
var counterValues []CounterValue
|
var counterValues []counterValue
|
||||||
if metric.useRawValue {
|
if metric.useRawValue {
|
||||||
counterValues, err = hostCounterInfo.query.GetRawCounterArray(metric.counterHandle)
|
counterValues, err = hostCounterInfo.query.GetRawCounterArray(metric.counterHandle)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -543,7 +543,7 @@ func (m *WinPerfCounters) cleanQueries() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldIncludeMetric(metric *counter, cValue CounterValue) bool {
|
func shouldIncludeMetric(metric *counter, cValue counterValue) bool {
|
||||||
if metric.includeTotal {
|
if metric.includeTotal {
|
||||||
// If IncludeTotal is set, include all.
|
// If IncludeTotal is set, include all.
|
||||||
return true
|
return true
|
||||||
|
|
@ -571,7 +571,7 @@ func addCounterMeasurement(metric *counter, instanceName string, value interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func isKnownCounterDataError(err error) bool {
|
func isKnownCounterDataError(err error) bool {
|
||||||
var pdhErr *PdhError
|
var pdhErr *pdhError
|
||||||
if errors.As(err, &pdhErr) && (pdhErr.ErrorCode == PdhInvalidData ||
|
if errors.As(err, &pdhErr) && (pdhErr.ErrorCode == PdhInvalidData ||
|
||||||
pdhErr.ErrorCode == PdhCalcNegativeDenominator ||
|
pdhErr.ErrorCode == PdhCalcNegativeDenominator ||
|
||||||
pdhErr.ErrorCode == PdhCalcNegativeValue ||
|
pdhErr.ErrorCode == PdhCalcNegativeValue ||
|
||||||
|
|
@ -627,7 +627,7 @@ func init() {
|
||||||
CountersRefreshInterval: config.Duration(time.Second * 60),
|
CountersRefreshInterval: config.Duration(time.Second * 60),
|
||||||
LocalizeWildcardsExpansion: true,
|
LocalizeWildcardsExpansion: true,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
query := &PerformanceQueryImpl{maxBufferSize: uint32(defaultMaxBufferSize)}
|
query := &performanceQueryImpl{maxBufferSize: uint32(defaultMaxBufferSize)}
|
||||||
|
|
||||||
err := query.Close()
|
err := query.Close()
|
||||||
require.Error(t, err, "uninitialized query must return errors")
|
require.Error(t, err, "uninitialized query must return errors")
|
||||||
|
|
@ -98,7 +98,7 @@ func TestWinPerformanceQueryImplIntegration(t *testing.T) {
|
||||||
require.NoError(t, query.CollectData())
|
require.NoError(t, query.CollectData())
|
||||||
|
|
||||||
farr, err := query.GetFormattedCounterArrayDouble(hCounter)
|
farr, err := query.GetFormattedCounterArrayDouble(hCounter)
|
||||||
var phdErr *PdhError
|
var phdErr *pdhError
|
||||||
if errors.As(err, &phdErr) && phdErr.ErrorCode != PdhInvalidData && phdErr.ErrorCode != PdhCalcNegativeValue {
|
if errors.As(err, &phdErr) && phdErr.ErrorCode != PdhInvalidData && phdErr.ErrorCode != PdhCalcNegativeValue {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
farr, err = query.GetFormattedCounterArrayDouble(hCounter)
|
farr, err = query.GetFormattedCounterArrayDouble(hCounter)
|
||||||
|
|
@ -135,7 +135,7 @@ func TestWinPerfCountersConfigGet1Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -163,7 +163,7 @@ func TestWinPerfCountersConfigGet2Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -206,7 +206,7 @@ func TestWinPerfCountersConfigGet3Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -247,7 +247,7 @@ func TestWinPerfCountersConfigGet4Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -288,7 +288,7 @@ func TestWinPerfCountersConfigGet5Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -329,7 +329,7 @@ func TestWinPerfCountersConfigGet6Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -357,7 +357,7 @@ func TestWinPerfCountersConfigGet7Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -398,7 +398,7 @@ func TestWinPerfCountersConfigError1Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Error(t, m.ParseConfig())
|
require.Error(t, m.ParseConfig())
|
||||||
|
|
@ -426,7 +426,7 @@ func TestWinPerfCountersConfigError2Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, m.ParseConfig())
|
require.NoError(t, m.ParseConfig())
|
||||||
|
|
@ -456,7 +456,7 @@ func TestWinPerfCountersConfigError3Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Error(t, m.ParseConfig())
|
require.Error(t, m.ParseConfig())
|
||||||
|
|
@ -484,7 +484,7 @@ func TestWinPerfCountersCollect1Integration(t *testing.T) {
|
||||||
Object: perfObjects,
|
Object: perfObjects,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -524,7 +524,7 @@ func TestWinPerfCountersCollect2Integration(t *testing.T) {
|
||||||
UseWildcardsExpansion: true,
|
UseWildcardsExpansion: true,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
@ -565,7 +565,7 @@ func TestWinPerfCountersCollectRawIntegration(t *testing.T) {
|
||||||
UseWildcardsExpansion: true,
|
UseWildcardsExpansion: true,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
require.NoError(t, m.Gather(&acc))
|
require.NoError(t, m.Gather(&acc))
|
||||||
|
|
@ -590,7 +590,7 @@ func TestWinPerfCountersCollectRawIntegration(t *testing.T) {
|
||||||
UseWildcardsExpansion: false,
|
UseWildcardsExpansion: false,
|
||||||
MaxBufferSize: defaultMaxBufferSize,
|
MaxBufferSize: defaultMaxBufferSize,
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
}
|
}
|
||||||
var acc2 testutil.Accumulator
|
var acc2 testutil.Accumulator
|
||||||
require.NoError(t, m.Gather(&acc))
|
require.NoError(t, m.Gather(&acc))
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ type FakePerformanceQuery struct {
|
||||||
|
|
||||||
var MetricTime = time.Date(2018, 5, 28, 12, 0, 0, 0, time.UTC)
|
var MetricTime = time.Date(2018, 5, 28, 12, 0, 0, 0, time.UTC)
|
||||||
|
|
||||||
func (m *testCounter) ToCounterValue(raw bool) *CounterValue {
|
func (m *testCounter) ToCounterValue(raw bool) *counterValue {
|
||||||
//nolint:dogsled,errcheck // only instance is needed for this helper function in tests
|
//nolint:dogsled,errcheck // only instance is needed for this helper function in tests
|
||||||
_, _, inst, _, _ := extractCounterInfoFromCounterPath(m.path)
|
_, _, inst, _, _ := extractCounterInfoFromCounterPath(m.path)
|
||||||
if inst == "" {
|
if inst == "" {
|
||||||
|
|
@ -44,7 +44,7 @@ func (m *testCounter) ToCounterValue(raw bool) *CounterValue {
|
||||||
val = m.value
|
val = m.value
|
||||||
}
|
}
|
||||||
|
|
||||||
return &CounterValue{inst, val}
|
return &counterValue{inst, val}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FakePerformanceQuery) Open() error {
|
func (m *FakePerformanceQuery) Open() error {
|
||||||
|
|
@ -141,14 +141,14 @@ func (m *FakePerformanceQuery) findCounterByPath(counterPath string) *testCounte
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FakePerformanceQuery) GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]CounterValue, error) {
|
func (m *FakePerformanceQuery) GetFormattedCounterArrayDouble(hCounter pdhCounterHandle) ([]counterValue, error) {
|
||||||
if !m.openCalled {
|
if !m.openCalled {
|
||||||
return nil, errors.New("in GetFormattedCounterArrayDouble: uninitialized query")
|
return nil, errors.New("in GetFormattedCounterArrayDouble: uninitialized query")
|
||||||
}
|
}
|
||||||
for _, c := range m.counters {
|
for _, c := range m.counters {
|
||||||
if c.handle == hCounter {
|
if c.handle == hCounter {
|
||||||
if e, ok := m.expandPaths[c.path]; ok {
|
if e, ok := m.expandPaths[c.path]; ok {
|
||||||
counters := make([]CounterValue, 0, len(e))
|
counters := make([]counterValue, 0, len(e))
|
||||||
for _, p := range e {
|
for _, p := range e {
|
||||||
counter := m.findCounterByPath(p)
|
counter := m.findCounterByPath(p)
|
||||||
if counter == nil {
|
if counter == nil {
|
||||||
|
|
@ -167,14 +167,14 @@ func (m *FakePerformanceQuery) GetFormattedCounterArrayDouble(hCounter pdhCounte
|
||||||
return nil, fmt.Errorf("in GetFormattedCounterArrayDouble: invalid counter: %q, no paths found", hCounter)
|
return nil, fmt.Errorf("in GetFormattedCounterArrayDouble: invalid counter: %q, no paths found", hCounter)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *FakePerformanceQuery) GetRawCounterArray(hCounter pdhCounterHandle) ([]CounterValue, error) {
|
func (m *FakePerformanceQuery) GetRawCounterArray(hCounter pdhCounterHandle) ([]counterValue, error) {
|
||||||
if !m.openCalled {
|
if !m.openCalled {
|
||||||
return nil, errors.New("in GetRawCounterArray: uninitialised query")
|
return nil, errors.New("in GetRawCounterArray: uninitialised query")
|
||||||
}
|
}
|
||||||
for _, c := range m.counters {
|
for _, c := range m.counters {
|
||||||
if c.handle == hCounter {
|
if c.handle == hCounter {
|
||||||
if e, ok := m.expandPaths[c.path]; ok {
|
if e, ok := m.expandPaths[c.path]; ok {
|
||||||
counters := make([]CounterValue, 0, len(e))
|
counters := make([]counterValue, 0, len(e))
|
||||||
for _, p := range e {
|
for _, p := range e {
|
||||||
counter := m.findCounterByPath(p)
|
counter := m.findCounterByPath(p)
|
||||||
if counter == nil {
|
if counter == nil {
|
||||||
|
|
@ -2038,7 +2038,7 @@ func TestLocalizeWildcardsExpansion(t *testing.T) {
|
||||||
|
|
||||||
const counter = "% Processor Time"
|
const counter = "% Processor Time"
|
||||||
m := WinPerfCounters{
|
m := WinPerfCounters{
|
||||||
queryCreator: &PerformanceQueryCreatorImpl{},
|
queryCreator: &performanceQueryCreatorImpl{},
|
||||||
CountersRefreshInterval: config.Duration(time.Second * 60),
|
CountersRefreshInterval: config.Duration(time.Second * 60),
|
||||||
Object: createPerfObject("", "measurement", "Processor Information",
|
Object: createPerfObject("", "measurement", "Processor Information",
|
||||||
[]string{"_Total"}, []string{counter}, true, false, false),
|
[]string{"_Total"}, []string{counter}, true, false, false),
|
||||||
|
|
@ -2068,7 +2068,7 @@ func TestCheckError(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
Name: "Ignore PDH_NO_DATA",
|
Name: "Ignore PDH_NO_DATA",
|
||||||
Err: &PdhError{
|
Err: &pdhError{
|
||||||
ErrorCode: uint32(PdhNoData),
|
ErrorCode: uint32(PdhNoData),
|
||||||
},
|
},
|
||||||
IgnoredErrors: []string{
|
IgnoredErrors: []string{
|
||||||
|
|
@ -2078,10 +2078,10 @@ func TestCheckError(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Don't ignore PDH_NO_DATA",
|
Name: "Don't ignore PDH_NO_DATA",
|
||||||
Err: &PdhError{
|
Err: &pdhError{
|
||||||
ErrorCode: uint32(PdhNoData),
|
ErrorCode: uint32(PdhNoData),
|
||||||
},
|
},
|
||||||
ExpectedErr: &PdhError{
|
ExpectedErr: &pdhError{
|
||||||
ErrorCode: uint32(PdhNoData),
|
ErrorCode: uint32(PdhNoData),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -23,18 +23,18 @@ import (
|
||||||
//go:embed sample.conf
|
//go:embed sample.conf
|
||||||
var sampleConfig string
|
var sampleConfig string
|
||||||
|
|
||||||
type ServiceError struct {
|
type serviceError struct {
|
||||||
Message string
|
Message string
|
||||||
Service string
|
Service string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ServiceError) Error() string {
|
func (e *serviceError) Error() string {
|
||||||
return fmt.Sprintf("%s: %q: %v", e.Message, e.Service, e.Err)
|
return fmt.Sprintf("%s: %q: %v", e.Message, e.Service, e.Err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPermission(err error) bool {
|
func IsPermission(err error) bool {
|
||||||
var serviceErr *ServiceError
|
var serviceErr *serviceError
|
||||||
if errors.As(err, &serviceErr) {
|
if errors.As(err, &serviceErr) {
|
||||||
return errors.Is(serviceErr, fs.ErrPermission)
|
return errors.Is(serviceErr, fs.ErrPermission)
|
||||||
}
|
}
|
||||||
|
|
@ -60,16 +60,16 @@ type WinServiceManager interface {
|
||||||
ListServices() ([]string, error)
|
ListServices() ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WinSvcMgr is wrapper for mgr.Mgr implementing WinServiceManager interface
|
// winSvcMgr is wrapper for mgr.Mgr implementing WinServiceManager interface
|
||||||
type WinSvcMgr struct {
|
type winSvcMgr struct {
|
||||||
realMgr *mgr.Mgr
|
realMgr *mgr.Mgr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *WinSvcMgr) Disconnect() error {
|
func (m *winSvcMgr) Disconnect() error {
|
||||||
return m.realMgr.Disconnect()
|
return m.realMgr.Disconnect()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *WinSvcMgr) OpenService(name string) (WinService, error) {
|
func (m *winSvcMgr) OpenService(name string) (WinService, error) {
|
||||||
serviceName, err := syscall.UTF16PtrFromString(name)
|
serviceName, err := syscall.UTF16PtrFromString(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot convert service name %q: %w", name, err)
|
return nil, fmt.Errorf("cannot convert service name %q: %w", name, err)
|
||||||
|
|
@ -81,21 +81,21 @@ func (m *WinSvcMgr) OpenService(name string) (WinService, error) {
|
||||||
return &mgr.Service{Name: name, Handle: h}, nil
|
return &mgr.Service{Name: name, Handle: h}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *WinSvcMgr) ListServices() ([]string, error) {
|
func (m *winSvcMgr) ListServices() ([]string, error) {
|
||||||
return m.realMgr.ListServices()
|
return m.realMgr.ListServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MgProvider is an implementation of WinServiceManagerProvider interface returning WinSvcMgr
|
// mgProvider is an implementation of WinServiceManagerProvider interface returning winSvcMgr
|
||||||
type MgProvider struct {
|
type mgProvider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rmr *MgProvider) Connect() (WinServiceManager, error) {
|
func (rmr *mgProvider) Connect() (WinServiceManager, error) {
|
||||||
h, err := windows.OpenSCManager(nil, nil, windows.GENERIC_READ)
|
h, err := windows.OpenSCManager(nil, nil, windows.GENERIC_READ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
scmgr := &mgr.Mgr{Handle: h}
|
scmgr := &mgr.Mgr{Handle: h}
|
||||||
return &WinSvcMgr{scmgr}, nil
|
return &winSvcMgr{scmgr}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WinServices is an implementation if telegraf.Input interface, providing info about Windows Services
|
// WinServices is an implementation if telegraf.Input interface, providing info about Windows Services
|
||||||
|
|
@ -109,7 +109,7 @@ type WinServices struct {
|
||||||
servicesFilter filter.Filter
|
servicesFilter filter.Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceInfo struct {
|
type serviceInfo struct {
|
||||||
ServiceName string
|
ServiceName string
|
||||||
DisplayName string
|
DisplayName string
|
||||||
State int
|
State int
|
||||||
|
|
@ -202,10 +202,10 @@ func (m *WinServices) listServices(scmgr WinServiceManager) ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// collectServiceInfo gathers info about a service.
|
// collectServiceInfo gathers info about a service.
|
||||||
func collectServiceInfo(scmgr WinServiceManager, serviceName string) (*ServiceInfo, error) {
|
func collectServiceInfo(scmgr WinServiceManager, serviceName string) (*serviceInfo, error) {
|
||||||
srv, err := scmgr.OpenService(serviceName)
|
srv, err := scmgr.OpenService(serviceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &ServiceError{
|
return nil, &serviceError{
|
||||||
Message: "could not open service",
|
Message: "could not open service",
|
||||||
Service: serviceName,
|
Service: serviceName,
|
||||||
Err: err,
|
Err: err,
|
||||||
|
|
@ -215,7 +215,7 @@ func collectServiceInfo(scmgr WinServiceManager, serviceName string) (*ServiceIn
|
||||||
|
|
||||||
srvStatus, err := srv.Query()
|
srvStatus, err := srv.Query()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &ServiceError{
|
return nil, &serviceError{
|
||||||
Message: "could not query service",
|
Message: "could not query service",
|
||||||
Service: serviceName,
|
Service: serviceName,
|
||||||
Err: err,
|
Err: err,
|
||||||
|
|
@ -224,14 +224,14 @@ func collectServiceInfo(scmgr WinServiceManager, serviceName string) (*ServiceIn
|
||||||
|
|
||||||
srvCfg, err := srv.Config()
|
srvCfg, err := srv.Config()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &ServiceError{
|
return nil, &serviceError{
|
||||||
Message: "could not get config of service",
|
Message: "could not get config of service",
|
||||||
Service: serviceName,
|
Service: serviceName,
|
||||||
Err: err,
|
Err: err,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceInfo := &ServiceInfo{
|
serviceInfo := &serviceInfo{
|
||||||
ServiceName: serviceName,
|
ServiceName: serviceName,
|
||||||
DisplayName: srvCfg.DisplayName,
|
DisplayName: srvCfg.DisplayName,
|
||||||
StartUpMode: int(srvCfg.StartType),
|
StartUpMode: int(srvCfg.StartType),
|
||||||
|
|
@ -243,7 +243,7 @@ func collectServiceInfo(scmgr WinServiceManager, serviceName string) (*ServiceIn
|
||||||
func init() {
|
func init() {
|
||||||
inputs.Add("win_services", func() telegraf.Input {
|
inputs.Add("win_services", func() telegraf.Input {
|
||||||
return &WinServices{
|
return &WinServices{
|
||||||
mgrProvider: &MgProvider{},
|
mgrProvider: &mgProvider{},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ func TestListIntegration(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
provider := &MgProvider{}
|
provider := &mgProvider{}
|
||||||
scmgr, err := provider.Connect()
|
scmgr, err := provider.Connect()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -41,7 +41,7 @@ func TestEmptyListIntegration(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping integration test in short mode")
|
t.Skip("Skipping integration test in short mode")
|
||||||
}
|
}
|
||||||
provider := &MgProvider{}
|
provider := &mgProvider{}
|
||||||
scmgr, err := provider.Connect()
|
scmgr, err := provider.Connect()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
|
@ -66,7 +66,7 @@ func TestGatherErrorsIntegration(t *testing.T) {
|
||||||
ws := &WinServices{
|
ws := &WinServices{
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
ServiceNames: InvalidServices,
|
ServiceNames: InvalidServices,
|
||||||
mgrProvider: &MgProvider{},
|
mgrProvider: &mgProvider{},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.NoError(t, ws.Init())
|
require.NoError(t, ws.Init())
|
||||||
|
|
|
||||||
|
|
@ -92,13 +92,13 @@ func (xio *XtremIO) Gather(acc telegraf.Accumulator) error {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := CollectorResponse{}
|
data := collectorResponse{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var arr []HREF
|
var arr []href
|
||||||
switch collector {
|
switch collector {
|
||||||
case "bbus":
|
case "bbus":
|
||||||
arr = data.BBUs
|
arr = data.BBUs
|
||||||
|
|
@ -168,7 +168,7 @@ func (xio *XtremIO) gatherBBUs(acc telegraf.Accumulator, url string, wg *sync.Wa
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := BBU{}
|
data := bbu{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
@ -201,7 +201,7 @@ func (xio *XtremIO) gatherClusters(acc telegraf.Accumulator, url string, wg *syn
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := Clusters{}
|
data := clusters{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
@ -237,7 +237,7 @@ func (xio *XtremIO) gatherSSDs(acc telegraf.Accumulator, url string, wg *sync.Wa
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := SSD{}
|
data := ssd{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
@ -273,7 +273,7 @@ func (xio *XtremIO) gatherVolumes(acc telegraf.Accumulator, url string, wg *sync
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := Volumes{}
|
data := volumes{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
@ -306,7 +306,7 @@ func (xio *XtremIO) gatherXMS(acc telegraf.Accumulator, url string, wg *sync.Wai
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := XMS{}
|
data := xms{}
|
||||||
err = json.Unmarshal([]byte(resp), &data)
|
err = json.Unmarshal([]byte(resp), &data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
acc.AddError(err)
|
acc.AddError(err)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package xtremio
|
package xtremio
|
||||||
|
|
||||||
type BBU struct {
|
type bbu struct {
|
||||||
Content struct {
|
Content struct {
|
||||||
Serial string `json:"serial-number"`
|
Serial string `json:"serial-number"`
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
|
|
@ -15,7 +15,7 @@ type BBU struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Clusters struct {
|
type clusters struct {
|
||||||
Content struct {
|
Content struct {
|
||||||
HardwarePlatform string `json:"hardware-platform"`
|
HardwarePlatform string `json:"hardware-platform"`
|
||||||
LicenseID string `json:"license-id"`
|
LicenseID string `json:"license-id"`
|
||||||
|
|
@ -33,7 +33,7 @@ type Clusters struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SSD struct {
|
type ssd struct {
|
||||||
Content struct {
|
Content struct {
|
||||||
ModelName string `json:"model-name"`
|
ModelName string `json:"model-name"`
|
||||||
FirmwareVersion string `json:"fw-version"`
|
FirmwareVersion string `json:"fw-version"`
|
||||||
|
|
@ -51,7 +51,7 @@ type SSD struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Volumes struct {
|
type volumes struct {
|
||||||
Content struct {
|
Content struct {
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
SysName string `json:"sys-name"`
|
SysName string `json:"sys-name"`
|
||||||
|
|
@ -66,7 +66,7 @@ type Volumes struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type XMS struct {
|
type xms struct {
|
||||||
Content struct {
|
Content struct {
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
@ -85,14 +85,14 @@ type XMS struct {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HREF struct {
|
type href struct {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CollectorResponse struct {
|
type collectorResponse struct {
|
||||||
BBUs []HREF `json:"bbus"`
|
BBUs []href `json:"bbus"`
|
||||||
Clusters []HREF `json:"clusters"`
|
Clusters []href `json:"clusters"`
|
||||||
SSDs []HREF `json:"ssds"`
|
SSDs []href `json:"ssds"`
|
||||||
Volumes []HREF `json:"volumes"`
|
Volumes []href `json:"volumes"`
|
||||||
XMS []HREF `json:"xmss"`
|
XMS []href `json:"xmss"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,14 @@ type Endpoint interface {
|
||||||
Name() string
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultEndpoint is used if the annotations have no endpoints
|
// defaultEndpoint is used if the annotations have no endpoints
|
||||||
type DefaultEndpoint struct{}
|
type defaultEndpoint struct{}
|
||||||
|
|
||||||
// Host returns 0.0.0.0; used when the host is unknown
|
// Host returns 0.0.0.0; used when the host is unknown
|
||||||
func (d *DefaultEndpoint) Host() string { return "0.0.0.0" }
|
func (d *defaultEndpoint) Host() string { return "0.0.0.0" }
|
||||||
|
|
||||||
// Name returns "unknown" when an endpoint doesn't exist
|
// Name returns "unknown" when an endpoint doesn't exist
|
||||||
func (d *DefaultEndpoint) Name() string { return DefaultServiceName }
|
func (d *defaultEndpoint) Name() string { return DefaultServiceName }
|
||||||
|
|
||||||
// MicroToTime converts zipkin's native time of microseconds into time.Time
|
// MicroToTime converts zipkin's native time of microseconds into time.Time
|
||||||
func MicroToTime(micro int64) time.Time {
|
func MicroToTime(micro int64) time.Time {
|
||||||
|
|
@ -206,5 +206,5 @@ func serviceEndpoint(ann []Annotation, bann []BinaryAnnotation) Endpoint {
|
||||||
return a.Host()
|
return a.Host()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &DefaultEndpoint{}
|
return &defaultEndpoint{}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ func Test_serviceEndpoint(t *testing.T) {
|
||||||
Val: "noop",
|
Val: "noop",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: &DefaultEndpoint{},
|
want: &defaultEndpoint{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Binary annotation with local component",
|
name: "Binary annotation with local component",
|
||||||
|
|
|
||||||
|
|
@ -60,28 +60,28 @@ type DatabaseNotFoundError struct {
|
||||||
Database string
|
Database string
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryResponseError is the response body from the /query endpoint
|
// queryResponseError is the response body from the /query endpoint
|
||||||
type QueryResponseError struct {
|
type queryResponseError struct {
|
||||||
Results []QueryResult `json:"results"`
|
Results []queryResult `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type QueryResult struct {
|
type queryResult struct {
|
||||||
Err string `json:"error,omitempty"`
|
Err string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r QueryResponseError) Error() string {
|
func (r queryResponseError) Error() string {
|
||||||
if len(r.Results) > 0 {
|
if len(r.Results) > 0 {
|
||||||
return r.Results[0].Err
|
return r.Results[0].Err
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteResponseError is the response body from the /write endpoint
|
// writeResponseError is the response body from the /write endpoint
|
||||||
type WriteResponseError struct {
|
type writeResponseError struct {
|
||||||
Err string `json:"error,omitempty"`
|
Err string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r WriteResponseError) Error() string {
|
func (r writeResponseError) Error() string {
|
||||||
return r.Err
|
return r.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -241,7 +241,7 @@ func (c *httpClient) CreateDatabase(ctx context.Context, database string) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
queryResp := &QueryResponseError{}
|
queryResp := &queryResponseError{}
|
||||||
dec := json.NewDecoder(body)
|
dec := json.NewDecoder(body)
|
||||||
err = dec.Decode(queryResp)
|
err = dec.Decode(queryResp)
|
||||||
|
|
||||||
|
|
@ -374,7 +374,7 @@ func (c *httpClient) writeBatch(ctx context.Context, db, rp string, metrics []te
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeResp := &WriteResponseError{}
|
writeResp := &writeResponseError{}
|
||||||
dec := json.NewDecoder(body)
|
dec := json.NewDecoder(body)
|
||||||
|
|
||||||
var desc string
|
var desc string
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
for name, family := range c.fam {
|
for name, family := range c.fam {
|
||||||
// Get list of all labels on MetricFamily
|
// Get list of all labels on metricFamily
|
||||||
var labelNames []string
|
var labelNames []string
|
||||||
for k, v := range family.LabelSet {
|
for k, v := range family.LabelSet {
|
||||||
if v > 0 {
|
if v > 0 {
|
||||||
|
|
|
||||||
|
|
@ -33,56 +33,56 @@ const (
|
||||||
defaultContentType = "application/json; charset=utf-8"
|
defaultContentType = "application/json; charset=utf-8"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OutputMetadata struct {
|
type outputMetadata struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputEntity struct {
|
type outputEntity struct {
|
||||||
Metadata *OutputMetadata `json:"metadata"`
|
Metadata *outputMetadata `json:"metadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputCheck struct {
|
type outputCheck struct {
|
||||||
Metadata *OutputMetadata `json:"metadata"`
|
Metadata *outputMetadata `json:"metadata"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
Output string `json:"output"`
|
Output string `json:"output"`
|
||||||
Issued int64 `json:"issued"`
|
Issued int64 `json:"issued"`
|
||||||
OutputMetricHandlers []string `json:"output_metric_handlers"`
|
OutputMetricHandlers []string `json:"output_metric_handlers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputMetrics struct {
|
type outputMetrics struct {
|
||||||
Handlers []string `json:"handlers"`
|
Handlers []string `json:"handlers"`
|
||||||
Metrics []*OutputMetric `json:"points"`
|
Metrics []*outputMetric `json:"points"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputMetric struct {
|
type outputMetric struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Tags []*OutputTag `json:"tags"`
|
Tags []*outputTag `json:"tags"`
|
||||||
Value interface{} `json:"value"`
|
Value interface{} `json:"value"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputTag struct {
|
type outputTag struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Value string `json:"value"`
|
Value string `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OutputEvent struct {
|
type outputEvent struct {
|
||||||
Entity *OutputEntity `json:"entity,omitempty"`
|
Entity *outputEntity `json:"entity,omitempty"`
|
||||||
Check *OutputCheck `json:"check"`
|
Check *outputCheck `json:"check"`
|
||||||
Metrics *OutputMetrics `json:"metrics"`
|
Metrics *outputMetrics `json:"metrics"`
|
||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SensuEntity struct {
|
type sensuEntity struct {
|
||||||
Name *string `toml:"name"`
|
Name *string `toml:"name"`
|
||||||
Namespace *string `toml:"namespace"`
|
Namespace *string `toml:"namespace"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SensuCheck struct {
|
type sensuCheck struct {
|
||||||
Name *string `toml:"name"`
|
Name *string `toml:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SensuMetrics struct {
|
type sensuMetrics struct {
|
||||||
Handlers []string `toml:"handlers"`
|
Handlers []string `toml:"handlers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,16 +90,16 @@ type Sensu struct {
|
||||||
APIKey *string `toml:"api_key"`
|
APIKey *string `toml:"api_key"`
|
||||||
AgentAPIURL *string `toml:"agent_api_url"`
|
AgentAPIURL *string `toml:"agent_api_url"`
|
||||||
BackendAPIURL *string `toml:"backend_api_url"`
|
BackendAPIURL *string `toml:"backend_api_url"`
|
||||||
Entity *SensuEntity `toml:"entity"`
|
Entity *sensuEntity `toml:"entity"`
|
||||||
Tags map[string]string `toml:"tags"`
|
Tags map[string]string `toml:"tags"`
|
||||||
Metrics *SensuMetrics `toml:"metrics"`
|
Metrics *sensuMetrics `toml:"metrics"`
|
||||||
Check *SensuCheck `toml:"check"`
|
Check *sensuCheck `toml:"check"`
|
||||||
|
|
||||||
Timeout config.Duration `toml:"timeout"`
|
Timeout config.Duration `toml:"timeout"`
|
||||||
ContentEncoding string `toml:"content_encoding"`
|
ContentEncoding string `toml:"content_encoding"`
|
||||||
|
|
||||||
EndpointURL string
|
EndpointURL string
|
||||||
OutEntity *OutputEntity
|
OutEntity *outputEntity
|
||||||
|
|
||||||
Log telegraf.Logger `toml:"-"`
|
Log telegraf.Logger `toml:"-"`
|
||||||
|
|
||||||
|
|
@ -154,19 +154,19 @@ func (s *Sensu) Close() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sensu) Write(metrics []telegraf.Metric) error {
|
func (s *Sensu) Write(metrics []telegraf.Metric) error {
|
||||||
var points []*OutputMetric
|
var points []*outputMetric
|
||||||
for _, metric := range metrics {
|
for _, metric := range metrics {
|
||||||
// Add tags from config to each metric point
|
// Add tags from config to each metric point
|
||||||
tagList := make([]*OutputTag, 0, len(s.Tags)+len(metric.TagList()))
|
tagList := make([]*outputTag, 0, len(s.Tags)+len(metric.TagList()))
|
||||||
for name, value := range s.Tags {
|
for name, value := range s.Tags {
|
||||||
tag := &OutputTag{
|
tag := &outputTag{
|
||||||
Name: name,
|
Name: name,
|
||||||
Value: value,
|
Value: value,
|
||||||
}
|
}
|
||||||
tagList = append(tagList, tag)
|
tagList = append(tagList, tag)
|
||||||
}
|
}
|
||||||
for _, tagSet := range metric.TagList() {
|
for _, tagSet := range metric.TagList() {
|
||||||
tag := &OutputTag{
|
tag := &outputTag{
|
||||||
Name: tagSet.Key,
|
Name: tagSet.Key,
|
||||||
Value: tagSet.Value,
|
Value: tagSet.Value,
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +191,7 @@ func (s *Sensu) Write(metrics []telegraf.Metric) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
point := &OutputMetric{
|
point := &outputMetric{
|
||||||
Name: metric.Name() + "." + key,
|
Name: metric.Name() + "." + key,
|
||||||
Tags: tagList,
|
Tags: tagList,
|
||||||
Timestamp: metric.Time().Unix(),
|
Timestamp: metric.Time().Unix(),
|
||||||
|
|
@ -321,7 +321,7 @@ func init() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sensu) encodeToJSON(metricPoints []*OutputMetric) ([]byte, error) {
|
func (s *Sensu) encodeToJSON(metricPoints []*outputMetric) ([]byte, error) {
|
||||||
timestamp := time.Now().Unix()
|
timestamp := time.Now().Unix()
|
||||||
|
|
||||||
check, err := s.getCheck(metricPoints)
|
check, err := s.getCheck(metricPoints)
|
||||||
|
|
@ -329,10 +329,10 @@ func (s *Sensu) encodeToJSON(metricPoints []*OutputMetric) ([]byte, error) {
|
||||||
return []byte{}, err
|
return []byte{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := json.Marshal(&OutputEvent{
|
output, err := json.Marshal(&outputEvent{
|
||||||
Entity: s.OutEntity,
|
Entity: s.OutEntity,
|
||||||
Check: check,
|
Check: check,
|
||||||
Metrics: &OutputMetrics{
|
Metrics: &outputMetrics{
|
||||||
Handlers: s.getHandlers(),
|
Handlers: s.getHandlers(),
|
||||||
Metrics: metricPoints,
|
Metrics: metricPoints,
|
||||||
},
|
},
|
||||||
|
|
@ -357,28 +357,28 @@ func (s *Sensu) setEntity() error {
|
||||||
entityName = defaultHostname
|
entityName = defaultHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
s.OutEntity = &OutputEntity{
|
s.OutEntity = &outputEntity{
|
||||||
Metadata: &OutputMetadata{
|
Metadata: &outputMetadata{
|
||||||
Name: entityName,
|
Name: entityName,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.OutEntity = &OutputEntity{}
|
s.OutEntity = &outputEntity{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constructs the check payload
|
// Constructs the check payload
|
||||||
// Throws if check name is not provided
|
// Throws if check name is not provided
|
||||||
func (s *Sensu) getCheck(metricPoints []*OutputMetric) (*OutputCheck, error) {
|
func (s *Sensu) getCheck(metricPoints []*outputMetric) (*outputCheck, error) {
|
||||||
count := len(metricPoints)
|
count := len(metricPoints)
|
||||||
|
|
||||||
if s.Check == nil || s.Check.Name == nil {
|
if s.Check == nil || s.Check.Name == nil {
|
||||||
return &OutputCheck{}, errors.New("missing check name")
|
return &outputCheck{}, errors.New("missing check name")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &OutputCheck{
|
return &outputCheck{
|
||||||
Metadata: &OutputMetadata{
|
Metadata: &outputMetadata{
|
||||||
Name: *s.Check.Name,
|
Name: *s.Check.Name,
|
||||||
},
|
},
|
||||||
Status: 0, // Always OK
|
Status: 0, // Always OK
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ func TestResolveEventEndpointUrl(t *testing.T) {
|
||||||
plugin: &Sensu{
|
plugin: &Sensu{
|
||||||
AgentAPIURL: &agentAPIURL,
|
AgentAPIURL: &agentAPIURL,
|
||||||
BackendAPIURL: &backendAPIURL,
|
BackendAPIURL: &backendAPIURL,
|
||||||
Entity: &SensuEntity{
|
Entity: &sensuEntity{
|
||||||
Namespace: &entityNamespace,
|
Namespace: &entityNamespace,
|
||||||
},
|
},
|
||||||
Log: testutil.Logger{},
|
Log: testutil.Logger{},
|
||||||
|
|
@ -95,14 +95,14 @@ func TestConnectAndWrite(t *testing.T) {
|
||||||
AgentAPIURL: nil,
|
AgentAPIURL: nil,
|
||||||
BackendAPIURL: &testURL,
|
BackendAPIURL: &testURL,
|
||||||
APIKey: &testAPIKey,
|
APIKey: &testAPIKey,
|
||||||
Check: &SensuCheck{
|
Check: &sensuCheck{
|
||||||
Name: &testCheck,
|
Name: &testCheck,
|
||||||
},
|
},
|
||||||
Entity: &SensuEntity{
|
Entity: &sensuEntity{
|
||||||
Name: &testEntity,
|
Name: &testEntity,
|
||||||
Namespace: &testNamespace,
|
Namespace: &testNamespace,
|
||||||
},
|
},
|
||||||
Metrics: &SensuMetrics{
|
Metrics: &sensuMetrics{
|
||||||
Handlers: []string{testHandler},
|
Handlers: []string{testHandler},
|
||||||
},
|
},
|
||||||
Tags: map[string]string{testTagName: testTagValue},
|
Tags: map[string]string{testTagName: testTagValue},
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type Parser struct {
|
||||||
|
|
||||||
// **** Specific for object configuration ****
|
// **** Specific for object configuration ****
|
||||||
// subPathResults contains the results of sub-gjson path expressions provided in fields/tags table within object config
|
// subPathResults contains the results of sub-gjson path expressions provided in fields/tags table within object config
|
||||||
subPathResults []PathResult
|
subPathResults []pathResult
|
||||||
// iterateObjects dictates if ExpandArray function will handle objects
|
// iterateObjects dictates if ExpandArray function will handle objects
|
||||||
iterateObjects bool
|
iterateObjects bool
|
||||||
// objectConfig contains the config for an object, some info is needed while iterating over the gjson results
|
// objectConfig contains the config for an object, some info is needed while iterating over the gjson results
|
||||||
|
|
@ -78,13 +78,13 @@ type Object struct {
|
||||||
TagPaths []DataSet `toml:"tag"`
|
TagPaths []DataSet `toml:"tag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PathResult struct {
|
type pathResult struct {
|
||||||
result gjson.Result
|
result gjson.Result
|
||||||
tag bool
|
tag bool
|
||||||
DataSet
|
DataSet
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricNode struct {
|
type metricNode struct {
|
||||||
ParentIndex int
|
ParentIndex int
|
||||||
OutputName string
|
OutputName string
|
||||||
SetName string
|
SetName string
|
||||||
|
|
@ -94,7 +94,7 @@ type MetricNode struct {
|
||||||
IncludeCollection is only used when processing objects and is responsible for containing the gjson results
|
IncludeCollection is only used when processing objects and is responsible for containing the gjson results
|
||||||
found by the gjson paths provided in the FieldPaths and TagPaths configs.
|
found by the gjson paths provided in the FieldPaths and TagPaths configs.
|
||||||
*/
|
*/
|
||||||
IncludeCollection *PathResult
|
IncludeCollection *pathResult
|
||||||
|
|
||||||
Metric telegraf.Metric
|
Metric telegraf.Metric
|
||||||
gjson.Result
|
gjson.Result
|
||||||
|
|
@ -253,7 +253,7 @@ func (p *Parser) processMetric(input []byte, data []DataSet, tag bool, timestamp
|
||||||
}
|
}
|
||||||
setName = strings.ReplaceAll(setName, " ", "_")
|
setName = strings.ReplaceAll(setName, " ", "_")
|
||||||
|
|
||||||
mNode := MetricNode{
|
mNode := metricNode{
|
||||||
OutputName: setName,
|
OutputName: setName,
|
||||||
SetName: setName,
|
SetName: setName,
|
||||||
DesiredType: c.Type,
|
DesiredType: c.Type,
|
||||||
|
|
@ -316,8 +316,8 @@ func mergeMetric(a telegraf.Metric, m telegraf.Metric) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// expandArray will recursively create a new MetricNode for each element in a JSON array or single value
|
// expandArray will recursively create a new metricNode for each element in a JSON array or single value
|
||||||
func (p *Parser) expandArray(result MetricNode, timestamp time.Time) ([]telegraf.Metric, error) {
|
func (p *Parser) expandArray(result metricNode, timestamp time.Time) ([]telegraf.Metric, error) {
|
||||||
var results []telegraf.Metric
|
var results []telegraf.Metric
|
||||||
|
|
||||||
if result.IsObject() {
|
if result.IsObject() {
|
||||||
|
|
@ -410,7 +410,7 @@ func (p *Parser) expandArray(result MetricNode, timestamp time.Time) ([]telegraf
|
||||||
desiredType := result.DesiredType
|
desiredType := result.DesiredType
|
||||||
|
|
||||||
if len(p.objectConfig.FieldPaths) > 0 || len(p.objectConfig.TagPaths) > 0 {
|
if len(p.objectConfig.FieldPaths) > 0 || len(p.objectConfig.TagPaths) > 0 {
|
||||||
var pathResult *PathResult
|
var pathResult *pathResult
|
||||||
// When IncludeCollection isn't nil, that means the current result is included in the collection.
|
// When IncludeCollection isn't nil, that means the current result is included in the collection.
|
||||||
if result.IncludeCollection != nil {
|
if result.IncludeCollection != nil {
|
||||||
pathResult = result.IncludeCollection
|
pathResult = result.IncludeCollection
|
||||||
|
|
@ -453,7 +453,7 @@ func (p *Parser) expandArray(result MetricNode, timestamp time.Time) ([]telegraf
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Parser) existsInpathResults(index int) *PathResult {
|
func (p *Parser) existsInpathResults(index int) *pathResult {
|
||||||
for _, f := range p.subPathResults {
|
for _, f := range p.subPathResults {
|
||||||
if f.result.Index == index {
|
if f.result.Index == index {
|
||||||
return &f
|
return &f
|
||||||
|
|
@ -490,7 +490,7 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T
|
||||||
|
|
||||||
scopedJSON := []byte(result.Raw)
|
scopedJSON := []byte(result.Raw)
|
||||||
for _, f := range c.FieldPaths {
|
for _, f := range c.FieldPaths {
|
||||||
var r PathResult
|
var r pathResult
|
||||||
r.result = gjson.GetBytes(scopedJSON, f.Path)
|
r.result = gjson.GetBytes(scopedJSON, f.Path)
|
||||||
if err := p.checkResult(r.result, f.Path); err != nil {
|
if err := p.checkResult(r.result, f.Path); err != nil {
|
||||||
if f.Optional {
|
if f.Optional {
|
||||||
|
|
@ -503,7 +503,7 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range c.TagPaths {
|
for _, f := range c.TagPaths {
|
||||||
var r PathResult
|
var r pathResult
|
||||||
r.result = gjson.GetBytes(scopedJSON, f.Path)
|
r.result = gjson.GetBytes(scopedJSON, f.Path)
|
||||||
if err := p.checkResult(r.result, f.Path); err != nil {
|
if err := p.checkResult(r.result, f.Path); err != nil {
|
||||||
if f.Optional {
|
if f.Optional {
|
||||||
|
|
@ -516,7 +516,7 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T
|
||||||
p.subPathResults = append(p.subPathResults, r)
|
p.subPathResults = append(p.subPathResults, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
rootObject := MetricNode{
|
rootObject := metricNode{
|
||||||
Metric: metric.New(
|
Metric: metric.New(
|
||||||
p.measurementName,
|
p.measurementName,
|
||||||
map[string]string{},
|
map[string]string{},
|
||||||
|
|
@ -539,7 +539,7 @@ func (p *Parser) processObjects(input []byte, objects []Object, timestamp time.T
|
||||||
|
|
||||||
// combineObject will add all fields/tags to a single metric
|
// combineObject will add all fields/tags to a single metric
|
||||||
// If the object has multiple array's as elements it won't comine those, they will remain separate metrics
|
// If the object has multiple array's as elements it won't comine those, they will remain separate metrics
|
||||||
func (p *Parser) combineObject(result MetricNode, timestamp time.Time) ([]telegraf.Metric, error) {
|
func (p *Parser) combineObject(result metricNode, timestamp time.Time) ([]telegraf.Metric, error) {
|
||||||
var results []telegraf.Metric
|
var results []telegraf.Metric
|
||||||
if result.IsArray() || result.IsObject() {
|
if result.IsArray() || result.IsObject() {
|
||||||
var err error
|
var err error
|
||||||
|
|
|
||||||
|
|
@ -8,29 +8,29 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrEOF = errors.New("EOF")
|
errEOF = errors.New("EOF")
|
||||||
ErrInvalidTimestamp = errors.New("invalid timestamp")
|
errInvalidTimestamp = errors.New("invalid timestamp")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ElementParser interface {
|
type elementParser interface {
|
||||||
parse(p *PointParser, pt *Point) error
|
parse(p *PointParser, pt *Point) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type NameParser struct{}
|
type nameParser struct{}
|
||||||
type ValueParser struct{}
|
type valueParser struct{}
|
||||||
type TimestampParser struct {
|
type timestampParser struct {
|
||||||
optional bool
|
optional bool
|
||||||
}
|
}
|
||||||
type WhiteSpaceParser struct {
|
type whiteSpaceParser struct {
|
||||||
nextOptional bool
|
nextOptional bool
|
||||||
}
|
}
|
||||||
type TagParser struct{}
|
type tagParser struct{}
|
||||||
type LoopedParser struct {
|
type loopedParser struct {
|
||||||
wrappedParser ElementParser
|
wrappedParser elementParser
|
||||||
wsParser *WhiteSpaceParser
|
wsParser *whiteSpaceParser
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *NameParser) parse(p *PointParser, pt *Point) error {
|
func (ep *nameParser) parse(p *PointParser, pt *Point) error {
|
||||||
//Valid characters are: a-z, A-Z, 0-9, hyphen ("-"), underscore ("_"), dot (".").
|
//Valid characters are: a-z, A-Z, 0-9, hyphen ("-"), underscore ("_"), dot (".").
|
||||||
// Forward slash ("/") and comma (",") are allowed if metricName is enclosed in double quotes.
|
// Forward slash ("/") and comma (",") are allowed if metricName is enclosed in double quotes.
|
||||||
// Delta (U+2206) is allowed as the first character of the
|
// Delta (U+2206) is allowed as the first character of the
|
||||||
|
|
@ -44,7 +44,7 @@ func (ep *NameParser) parse(p *PointParser, pt *Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *ValueParser) parse(p *PointParser, pt *Point) error {
|
func (ep *valueParser) parse(p *PointParser, pt *Point) error {
|
||||||
tok, lit := p.scan()
|
tok, lit := p.scan()
|
||||||
if tok == EOF {
|
if tok == EOF {
|
||||||
return fmt.Errorf("found %q, expected number", lit)
|
return fmt.Errorf("found %q, expected number", lit)
|
||||||
|
|
@ -69,7 +69,7 @@ func (ep *ValueParser) parse(p *PointParser, pt *Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *TimestampParser) parse(p *PointParser, pt *Point) error {
|
func (ep *timestampParser) parse(p *PointParser, pt *Point) error {
|
||||||
tok, lit := p.scan()
|
tok, lit := p.scan()
|
||||||
if tok == EOF {
|
if tok == EOF {
|
||||||
if ep.optional {
|
if ep.optional {
|
||||||
|
|
@ -84,7 +84,7 @@ func (ep *TimestampParser) parse(p *PointParser, pt *Point) error {
|
||||||
p.unscanTokens(2)
|
p.unscanTokens(2)
|
||||||
return setTimestamp(pt, 0, 1)
|
return setTimestamp(pt, 0, 1)
|
||||||
}
|
}
|
||||||
return ErrInvalidTimestamp
|
return errInvalidTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
p.writeBuf.Reset()
|
p.writeBuf.Reset()
|
||||||
|
|
@ -115,7 +115,7 @@ func setTimestamp(pt *Point, ts int64, numDigits int) error {
|
||||||
} else if numDigits != 10 {
|
} else if numDigits != 10 {
|
||||||
// must be in seconds, return error if not 0
|
// must be in seconds, return error if not 0
|
||||||
if ts != 0 {
|
if ts != 0 {
|
||||||
return ErrInvalidTimestamp
|
return errInvalidTimestamp
|
||||||
}
|
}
|
||||||
ts = getCurrentTime()
|
ts = getCurrentTime()
|
||||||
}
|
}
|
||||||
|
|
@ -123,21 +123,21 @@ func setTimestamp(pt *Point, ts int64, numDigits int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *LoopedParser) parse(p *PointParser, pt *Point) error {
|
func (ep *loopedParser) parse(p *PointParser, pt *Point) error {
|
||||||
for {
|
for {
|
||||||
err := ep.wrappedParser.parse(p, pt)
|
err := ep.wrappedParser.parse(p, pt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = ep.wsParser.parse(p, pt)
|
err = ep.wsParser.parse(p, pt)
|
||||||
if errors.Is(err, ErrEOF) {
|
if errors.Is(err, errEOF) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *TagParser) parse(p *PointParser, pt *Point) error {
|
func (ep *tagParser) parse(p *PointParser, pt *Point) error {
|
||||||
k, err := parseLiteral(p)
|
k, err := parseLiteral(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if k == "" {
|
if k == "" {
|
||||||
|
|
@ -162,7 +162,7 @@ func (ep *TagParser) parse(p *PointParser, pt *Point) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *WhiteSpaceParser) parse(p *PointParser, _ *Point) error {
|
func (ep *whiteSpaceParser) parse(p *PointParser, _ *Point) error {
|
||||||
tok := Ws
|
tok := Ws
|
||||||
for tok == Ws {
|
for tok == Ws {
|
||||||
tok, _ = p.scan()
|
tok, _ = p.scan()
|
||||||
|
|
@ -170,7 +170,7 @@ func (ep *WhiteSpaceParser) parse(p *PointParser, _ *Point) error {
|
||||||
|
|
||||||
if tok == EOF {
|
if tok == EOF {
|
||||||
if !ep.nextOptional {
|
if !ep.nextOptional {
|
||||||
return ErrEOF
|
return errEOF
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,18 +39,18 @@ type PointParser struct {
|
||||||
}
|
}
|
||||||
scanBuf bytes.Buffer // buffer reused for scanning tokens
|
scanBuf bytes.Buffer // buffer reused for scanning tokens
|
||||||
writeBuf bytes.Buffer // buffer reused for parsing elements
|
writeBuf bytes.Buffer // buffer reused for parsing elements
|
||||||
Elements []ElementParser
|
Elements []elementParser
|
||||||
parent *Parser
|
parent *Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWavefrontElements returns a slice of ElementParser's for the Graphite format
|
// NewWavefrontElements returns a slice of elementParser's for the Graphite format
|
||||||
func NewWavefrontElements() []ElementParser {
|
func NewWavefrontElements() []elementParser {
|
||||||
var elements []ElementParser
|
var elements []elementParser
|
||||||
wsParser := WhiteSpaceParser{}
|
wsParser := whiteSpaceParser{}
|
||||||
wsParserNextOpt := WhiteSpaceParser{nextOptional: true}
|
wsParserNextOpt := whiteSpaceParser{nextOptional: true}
|
||||||
repeatParser := LoopedParser{wrappedParser: &TagParser{}, wsParser: &wsParser}
|
repeatParser := loopedParser{wrappedParser: &tagParser{}, wsParser: &wsParser}
|
||||||
elements = append(elements, &NameParser{}, &wsParser, &ValueParser{}, &wsParserNextOpt,
|
elements = append(elements, &nameParser{}, &wsParser, &valueParser{}, &wsParserNextOpt,
|
||||||
&TimestampParser{optional: true}, &wsParserNextOpt, &repeatParser)
|
×tampParser{optional: true}, &wsParserNextOpt, &repeatParser)
|
||||||
return elements
|
return elements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,46 +17,46 @@ const helpString = "Telegraf collected metric"
|
||||||
|
|
||||||
type TimeFunc func() time.Time
|
type TimeFunc func() time.Time
|
||||||
|
|
||||||
type MetricFamily struct {
|
type metricFamily struct {
|
||||||
Name string
|
Name string
|
||||||
Type telegraf.ValueType
|
Type telegraf.ValueType
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
Labels []LabelPair
|
Labels []labelPair
|
||||||
Time time.Time
|
Time time.Time
|
||||||
AddTime time.Time
|
AddTime time.Time
|
||||||
Scaler *Scaler
|
Scaler *scaler
|
||||||
Histogram *Histogram
|
Histogram *histogram
|
||||||
Summary *Summary
|
Summary *summary
|
||||||
}
|
}
|
||||||
|
|
||||||
type LabelPair struct {
|
type labelPair struct {
|
||||||
Name string
|
Name string
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scaler struct {
|
type scaler struct {
|
||||||
Value float64
|
Value float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Bucket struct {
|
type bucket struct {
|
||||||
Bound float64
|
Bound float64
|
||||||
Count uint64
|
Count uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Quantile struct {
|
type quantile struct {
|
||||||
Quantile float64
|
Quantile float64
|
||||||
Value float64
|
Value float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Histogram struct {
|
type histogram struct {
|
||||||
Buckets []Bucket
|
Buckets []bucket
|
||||||
Count uint64
|
Count uint64
|
||||||
Sum float64
|
Sum float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Histogram) merge(b Bucket) {
|
func (h *histogram) merge(b bucket) {
|
||||||
for i := range h.Buckets {
|
for i := range h.Buckets {
|
||||||
if h.Buckets[i].Bound == b.Bound {
|
if h.Buckets[i].Bound == b.Bound {
|
||||||
h.Buckets[i].Count = b.Count
|
h.Buckets[i].Count = b.Count
|
||||||
|
|
@ -66,13 +66,13 @@ func (h *Histogram) merge(b Bucket) {
|
||||||
h.Buckets = append(h.Buckets, b)
|
h.Buckets = append(h.Buckets, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Summary struct {
|
type summary struct {
|
||||||
Quantiles []Quantile
|
Quantiles []quantile
|
||||||
Count uint64
|
Count uint64
|
||||||
Sum float64
|
Sum float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Summary) merge(q Quantile) {
|
func (s *summary) merge(q quantile) {
|
||||||
for i := range s.Quantiles {
|
for i := range s.Quantiles {
|
||||||
if s.Quantiles[i].Quantile == q.Quantile {
|
if s.Quantiles[i].Quantile == q.Quantile {
|
||||||
s.Quantiles[i].Value = q.Value
|
s.Quantiles[i].Value = q.Value
|
||||||
|
|
@ -82,9 +82,9 @@ func (s *Summary) merge(q Quantile) {
|
||||||
s.Quantiles = append(s.Quantiles, q)
|
s.Quantiles = append(s.Quantiles, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricKey uint64
|
type metricKey uint64
|
||||||
|
|
||||||
func MakeMetricKey(labels []LabelPair) MetricKey {
|
func makeMetricKey(labels []labelPair) metricKey {
|
||||||
h := fnv.New64a()
|
h := fnv.New64a()
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
h.Write([]byte(label.Name))
|
h.Write([]byte(label.Name))
|
||||||
|
|
@ -92,28 +92,28 @@ func MakeMetricKey(labels []LabelPair) MetricKey {
|
||||||
h.Write([]byte(label.Value))
|
h.Write([]byte(label.Value))
|
||||||
h.Write([]byte("\x00"))
|
h.Write([]byte("\x00"))
|
||||||
}
|
}
|
||||||
return MetricKey(h.Sum64())
|
return metricKey(h.Sum64())
|
||||||
}
|
}
|
||||||
|
|
||||||
type Entry struct {
|
type entry struct {
|
||||||
Family MetricFamily
|
Family metricFamily
|
||||||
Metrics map[MetricKey]*Metric
|
Metrics map[metricKey]*Metric
|
||||||
}
|
}
|
||||||
|
|
||||||
type Collection struct {
|
type Collection struct {
|
||||||
Entries map[MetricFamily]Entry
|
Entries map[metricFamily]entry
|
||||||
config FormatConfig
|
config FormatConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCollection(config FormatConfig) *Collection {
|
func NewCollection(config FormatConfig) *Collection {
|
||||||
cache := &Collection{
|
cache := &Collection{
|
||||||
Entries: make(map[MetricFamily]Entry),
|
Entries: make(map[metricFamily]entry),
|
||||||
config: config,
|
config: config,
|
||||||
}
|
}
|
||||||
return cache
|
return cache
|
||||||
}
|
}
|
||||||
|
|
||||||
func hasLabel(name string, labels []LabelPair) bool {
|
func hasLabel(name string, labels []labelPair) bool {
|
||||||
for _, label := range labels {
|
for _, label := range labels {
|
||||||
if name == label.Name {
|
if name == label.Name {
|
||||||
return true
|
return true
|
||||||
|
|
@ -122,8 +122,8 @@ func hasLabel(name string, labels []LabelPair) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) createLabels(metric telegraf.Metric) []LabelPair {
|
func (c *Collection) createLabels(metric telegraf.Metric) []labelPair {
|
||||||
labels := make([]LabelPair, 0, len(metric.TagList()))
|
labels := make([]labelPair, 0, len(metric.TagList()))
|
||||||
for _, tag := range metric.TagList() {
|
for _, tag := range metric.TagList() {
|
||||||
// Ignore special tags for histogram and summary types.
|
// Ignore special tags for histogram and summary types.
|
||||||
switch metric.Type() {
|
switch metric.Type() {
|
||||||
|
|
@ -142,7 +142,7 @@ func (c *Collection) createLabels(metric telegraf.Metric) []LabelPair {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
labels = append(labels, LabelPair{Name: name, Value: tag.Value})
|
labels = append(labels, labelPair{Name: name, Value: tag.Value})
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.config.StringAsLabel {
|
if !c.config.StringAsLabel {
|
||||||
|
|
@ -167,7 +167,7 @@ func (c *Collection) createLabels(metric telegraf.Metric) []LabelPair {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
labels = append(labels, LabelPair{Name: name, Value: value})
|
labels = append(labels, labelPair{Name: name, Value: value})
|
||||||
addedFieldLabel = true
|
addedFieldLabel = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,23 +190,23 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
}
|
}
|
||||||
metricType := c.config.TypeMappings.DetermineType(metricName, metric)
|
metricType := c.config.TypeMappings.DetermineType(metricName, metric)
|
||||||
|
|
||||||
family := MetricFamily{
|
family := metricFamily{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Type: metricType,
|
Type: metricType,
|
||||||
}
|
}
|
||||||
|
|
||||||
entry, ok := c.Entries[family]
|
singleEntry, ok := c.Entries[family]
|
||||||
if !ok {
|
if !ok {
|
||||||
entry = Entry{
|
singleEntry = entry{
|
||||||
Family: family,
|
Family: family,
|
||||||
Metrics: make(map[MetricKey]*Metric),
|
Metrics: make(map[metricKey]*Metric),
|
||||||
}
|
}
|
||||||
c.Entries[family] = entry
|
c.Entries[family] = singleEntry
|
||||||
}
|
}
|
||||||
|
|
||||||
metricKey := MakeMetricKey(labels)
|
metricKey := makeMetricKey(labels)
|
||||||
|
|
||||||
m, ok := entry.Metrics[metricKey]
|
m, ok := singleEntry.Metrics[metricKey]
|
||||||
if ok {
|
if ok {
|
||||||
// A batch of metrics can contain multiple values for a single
|
// A batch of metrics can contain multiple values for a single
|
||||||
// Prometheus sample. If this metric is older than the existing
|
// Prometheus sample. If this metric is older than the existing
|
||||||
|
|
@ -231,17 +231,17 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Time: metric.Time(),
|
Time: metric.Time(),
|
||||||
AddTime: now,
|
AddTime: now,
|
||||||
Scaler: &Scaler{Value: value},
|
Scaler: &scaler{Value: value},
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.Metrics[metricKey] = m
|
singleEntry.Metrics[metricKey] = m
|
||||||
case telegraf.Histogram:
|
case telegraf.Histogram:
|
||||||
if m == nil {
|
if m == nil {
|
||||||
m = &Metric{
|
m = &Metric{
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Time: metric.Time(),
|
Time: metric.Time(),
|
||||||
AddTime: now,
|
AddTime: now,
|
||||||
Histogram: &Histogram{},
|
Histogram: &histogram{},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.Time = metric.Time()
|
m.Time = metric.Time()
|
||||||
|
|
@ -263,7 +263,7 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Histogram.merge(Bucket{
|
m.Histogram.merge(bucket{
|
||||||
Bound: bound,
|
Bound: bound,
|
||||||
Count: count,
|
Count: count,
|
||||||
})
|
})
|
||||||
|
|
@ -285,14 +285,14 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.Metrics[metricKey] = m
|
singleEntry.Metrics[metricKey] = m
|
||||||
case telegraf.Summary:
|
case telegraf.Summary:
|
||||||
if m == nil {
|
if m == nil {
|
||||||
m = &Metric{
|
m = &Metric{
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Time: metric.Time(),
|
Time: metric.Time(),
|
||||||
AddTime: now,
|
AddTime: now,
|
||||||
Summary: &Summary{},
|
Summary: &summary{},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
m.Time = metric.Time()
|
m.Time = metric.Time()
|
||||||
|
|
@ -318,7 +318,7 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
quantile, err := strconv.ParseFloat(quantileTag, 64)
|
singleQuantile, err := strconv.ParseFloat(quantileTag, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -328,13 +328,13 @@ func (c *Collection) Add(metric telegraf.Metric, now time.Time) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Summary.merge(Quantile{
|
m.Summary.merge(quantile{
|
||||||
Quantile: quantile,
|
Quantile: singleQuantile,
|
||||||
Value: value,
|
Value: value,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.Metrics[metricKey] = m
|
singleEntry.Metrics[metricKey] = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -353,8 +353,8 @@ func (c *Collection) Expire(now time.Time, age time.Duration) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) GetEntries() []Entry {
|
func (c *Collection) GetEntries() []entry {
|
||||||
entries := make([]Entry, 0, len(c.Entries))
|
entries := make([]entry, 0, len(c.Entries))
|
||||||
for _, entry := range c.Entries {
|
for _, entry := range c.Entries {
|
||||||
entries = append(entries, entry)
|
entries = append(entries, entry)
|
||||||
}
|
}
|
||||||
|
|
@ -373,7 +373,7 @@ func (c *Collection) GetEntries() []Entry {
|
||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Collection) GetMetrics(entry Entry) []*Metric {
|
func (c *Collection) GetMetrics(entry entry) []*Metric {
|
||||||
metrics := make([]*Metric, 0, len(entry.Metrics))
|
metrics := make([]*Metric, 0, len(entry.Metrics))
|
||||||
for _, metric := range entry.Metrics {
|
for _, metric := range entry.Metrics {
|
||||||
metrics = append(metrics, metric)
|
metrics = append(metrics, metric)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue