Hugh's Blog

Docker ELK 配置

docker-compose.yml version: "3.3" services: elasticsearch: image: elasticsearch:6.4.3 environment: LOGSPOUT: ignore ES_JAVA_OPTS: "-Xmx256m -Xms256m" volumes: - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro ports: - "9200:9200" logstash: image: logstash:6.4.3 environment: LOGSPOUT: ignore volumes: - ./temp.log:/var/log/temp.log - ./logstash.conf:/etc/logstash.conf ports: - "5000:5000" links: - elasticsearch command: -f /etc/logstash.conf kibana: image: kibana:6.4.3 environment: LOGSPOUT: ignore ELASTICSEARCH_URL: http://elasticsearch:9200 volumes: - ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:ro ports: - "5601:5601" links: - elasticsearch elasticsearch.yml http.port: 9200 network.host: 0.0.0.0 discovery.type: single-node logstash.conf input { file { path => ...

 

Python 简单实现多线程任务队列

使用队列实现一个简单的多线程任务。 from queue import Queue from threading import Thread class TaskQueue(Queue): def __init__(self, num_workers=1): Queue.__init__(self) self.num_workers = num_workers self.start_workers() def start_workers(self): for _ in range(self.num_workers): t = Thread(target=self.do_task) t.daemon = True t.start() def add_task(self, func, *args, **kwargs): args = args or () kwargs = kwargs or {} self.put((func, args, kwargs)) def do_task(self): while True: ...

 

控制 Goroutine 的并发数量

在 Go 中创建协程的成本很低,为了避免造成资源的浪费,有必要限制协程的数量,下面是一个简单的实现。 package main import ( "fmt" "sync" "time" ) var wg = sync.WaitGroup{} var jobs = make(chan int, 2) func main() { // 设 ...

 

Python 连接池简单实现

使用队列实现一个简单的连接池。 from queue import Queue class Client(object): def query(self, sql:str): return ['ok'] def disconnect(self): pass class MyClient(object): def __init__(self): self.pool = None self._client = Client() def query(self, sql:str): try: data = self._client.query(sql) except: data = [] if self.pool is not None: self.pool.free(self) return data def disconnect(self): self._client.disconnect() class MyClientPool(object): def __init__(self, max_conns=5, max_timeout=5): self.max_conns = max_conns ...

 

虚拟机下无法访问宿主机

开发环境一直都是 Hyper-V 下虚拟机,但是最近不知道为什么,虚拟机无法访问宿主机,如虚拟机 IP 段为 237,在虚拟机内无法访问 128 或者 137 等 IP 段。 最后发现是某 ...

 
<< Newer Posts Older Posts >>