Skip to content

Added Grafana #194

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

Merged
merged 9 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# azhpc Change log

* 01-Apr-2020 : Added Grafana and Telegraf
* 04-Feb-2020 : Added permission option to sasurl variable value. Append ",rw" for read write access. Default is read.
71 changes: 71 additions & 0 deletions examples/grafana/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"location": "variables.location",
"resource_group": "variables.resource_group",
"install_from": "jumpbox",
"admin_user": "hpcadmin",
"vnet": {
"name": "hpcvnet",
"address_prefix": "10.2.0.0/20",
"subnets": {
"admin": "10.2.1.0/24"
}
},
"variables": {
"location": "<NOT-SET>",
"resource_group": "<NOT-SET>",
"vm_type": "<NOT-SET>",
"image": "OpenLogic:CentOS:7.7:latest",
"key_vault": "<NOT-SET>"
},
"resources": {
"jumpbox": {
"type": "vm",
"vm_type": "variables.vm_type",
"public_ip": true,
"image": "variables.image",
"subnet": "admin",
"tags": [
]
},
"grafana": {
"type": "vm",
"vm_type": "variables.vm_type",
"accelerated_networking": true,
"public_ip": true,
"image": "variables.image",
"subnet": "admin",
"tags": [
"disable-selinux",
"grafana",
"telegraf"
]
}
},
"install": [
{
"script": "disable-selinux.sh",
"tag": "disable-selinux",
"sudo": true
},
{
"script": "install-grafana.sh",
"tag": "grafana",
"sudo": true,
"args": [
"azhpc",
"secret.{{variables.key_vault}}.GrafanaPassword"
],
"deps" : ["telegraf_dashboard.json"]
},
{
"script": "install-telegraf.sh",
"tag": "telegraf",
"sudo": true,
"args": [
"$(<hostlists/tags/grafana)",
"azhpc",
"secret.{{variables.key_vault}}.GrafanaPassword"
]
}
]
}
35 changes: 35 additions & 0 deletions examples/grafana/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Deploy an initialize a Grafana server
This example shows how deploy a [Grafana](https://grafana.com/grafana/) server and configure [Telegraf](https://www.influxdata.com/time-series-platform/telegraf/) on monitored machines.


The configuration file requires the following variables to be set:

| Variable | Description |
|-------------------------|----------------------------------------------|
| location | The location of resources |
| resource_group | The resource group for the project |
| vm_type | Azure GPU VM full name (NC or ND series) |
| key_vault | Keyvault to store the GrafanaPassword secret |

> Note : Create an Azure Key Vault and store the Grafana Password in the secret named _GrafanaPassword_

Once deployed:
- Add port 3000 to the NSG of the grafana server
- access the portal thru the URL : **http://[grafana server fqdn]:3000/**
- Authenticate with the **admin** user and the password stored into your KeyVault
- Access the dashboard thru the left meny **Dashboards/Manage** and then select "Telegraf : system dashboard"

> Note : To monitor other VMs, just add the **telegraf** tag to your resources and its associated install script as specified the in the configuration file

```json
{
"script": "install-telegraf.sh",
"tag": "telegraf",
"sudo": true,
"args": [
"<grafana server or ip address>",
"azhpc",
"secret.{{variables.key_vault}}.GrafanaPassword"
]
}
```
112 changes: 112 additions & 0 deletions scripts/install-grafana.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GRAFANA_USER=${1-azhpc}
GRAFANA_PWD=$2

if [ -z "$GRAFANA_PWD" ]; then
echo "Grafana password parameter is required"
exit 1
fi

echo "#### Configuration repo for InfluxDB:"
cat <<EOF | tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/centos/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

echo "#### Configuration repo for Grafana:"
cat <<EOF | tee /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
EOF

echo "#### InfluxDB Installation:"
yum -y install influxdb
echo "#### Grafana Installation:"
yum -y install grafana


echo "#### Starting InfluxDB services:"
systemctl daemon-reload
systemctl start influxdb
systemctl enable influxdb
echo "#### Starting Grafana services:"
systemctl start grafana-server
systemctl enable grafana-server

#echo "#### Opening InfluxDB firewalld port 80(83|86):"
#sudo firewall-cmd --permanent --zone=public --add-port=8086/tcp
#sudo firewall-cmd --permanent --zone=public --add-port=8083/tcp
#echo "#### Opening Grafana firewalld port 3000:"
#sudo firewall-cmd --permanent --zone=public --add-port=3000/tcp
#echo "#### Reload firewall rules:"
#sudo firewall-cmd --reload


echo "#### Configuration of influxDB User and DB:"
curl "http://localhost:8086/query" --data-urlencode "q=CREATE USER admindb WITH PASSWORD '$GRAFANA_PWD' WITH ALL PRIVILEGES"
curl "http://localhost:8086/query" --data-urlencode "q=CREATE USER $GRAFANA_USER WITH PASSWORD '$GRAFANA_PWD'"
curl "http://localhost:8086/query" --data-urlencode "q=CREATE DATABASE monitor"
curl "http://localhost:8086/query" --data-urlencode "q=GRANT ALL ON monitor to $GRAFANA_USER"

echo "Add the administrator"
# https://grafana.com/docs/grafana/latest/administration/cli/
grafana-cli admin reset-admin-password "$GRAFANA_PWD"

echo "Create the datasource"
# https://grafana.com/docs/grafana/latest/administration/provisioning/
grafana_etc_root=/etc/grafana/provisioning
dashboard_dir=/var/lib/grafana/dashboards
cat <<EOF > $grafana_etc_root/datasources/azhpc.yml
apiVersion: 1

datasources:
- name: azhpc
type: influxdb
access: proxy
database: monitor
user: $GRAFANA_USER
password: "$GRAFANA_PWD"
url: http://localhost:8086
jsonData:
httpMode: GET
EOF
chown root:grafana $grafana_etc_root/datasources/azhpc.yml

cat <<EOF > $grafana_etc_root/dashboards/azhpc.yml
apiVersion: 1

providers:
- name: 'azhpc'
orgId: 1
folder: ''
folderUid: ''
type: file
disableDeletion: false
editable: true
allowUiUpdates: true
options:
path: $dashboard_dir
EOF

chown root:grafana $grafana_etc_root/dashboards/azhpc.yaml

mkdir $dashboard_dir
chown grafana:grafana $dashboard_dir

cp $DIR/telegraf_dashboard.json $dashboard_dir

systemctl stop grafana-server
systemctl start grafana-server

77 changes: 77 additions & 0 deletions scripts/install-telegraf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
GRAFANA_SERVER=$1
GRAFANA_USER=$2
GRAFANA_PWD=$3

if [ -z "$GRAFANA_SERVER" ]; then
echo "Grafana server parameter is required"
exit 1
fi
if [ -z "$GRAFANA_USER" ]; then
echo "Grafana user parameter is required"
exit 1
fi
if [ -z "$GRAFANA_PWD" ]; then
echo "Grafana password parameter is required"
exit 1
fi

echo "#### Configuration repo for InfluxDB:"
cat <<EOF | tee /etc/yum.repos.d/influxdb.repo
[influxdb]
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/centos/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF

echo "#### Telegraf Installation:"
yum -y install telegraf

echo "Push right config .... "
# Update telegraph.conf
cp /etc/telegraf/telegraf.conf /etc/telegraf/telegraf.conf.origin

cat << EOF > /etc/telegraf/telegraf.conf
[global_tags]
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false

[[outputs.influxdb]]
urls = ["http://$GRAFANA_SERVER:8086"]
database = "monitor"
username = "$GRAFANA_USER"
password = "$GRAFANA_PWD"

[[inputs.cpu]]
percpu = true
totalcpu = true
collect_cpu_time = false
report_active = false

[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

[[inputs.diskio]]
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
[[inputs.net]]
EOF

echo "#### Starting Telegraf services:"
systemctl daemon-reload
systemctl start telegraf
systemctl enable telegraf
Loading