Skip to content

Commit

Permalink
Building the RPM with travis (#1)
Browse files Browse the repository at this point in the history
* Adding env variables that can be used by systemd config

* Adding rpmbuild in travis
  • Loading branch information
guilbaults authored Mar 27, 2020
1 parent 1d04870 commit 789eed2
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 11 deletions.
27 changes: 23 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
language: python
sudo: false
sudo: required
cache: pip
python:
- '3.6'
fail_fast: true
env:
global:
- DOCKER_IMAGE=alectolytic/rpmbuilder
- OS_ARCH=x86_64
matrix:
- OS_TYPE=centos OS_DIST=epel OS_VERSION=7
services:
- docker
install: true
before_install:
- pip install flake8
install: "pip install -r requirements.txt"
- pip install flake8
script:
- flake8 infiniband-exporter.py
- flake8 infiniband-exporter.py
- docker run -v ${PWD}:/sources -v ${PWD}:/output:Z ${DOCKER_IMAGE}:${OS_TYPE}-${OS_VERSION}
deploy:
provider: releases
api_key:
secure: nMgeXt/NZ1Rj2DUx2hcr48TGr+d8rFCVBhb1j8RQRYqArV3MRGRhNYHjel5ncJqLPBjXx4wZmd6++zw4dzmIm9BjcGugM/7bntCs2hrwTRMkX9xZt1EXzuM/pPnSd8808buyDBAeR4jfTJmZBTJ+Ht7zc8tWAqT6AFWlT4J/l/OPHlVxVkt7uF3aUCDiNvMuBRx83vrDeogbOBwZl+A7SwZq8i5caTYEjyahoQk/QuGnqjoiSUqVSWQntATkWxzKosCQm9UDIEFak+OYkrBA7OqtRyz+ssE3cyE4bL6uoXEOI7iZ1l4YPoVFi+/w+MJE8GDL8VH6uz5MgRiuOYYHE5DaAYru0vlwB0HFklj9TnUbifwUgBi1wbBTvL4vEjLAiCTPyhdqf6iw7sUQOxDCk1SiNUkGX/NvMqoTvK4EQASzdekV8bQ11jAb3GTuC9vP0fm4g1L9nwpLatLTss5Cf//Z+1FoYInj1SzOR1TTjVDHRG+kFqFb7C2IIF6r6m6Hp6S5DvMzefXaR12ZovcY7JI/bJ4hTQoPZMwfY+M+8ufAfWnEw4duWbKeRmps6ENCuofGySK8srfXDlQy7lNcMZt75OuyNdn9kmPPlmMCCNx78UvCqxrO+IzNc8moRqSzvhLjRVS9Lffjk3+NI2NH3+m0+DX0jnZcXGughRyX+vc=
file: "*.rpm"
draft: true
file_glob: true
skip_cleanup: true
on:
tags: true
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This exporter takes 3 seconds to collect the information of 60+ IB switches, and

## Requirements

* Python >= 3.6
* prometheus-client==0.7.1
* Python
* prometheus-client
* `ibqueryerrors`

## Usage
Expand Down Expand Up @@ -45,4 +45,4 @@ infiniband_linkdownedcounter_total{local_guid="0x506b4b03005d3101",local_name="s
# TYPE infiniband_portrcvdata_total counter
infiniband_portrcvdata_total{local_guid="0x506b4b03005d3101",local_name="switch1",local_port="2",remote_guid="0x506b4b0300e5e461",remote_name="node1 mlx5_0",remote_port="1"} 5.149057134655e+012
infiniband_portrcvdata_total{local_guid="0x506b4b03005d3101",local_name="switch1",local_port="3",remote_guid="0x506b4b0300c35b61",remote_name="node2 mlx5_0",remote_port="1"} 6.051662505593e+012
```
```
48 changes: 48 additions & 0 deletions infiniband-exporter-el7.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Name: infiniband-exporter
Version: 0.0.1
%global gittag 0.0.1
Release: 1%{?dist}
Summary: Prometheus exporter for a Infiniband Fabric

License: Apache License 2.0
URL: https://github.com/guilbaults/infiniband-exporter
Source0: https://github.com/guilbaults/%{name}/archive/v%{gittag}/%{name}-%{version}.tar.gz

BuildArch: noarch
BuildRequires: systemd
Requires: python2-prometheus_client
Requires: infiniband-diags

%description
Prometheus exporter for a Infiniband fabric. This exporter only need to be installed on one server connected to the fabric, it will collect all the ports statistics on all the switches.

Metrics are identified by type, port number, switch GUID and name. The remote connection of each port is also collected. Thus each metric represents a cable between 2 switches, or between a switch and a card in a server.

When a node name map file is provided, it will be used by ibquerryerror to put a more human friendly name on switches.

This exporter takes 3 seconds to collect the information of 60+ IB switches, and 900+ compute nodes. The information takes about 7.5MB in ASCII format for that fabric.

%prep
%autosetup -n %{name}-%{gittag}
%setup -q

%build

%install
mkdir -p %{buildroot}/%{_bindir}
mkdir -p %{buildroot}/%{_unitdir}

sed -i -e '1i#!/usr/bin/python' infiniband-exporter.py
install -m 0755 %{name}.py %{buildroot}/%{_bindir}/%{name}
install -m 0644 infiniband-exporter.service %{buildroot}/%{_unitdir}/infiniband-exporter.service

%clean
rm -rf $RPM_BUILD_ROOT

%files
%{_bindir}/%{name}
%{_unitdir}/infiniband-exporter.service

%changelog
* Fri Mar 20 2020 Simon Guilbault <[email protected]> 0.0.1-1
- Initial release
21 changes: 17 additions & 4 deletions infiniband-exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import argparse
import subprocess
import os

from prometheus_client.core import REGISTRY, CounterMetricFamily, \
GaugeMetricFamily
Expand All @@ -10,9 +11,19 @@

class InfinibandCollector(object):
def __init__(self, can_reset_counter, input_file, node_name_map):
self.can_reset_counter = can_reset_counter
if can_reset_counter:
self.can_reset_counter = True
elif 'CAN_RESET_COUNTER' in os.environ:
self.can_reset_counter = True
else:
self.can_reset_counter = False

self.input_file = input_file
self.node_name_map = node_name_map

if node_name_map:
self.node_name_map = node_name_map
elif 'NODE_NAME_MAP' in os.environ:
self.node_name_map = os.environ['NODE_NAME_MAP']

self.node_name = {}
if self.node_name_map:
Expand Down Expand Up @@ -316,7 +327,8 @@ def collect(self):
parser.add_argument(
'--can-reset-counter',
dest='can_reset_counter',
help='Will reset counter as required when maxed out',
help='Will reset counter as required when maxed out. Can also be \
set with env variable CAN_RESET_COUNTER',
action='store_true')
parser.add_argument(
'--from-file',
Expand All @@ -328,7 +340,8 @@ def collect(self):
'--node-name-map',
action='store',
dest='node_name_map',
help='Node name map used by ibqueryerrors')
help='Node name map used by ibqueryerrors. Ccan also be set with env \
var NODE_NAME_MAP')

args = parser.parse_args()

Expand Down
13 changes: 13 additions & 0 deletions infiniband-exporter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Infiniband-exporter
After=network.target

[Service]
Type=simple
EnvironmentFile=-/etc/sysconfig/infiniband-exporter.conf
ExecStart=/usr/bin/infiniband-exporter
PIDFile=/var/run/infiniband-exporter.pid
KillMode=process

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions mkrpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
spectool -g -R infiniband-exporter-el7.spec
rpmbuild --define "dist .el7" -ba infiniband-exporter-el7.spec

0 comments on commit 789eed2

Please sign in to comment.