All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scouter.server.support.telegraf.TgConfig Maven / Gradle / Ivy

There is a newer version: 2.20.0
Show newest version
/*
 *  Copyright 2015 the original author or authors.
 *  @https://github.com/scouter-project/scouter
 *
 *  Licensed 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 scouter.server.support.telegraf;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Gun Lee ([email protected]) on 05/01/2019
 */
@XmlRootElement(name = "TelegrafConfig")
public class TgConfig {

    public boolean enabled;
    public boolean debugEnabled;
    public boolean deltaCounterNormalizeDefault;
    public int deltaCounterNormalizeDefaultSeconds;
    public int objectDeadtimeMs;

    @XmlElementWrapper
    @XmlElement(name = "measurement")
    public List measurements = new ArrayList();

    public TgConfig() {
        asDefault();
    }

    public void asDefault() {
        enabled = true;
        debugEnabled = false;
        deltaCounterNormalizeDefault = true;
        deltaCounterNormalizeDefaultSeconds = 30;
        objectDeadtimeMs = 35000;
    }

    public static void main(String[] args) throws JAXBException {
        TgmConfig tgmConfig = new TgmConfig("M1");
        tgmConfig.objFamilyAppendTags.add("tag1");
        tgmConfig.objFamilyAppendTags.add("tag2");

        tgmConfig.objTypeAppendTags.add("tg1");
        tgmConfig.objTypeAppendTags.add("tg2");

        tgmConfig.hostMappings.add(new TgmConfig.HostMapping("host1", "sc-host1"));
        tgmConfig.hostMappings.add(new TgmConfig.HostMapping("host2", "sc-host2"));

        TgmConfig tgmConfig2 = new TgmConfig("M2");

        TgConfig tgConfig = new TgConfig();
        tgConfig.measurements.add(tgmConfig);
        tgConfig.measurements.add(tgmConfig2);

        JAXBContext jc = JAXBContext.newInstance(TgConfig.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(tgConfig, System.out);

        m.marshal(tgmConfig, new File("./temp.xml"));

        Unmarshaller um = jc.createUnmarshaller();
        Object o = um.unmarshal(new File("./temp.xml"));
        System.out.println(o);

    }

    public static String getSampleContents() {
        return "\n" +
                "\n" +
                "    true\n" +
                "    true\n" +
                "    true\n" +
                "    30\n" +
                "    35000\n" +
                "    \n" +
                "        \n" +
                "            cpu\n" +
                "            true\n" +
                "            false\n" +
                "            HOST_METRIC\n" +
                "            \n" +
                "            HOST_NEW\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            linux\n" +
                "            LINUX_NEW\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    cpu\n" +
                "                    cpu-total\n" +
                "                \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    usage_user\n" +
                "                    cpu_user_$cpu$\n" +
                "                    cpu_user_$cpu$\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    usage_system\n" +
                "                    cpu_system_$cpu$\n" +
                "                    cpu_system_$cpu$\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    usage_steal\n" +
                "                    cpu_steal_$cpu$\n" +
                "                    cpu_steal_$cpu$\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    usage_iowait\n" +
                "                    cpu_iowait_$cpu$\n" +
                "                    cpu_iowait_$cpu$\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    usage_nice\n" +
                "                    cpu_nice_$cpu$\n" +
                "                    cpu_nice_$cpu$\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            mem\n" +
                "            true\n" +
                "            false\n" +
                "            HOST_METRIC\n" +
                "            \n" +
                "            HOST_NEW\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            linux\n" +
                "            LINUX_NEW\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    used_percent\n" +
                "                    mem-used_percent\n" +
                "                    mem_used_percent\n" +
                "                    %\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    free\n" +
                "                    mem-free\n" +
                "                    mem_free\n" +
                "                    byte\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    total\n" +
                "                    mem-total\n" +
                "                    mem_total\n" +
                "                    byte\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            redis\n" +
                "            true\n" +
                "            false\n" +
                "            redis\n" +
                "            \n" +
                "            redis\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            redis\n" +
                "            redis\n" +
                "            \n" +
                "                port\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    keyspace_hits\n" +
                "                    keyspace_hits\n" +
                "                    keyspace_hits\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    used_memory\n" +
                "                    used_memory\n" +
                "                    used_memory\n" +
                "                    bytes\n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    expired_keys\n" +
                "                    expired_keys\n" +
                "                    expired_keys\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "                \n" +
                "                    evicted_keys\n" +
                "                    evicted_keys\n" +
                "                    expired_keys\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "                \n" +
                "                    total_connections_received\n" +
                "                    total_connections_received\n" +
                "                    total_connections_received\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "                \n" +
                "                    total_commands_processed\n" +
                "                    total_commands_processed\n" +
                "                    total_commands_processed\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            redis_keyspace\n" +
                "            true\n" +
                "            false\n" +
                "            redis\n" +
                "            \n" +
                "            redis\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            redis\n" +
                "            redis\n" +
                "            \n" +
                "                port\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    keys\n" +
                "                    keys-$database$\n" +
                "                    keys-$database$\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "                \n" +
                "                    expires\n" +
                "                    expires-$database$\n" +
                "                    expires-$database$\n" +
                "                    ea\n" +
                "                    false\n" +
                "                    30\n" +
                "                    BOTH\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            nginx\n" +
                "            true\n" +
                "            false\n" +
                "            nginx\n" +
                "            \n" +
                "            nginx\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            nginx\n" +
                "            nginx\n" +
                "            \n" +
                "                port\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    active\n" +
                "                    active\n" +
                "                    active-connections\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    reading\n" +
                "                    reading\n" +
                "                    active-conn-header-reading\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    writing\n" +
                "                    writing\n" +
                "                    active-conn-working\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    waiting\n" +
                "                    waiting\n" +
                "                    keepalived-connections\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    accepts\n" +
                "                    accepts\n" +
                "                    accepted-connections\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    handled\n" +
                "                    handled\n" +
                "                    handled-connections\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    requests\n" +
                "                    requests\n" +
                "                    request-count\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            mysql\n" +
                "            true\n" +
                "            false\n" +
                "            mysql\n" +
                "            \n" +
                "            mysql\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            mysql\n" +
                "            \n" +
                "            \n" +
                "                server\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    connections\n" +
                "                    connections\n" +
                "                    connections\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    bytes_received\n" +
                "                    bytes_received\n" +
                "                    bytes_received\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    bytes_sent\n" +
                "                    bytes_sent\n" +
                "                    bytes_sent\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    com_commit\n" +
                "                    com_commit\n" +
                "                    com_commit\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    com_insert\n" +
                "                    com_insert\n" +
                "                    com_insert\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    com_update\n" +
                "                    com_update\n" +
                "                    com_update\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    com_select\n" +
                "                    com_select\n" +
                "                    com_select\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    innodb_data_reads\n" +
                "                    innodb_data_reads\n" +
                "                    innodb_data_reads\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    innodb_data_writes\n" +
                "                    innodb_data_writes\n" +
                "                    innodb_data_writes\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    innodb_row_lock_waits\n" +
                "                    innodb_row_lock_waits\n" +
                "                    innodb_row_lock_waits\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    innodb_buffer_pool_pages_total\n" +
                "                    innodb_buffer_pool_pages_dirty\n" +
                "                    innodb_buffer_pool_pages_dirty\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_buffer_pool_pages_dirty\n" +
                "                    innodb_buffer_pool_pages_dirty\n" +
                "                    innodb_buffer_pool_pages_dirty\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_buffer_pool_pages_free\n" +
                "                    innodb_buffer_pool_pages_free\n" +
                "                    innodb_buffer_pool_pages_free\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_data_pending_fsyncs\n" +
                "                    innodb_data_pending_fsyncs\n" +
                "                    innodb_data_pending_fsyncs\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_data_pending_reads\n" +
                "                    innodb_data_pending_reads\n" +
                "                    innodb_data_pending_reads\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_data_pending_writes\n" +
                "                    innodb_data_pending_writes\n" +
                "                    innodb_data_pending_writes\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "                \n" +
                "                    innodb_row_lock_current_waits\n" +
                "                    innodb_row_lock_current_waits\n" +
                "                    innodb_row_lock_current_waits\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    NONE\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "        \n" +
                "            mysql_innodb\n" +
                "            true\n" +
                "            false\n" +
                "            mysql\n" +
                "            \n" +
                "            mysql\n" +
                "            \n" +
                "                scouter_obj_type_prefix\n" +
                "            \n" +
                "            \n" +
                "            mysql\n" +
                "            mysql\n" +
                "            \n" +
                "                server\n" +
                "            \n" +
                "            host\n" +
                "            \n" +
                "            \n" +
                "            \n" +
                "                \n" +
                "                    dml_deletes\n" +
                "                    dml_deletes\n" +
                "                    dml_deletes\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    dml_updates\n" +
                "                    dml_updates\n" +
                "                    dml_updates\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    dml_inserts\n" +
                "                    dml_inserts\n" +
                "                    dml_inserts\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "                \n" +
                "                    dml_reads\n" +
                "                    dml_reads\n" +
                "                    dml_reads\n" +
                "                    \n" +
                "                    false\n" +
                "                    30\n" +
                "                    DELTA\n" +
                "                \n" +
                "            \n" +
                "        \n" +
                "    \n" +
                "\n";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy