# Execute a custom SQL query using mysql metricbeat module

**URL:** <https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [March 28, 2018, 3:14pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960 "2018-03-28T15:14:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [March 28, 2018, 3:14pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/1 "2018-03-28T15:14:07Z")

</div>

Hi,  
I want to run a custom SQL query (to get the count of records in a table) using mysql metricbeat module. Is this possible?

If this is not possible, then I want to create a custom metricset in mysql metricbeat module using the command "make create-metricset" but I dont know what is the location of Beat directory? (I tried /usr/share/metricbeat, /usr/share/metricbeat/bin, /etc/metricbeat but none of them worked)

Also, Where can I view the configuration (({metricset}.go, \_meta/docs.asciidoc, meta/data.json, \_meta/fields.yml)) for existing metricsets like the "status" metricset of mysql metricbeat module?

---

<div class="post-metadata">

**Author:** ![kvch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kvch/32/72058_2.png) [@kvch](https://discuss.elastic.co/u/kvch)\
**Post date:** [March 28, 2018, 4:43pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/2 "2018-03-28T16:43:07Z")

</div>

It is not possible to run a custom SQL query right now using the MySQL module.

To generate a new metricset, you need to clone our repository: [https://github.com/elastic/beats](https://github.com/elastic/beats)  
You need to run `make create-metricset` inside the metricbeat folder of the repository. The default value of the path of the beats directory would be sufficient in this case. This make target generates and copies the files you mentioned in your comment.

---

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [March 30, 2018, 10:25am UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/3 "2018-03-30T10:25:52Z")

</div>

Hi Kvch,  
What should be the GOPATH and GOROOT environment variable values?

Also, after I create the metricset, how do I install the new package in Linux machine. Earlier I have used the rpm package to deploy metricbeat in CentOS

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [March 30, 2018, 12:42pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/4 "2018-03-30T12:42:51Z")

</div>

@firstpostcommenter You should take a look at our [contributing guide](https://www.elastic.co/guide/en/beats/devguide/current/beats-contributing.html) to get your environment configured.

---

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [April 5, 2018, 11:25am UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/5 "2018-04-05T11:25:23Z")

</div>

Hi @pierhugues,  
How to do a build in local machine, since I get the error that the package "[github.com/elastic/beats/metricbeat/cmd](http://github.com/elastic/beats/metricbeat/cmd)" is not found when I try to run the main.go file present in metricbeat folder using the command `go run main.go`

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [April 5, 2018, 1:24pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/6 "2018-04-05T13:24:37Z")

</div>

If you have following the instruction in the documentation `$GOROOT` and `$GOPATH`, should be set correct.

After that inside the metricbeat directory you should be able to run `make` which will create the `metricbeat` binary.

---

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [April 5, 2018, 2:03pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/7 "2018-04-05T14:03:01Z")

</div>

Hi @pierhugues,  
When I try to run `make` command in the metricbeat directory I get the below error. I am running in windows:  
: 67.6% of statements  
ok [github.com/elastic/beats/metricbeat/module/vsphere/virtualmachine](http://github.com/elastic/beats/metricbeat/module/vsphere/virtualmachine)  
1.363s coverage: 39.8% of statements  
ok [github.com/elastic/beats/metricbeat/module/windows/service](http://github.com/elastic/beats/metricbeat/module/windows/service) 1.517s  
coverage: 74.9% of statements  
command [go test -race -cover -coverprofile C:\Users{user}\AppData\Local\Temp  
gotestcover-004682626 [github.com/elastic/beats/metricbeat/module/windows/perfmon](http://github.com/elastic/beats/metricbeat/module/windows/perfmon)  
]: exit status 1  
--- FAIL: TestData (0.83s)  
modules.go:77: failed to create new MetricSet 1 error: initialization of  
reader failed: failed to add counter (query="\FileSystem Disk Activity(\_Total)  
FileSystem Bytes Read"): The specified object was not found on the computer.  
FAIL  
coverage: 76.0% of statements  
FAIL [github.com/elastic/beats/metricbeat/module/windows/perfmon](http://github.com/elastic/beats/metricbeat/module/windows/perfmon) 5.941s

---

<div class="post-metadata">

**Author:** ![pierhugues](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pierhugues/32/48383_2.png) [@pierhugues](https://discuss.elastic.co/u/pierhugues)\
**Post date:** [April 6, 2018, 1:35pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/8 "2018-04-06T13:35:26Z")

</div>

What version of go you are running?

---

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [April 10, 2018, 8:55am UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/9 "2018-04-10T08:55:17Z")

</div>

Hi @pierhugues,  
I am using 1.10 version (go version go1.10.1 windows/amd64).

I have manually created gotestcover using the code [https://github.com/pierrre/gotestcover](https://github.com/pierrre/gotestcover)

I am unable to run `make package` command due to this error

---

<div class="post-metadata">

**Author:** ![firstpostcommenter](https://avatars.discourse-cdn.com/v4/letter/f/ad7895/32.png) [@firstpostcommenter](https://discuss.elastic.co/u/firstpostcommenter)\
**Post date:** [April 10, 2018, 6:21pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/10 "2018-04-10T18:21:03Z")

</div>

Hi @pierhugues,  
Is there any other way for me to create rpm file from the metricbeat code  
If I have the code in github, is there a travis-CI build setting that I can configure to generate rpm file from the code. I want to generate the rpm file and install this rpm file in Cent OS

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 8, 2018, 6:21pm UTC](https://discuss.elastic.co/t/execute-a-custom-sql-query-using-mysql-metricbeat-module/125960/11 "2018-05-08T18:21:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
