<commit_before>#  Copyright 2014 <NAME>
#
#  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.
#
# This plugin reads data from /sys/block/<device>/stat
#
# It will only work on Linux 2.6
#
# To configure the plugin, you must specify the devices to monitor.
# The plugin takes a param 'Disk' whose string value is the exact
# device name. This param can be defined multiple times.
#
# e.g.
#
#<Plugin python>
#    ModulePath "/path/to/modules"
#    Import "blockstat"
#
#    <Module blockstat>
#        Device sda
#        Device sda1
#    </Module>
#</Plugin>
#
# The fields in /sys/block/<device>/stat are documented in
# the Linux kernel source code.
# https://www.kernel.org/doc/Documentation/block/stat.txt
#
# code borrows heavily from <NAME>'s diskstats collectd plugin
# https://github.com/indygreg/collectd-diskstats
#

import collectd
import os.path

field_map = {
    0: 'read_ios',
    1: 'read_merges',
    2: 'read_sectors',
    3: 'read_ticks',
    4: 'write_ios',
    5: 'write_merges',
    6: 'write_sectors',
    7: 'write_ticks',
    8: 'in_flight',
    9: 'io_ticks',
    10: 'time_in_queue'
}
devices = []
previous_values = {}


def blockstat_config(c):
    if c.values[0] != 'blockstat':
        return
    for child in c.children:
        if child.key == 'Device':
            for v in child.values:
                if v not in devices:
                    devices.append(v)
                    if v not in previous_values:
                        previous_values[v] = {}


def blockstat_read(data=None):
    # if no devices to monitor, do nothing
    if not len(devices):
        return
    for device in devices:
        statspath = "/sys/block/{0}/stat".format(device)
        # skip devices that don't exist<commit_msg>add info string on monitored devices<commit_after>#  Copyright 2014 <NAME>
#
#  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.
#
# This plugin reads data from /sys/block/<device>/stat
#
# It will only work on Linux 2.6
#
# To configure the plugin, you must specify the devices to monitor.
# The plugin takes a param 'Disk' whose string value is the exact
# device name. This param can be defined multiple times.
#
# e.g.
#
#<Plugin python>
#    ModulePath "/path/to/modules"
#    Import "blockstat"
#
#    <Module blockstat>
#        Device sda
#        Device sda1
#    </Module>
#</Plugin>
#
# The fields in /sys/block/<device>/stat are documented in
# the Linux kernel source code.
# https://www.kernel.org/doc/Documentation/block/stat.txt
#
# code borrows heavily from Gregory Szorc's diskstats collectd plugin
# https://github.com/indygreg/collectd-diskstats
#

import collectd
import os.path

field_map = {
    0: 'read_ios',
    1: 'read_merges',
    2: 'read_sectors',
    3: 'read_ticks',
    4: 'write_ios',
    5: 'write_merges',
    6: 'write_sectors',
    7: 'write_ticks',
    8: 'in_flight',
    9: 'io_ticks',
    10: 'time_in_queue'
}
devices = []
previous_values = {}


def blockstat_config(c):
    if c.values[0] != 'blockstat':
        return
    for child in c.children:
        if child.key == 'Device':
            for v in child.values:
                if v not in devices:
                    devices.append(v)
                    collectd.info(
                        'collecting blockstat for: %s' % v
                    )
                    if v not in previous_values:
                        previous_values[v] = {}


def blockstat_read(data=None):
    # if no devices to monitor, do nothing
    if not len(devices):
        return
    for device in devices:
        statspath = "/sys/block/{0}/stat".format(device)
        # skip devices that don't exist
{'fraction_non_alphanumeric': 0.10353753235547886, 'fraction_numerical': 0.010785159620362382, 'mean_word_length': 2.6397174254317113, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '446802', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1397, 'n_words': 503}