我使用SQLAlchemy来处理使用奇怪时间戳格式的远程数据库 - 它将时间戳存储为自纪元以来的双精度毫秒.我想使用python datetime对象,所以我在我的模型中编写了getter/setter方法,遵循以下要点:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import synonym
from sqlalchemy.dialects.mysql import DOUBLE
import datetime
Base = declarative_base()
class Table(Base):
__tablename__ = "table"
id = Column(Integer, primary_key=True)
_timestamp = Column("timestamp", DOUBLE(asdecimal=False))
@property
def timestamp(self):
return datetime.datetime.utcfromtimestamp(float(self._timestamp)/1000.)
@timestamp.setter
def timestamp(self, dt):
self._timestamp = float(dt.strftime("%s"))*1000.
timestamp = synonym('_timestamp', descriptor=timestamp)
Run Code Online (Sandbox Code Playgroud)
这非常适合在表中插入新行并使用表中的对象:
>>> table = session.query(Table).first()
<Table id=1>
>>> table.timestamp
datetime.datetime(2016, 6, 27, 16, 9, 3, 320000)
>>> table._timestamp
1467043743320.0
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在过滤器表达式中使用datetime时,它会崩溃:
>>> july = datetime.datetime(2016, 7, 1)
>>> old …Run Code Online (Sandbox Code Playgroud) 我使用docker-machine在AWS上管理Docker节点。今天,我尝试创建一个新节点,但由于实例类型与指定的AMI之间不兼容而失败:
docker-machine create --driver amazonec2 --amazonec2-instance-type t2.micro --amazonec2-ami ami-b4a015d4 certbot-config
Running pre-create checks...
Creating machine...
(certbot-config) Launching instance...
Error creating machine:
Error in driver during machine creation:
Error launching instance: InvalidParameterCombination: Virtualization type 'hvm' is required for instances of type 't2.micro'. Ensure that you are using an AMI with virtualization type 'hvm'. For more information, see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/virtualization_types.html
Run Code Online (Sandbox Code Playgroud)
无论如何,我都会纠正错误。我的问题是我似乎创建了一个幽灵机器。如果我运行docker-machine ls,则会得到以下信息:
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
certbot-config - amazonec2 Error Unknown MissingParameter: The request must contain the parameter InstanceId …Run Code Online (Sandbox Code Playgroud) 编辑:塔伦(Tarun)的答案正是我所要求的。Eugen的答案也是一个很好的解决方案。我最终接受塔伦(Tarun)的答案是正确的,但使用了欧根(Eugen)的答案。如果您有类似的问题,并且担心其他容器访问nginx状态服务器,请使用Tarun的答案。如果您想坚持使用Docker的常规主机名方案,请使用Eugen的方案。
+++原始问题+++
我有一个使用docker-compose构建的应用程序。我正在尝试通过DataDog集成监视。我正在使用DataDog的Agent容器,到目前为止一切正常。我试图通过改编本教程来使nginx监视和运行。
我的应用程序是在docker-compose文件中定义的,如下所示:
version: '2'
services:
flask:
restart: always
image: me/flask-app
command: /home/app/flask/start_app.sh
expose:
- "8080"
nginx:
restart: always
build: ./nginx
command: /runtime/start_nginx.sh
ports:
- "80:80"
- "443:443"
expose:
- "81"
volumes:
- app-static:/app-static:ro
links:
- flask:flask
datadog-agent:
image: me/datadog-agent
env_file: ./datadog-agent/dev.env
links:
- flask
- nginx
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /proc/mounts:/host/proc/mounts:ro
- /sys/fs/cgroup:/host/sys/fs/cgroup:ro
Run Code Online (Sandbox Code Playgroud)
在本教程中,我向nginx添加了一个服务器块,如下所示:
server {
listen 81;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
Run Code Online (Sandbox Code Playgroud)
通过这种配置,我可以从nginx容器中检查nginx的状态。到目前为止,一切都很好。现在,我想更改位置块中的“ allow”指令,以仅允许访问datadog-agent服务。但是,我不知道datadog-agent的IP。在配置对Flask uwsgi服务器的访问时,我能够使用如下指令:
location / …Run Code Online (Sandbox Code Playgroud) 我有一个带有两个索引的 DataFrame;它看起来像这样:
>>> by_hour
pr da delta delta_sq
node timestamputc
A 1 20.540423 21.093659 0.553237 9.869976
B 1 17.675580 18.183104 0.507524 11.474762
C 1 16.257307 16.961944 0.704638 68.023460
... ... ... ... ...
X 24 20.649155 20.805145 0.155990 43.176084
Y 24 20.677271 21.183925 0.506655 47.746125
Z 24 21.455556 21.725556 0.270000 39.393092
[60312 rows x 4 columns]
Run Code Online (Sandbox Code Playgroud)
我有另一个带有单个索引的 DataFrame,与 0 级索引相同by_hour:
>>> nodes
type
node
A type 1
B type 1
C type 2
... ...
X type 3 …Run Code Online (Sandbox Code Playgroud)