mirror of
https://github.com/kemko/keenetic-grafana-monitoring.git
synced 2026-01-01 15:45:43 +03:00
Add influxdb 2.x support
This commit is contained in:
committed by
Vitaliy Skrypnyk
parent
b62d650cb5
commit
26ea31e401
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@ __pycache__
|
|||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
config/config.ini
|
config/config.ini
|
||||||
|
_data
|
||||||
16
.vscode/launch.json
vendored
Normal file
16
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Python: Exporter",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "keentic_influxdb_exporter.py",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
46
README.md
46
README.md
@@ -18,22 +18,29 @@ Tested with:
|
|||||||
|
|
||||||
May work on other Keenetic routers
|
May work on other Keenetic routers
|
||||||
|
|
||||||
|
# Supported InfluxDB version
|
||||||
|
|
||||||
|
InfluxDB 2.x (recomended) and InfluxDB 1.8+
|
||||||
|
|
||||||
# Preparation
|
# Preparation
|
||||||
|
|
||||||
* Create configuration file `config.ini`
|
* Create configuration file `config.ini`
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
[influxdb]
|
[influx2]
|
||||||
host=<HOST>
|
url=http://localhost:8086
|
||||||
port=80
|
# For influx v1.x please use "-" as a value
|
||||||
username=admin
|
org=keenetic
|
||||||
password=<INFLUX_PASS>
|
# For influx v1.x please use "username:password" as a token
|
||||||
db=keenetic
|
token=<token>
|
||||||
|
timeout=6000
|
||||||
|
# For influx v1.x DB name
|
||||||
|
bucket=keenetic
|
||||||
[keenetic]
|
[keenetic]
|
||||||
|
admin_endpoint=http://<keenetic_ip>:80
|
||||||
skip_auth=false
|
skip_auth=false
|
||||||
admin_endpoint=http://192.168.1.1:80
|
login=<user>
|
||||||
login=admin
|
password=<pass>
|
||||||
password=<KEENETIC_PASS>
|
|
||||||
[collector]
|
[collector]
|
||||||
interval_sec=30
|
interval_sec=30
|
||||||
```
|
```
|
||||||
@@ -87,9 +94,11 @@ nohup python /opt/home/keenetic-grafana-monitoring/keentic_influxdb_exporter.py
|
|||||||
```
|
```
|
||||||
---
|
---
|
||||||
version: '3.7'
|
version: '3.7'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
keenetic-grafana-monitoring:
|
keenetic-grafana-monitoring:
|
||||||
image: techh/keenetic-grafana-monitoring:1.1.1
|
image: techh/keenetic-grafana-monitoring:2.0.0
|
||||||
container_name: keenetic-grafana-monitoring
|
container_name: keenetic-grafana-monitoring
|
||||||
# environment:
|
# environment:
|
||||||
# - TZ=Europe/Kiev
|
# - TZ=Europe/Kiev
|
||||||
@@ -98,6 +107,23 @@ services:
|
|||||||
# Optionally you can override metrics
|
# Optionally you can override metrics
|
||||||
- ./config/metrics.json:/home/config/metrics.json:ro
|
- ./config/metrics.json:/home/config/metrics.json:ro
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
# Influx 2.x
|
||||||
|
|
||||||
|
influxdb:
|
||||||
|
image: 'influxdb:2.1'
|
||||||
|
volumes:
|
||||||
|
- ./_data/influxdb:/var/lib/influxdb
|
||||||
|
ports:
|
||||||
|
- 8086:8086
|
||||||
|
environment:
|
||||||
|
- DOCKER_INFLUXDB_INIT_MODE=setup
|
||||||
|
- DOCKER_INFLUXDB_INIT_ORG=keenetic
|
||||||
|
- DOCKER_INFLUXDB_INIT_BUCKET=keenetic
|
||||||
|
- DOCKER_INFLUXDB_INIT_RETENTION=52w
|
||||||
|
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=admin_token
|
||||||
|
- DOCKER_INFLUXDB_INIT_USERNAME=admin
|
||||||
|
- DOCKER_INFLUXDB_INIT_PASSWORD=password
|
||||||
```
|
```
|
||||||
|
|
||||||
# Build Docker image
|
# Build Docker image
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
[influxdb]
|
|
||||||
host=<HOST>
|
|
||||||
port=80
|
|
||||||
username=admin
|
|
||||||
password=<INFLUX_PASS>
|
|
||||||
db=keenetic
|
|
||||||
[keenetic]
|
|
||||||
admin_endpoint=http://192.168.1.1:80
|
|
||||||
skip_auth=false
|
|
||||||
login=admin
|
|
||||||
password=<KEENETIC_PASS>
|
|
||||||
[collector]
|
|
||||||
interval_sec=30
|
|
||||||
16
config/config.sample-influx-1.8.ini
Normal file
16
config/config.sample-influx-1.8.ini
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[influx2]
|
||||||
|
url=http://<influx_ip>:8086
|
||||||
|
# For influx v1.x please use "-" as a value
|
||||||
|
org=-
|
||||||
|
# For influx v1.x please use "username:password" as a token
|
||||||
|
token=username:password
|
||||||
|
timeout=6000
|
||||||
|
# For influx v1.x DB name
|
||||||
|
bucket=keenetic
|
||||||
|
[keenetic]
|
||||||
|
admin_endpoint=http://<keenetic_ip>:80
|
||||||
|
skip_auth=false
|
||||||
|
login=<user>
|
||||||
|
password=<pass>
|
||||||
|
[collector]
|
||||||
|
interval_sec=30
|
||||||
16
config/config.sample-influx-2.x.ini
Normal file
16
config/config.sample-influx-2.x.ini
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[influx2]
|
||||||
|
url=http://<influx_ip>:8086
|
||||||
|
# For influx v1.x please use "-" as a value
|
||||||
|
org=keenetic
|
||||||
|
# For influx v1.x please use "username:password" as a token
|
||||||
|
token=<token>
|
||||||
|
timeout=6000
|
||||||
|
# For influx v1.x DB name
|
||||||
|
bucket=keenetic
|
||||||
|
[keenetic]
|
||||||
|
admin_endpoint=http://<keenetic_ip>:80
|
||||||
|
skip_auth=false
|
||||||
|
login=<user>
|
||||||
|
password=<pass>
|
||||||
|
[collector]
|
||||||
|
interval_sec=30
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
version: '3.7'
|
version: '3.7'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
|
|
||||||
keenetic-grafana-monitoring:
|
keenetic-grafana-monitoring:
|
||||||
build: .
|
build: .
|
||||||
container_name: keenetic-grafana-monitoring
|
container_name: keenetic-grafana-monitoring
|
||||||
@@ -10,3 +12,34 @@ services:
|
|||||||
- ./config/config.ini:/home/config/config.ini:ro
|
- ./config/config.ini:/home/config/config.ini:ro
|
||||||
- ./config/metrics.json:/home/config/metrics.json:ro
|
- ./config/metrics.json:/home/config/metrics.json:ro
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
# Influx 2.x
|
||||||
|
|
||||||
|
influxdb:
|
||||||
|
image: 'influxdb:2.1'
|
||||||
|
volumes:
|
||||||
|
- ./_data/influxdb:/var/lib/influxdb
|
||||||
|
ports:
|
||||||
|
- 8086:8086
|
||||||
|
environment:
|
||||||
|
- DOCKER_INFLUXDB_INIT_MODE=setup
|
||||||
|
- DOCKER_INFLUXDB_INIT_ORG=keenetic
|
||||||
|
- DOCKER_INFLUXDB_INIT_BUCKET=keenetic
|
||||||
|
- DOCKER_INFLUXDB_INIT_RETENTION=52w
|
||||||
|
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=admin_token
|
||||||
|
- DOCKER_INFLUXDB_INIT_USERNAME=admin
|
||||||
|
- DOCKER_INFLUXDB_INIT_PASSWORD=password
|
||||||
|
|
||||||
|
# Influx 1.x
|
||||||
|
|
||||||
|
# influxdb:
|
||||||
|
# image: 'influxdb:1.8.1'
|
||||||
|
# volumes:
|
||||||
|
# - ./_data/influxdb:/var/lib/influxdb
|
||||||
|
# ports:
|
||||||
|
# - 8086:8086
|
||||||
|
# environment:
|
||||||
|
# - INFLUXDB_DB=db0
|
||||||
|
# - INFLUXDB_HTTP_AUTH_ENABLED=true
|
||||||
|
# - INFLUXDB_ADMIN_USER=admin
|
||||||
|
# - INFLUXDB_ADMIN_PASSWORD=password
|
||||||
|
|||||||
@@ -1,27 +1,18 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from influxdb import InfluxDBClient
|
|
||||||
|
|
||||||
|
from influxdb_client import InfluxDBClient
|
||||||
|
from influxdb_client.client.write_api import SYNCHRONOUS
|
||||||
|
|
||||||
class InfuxWriter(object):
|
class InfuxWriter(object):
|
||||||
|
|
||||||
def __init__(self, configuration):
|
def __init__(self, configuration, configuration_file):
|
||||||
requests.packages.urllib3.disable_warnings()
|
requests.packages.urllib3.disable_warnings()
|
||||||
self._configuration = configuration
|
self._configuration = configuration
|
||||||
self._client = InfluxDBClient(self._configuration['host'], self._configuration['port'],
|
self._client = InfluxDBClient.from_config_file(configuration_file)
|
||||||
self._configuration['username'], self._configuration['password'],
|
self._write_api = self._client.write_api(write_options=SYNCHRONOUS)
|
||||||
self._configuration['db'])
|
logging.info("Connecting to InfluxDB: " + self._configuration['url'])
|
||||||
self.init_database()
|
|
||||||
|
|
||||||
def init_database(self):
|
|
||||||
logging.info("Connecting to InfluxDB: " + self._configuration['host'])
|
|
||||||
db_name = self._configuration['db']
|
|
||||||
# self._client.drop_database(db_name)
|
|
||||||
|
|
||||||
if db_name not in self._client.get_list_database():
|
|
||||||
logging.info("Creating InfluxDB database: " + db_name)
|
|
||||||
self._client.create_database(db_name)
|
|
||||||
|
|
||||||
def write_metrics(self, metrics):
|
def write_metrics(self, metrics):
|
||||||
self._client.write_points(metrics)
|
self._write_api.write(bucket=self._configuration['bucket'], record=metrics)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
from influxdb_client.client.write.point import Point
|
||||||
|
|
||||||
from jsonpath_rw import parse
|
from jsonpath_rw import parse
|
||||||
|
|
||||||
@@ -80,12 +81,12 @@ class KeeneticCollector(object):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_metric(measurement, tags, values):
|
def create_metric(measurement, tags, values):
|
||||||
return {
|
return Point.from_dict({
|
||||||
"measurement": measurement,
|
"measurement": measurement,
|
||||||
"tags": tags,
|
"tags": tags,
|
||||||
"time": time.time_ns(),
|
"time": time.time_ns(),
|
||||||
"fields": values
|
"fields": values
|
||||||
}
|
})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_first_value(array):
|
def get_first_value(array):
|
||||||
@@ -104,8 +105,10 @@ if __name__ == '__main__':
|
|||||||
metrics = metrics_configuration['metrics']
|
metrics = metrics_configuration['metrics']
|
||||||
|
|
||||||
config = configparser.ConfigParser(interpolation=None)
|
config = configparser.ConfigParser(interpolation=None)
|
||||||
config.read(pwd + "/config/config.ini")
|
config_path = pwd + "/config/config.ini"
|
||||||
infuxdb_writer = InfuxWriter(config['influxdb'])
|
config.read(config_path)
|
||||||
|
|
||||||
|
infuxdb_writer = InfuxWriter(config['influx2'], config_path)
|
||||||
|
|
||||||
keenetic_config = config['keenetic']
|
keenetic_config = config['keenetic']
|
||||||
logging.info("Connecting to router: " + keenetic_config['admin_endpoint'])
|
logging.info("Connecting to router: " + keenetic_config['admin_endpoint'])
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
influxdb==5.3.1
|
|
||||||
jsonpath-rw==1.4.0
|
jsonpath-rw==1.4.0
|
||||||
requests==2.25.1
|
requests==2.25.1
|
||||||
|
influxdb-client==1.23.0
|
||||||
Reference in New Issue
Block a user