由于找不到路径,这是OSError 。确保您以正确的格式分配路径,并且文件/文件夹具有读/写权限。还要确保在导出器配置中增加“'storage_max_size'”的值。
您可以参考此 Python 代码进行检查test_check_storage_size_error
:
def put(self, data, lease_period=0):
if not self._check_storage_size():
return None
blob = LocalFileBlob(os.path.join(
self.path,
'{}-{}.blob'.format(
_fmt(_now()),
'{:08x}'.format(random.getrandbits(32)), # thread-safe random
),
))
return blob.put(data, lease_period=lease_period)
def _check_storage_size(self):
size = 0
for dirpath, dirnames, filenames in os.walk(self.path):
for f in filenames:
fp = os.path.join(dirpath, f)
# skip if it is symbolic link
if not os.path.islink(fp):
try:
size += os.path.getsize(fp)
except OSError:
logger.error(
"Path %s does not exist or is inaccessible.", fp
)
continue
if size >= self.max_size:
logger.warning(
"Persistent storage max capacity has been "
"reached. Currently at %fKB. Telemetry will be "
"lost. Please consider increasing the value of "
"'storage_max_size' in exporter config.",
format(size/1024)
)
return False
return True
def test_check_storage_size_error(self):
input = (1, 2, 3)
with LocalFileStorage(os.path.join(TEST_FOLDER, 'asd5'), 1) as stor:
with mock.patch('os.path.getsize', side_effect=throw(OSError)):
stor.put(input)
with mock.patch('os.path.islink') as os_mock:
os_mock.return_value = True
self.assertTrue(stor._check_storage_size())
可以参考opencesus-python-storage.py和opencesus-python-test_storage.py