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

Linux recipes for MySQL #100

Merged
merged 122 commits into from
Dec 22, 2020
Merged
Show file tree
Hide file tree
Changes from 121 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
351903b
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 3, 2020
f0e07d4
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 4, 2020
193c75d
feat(mysql): added recipes for linux
JakubKotkowiak Dec 4, 2020
0608483
refactor(mysql): removed metrics section, adjusted role in labels
JakubKotkowiak Dec 4, 2020
c0222b3
refactor(recipe): fixed input vars, renamed recipe to rhel
JakubKotkowiak Dec 7, 2020
e6a3832
feat(mysql): added deployment tasks and test definitions
JakubKotkowiak Dec 7, 2020
bd006b2
refactor(definitions): added ami_name
JakubKotkowiak Dec 7, 2020
60aa135
refactor(mysql): extended debian deploy tasks
JakubKotkowiak Dec 7, 2020
1be7ca8
refactor(tasks): added dkpg to the task
JakubKotkowiak Dec 8, 2020
8599ac7
refactor(tasks): fixed typo in task
JakubKotkowiak Dec 8, 2020
006d995
refactor(tasks): fixed ami names
JakubKotkowiak Dec 8, 2020
c53eba0
refactor(tasks): adapted tasks
JakubKotkowiak Dec 8, 2020
03e3664
refactor(tasks): remove obsolete test
JakubKotkowiak Dec 8, 2020
4eb3175
refactor(tasks): modify restart command
JakubKotkowiak Dec 8, 2020
522108e
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 8, 2020
0b1e53d
refactor(recipes): small adaptations for new schema
JakubKotkowiak Dec 8, 2020
8df1f94
refactor(recipes): changed instance size
JakubKotkowiak Dec 8, 2020
1263363
refactor(definitions): changed ami name
JakubKotkowiak Dec 8, 2020
3a2a9ca
refactor(tasks): fix deploy tasks to include necessary dependencies
JakubKotkowiak Dec 9, 2020
0f9242b
refactor(tasks): added missing permissions and changed implementation…
JakubKotkowiak Dec 9, 2020
c8e3206
refactor(tasks): verify that mysql is running
JakubKotkowiak Dec 9, 2020
c0745f4
refactor(tasks): ignore error for mysql installation
JakubKotkowiak Dec 9, 2020
b15d3a5
refactor(tasks): added systemctl, modify restart for debian
JakubKotkowiak Dec 9, 2020
61a4fef
refactor(tasks): change the way that starting mysql is called
JakubKotkowiak Dec 9, 2020
b4990dd
refactor(tasks): changed name of mysql service to start
JakubKotkowiak Dec 9, 2020
eaebb5b
refactor(tasks): check different way to install mysql
JakubKotkowiak Dec 9, 2020
896ebee
refactor(tasks): fix indentation in debian task
JakubKotkowiak Dec 9, 2020
eb6083d
refactor(tasks): change rhel start mysql to systemctl
JakubKotkowiak Dec 9, 2020
2c0ba2c
refactor(tasks): add root permissions to start mysql service instruction
JakubKotkowiak Dec 9, 2020
c97d73c
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 9, 2020
4fc278e
refactor(tasks): add user and db
JakubKotkowiak Dec 10, 2020
cf1eeaf
refactor(recipes): fixed spacing issue
JakubKotkowiak Dec 10, 2020
9691c6f
refactor(tasks): modify db and user creation tasks
JakubKotkowiak Dec 10, 2020
4a44eb1
refactor(tasks): fix create db command
JakubKotkowiak Dec 10, 2020
4faac6c
refactor(tasks): fixed create user command
JakubKotkowiak Dec 10, 2020
db42889
refactor(tmp): temporarily changed input variables to variables
JakubKotkowiak Dec 10, 2020
4ada089
refactor(tasks): modified database name
JakubKotkowiak Dec 10, 2020
f71e3c9
refactor(general): modify recipes and tasks
JakubKotkowiak Dec 10, 2020
ca7e268
refactor(general): modify recipes and tasks
JakubKotkowiak Dec 10, 2020
cda5e72
refactor(tasks): adapted tasks and recipes
JakubKotkowiak Dec 10, 2020
1b1ec6c
refactor(tasks): changed export variables
JakubKotkowiak Dec 10, 2020
97d5d14
refactor(tasks): added exports
JakubKotkowiak Dec 11, 2020
b29d82f
refactor(tasks): change activate bashrc command
JakubKotkowiak Dec 11, 2020
b914cdb
refactor(recipe): removed hostname
JakubKotkowiak Dec 11, 2020
5877d66
refactor(tasks): changed hostname variable
JakubKotkowiak Dec 11, 2020
f61e898
refactor(recipe): check if exported variables work
JakubKotkowiak Dec 11, 2020
4869fd4
Update mysql-debian.json
JakubKotkowiak Dec 11, 2020
5aa2025
refactor(recipe): commented out user input
JakubKotkowiak Dec 11, 2020
223eb11
Merge branch 'linuxMySql' of github.com:newrelic/open-install-library…
JakubKotkowiak Dec 11, 2020
10c7157
refactor(recipe): commented out inputvars
JakubKotkowiak Dec 11, 2020
e707990
refactor(recipe): change nrql
JakubKotkowiak Dec 11, 2020
63bc59b
refactor(tasks): fixed missing socket error for amazonlinux2
JakubKotkowiak Dec 11, 2020
5fd01f0
refactor(recipe): comment out rhel inputs, change service to systemctl
JakubKotkowiak Dec 11, 2020
c17c145
refactor(tasks): added missing permissions
JakubKotkowiak Dec 11, 2020
a26b23f
refactor(recipes): modify the way that mysql-config.yml is created
JakubKotkowiak Dec 11, 2020
190dc73
refactor(recipe): switch to user input debian
JakubKotkowiak Dec 11, 2020
8631226
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 14, 2020
6a89749
refactor(tasks): added reset connection command to refresh env for cu…
JakubKotkowiak Dec 14, 2020
a8baf0c
refactor(general): added reset connection that was missing in previou…
JakubKotkowiak Dec 14, 2020
0bbf97a
refactor(general): temporary push using existing env var
JakubKotkowiak Dec 14, 2020
445fa87
refactor(general): removed unnecessary comment
JakubKotkowiak Dec 14, 2020
8b78745
refactor(general): added source for exporting variables
JakubKotkowiak Dec 14, 2020
2f30d36
refactor(general): fix passing username
JakubKotkowiak Dec 14, 2020
676b00c
refactor(general): fix source command not found
JakubKotkowiak Dec 14, 2020
6829a79
refactor(test): check if recipe works with manual input
JakubKotkowiak Dec 14, 2020
f1d036c
refactor(test): comment missing line
JakubKotkowiak Dec 14, 2020
e7dd364
Update infra config for mysql and debian
Julien4218 Dec 14, 2020
1630336
skip prompt for now.
Julien4218 Dec 14, 2020
2090aa6
Add select permission to newrelic user for mysql
Julien4218 Dec 14, 2020
8593775
Wire db port in debian mysql for now.
Julien4218 Dec 14, 2020
0354bd4
Comment inputVars for now.
Julien4218 Dec 14, 2020
bad8e08
Default hostname to localhost ip and put back input vars with sudo -E…
Julien4218 Dec 14, 2020
6136a4c
Fix var names
Julien4218 Dec 14, 2020
f913b87
Rename mysql debian recipe and use bashrc for env var.
Julien4218 Dec 14, 2020
fb91893
Fix file rename and make mysql install rerunable.
Julien4218 Dec 14, 2020
43ed2ac
Revert file rename and single exec of cli.
Julien4218 Dec 15, 2020
5d6a5ad
Explicitly pass-through all required environment variables for the ne…
Julien4218 Dec 15, 2020
73bede2
Remove become.
Julien4218 Dec 15, 2020
ec5e50b
refactor(general): updated rhel recipe
JakubKotkowiak Dec 15, 2020
54a0074
refactor(general): adapt rhel recipe
JakubKotkowiak Dec 15, 2020
3cdaa5d
refactor(general): update rhel recipe
JakubKotkowiak Dec 15, 2020
77d9279
refactor(general): fix limit file
JakubKotkowiak Dec 15, 2020
5ab828f
refactor(general): add alter user for root pwd
JakubKotkowiak Dec 15, 2020
8d582c9
refactor(general): add option for alter root pwd
JakubKotkowiak Dec 15, 2020
2b013ca
refactor(general): removed indentation for alter root command
JakubKotkowiak Dec 15, 2020
1297e35
refactor(tasks): changed options in grant replication task
JakubKotkowiak Dec 15, 2020
3169bbb
refactor(general): removed incorrect syntax
JakubKotkowiak Dec 15, 2020
b501807
refactor(general): fix syntax error with max_user_connections
JakubKotkowiak Dec 15, 2020
f171014
Merge remote-tracking branch 'origin/main' into linuxMySql
JakubKotkowiak Dec 15, 2020
84c8442
refactor(general): added user
JakubKotkowiak Dec 15, 2020
a6cb2c9
Validation nrql with hostname need to handle long host names for aws …
Julien4218 Dec 15, 2020
4364242
feat(general): fix suse integration
setamyDG Dec 16, 2020
3b90d81
refactor(general): added % to hostname
setamyDG Dec 16, 2020
5c4c072
feat(general): change to zypper command
setamyDG Dec 16, 2020
428a29f
refactor(general): added password generator and additional info for user
JakubKotkowiak Dec 17, 2020
d55d5ed
refactor(general): changed the way that the password is generated
JakubKotkowiak Dec 17, 2020
e8fccc8
refactor(general): changed password generation for rhel task
JakubKotkowiak Dec 17, 2020
943c029
revert(tasks): removed password generation
JakubKotkowiak Dec 17, 2020
6349502
refactor(general): check if user can connect
JakubKotkowiak Dec 17, 2020
61e5b01
refactor(recipe): fixed typo in check
JakubKotkowiak Dec 17, 2020
278e85b
refactor(tasks): fixed spacing
JakubKotkowiak Dec 17, 2020
d92ce41
refactor(general): extended user notification, added checks for rhel …
JakubKotkowiak Dec 17, 2020
546051b
refactor(general): added password generation for debian, added exit 1…
JakubKotkowiak Dec 18, 2020
bdb9c80
refactor(general): fix passing of user_pwd
JakubKotkowiak Dec 18, 2020
44826a9
refactor(general): revert changes to rhel and suse recipes
JakubKotkowiak Dec 18, 2020
a6ff089
refactor(general): remove newline after error message
JakubKotkowiak Dec 18, 2020
d2f59b7
refactor(recipes): extended validationnrql by facet entityguid
JakubKotkowiak Dec 18, 2020
b06dbc5
Merge branch 'main' into linuxMySql
Julien4218 Dec 18, 2020
bb95874
refactor(recipes): increase size for rhel recipe
JakubKotkowiak Dec 21, 2020
3e98fe8
refactor(recipes): change command for creation of mysql-config file
JakubKotkowiak Dec 21, 2020
9adaa5f
refactor(recipes): modify rhel recipe nrql
JakubKotkowiak Dec 21, 2020
10bb22a
refactor(recipes): test no user notification
JakubKotkowiak Dec 21, 2020
cce02fd
refactor(recipes): removed one of logmatches for rhel
JakubKotkowiak Dec 21, 2020
04ce0c5
refactor(recipes): rhel added check for infra-agent
JakubKotkowiak Dec 21, 2020
74e28f0
refactor(recipes): rhel changed the way that config file is populated
JakubKotkowiak Dec 21, 2020
d773d32
refactor(deploys): changed rhel instance
JakubKotkowiak Dec 21, 2020
1ac57cb
refactor(recipes): changed port for rhel recipe
JakubKotkowiak Dec 21, 2020
2aba6b5
Fix password creation for rhel.
Julien4218 Dec 21, 2020
0b36401
refactor(recipes): fixed suse password, added checks to the recipe
JakubKotkowiak Dec 22, 2020
3113f1f
refactor(infra): removed duplicate of build env vars
JakubKotkowiak Dec 22, 2020
ef78f52
revert(infra): removed changes from infra agent
JakubKotkowiak Dec 22, 2020
888a6e2
refactor(tests): changed ports to 9999 for debian and suse
JakubKotkowiak Dec 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions recipes/newrelic/mysql/debian.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
name: MySQL Open Source Integration
description: New Relic install recipe for default MySQL Open Source on-host integration (via Infra-Agent)
repository: https://github.com/newrelic/nri-mysql

installTargets:
- type: host
os: linux
platform: "debian"
- type: host
os: linux
platform: "ubuntu"

# keyword convention for dealing with search terms that could land someone on this instrumentation project
keywords:
- Infrastructure
- Integration
- mysql

# Examine Infrastructure events for correlated data
processMatch:
- mysql
- mysqld

# Matches partial list of the Log forwarding parameters
# https://docs.newrelic.com/docs/logs/enable-log-management-new-relic/enable-log-monitoring-new-relic/forward-your-logs-using-infrastructure-agent#parameters
logMatch:
- name: mysql
file: /var/log/mysql/mysqld.log
- name: mysql-error
file: /var/log/mysql/error.log
attributes:
logtype: mysql-error

# NRQL the newrelic-cli will use to validate the agent/integration this recipe
# installed is successfully sending data to New Relic
validationNrql: "SELECT count(*) from MysqlSample where hostname like '{{.HOSTNAME}}' FACET entityGuid SINCE 10 minutes ago"

# Prompts for input from the user. These variables then become
# available to go-task in the form of {{.VAR_NAME}}
inputVars:
- name: "NR_CLI_DB_USERNAME"
prompt: "Please enter your NR username below."
- name: "NR_CLI_DB_PASSWORD"
prompt: "Please enter your NR password below."
secret: true
- name: "NR_CLI_DB_HOSTNAME"
prompt: "Please enter your MySQL hostname below. If none is provided, the default value: localhost, will be used."
default: "localhost"
- name: "NR_CLI_DB_PORT"
prompt: "Please enter your MySQL port below. If none is provided, the default value: 3306, will be used."
default: 3306
- name: "NR_CLI_DATABASE"
prompt: "Please enter your MySQL database name below."

install:
version: "3"

silent: true

tasks:
default:
cmds:
- task: create_user_notification
- task: assert_pre_req
- task: setup
- task: restart

create_user_notification:
cmds:
- |
echo "_ Note: __ You need to have a MySQL user with replication permissions for enabling this integration. If you’d like to create a new user please use these commands as reference. _\n
sudo mysql -e \"CREATE USER 'newrelic'@'localhost' IDENTIFIED BY 'YOUR_SELECTED_PASSWORD';\"\n
sudo mysql -e \"GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost' WITH MAX_USER_CONNECTIONS 5;\"\n
sudo mysql -e \"GRANT SELECT ON *.* TO 'newrelic'@'localhost' WITH MAX_USER_CONNECTIONS 5;\""

assert_pre_req:
cmds:
- |
SERVICE_EXIST=$(sudo systemctl status newrelic-infra.service | grep "Active" | wc -l)
if [ $SERVICE_EXIST -eq 0 ]; then
echo "The newrelic-infra agent service is NOT installed on the host, but is required to install this integration." >> /dev/stderr
exit 1
fi
- |
CHECK_DB=$(mysql -u{{.NR_CLI_DB_USERNAME}} -p{{.NR_CLI_DB_PASSWORD}} -e "SHOW GRANTS FOR CURRENT_USER" | grep 'GRANT SELECT' | awk '{print $2, $3}')
EXPECTED=$(echo 'SELECT, REPLICATION')
if [ "$CHECK_DB" != "$EXPECTED" ] ; then
echo -e "[Error]: Provided user has no access to the desired database.\n - See https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration#config for more info."
exit 2
fi

setup:
label: "Installing mysql integration..."
cmds:
- |
sudo mkdir -p "/etc/newrelic-infra/integrations.d"
- |
sudo apt-get update
- |
sudo apt-get install nri-mysql -y
- |
if [ -f /etc/newrelic-infra/integrations.d/mysql-config.yml ]; then
sudo rm /etc/newrelic-infra/integrations.d/mysql-config.yml;
fi

sudo cp /etc/newrelic-infra/integrations.d/mysql-config.yml.sample /etc/newrelic-infra/integrations.d/mysql-config.yml;

- |
sudo tee /etc/newrelic-infra/integrations.d/mysql-config.yml > /dev/null <<"EOT"
integration_name: com.newrelic.mysql

instances:
- name: mysql-status
command: status
arguments:
hostname: {{.NR_CLI_DB_HOSTNAME}}
port: {{.NR_CLI_DB_PORT}}
username: {{.NR_CLI_DB_USERNAME}}
password: {{.NR_CLI_DB_PASSWORD}}
database: {{.NR_CLI_DATABASE}}
extended_metrics: true
extended_innodb_metrics: true
extended_myisam_metrics: true
remote_monitoring: true
EOT

restart:
cmds:
- sudo systemctl restart newrelic-infra.service
128 changes: 128 additions & 0 deletions recipes/newrelic/mysql/rhel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: MySQL Open Source Integration
description: New Relic install recipe for default MySQL Open Source on-host integration (via Infra-Agent)
repository: https://github.com/newrelic/nri-mysql

installTargets:
- type: host
os: linux
platform: amazonLinux
platformVersion: "2"
- type: host
os: linux
platform: "redhat"
- type: host
os: linux
platform: "centos"

# keyword convention for dealing with search terms that could land someone on this instrumentation project
keywords:
- Infrastructure
- Integration
- mysql

# Examine Infrastructure events for correlated data
processMatch:
- mysqld

# Matches partial list of the Log forwarding parameters
# https://docs.newrelic.com/docs/logs/enable-log-management-new-relic/enable-log-monitoring-new-relic/forward-your-logs-using-infrastructure-agent#parameters
logMatch:
- name: mysql
file: /var/log/mysqld.log

# NRQL the newrelic-cli will use to validate the agent/integration this recipe
# installed is successfully sending data to New Relic
validationNrql: "SELECT count(*) from MysqlSample where hostname like '{{.HOSTNAME}}%' FACET entityGuid SINCE 10 minutes ago"

# Prompts for input from the user. These variables then become
# available to go-task in the form of {{.VAR_NAME}}
inputVars:
- name: "NR_CLI_DB_USERNAME"
prompt: "Please enter your NR username below."
- name: "NR_CLI_DB_PASSWORD"
prompt: "Please enter your NR password below."
secret: true
- name: "NR_CLI_DB_HOSTNAME"
prompt: "Please enter your MySQL hostname below. If none is provided, the default value: localhost, will be used."
default: "localhost"
- name: "NR_CLI_DB_PORT"
prompt: "Please enter your MySQL port below. If none is provided, the default value: 3306, will be used."
default: 3306
- name: "NR_CLI_DATABASE"
prompt: "Please enter your MySQL database name below."

install:
version: "3"

silent: true

tasks:
default:
cmds:
- task: create_user_notification
- task: assert_pre_req
- task: setup
- task: restart

create_user_notification:
cmds:
- |
echo "_ Note: __ You need to have a MySQL user with replication permissions for enabling this integration. If you'd like to create a new user please use these commands as reference. _\n
sudo mysql -e \"CREATE USER 'newrelic'@'localhost' IDENTIFIED BY 'YOUR_SELECTED_PASSWORD' WITH MAX_USER_CONNECTIONS 5;\"\n
sudo mysql -e \"GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost';\"\n
sudo mysql -e \"GRANT SELECT ON *.* TO 'newrelic'@'localhost';\""

assert_pre_req:
cmds:
- |
SERVICE_EXIST=$(sudo systemctl status newrelic-infra.service | grep "Active" | wc -l)
if [ $SERVICE_EXIST -eq 0 ]; then
echo "The newrelic-infra agent service is NOT installed on the host, but is required to install this integration." >> /dev/stderr
exit 1
fi
- |
CHECK_DB=$(mysql -u{{.NR_CLI_DB_USERNAME}} -p{{.NR_CLI_DB_PASSWORD}} -e "SHOW GRANTS FOR CURRENT_USER" | grep 'GRANT SELECT' | awk '{print $2, $3}')
EXPECTED=$(echo 'SELECT, REPLICATION')
if [ "$CHECK_DB" != "$EXPECTED" ] ; then
echo -e "[Error]: Provided user has no access to the desired database.\n - See https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration#config for more info."
exit 2
fi

setup:
label: "Installing mysql integration..."
cmds:
- |
sudo mkdir -p "/etc/newrelic-infra/integrations.d"
- |
sudo yum -q makecache -y --disablerepo='*' --enablerepo='newrelic-infra'
- |
sudo yum install nri-mysql -y
- |
if [ -f /etc/newrelic-infra/integrations.d/mysql-config.yml ]; then
sudo rm /etc/newrelic-infra/integrations.d/mysql-config.yml;
fi

sudo cp /etc/newrelic-infra/integrations.d/mysql-config.yml.sample /etc/newrelic-infra/integrations.d/mysql-config.yml;

- |
sudo tee /etc/newrelic-infra/integrations.d/mysql-config.yml > /dev/null <<"EOT"
integration_name: com.newrelic.mysql

instances:
- name: mysql-status
command: status
arguments:
hostname: {{.NR_CLI_DB_HOSTNAME}}
port: {{.NR_CLI_DB_PORT}}
username: {{.NR_CLI_DB_USERNAME}}
password: {{.NR_CLI_DB_PASSWORD}}
database: {{.NR_CLI_DATABASE}}
extended_metrics: true
extended_innodb_metrics: true
extended_myisam_metrics: true
remote_monitoring: true
EOT

restart:
cmds:
- sudo systemctl restart newrelic-infra.service
125 changes: 125 additions & 0 deletions recipes/newrelic/mysql/suse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: MySQL Open Source Integration
description: New Relic install recipe for default MySQL Open Source on-host integration (via Infra-Agent)
repository: https://github.com/newrelic/nri-mysql

installTargets:
- type: host
os: linux
platformFamily: "suse"

# keyword convention for dealing with search terms that could land someone on this instrumentation project
keywords:
- Infrastructure
- Integration
- mysql

# Examine Infrastructure events for correlated data
processMatch:
- mysql
- mysqld

# Matches partial list of the Log forwarding parameters
# https://docs.newrelic.com/docs/logs/enable-log-management-new-relic/enable-log-monitoring-new-relic/forward-your-logs-using-infrastructure-agent#parameters
logMatch:
- name: mysql
file: /var/log/mysql/mysqld.log
- name: mysql-error
file: /var/log/mysql/error.log
attributes:
logtype: mysql-error

# NRQL the newrelic-cli will use to validate the agent/integration this recipe
# installed is successfully sending data to New Relic
validationNrql: "SELECT count(*) from MysqlSample where hostname like '{{.HOSTNAME}}%' FACET entityGuid SINCE 10 minutes ago"

# Prompts for input from the user. These variables then become
# available to go-task in the form of {{.VAR_NAME}}
inputVars:
- name: "NR_CLI_DB_USERNAME"
prompt: "Please enter your NR username below."
- name: "NR_CLI_DB_PASSWORD"
prompt: "Please enter your NR password below."
secret: true
- name: "NR_CLI_DB_HOSTNAME"
prompt: "Please enter your MySQL hostname below. If none is provided, the default value: localhost, will be used."
default: "localhost"
- name: "NR_CLI_DB_PORT"
prompt: "Please enter your MySQL port below. If none is provided, the default value: 3306, will be used."
default: 3306
- name: "NR_CLI_DATABASE"
prompt: "Please enter your MySQL database name below."

install:
version: "3"

silent: true

tasks:
default:
cmds:
- task: create_user_notification
- task: assert_pre_req
- task: setup
- task: restart

create_user_notification:
cmds:
- |
echo "_ Note: __ You need to have a MySQL user with replication permissions for enabling this integration. If you’d like to create a new user please use these commands as reference. _\n
sudo mysql -e \"CREATE USER 'newrelic'@'localhost' IDENTIFIED BY 'YOUR_SELECTED_PASSWORD';\"\n
sudo mysql -e \"GRANT REPLICATION CLIENT ON *.* TO 'newrelic'@'localhost';\"\n
sudo mysql -e \"GRANT SELECT ON *.* TO 'newrelic'@'localhost';\""

assert_pre_req:
cmds:
- |
SERVICE_EXIST=$(sudo systemctl status newrelic-infra.service | grep "Active" | wc -l)
if [ $SERVICE_EXIST -eq 0 ]; then
echo "The newrelic-infra agent service is NOT installed on the host, but is required to install this integration." >> /dev/stderr
exit 1
fi
- |
CHECK_DB=$(mysql -u{{.NR_CLI_DB_USERNAME}} -p{{.NR_CLI_DB_PASSWORD}} -e "SHOW GRANTS FOR CURRENT_USER" | grep 'GRANT SELECT' | awk '{print $2, $3}')
EXPECTED=$(echo 'SELECT, REPLICATION')
if [ "$CHECK_DB" != "$EXPECTED" ] ; then
echo -e "[Error]: Provided user has no access to the desired database.\n - See https://docs.newrelic.com/docs/integrations/host-integrations/host-integrations-list/mysql-monitoring-integration#config for more info."
exit 2
fi

setup:
label: "Installing mysql integration..."
cmds:
- |
sudo mkdir -p "/etc/newrelic-infra/integrations.d"
- |
sudo zypper -n ref -r newrelic-infra
- |
sudo zypper -n install nri-mysql
- |
if [ -f /etc/newrelic-infra/integrations.d/mysql-config.yml ]; then
sudo rm /etc/newrelic-infra/integrations.d/mysql-config.yml;
fi

sudo touch /etc/newrelic-infra/integrations.d/mysql-config.yml;
- |
sudo tee -a /etc/newrelic-infra/integrations.d/mysql-config.yml > /dev/null <<"EOT"
integration_name: com.newrelic.mysql

instances:
- name: mysql-status
command: status
arguments:
hostname: {{.NR_CLI_DB_HOSTNAME}}
port: {{.NR_CLI_DB_PORT}}
username: {{.NR_CLI_DB_USERNAME}}
password: {{.NR_CLI_DB_PASSWORD}}
database: {{.NR_CLI_DATABASE}}
extended_metrics: true
extended_innodb_metrics: true
extended_myisam_metrics: true
remote_monitoring: true
EOT

restart:
cmds:
- sudo systemctl restart newrelic-infra.service
Loading