Hyperflex-API/README.md

130 lines
4.2 KiB
Markdown
Raw Normal View History

2018-01-25 01:12:00 -08:00
# Hyperflex-API
2018-01-25 01:21:39 -08:00
2018-01-26 07:19:08 -08:00
This is an example of how to use Cisco Hyperflex API with python. I've been tasked with deploying multiple Hyperflex Clusters at Cisco Live 2018 in Barcelona. As part of that deployment I wanted to have a way to monitor performace of the system. The Hyperflex system has a built performace "screen" that can be accessed via the http://hx-controller/perf link but I wanted to have both of my systems data presented on one screen.
2018-01-26 07:07:44 -08:00
2018-01-31 06:28:54 -08:00
I decided to use the "Prometheus" https://prometheus.io/ as backend, Grafana as frontend and a python script to bring the data from the HX systems to Prometheus. This script crates a local web server on address http://localhost:8082/metrics that will serve the data that looks like this:
2018-01-26 07:17:42 -08:00
```
2018-01-26 07:16:07 -08:00
MBps_Read{host="10.127.253.81"} 1728.0
MBps_Write{host="10.127.253.81"} 1490454.7
IOPS_Read{host="10.127.253.81"} 0.9
IOPS_Write{host="10.127.253.81"} 42.9
Lat_Read{host="10.127.253.81"} 2.333
Lat_Write{host="10.127.253.81"} 6.261
2018-01-26 07:17:42 -08:00
```
2018-01-26 07:07:44 -08:00
Every 1 min Prometheus calls the url and processes the data.
2018-02-27 12:01:26 -08:00
Here is an example of thos the graphs look like:
2018-02-27 12:05:05 -08:00
![alt text](https://github.com/Kris-Sekula/Hyperflex-API/blob/master/cl2018-stats-example.png "Graphana Dashboard")
2018-02-27 12:01:26 -08:00
2019-01-23 04:56:30 -08:00
## How to deploy.
2019-01-23 06:24:57 -08:00
1. Install ubuntu server 16.04 64bit (I used: ubuntu-16.04.5-server-amd64.iso):
2019-01-23 07:19:18 -08:00
* Basic installation, only select OpenSSH from the package list, create a user.
2019-01-23 06:24:57 -08:00
2. Install Prometheus:
2019-01-23 07:19:18 -08:00
* create required user:
```
sudo useradd -M -s /bin/fals prometheus
```
* create required folders:
```
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
```
2019-01-23 06:35:35 -08:00
- download and extract:
```
2019-01-23 05:45:10 -08:00
curl -LO https://github.com/prometheus/prometheus/releases/download/v2.6.1/prometheus-2.6.1.linux-amd64.tar.gz
tar xvf prometheus-2.6.1.linux-amd64.tar.gz
2019-01-23 06:35:35 -08:00
```
- copy files and change premissions:
```
2019-01-23 05:49:25 -08:00
sudo cp prometheus-2.6.1.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-2.6.1.linux-amd64/promtool /usr/local/bin/
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo cp -r prometheus-2.6.1.linux-amd64/consoles /etc/prometheus
sudo cp -r prometheus-2.6.1.linux-amd64/console_libraries /etc/prometheus
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
2019-01-23 06:35:35 -08:00
```
2019-01-23 06:50:27 -08:00
- configure prometheus:
2019-01-23 06:35:35 -08:00
```
2019-01-23 05:49:25 -08:00
sudo vim /etc/prometheus/prometheus.yml
2019-01-23 06:35:35 -08:00
```
2019-01-23 07:07:16 -08:00
**Note:** watch out for formatting this is YAML, no TABs allowed, use two spaces instead.
2019-01-23 06:50:27 -08:00
2019-01-23 07:02:31 -08:00
```yaml
2019-01-23 06:47:37 -08:00
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'hx_metrics'
scrape_interval: 1m
static_configs:
- targets: ['localhost:8082']
labels:
service_name: hx_read_write_stats
2019-01-23 07:03:58 -08:00
```
2019-01-23 07:19:18 -08:00
- try to start prometheus:
2019-01-23 06:55:58 -08:00
2019-01-23 05:49:25 -08:00
sudo -u prometheus /usr/local/bin/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/prometheus --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries
2019-01-23 06:55:58 -08:00
2019-01-23 04:56:30 -08:00
2019-01-23 06:47:37 -08:00
- verfiy if it works:
2019-01-23 05:37:58 -08:00
2019-01-23 06:47:37 -08:00
http://localhost:9090/status
2019-01-23 04:56:30 -08:00
2019-01-23 06:47:37 -08:00
- if all good stop it:
2019-01-23 05:37:58 -08:00
2019-01-23 06:47:37 -08:00
CTRL+C
2019-01-23 04:56:30 -08:00
2019-01-23 06:47:37 -08:00
- create prometheus service:
2019-01-23 05:49:25 -08:00
```
sudo vim /etc/systemd/system/prometheus.service
```
2019-01-23 06:47:37 -08:00
File should looks like this:
```
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
```
2019-01-23 04:56:30 -08:00
2019-01-23 06:47:37 -08:00
- reload services:
2019-01-23 05:49:25 -08:00
```
sudo systemctl daemon-reload
```
2019-01-23 06:47:37 -08:00
- start Prometheus using the following command:
2019-01-23 05:49:25 -08:00
```
sudo systemctl start prometheus
```
2019-01-23 06:47:37 -08:00
- check if Prometheus is running, check the service.s status.
2019-01-23 05:49:25 -08:00
```
sudo systemctl status prometheus
```
2019-01-23 06:47:37 -08:00
- enable service:
2019-01-23 05:49:25 -08:00
```
sudo systemctl enable prometheus
```
2019-01-23 04:56:30 -08:00
2018-01-26 07:08:37 -08:00
Keywords: Cisco Hyperflex, API, python.