当我在文件中包含这一行
from prometheus_client import CollectorRegistry, pushadd_to_gateway, Info
当我使用2.7 python解释器时,代码运行良好。
但是在3.6中它给出了: ImportError:无法导入名称“信息”
from prometheus_client import CollectorRegistry, pushadd_to_gateway, Info
def write_to_gateway(key, value):
registry = CollectorRegistry()
i = Info('sql_monitor_results', 'These are results of SQL queries converted into key/value info', registry=registry)
i.info({key: value})
pushadd_to_gateway('localhost:9091', job='MonitorResults', registry=registry)
if __name__ == "__main__":
write_to_gateway("xxx", "yyyy")
答案 0 :(得分:0)
您很可能已安装了适用于Python 3的旧版库,请使用 <activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.custom"/>
<!-- These additional pathPattern blocks are to allow for paths with
additional periods in them. See:
http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="file"/>
<data android:pathPattern=".*\\.custom"/>
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:mimeType="application/vnd.ni.custom" android:scheme="file"/>
</intent-filter>
</activity>
对其进行升级。
答案 1 :(得分:0)
谢谢。原来我没有在virtualenv中运行pip install。因此,它从即时起就可以工作了,但从PyCharm却没有。在源bin / activate和pip3安装prometheus_client之后,它就起作用了。
再次感谢, --vadim