Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add ActiveMQ input plugin #2689

Merged
merged 7 commits into from
Aug 13, 2018
Merged

Add ActiveMQ input plugin #2689

merged 7 commits into from
Aug 13, 2018

Conversation

mlabouardy
Copy link
Contributor

@mlabouardy mlabouardy commented Apr 19, 2017

Resolves #2622

Required for all PRs:

  • CHANGELOG.md updated (we recommend not updating this until the PR has been approved by a maintainer)
  • Sign CLA (if not already signed)
  • README.md updated (if adding a new plugin)

@nhaugo nhaugo requested a review from danielnelson April 19, 2017 17:09
@danielnelson danielnelson added this to the 1.4.0 milestone Apr 19, 2017
$ ./telegraf -config telegraf.conf -input-filter activemq -test
queues_metrics,name=sandra,host=88284b2fe51b consumer_count=0i,enqueue_count=0i,dequeue_count=0i,size=0i 1492610703000000000
queues_metrics,name=Test,host=88284b2fe51b dequeue_count=0i,size=0i,consumer_count=0i,enqueue_count=0i 1492610703000000000
topics_metrics,name=ActiveMQ.Advisory.MasterBroker\ ,host=88284b2fe51b size=0i,consumer_count=0i,enqueue_count=1i,dequeue_count=0i 1492610703000000000
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like there might be a bug where the name has trailing whitespace characters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to regenerate this section

## Required password used for HTTP Basic Authentication
# password = "admin"
## Required ActiveMQ webadmin root path
# webadmin = "admin"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do a two space indent here

a.GatherSubscribersMetrics(acc, subscribers)

return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you reduce the amount of vertical whitespace in this function?

defer resp.Body.Close()

return ioutil.ReadAll(resp.Body)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you reduce the amount of vertical whitespace in this function?

@danielnelson danielnelson modified the milestones: 1.4.0, 1.5.0 Aug 14, 2017
@danielnelson danielnelson added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Aug 24, 2017
@danielnelson danielnelson removed this from the 1.5.0 milestone Sep 13, 2017
vasechko-sergey pushed a commit to vasechko-sergey/telegraf that referenced this pull request Mar 30, 2018
remove trailing spaces for queue name in gather metrics
remove indent
mlabouardy added a commit to mlabouardy/telegraf that referenced this pull request Mar 30, 2018
@danielnelson
Copy link
Contributor

@mlabouardy I think the tests will pass if we rebase the branch, could you do that for me and then I'll take a final look.

mlabouardy and others added 3 commits August 4, 2018 23:03
remove trailing spaces for queue name in gather metrics
remove indent
@mlabouardy
Copy link
Contributor Author

@danielnelson done

Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

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

Here are a few minor things we should address before merging:

}

func (a *ActiveMQ) GetMetrics(keyword string) ([]byte, error) {
client := &http.Client{}
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid any issues sharing the underlying http.Transport we don't use the DefaultTransport. We can use the same pattern as the apache plugin:

Add a field to the ActiveMQ struct to hold the client, and initialize it the first call to Gather:

if n.client == nil {
client, err := n.createHttpClient()
if err != nil {
return err
}
n.client = client
}

Initialization:

func (n *Apache) createHttpClient() (*http.Client, error) {
tlsCfg, err := n.ClientConfig.TLSConfig()
if err != nil {
return nil, err
}
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsCfg,
},
Timeout: n.ResponseTimeout.Duration,
}
return client, nil
}

records["enqueue_count"] = queue.Stats.EnqueueCount
records["dequeue_count"] = queue.Stats.DequeueCount

acc.AddFields("queues_metrics", records, tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid confusion with other plugins we should call this activemq_queues.

records["enqueue_count"] = topic.Stats.EnqueueCount
records["dequeue_count"] = topic.Stats.DequeueCount

acc.AddFields("topics_metrics", records, tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename activemq_topics

records["enqueue_counter"] = subscriber.Stats.EnqueueCounter
records["dequeue_counter"] = subscriber.Stats.DequeueCounter

acc.AddFields("subscribers_metrics", records, tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename activemq_subscribers

- enqueue_counter
- dequeue_counter

### Tags:
Copy link
Contributor

Choose a reason for hiding this comment

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

We will also need a tag for the server for differentiation when running the plugin multiple times. Following the discussion on #4413, let's add source and port tags to all three measurements:

source=192.168.50.10,port=8161

$ ./telegraf -config telegraf.conf -input-filter activemq -test
queues_metrics,name=sandra,host=88284b2fe51b consumer_count=0i,enqueue_count=0i,dequeue_count=0i,size=0i 1492610703000000000
queues_metrics,name=Test,host=88284b2fe51b dequeue_count=0i,size=0i,consumer_count=0i,enqueue_count=0i 1492610703000000000
topics_metrics,name=ActiveMQ.Advisory.MasterBroker\ ,host=88284b2fe51b size=0i,consumer_count=0i,enqueue_count=1i,dequeue_count=0i 1492610703000000000
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to regenerate this section

@mlabouardy
Copy link
Contributor Author

@danielnelson done

@mlabouardy
Copy link
Contributor Author

@danielnelson I cannot make the test pass, any idea what I did wrong ?

Copy link
Contributor

@danielnelson danielnelson left a comment

Choose a reason for hiding this comment

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

I think these are the cause of test failures:


tags["name"] = topic.Name
tags["source"] = a.Server
tags["port"] = string(a.Port)
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work, instead use strconv.FormatInt.


var acc testutil.Accumulator

activeMQ := new(ActiveMQ)
Copy link
Contributor

Choose a reason for hiding this comment

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

You will need to initialize the struct in the same way as in the init function:

activeMQ := &ActiveMQ{
	Server: "localhost",
	Port:   8161,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mlabouardy
Copy link
Contributor Author

@danielnelson resolved

var sampleConfig = `
## Required ActiveMQ Endpoint
# server = "192.168.50.10"
## Required ActiveMQ port
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick/suggestion: add newlines between config options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mlabouardy
Copy link
Contributor Author

@danielnelson when this can be merged ? :)

@glinton glinton added this to the 1.8.0 milestone Aug 13, 2018
@glinton glinton merged commit b9ff1d0 into influxdata:master Aug 13, 2018
rgitzel pushed a commit to rgitzel/telegraf that referenced this pull request Oct 17, 2018
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
otherpirate pushed a commit to otherpirate/telegraf that referenced this pull request Mar 15, 2019
dupondje pushed a commit to dupondje/telegraf that referenced this pull request Apr 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin new plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants