Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id BDBD2200BF3 for ; Thu, 5 Jan 2017 08:41:00 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id BC6CE160B26; Thu, 5 Jan 2017 07:41:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 11E11160B42 for ; Thu, 5 Jan 2017 08:40:59 +0100 (CET) Received: (qmail 13173 invoked by uid 500); 5 Jan 2017 07:40:58 -0000 Mailing-List: contact issues-help@eagle.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@eagle.apache.org Delivered-To: mailing list issues@eagle.apache.org Received: (qmail 13158 invoked by uid 99); 5 Jan 2017 07:40:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 07:40:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 6C5ED2C03DB for ; Thu, 5 Jan 2017 07:40:58 +0000 (UTC) Date: Thu, 5 Jan 2017 07:40:58 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@eagle.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (EAGLE-849) System metric collector python script MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 05 Jan 2017 07:41:00 -0000 [ https://issues.apache.org/jira/browse/EAGLE-849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15800647#comment-15800647 ] ASF GitHub Bot commented on EAGLE-849: -------------------------------------- Github user haoch commented on a diff in the pull request: https://github.com/apache/eagle/pull/763#discussion_r94724261 --- Diff: eagle-external/hadoop_jmx_collector/system_metric_collector.py --- @@ -0,0 +1,300 @@ +# !/usr/bin/python +# +# 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. +# + +from metric_collector import MetricCollector, Runner +import logging, socket, string, os, re, time + + +class SystemMetricCollector(MetricCollector): + METRIC_PREFIX = "system" + METRIC_NAME_EXCLUDE = re.compile(r"[\(|\)]") + + def run(self): + self.try_exec_func( + self.collect_cpu_metric, + self.collect_uptime_metric, + self.collect_memory_metric, + self.collect_loadavg_metric, + self.collect_ipmi_cpu_temp, + self.collect_nic_metric, + self.collect_smartdisk_metric, + self.collect_diskstat_metric + ) + + def try_exec_func(self, *funcs): + for func in funcs: + try: + logging.info("Executing: %s", func.__name__) + func() + except Exception as e: + logging.warn("Failed to execute: %s", func.__name__) + logging.exception(e) + + # ==================================== + # CPU Usage + # ==================================== + + def collect_cpu_metric(self): + cpu_metric = self.new_metric() + cpu_info = os.popen('cat /proc/stat').readlines() + demension = ["cpu", "user", "nice", "system", "idle", "wait", "irq", "softirq", "steal", "guest"] + + total_cpu = 0 + total_cpu_usage = 0 + cpu_stat_pre = None + + data_dir = "/tmp/eagle_cpu_stat_previous" --- End diff -- Resolved as suggested > System metric collector python script > ------------------------------------- > > Key: EAGLE-849 > URL: https://issues.apache.org/jira/browse/EAGLE-849 > Project: Eagle > Issue Type: Improvement > Components: System Metric Monitor > Affects Versions: v0.5.0 > Reporter: Hao Chen > Assignee: Hao Chen > Fix For: v0.5.0 > > > Refactor System metric collector python script following similar framework as existing jmx metric collector. > {code} > Single CPU Used (per_cpu_usage) = user + nice + system + wait + irq + softirq + steal + guest > Single CPU Total (per_cpu_total) = user + nice + system + idle + wait + irq + softirq + steal + guest > Single CPU Usage (%) = Single CPU Used (per_cpu_usage) / Single CPU Total (per_cpu_total) > Total CPU Usage (system.cpu.totalusage) = (total_cpu_usage - pre_total_cpu_usage) / (total_cpu - pre_total_cpu) % > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)