0%

docker启动Grafana + Influexdb

docker run -d \
  --name docker-statsd-influxdb-grafana \
  -p 3003:3003 \
  -p 8083:8083 \
  -p 8086:8086 \
  -p 22022:22 \
  -p 8125:8125/udp \
  samuelebistoletti/docker-statsd-influxdb-grafana:latest

设置InfluxDB

打开 http:localhost:8083,设置用户名密码

Username: root
Password: root
Port: 8086

设置Grafana

打开http:localhost:3003,登录用户名密码为

Username: root
Password: root

登录之后按步骤设置数据源

Url: http://localhost:8086
Database:	telegraf
User: telegraf
Password:	telegraf

安装并设置TeleGraf

下载地址:https://portal.influxdata.com/downloads

设置

/etc/telegraf/telegraf.conf
修改influxdb地址,用户名及密码,设置hostname

重启服务

service telegraf restart

导入Grafana Dashboard

下载最新版本的dashboard配置:
https://grafana.com/dashboards/1443/revisions

在grafana的新建dashboard并导入配置,完成。

注意

docker内部已经启动了telegraf,如果不需要的话可以停掉,在多台服务器上安装并配置Telegraf写入同一Influxdb就可以实现对集群进行系统监控。

参考

  1. 使用 Grafana、collectd 和 InfluxDB 打造现代监控系统
  2. docker-statsd-influxdb-grafana
  3. Send CollectD metrics to InfluxDB
Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

jupyter notebook extensions 安装

pip方式安装

pip install jupyter_contrib_nbextensions

或者通过github master branch安装

pip install https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tarball/master

Conda方式安装

conda install -c conda-forge jupyter_contrib_nbextensions

通过github 仓库安装

git clone https://github.com/ipython-contrib/jupyter_contrib_nbextensions.git
pip install -e jupyter_contrib_nbextensions

常用插件列表

全部jupyter插件列表在这里:

http://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions.html

我觉得有用的插件列表:

  • Autopep8

    格式化代码插件

  • Codefolding 和 Codefolding in Editor

    折叠代码插件

  • Collapsible Headings

    Collapsible Headings icon
    Allows notebook to have collapsible sections, separated by headings

  • contrib_nbextensions_help_item:帮助

  • Drag and Drop

    This extension allows dragging&dropping images from the desktop or other programs into a notebook.

  • ExecuteTime:

    Display when each cell has been executed and how long it took

  • Freeze

    Freeze cells (forbid editing and executing) or make them read-only

  • highlighter

    markdown内容高亮

  • Hinterland

    实时的自动补全,很不错

  • Nbextensions dashboard tab & Nbextensions edit menu item

  • ScrollDown

    自动向下滚动输出

  • Snippets & Snippets Menu

    插入代码片段的,可以自定义

  • Table of Contents (2)

    The toc2 extension enables to collect all running headers and display them in a floating window, as a sidebar or with a navigation menu. The extension is also draggable, resizable, collapsable, dockable and features automatic numerotation with unique links ids, and an optional toc cell.

  • table_beautifier

    Add bootstrap styling to tables in markdown cells and in html/md output

  • Toggle all line numbers

    Add a toolbar button and hotkey to toggle all cells’ line numbers on or off

  • Tree Filter

    An extension that allows you to filter by filename in the Jupyter notebook file tree (aka dashboard) page.

  • Variable Inspector

    The Variable Inspector extension collects all defined variables and display them in a floating window.

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

原始数据样例如下:

date        code    count
20170801    000001      10
20170802    000002      20
20170803    000001      30

使用pivot处理数据,命令如下:

df.pivot(index=‘date’,columns=‘code’,values=‘count’)

执行后报错信息:

ValueError: Index contains duplicate entries, cannot reshape

说明column有重复信息,使用如下命令检查重复列内容:

df = df.sort_values(['date','code','count'],ascending=[1,1,0])
df = df[(df['code'] == df['code'].shift(1)) | (df['code'] == df['code'].shift(-1))]

发现code列有哪些重复数据

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant

生成jupyter配置文件:

jupyter notebook --generate-config

注意:generate前是两个"-",不知道为什么markdown里是两个,显示的时候成一个了

生成好的配置文件位置在:

~/.jupyter/jupyter_notebook_config.py

生成自签名SSL证书:

cd ~/.jupyter
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout notebook_cert.key -out notebook_cert.pem

生成一个登录密码的hash:

python -c “import IPython;print(IPython.lib.passwd())”

修改jupyter_notebook_config.py配置文件中的如下选项:

c.NotebookApp.certfile = u'/home/xxxx/.jupyter/notebook_cert.pem'
c.NotebookApp.keyfile = u'/home/xxxx/.jupyter/notebook_cert.key'
c.NotebookApp.password = u'sha1:991ec9cd2f39:522598e19891bab1ecaa3a9072e71f45811af9f2'

重启jupyter,使用浏览器访问:https://your_domain_or_IP:8080

参考

http://jupyter-notebook.readthedocs.io/en/latest/public_server.html#notebook-server-security

http://www.linuxdiyf.com/linux/22884.html

Python量化交易实战
欢迎您扫码订阅我的微信公众号: pyquant