You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/02/07 08:24:06 UTC

[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #6176: Adopt Zabbix protocol

kezhenxu94 commented on a change in pull request #6176:
URL: https://github.com/apache/skywalking/pull/6176#discussion_r571572085



##########
File path: docs/en/setup/backend/backend-zabbix.md
##########
@@ -0,0 +1,70 @@
+# Zabbix Receiver
+Zabbix receiver is accepting the metrics of [Zabbix Agent Active Checks protocol](https://www.zabbix.com/documentation/current/manual/appendix/items/activepassive#active_checks) fromat into the [Meter System](./../../concepts-and-designs/meter.md).
+
+## Module define
+```yaml
+receiver-zabbix:
+  selector: ${SW_RECEIVER_METER:default}
+  default:
+    # Export tcp port, Zabbix agent could connected and transport data
+    port: 13800
+    # Enable config when receive agent request
+    activeFiles: agent
+```
+
+## Configuration file
+Zabbix receiver is configured via a configuration file. The configuration file defines everything related to receiving 
+ from agents, as well as which rule files to load.
+ 
+OAP can load the configuration at bootstrap. If the new configuration is not well-formed, OAP fails to start up. The files
+are located at `$CLASSPATH/zabbix-rules`.
+
+The file is written in YAML format, defined by the scheme described below. Brackets indicate that a parameter is optional.
+
+A example for zabbix agent configuration could be found [here](../../../../test/e2e/e2e-test/docker/zabbix/zabbix_agentd.conf).

Review comment:
       ```suggestion
   An example for zabbix agent configuration could be found [here](../../../../test/e2e/e2e-test/docker/zabbix/zabbix_agentd.conf).
   ```

##########
File path: docs/en/setup/backend/backend-zabbix.md
##########
@@ -0,0 +1,70 @@
+# Zabbix Receiver
+Zabbix receiver is accepting the metrics of [Zabbix Agent Active Checks protocol](https://www.zabbix.com/documentation/current/manual/appendix/items/activepassive#active_checks) fromat into the [Meter System](./../../concepts-and-designs/meter.md).
+
+## Module define
+```yaml
+receiver-zabbix:
+  selector: ${SW_RECEIVER_METER:default}
+  default:
+    # Export tcp port, Zabbix agent could connected and transport data
+    port: 13800
+    # Enable config when receive agent request
+    activeFiles: agent
+```
+
+## Configuration file
+Zabbix receiver is configured via a configuration file. The configuration file defines everything related to receiving 
+ from agents, as well as which rule files to load.
+ 
+OAP can load the configuration at bootstrap. If the new configuration is not well-formed, OAP fails to start up. The files
+are located at `$CLASSPATH/zabbix-rules`.
+
+The file is written in YAML format, defined by the scheme described below. Brackets indicate that a parameter is optional.
+
+A example for zabbix agent configuration could be found [here](../../../../test/e2e/e2e-test/docker/zabbix/zabbix_agentd.conf).
+You could find the Zabbix agent detail items from [Zabbix Agent docucment](https://www.zabbix.com/documentation/current/manual/config/items/itemtypes/zabbix_agent).

Review comment:
       ```suggestion
   You could find the Zabbix agent detail items from [Zabbix Agent documentation](https://www.zabbix.com/documentation/current/manual/config/items/itemtypes/zabbix_agent).
   ```

##########
File path: docs/en/setup/backend/backend-zabbix.md
##########
@@ -0,0 +1,70 @@
+# Zabbix Receiver
+Zabbix receiver is accepting the metrics of [Zabbix Agent Active Checks protocol](https://www.zabbix.com/documentation/current/manual/appendix/items/activepassive#active_checks) fromat into the [Meter System](./../../concepts-and-designs/meter.md).

Review comment:
       ```suggestion
   Zabbix receiver is accepting the metrics of [Zabbix Agent Active Checks protocol](https://www.zabbix.com/documentation/current/manual/appendix/items/activepassive#active_checks) format into the [Meter System](./../../concepts-and-designs/meter.md).
   ```

##########
File path: oap-server/server-receiver-plugin/skywalking-zabbix-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/zabbix/provider/protocol/ZabbixProtocolEncoder.java
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.receiver.zabbix.provider.protocol;
+
+import com.google.common.base.Charsets;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.MessageToMessageEncoder;
+import org.apache.skywalking.oap.server.receiver.zabbix.provider.protocol.bean.ZabbixResponse;
+import org.apache.skywalking.oap.server.receiver.zabbix.provider.protocol.bean.ZabbixResponseJsonSerializer;
+
+import java.util.List;
+
+public class ZabbixProtocolEncoder extends MessageToMessageEncoder<ZabbixResponse> {
+    private final Gson gson = new GsonBuilder()
+        .registerTypeAdapter(ZabbixResponse.class, new ZabbixResponseJsonSerializer()).create();
+
+    @Override
+    protected void encode(ChannelHandlerContext channelHandlerContext, ZabbixResponse zabbixResponse, List<Object> list) throws Exception {
+        String responsePayload = gson.toJson(zabbixResponse);
+
+        // Build header
+        int payloadLength = responsePayload.length();
+        byte[] header = new byte[] {
+            'Z', 'B', 'X', 'D', '\1',
+            (byte) (payloadLength & 0xFF),
+            (byte) (payloadLength >> 8 & 0xFF),
+            (byte) (payloadLength >> 16 & 0xFF),
+            (byte) (payloadLength >> 24 & 0xFF),
+            '\0', '\0', '\0', '\0'};
+
+        // Build and write ByteBuf
+        ByteBuf buffer = channelHandlerContext.alloc().buffer(header.length + payloadLength);
+        buffer.writeBytes(header);
+        buffer.writeBytes(responsePayload.getBytes(Charsets.UTF_8));
+

Review comment:
       ```suggestion
           buffer.retain();
   ```

##########
File path: oap-server/server-bootstrap/src/main/resources/ui-initialized-templates/zabbix.yml
##########
@@ -0,0 +1,156 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# UI templates initialized file includes the default template when the SkyWalking OAP starts up at the first time.
+#
+# Also, SkyWalking would detect the existing templates in the database, once they are missing, all templates in this file
+# could be added automatically.
+
+templates:
+  - name: "Zabbix"
+    # The type includes DASHBOARD, TOPOLOGY_INSTANCE, TOPOLOGY_ENDPOINT.
+    # DASHBOARD type templates could have multiple definitions, by using different names.
+    # TOPOLOGY_INSTANCE, TOPOLOGY_ENDPOINT type templates should be defined once, as they are used in the topology page only.
+    type: "DASHBOARD"
+    # Configuration could be defined through UI, and use `export` to format in the standard JSON.
+    configuration: |-
+      [
+        {
+          "name": "Zabbix",
+          "type": "service",

Review comment:
       Need a service group here

##########
File path: docs/en/setup/backend/backend-zabbix.md
##########
@@ -0,0 +1,70 @@
+# Zabbix Receiver
+Zabbix receiver is accepting the metrics of [Zabbix Agent Active Checks protocol](https://www.zabbix.com/documentation/current/manual/appendix/items/activepassive#active_checks) fromat into the [Meter System](./../../concepts-and-designs/meter.md).
+
+## Module define
+```yaml
+receiver-zabbix:
+  selector: ${SW_RECEIVER_METER:default}
+  default:
+    # Export tcp port, Zabbix agent could connected and transport data
+    port: 13800
+    # Enable config when receive agent request
+    activeFiles: agent
+```
+
+## Configuration file
+Zabbix receiver is configured via a configuration file. The configuration file defines everything related to receiving 
+ from agents, as well as which rule files to load.
+ 
+OAP can load the configuration at bootstrap. If the new configuration is not well-formed, OAP fails to start up. The files
+are located at `$CLASSPATH/zabbix-rules`.
+
+The file is written in YAML format, defined by the scheme described below. Brackets indicate that a parameter is optional.

Review comment:
       ```suggestion
   The file is written in YAML format, defined by the scheme described below. Square brackets indicate that a parameter is optional.
   ```

##########
File path: test/e2e/e2e-test/docker/zabbix/zabbix_agentd.conf
##########
@@ -0,0 +1,529 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more

Review comment:
       I suppose this file is copied from somewhere, most of them are comments, can we simplify this file to only keep the uncommented lines?

##########
File path: oap-server/server-library/library-server/src/main/java/org/apache/skywalking/oap/server/library/server/tcp/TCPServerManager.java
##########
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.skywalking.oap.server.library.server.tcp;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.skywalking.oap.server.library.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Manager all the tcp servers.
+ */
+@Slf4j
+public class TCPServerManager {
+
+    private final String host;
+    private final EventLoopGroup bossGroup;
+    private final EventLoopGroup workerGroup;
+
+    private final AtomicBoolean started = new AtomicBoolean(false);
+
+    private final List<Server> servers = new ArrayList<>();
+
+    public TCPServerManager(String host, int bossGroupCount, int workerGroupCount) {
+        this.host = host;
+
+        this.bossGroup = new NioEventLoopGroup(bossGroupCount, new ThreadFactoryBuilder()
+            .setDaemon(true).setNameFormat("TCP-BOSS-THREAD-%d").build());
+        this.workerGroup = new NioEventLoopGroup(workerGroupCount, new ThreadFactoryBuilder()
+            .setDaemon(true).setNameFormat("TCP-WORKER-THREAD-%d").build());
+    }
+
+    /**
+     * Add new binder and save to {@link #servers}
+     */
+    public void addBinder(TCPBinder binder) {
+        ServerBootstrap bootstrap = new ServerBootstrap()
+            // All server using same group
+            .group(bossGroup, workerGroup)
+            .channel(NioServerSocketChannel.class)
+            .handler(new LoggingHandler(LogLevel.INFO))
+            .childHandler(new ChannelInitializer<SocketChannel>() {
+                @Override
+                protected void initChannel(SocketChannel channel) throws Exception {
+                    binder.initChannel(channel);
+                }
+            });
+
+        servers.add(new Server(binder, bootstrap));
+    }
+
+    /**
+     * Sync startup all TCP server
+     */
+    public void startAllServer() throws TCPServerException {
+        // Only start once
+        if (!started.compareAndSet(false, true)) {
+            return;
+        }
+
+        if (CollectionUtils.isEmpty(servers)) {
+            return;
+        }
+
+        // Bind all TCP server
+        for (Server server : servers) {
+            try {
+                server.bind();
+            } catch (Exception e) {
+                throw new TCPServerException("Starting TCP port " + server.binder.exportPort() + " failed", e);
+            }
+        }
+    }
+
+    private class Server {
+        private TCPBinder binder;
+        private ServerBootstrap bootstrap;

Review comment:
       Can be final




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org