问题是当grafana服务器停止进行备份或其他操作时,脚本会出错并且不会自动恢复,所以我正在寻找一种创建可发送数据的连接测试循环的方法,如果 Grafana 服务器关闭,则连续脚本将一直工作,直到 Grafana 服务器启动并运行,从而恢复向 Grafana 服务器发送温度数据。
因为当前我最终得到消息中错误的脚本 requests.exceptions.ConnectionError: HTTPConnectionPool
使用脚本 python templogger.py -db=influx_db_temperature -sn=temperature -rn=RUN
我的脚本:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import glob
import argparse
import time
import datetime
import sys
from influxdb import InfluxDBClient
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
# add more sensor variables here based on your setup
# For multiple sensor
# temp=['sensor code','tttttttttt','ddddddddddd','ssssssssss']
temp=['0120215dbea2','0120327e05bf']
base_dir = '/sys/bus/w1/devices/'
# Ext = 28-0120215dbea2
# Int = 28-0120327e05bf
device_folders = glob.glob(base_dir + '28*')
snum=2 #Number of connected temperature sensors
# Set required InfluxDB parameters.
# (this could be added to the program args instead of beeing hard coded...)
host = "NasGrafana.lan.prive" #Could also use local ip address like "192.168.1.136"
port = 8086
user = "temperature"
password = "12345678"
# Sample period (s).
# How frequently we will write sensor data from the temperature sensors to the database.
sampling_period = 120
def read_temp_raw(device_file):
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(device_file): # checks the temp recieved for errors
lines = read_temp_raw(device_file)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(device_file)
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
# set proper decimal place for C
temp = float(temp_string) / 1000.0
# Round temp to 2 decimal points
temp = round(temp, 1)
# value of temp might be unknown here if equals_pos == -1
return temp
慕斯王