Compare commits
13 Commits
master
...
branch-1.6
Author | SHA1 | Date | |
---|---|---|---|
|
5e25fccdb0 | ||
|
96083fd4fa | ||
|
fb7082b388 | ||
|
f20826e475 | ||
|
35d354c45c | ||
|
9eedeba999 | ||
|
8487889c24 | ||
|
d0401e7b1c | ||
|
06b4775271 | ||
|
eecc164c6d | ||
|
b1c4cc09be | ||
|
2889495a77 | ||
|
d41fb7baf7 |
1
.github/CODEOWNERS
vendored
1
.github/CODEOWNERS
vendored
@ -1 +0,0 @@
|
|||||||
* @penberg
|
|
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,9 +0,0 @@
|
|||||||
/target/
|
|
||||||
/bin/
|
|
||||||
dependency-reduced-pom.xml
|
|
||||||
scylla-apiclient/target/
|
|
||||||
.classpath
|
|
||||||
.project
|
|
||||||
.settings
|
|
||||||
build/
|
|
||||||
/.idea/
|
|
35
README.md
35
README.md
@ -1,25 +1,22 @@
|
|||||||
# Scylla JMX Server
|
# Urchin JMX Interface
|
||||||
|
This is the JMX interface for Scylla
|
||||||
Scylla JMX server implements the Apache Cassandra JMX interface for compatibility with tooling such as `nodetool`. The JMX server uses Scylla's REST API to communicate with a Scylla server.
|
## Compile
|
||||||
|
To compile do:
|
||||||
## Compiling
|
```
|
||||||
|
mvn install
|
||||||
To compile JMX server, run:
|
|
||||||
|
|
||||||
```console
|
|
||||||
$Â mvn --file scylla-jmx-parent/pom.xml package
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Running
|
## Run
|
||||||
|
The maven will create an uber-jar with all dependency under the target directory. You should run it with the remote jmx enable so the nodetool will be able to connect to it.
|
||||||
|
|
||||||
To start the JMX server, run:
|
```
|
||||||
|
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7199 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar target/scylla-jmx-1.0.jar
|
||||||
```console
|
|
||||||
$ ./scripts/scylla-jmx
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To get help on supported options:
|
## Setting IP and Port
|
||||||
|
By default the the JMX would connect to a node on the localhost
|
||||||
|
on port 10000.
|
||||||
|
|
||||||
```console
|
The jmx API uses the system properties to set the IP address and Port.
|
||||||
$ ./scripts/scylla-jmx --help
|
To change the ip address use the apiaddress property (e.g. -Dapiaddress=1.1.1.1)
|
||||||
```
|
To change the port use the apiport (e.g. -Dapiport=10001)
|
||||||
|
@ -1,49 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
PRODUCT=scylla
|
VERSION=1.6.6
|
||||||
VERSION=666.development
|
|
||||||
|
|
||||||
if test -f version
|
if test -f version
|
||||||
then
|
then
|
||||||
SCYLLA_VERSION=$(cat version | awk -F'-' '{print $1}')
|
SCYLLA_VERSION=$(cat version | awk -F'-' '{print $1}')
|
||||||
SCYLLA_RELEASE=$(cat version | awk -F'-' '{print $2}')
|
SCYLLA_RELEASE=$(cat version | awk -F'-' '{print $2}')
|
||||||
else
|
else
|
||||||
DATE=$(date --utc +%Y%m%d)
|
DATE=$(date +%Y%m%d)
|
||||||
GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
|
GIT_COMMIT=$(git log --pretty=format:'%h' -n 1)
|
||||||
SCYLLA_VERSION=$VERSION
|
SCYLLA_VERSION=$VERSION
|
||||||
SCYLLA_RELEASE=$DATE.$GIT_COMMIT
|
SCYLLA_RELEASE=$DATE.$GIT_COMMIT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
usage() {
|
|
||||||
echo "usage: $0"
|
|
||||||
echo " [--version product-version-release] # override p-v-r"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
OVERRIDE=
|
|
||||||
while [[ $# > 0 ]]; do
|
|
||||||
case "$1" in
|
|
||||||
--version)
|
|
||||||
OVERRIDE="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -n "$OVERRIDE" ]]; then
|
|
||||||
# regular expression for p-v-r: alphabetic+dashes for product, trailing non-dashes
|
|
||||||
# for release, everything else for version
|
|
||||||
RE='^([-a-z]+)-(.+)-([^-]+)$'
|
|
||||||
PRODUCT="$(sed -E "s/$RE/\\1/" <<<"$OVERRIDE")"
|
|
||||||
SCYLLA_VERSION="$(sed -E "s/$RE/\\2/" <<<"$OVERRIDE")"
|
|
||||||
SCYLLA_RELEASE="$(sed -E "s/$RE/\\3/" <<<"$OVERRIDE")"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$SCYLLA_VERSION-$SCYLLA_RELEASE"
|
echo "$SCYLLA_VERSION-$SCYLLA_RELEASE"
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
echo "$SCYLLA_VERSION" > build/SCYLLA-VERSION-FILE
|
echo "$SCYLLA_VERSION" > build/SCYLLA-VERSION-FILE
|
||||||
echo "$SCYLLA_RELEASE" > build/SCYLLA-RELEASE-FILE
|
echo "$SCYLLA_RELEASE" > build/SCYLLA-RELEASE-FILE
|
||||||
echo "$PRODUCT" > build/SCYLLA-PRODUCT-FILE
|
|
||||||
|
27
dist/common/sysconfig/scylla-jmx
vendored
27
dist/common/sysconfig/scylla-jmx
vendored
@ -3,30 +3,3 @@ SCYLLA_HOME=/var/lib/scylla
|
|||||||
|
|
||||||
# scylla config dir
|
# scylla config dir
|
||||||
SCYLLA_CONF=/etc/scylla
|
SCYLLA_CONF=/etc/scylla
|
||||||
|
|
||||||
# The jmx port to open
|
|
||||||
# SCYLLA_JMX_PORT="-jp 7199"
|
|
||||||
|
|
||||||
# The API port to connect to
|
|
||||||
#SCYLLA_API_PORT="-p 10000"
|
|
||||||
|
|
||||||
# API address to connect to
|
|
||||||
#SCYLLA_API_ADDR="-a localhost"
|
|
||||||
|
|
||||||
# use alternate jmx address
|
|
||||||
#SCYLLA_JMX_ADDR="-ja localhost"
|
|
||||||
|
|
||||||
# A configuration file to use
|
|
||||||
#SCYLLA_JMX_FILE="-cf /etc/scylla.d/scylla-user.cfg"
|
|
||||||
|
|
||||||
# The location of the jmx proxy jar file
|
|
||||||
SCYLLA_JMX_LOCAL="-l /opt/scylladb/jmx"
|
|
||||||
|
|
||||||
# allow to run remotely
|
|
||||||
#SCYLLA_JMX_REMOTE="-r"
|
|
||||||
|
|
||||||
# allow debug
|
|
||||||
#SCYLLA_JMX_DEBUG="-d"
|
|
||||||
|
|
||||||
# specify JVM options
|
|
||||||
JAVA_TOOL_OPTIONS=""
|
|
||||||
|
18
dist/common/systemd/scylla-jmx.service
vendored
18
dist/common/systemd/scylla-jmx.service
vendored
@ -1,18 +0,0 @@
|
|||||||
[Unit]
|
|
||||||
Description=Scylla JMX
|
|
||||||
Requires=scylla-server.service
|
|
||||||
After=scylla-server.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Type=simple
|
|
||||||
EnvironmentFile=/etc/sysconfig/scylla-jmx
|
|
||||||
User=scylla
|
|
||||||
Group=scylla
|
|
||||||
ExecStart=/opt/scylladb/jmx/scylla-jmx $SCYLLA_JMX_PORT $SCYLLA_API_PORT $SCYLLA_API_ADDR $SCYLLA_JMX_ADDR $SCYLLA_JMX_FILE $SCYLLA_JMX_LOCAL $SCYLLA_JMX_REMOTE $SCYLLA_JMX_DEBUG
|
|
||||||
KillMode=process
|
|
||||||
Restart=on-abnormal
|
|
||||||
Slice=scylla-helper.slice
|
|
||||||
WorkingDirectory=/var/lib/scylla
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
16
dist/common/systemd/scylla-jmx.service.in
vendored
Normal file
16
dist/common/systemd/scylla-jmx.service.in
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Scylla JMX
|
||||||
|
Requires=scylla-server.service
|
||||||
|
After=scylla-server.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
EnvironmentFile=@@SYSCONFDIR@@/scylla-jmx
|
||||||
|
User=scylla
|
||||||
|
Group=scylla
|
||||||
|
ExecStart=/usr/lib/scylla/jmx/scylla-jmx -l /usr/lib/scylla/jmx
|
||||||
|
KillMode=process
|
||||||
|
Restart=on-abnormal
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
14
dist/debian/control.template
vendored
14
dist/debian/control.template
vendored
@ -1,14 +0,0 @@
|
|||||||
Source: %{product}-jmx
|
|
||||||
Maintainer: Takuya ASADA <syuu@scylladb.com>
|
|
||||||
Homepage: http://scylladb.com
|
|
||||||
Section: database
|
|
||||||
Priority: optional
|
|
||||||
Standards-Version: 3.9.5
|
|
||||||
Rules-Requires-Root: no
|
|
||||||
|
|
||||||
Package: %{product}-jmx
|
|
||||||
Architecture: all
|
|
||||||
Depends: ${shlibs:Depends}, ${misc:Depends}, openjdk-8-jre-headless | openjdk-8-jre | oracle-java8-set-default | adoptopenjdk-8-hotspot-jre | openjdk-11-jre-headless | openjdk-11-jre |oracle-java11-set-default , %{product}-server
|
|
||||||
Description: Scylla JMX server binaries
|
|
||||||
Scylla is a highly scalable, eventually consistent, distributed,
|
|
||||||
partitioned row DB.
|
|
23
dist/debian/debian/rules
vendored
23
dist/debian/debian/rules
vendored
@ -1,23 +0,0 @@
|
|||||||
#!/usr/bin/make -f
|
|
||||||
|
|
||||||
include /usr/share/dpkg/pkg-info.mk
|
|
||||||
|
|
||||||
override_dh_auto_build:
|
|
||||||
|
|
||||||
override_dh_auto_clean:
|
|
||||||
|
|
||||||
override_dh_auto_install:
|
|
||||||
dh_auto_install
|
|
||||||
cd scylla-jmx; ./install.sh --packaging --root "$(CURDIR)/debian/tmp" --sysconfdir /etc/default
|
|
||||||
|
|
||||||
override_dh_installinit:
|
|
||||||
ifeq ($(DEB_SOURCE),scylla-jmx)
|
|
||||||
dh_installinit --no-start
|
|
||||||
else
|
|
||||||
dh_installinit --no-start --name scylla-jmx
|
|
||||||
endif
|
|
||||||
|
|
||||||
override_dh_strip_nondeterminism:
|
|
||||||
|
|
||||||
%:
|
|
||||||
dh $@
|
|
4
dist/debian/debian/scylla-jmx.install
vendored
4
dist/debian/debian/scylla-jmx.install
vendored
@ -1,4 +0,0 @@
|
|||||||
etc/default/scylla-jmx
|
|
||||||
etc/systemd/system/scylla-jmx.service.d/sysconfdir.conf
|
|
||||||
opt/scylladb/jmx/*
|
|
||||||
usr/lib/scylla/jmx/*
|
|
7
dist/debian/debian/scylla-jmx.postinst
vendored
7
dist/debian/debian/scylla-jmx.postinst
vendored
@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -d /run/systemd/system ]; then
|
|
||||||
systemctl --system daemon-reload >/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
#DEBHELPER#
|
|
7
dist/debian/debian/scylla-jmx.postrm
vendored
7
dist/debian/debian/scylla-jmx.postrm
vendored
@ -1,7 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
if [ -d /run/systemd/system ]; then
|
|
||||||
systemctl --system daemon-reload >/dev/null || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
#DEBHELPER#
|
|
1
dist/debian/debian/scylla-jmx.service
vendored
1
dist/debian/debian/scylla-jmx.service
vendored
@ -1 +0,0 @@
|
|||||||
../../common/systemd/scylla-jmx.service
|
|
80
dist/debian/debian_files_gen.py
vendored
80
dist/debian/debian_files_gen.py
vendored
@ -1,80 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
#
|
|
||||||
# Copyright (C) 2020 ScyllaDB
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# This file is part of Scylla.
|
|
||||||
#
|
|
||||||
# Scylla is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Scylla is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
import string
|
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import re
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
class DebianFilesTemplate(string.Template):
|
|
||||||
delimiter = '%'
|
|
||||||
|
|
||||||
scriptdir = os.path.dirname(__file__)
|
|
||||||
|
|
||||||
with open(os.path.join(scriptdir, 'changelog.template')) as f:
|
|
||||||
changelog_template = f.read()
|
|
||||||
|
|
||||||
with open(os.path.join(scriptdir, 'control.template')) as f:
|
|
||||||
control_template = f.read()
|
|
||||||
|
|
||||||
with open('build/SCYLLA-PRODUCT-FILE') as f:
|
|
||||||
product = f.read().strip()
|
|
||||||
|
|
||||||
with open('build/SCYLLA-VERSION-FILE') as f:
|
|
||||||
version = f.read().strip().replace('.rc', '~rc').replace('_', '-')
|
|
||||||
|
|
||||||
with open('build/SCYLLA-RELEASE-FILE') as f:
|
|
||||||
release = f.read().strip()
|
|
||||||
|
|
||||||
if os.path.exists('build/debian/debian'):
|
|
||||||
shutil.rmtree('build/debian/debian')
|
|
||||||
shutil.copytree('dist/debian/debian', 'build/debian/debian')
|
|
||||||
|
|
||||||
if product != 'scylla':
|
|
||||||
for p in Path('build/debian/debian').glob('scylla-*'):
|
|
||||||
# pat1: scylla-server.service
|
|
||||||
# -> scylla-enterprise-server.scylla-server.service
|
|
||||||
# pat2: scylla-server.scylla-fstrim.service
|
|
||||||
# -> scylla-enterprise-server.scylla-fstrim.service
|
|
||||||
# pat3: scylla-conf.install
|
|
||||||
# -> scylla-enterprise-conf.install
|
|
||||||
|
|
||||||
if m := re.match(r'^scylla(-[^.]+)\.service$', p.name):
|
|
||||||
p.rename(p.parent / f'{product}{m.group(1)}.{p.name}')
|
|
||||||
elif m := re.match(r'^scylla(-[^.]+\.scylla-[^.]+\.[^.]+)$', p.name):
|
|
||||||
p.rename(p.parent / f'{product}{m.group(1)}')
|
|
||||||
else:
|
|
||||||
p.rename(p.parent / p.name.replace('scylla', product, 1))
|
|
||||||
|
|
||||||
s = DebianFilesTemplate(changelog_template)
|
|
||||||
changelog_applied = s.substitute(product=product, version=version, release=release, revision='1', codename='stable')
|
|
||||||
|
|
||||||
s = DebianFilesTemplate(control_template)
|
|
||||||
control_applied = s.substitute(product=product)
|
|
||||||
|
|
||||||
with open('build/debian/debian/changelog', 'w') as f:
|
|
||||||
f.write(changelog_applied)
|
|
||||||
|
|
||||||
with open('build/debian/debian/control', 'w') as f:
|
|
||||||
f.write(control_applied)
|
|
34
dist/redhat/build_rpm.sh
vendored
Executable file
34
dist/redhat/build_rpm.sh
vendored
Executable file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
RPMBUILD=`pwd`/build/rpmbuild
|
||||||
|
|
||||||
|
if [ ! -e dist/redhat/build_rpm.sh ]; then
|
||||||
|
echo "run build_rpm.sh in top of scylla-jmx dir"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo yum install -y rpm-build git
|
||||||
|
|
||||||
|
OS=`awk '{print $1}' /etc/redhat-release`
|
||||||
|
if [ "$OS" = "Fedora" ] && [ ! -f /usr/bin/mock ]; then
|
||||||
|
sudo yum -y install mock
|
||||||
|
elif [ "$OS" = "CentOS" ] && [ ! -f /usr/bin/yum-builddep ]; then
|
||||||
|
sudo yum -y install yum-utils
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION=$(./SCYLLA-VERSION-GEN)
|
||||||
|
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE)
|
||||||
|
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)
|
||||||
|
mkdir -p $RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
||||||
|
git archive --format=tar --prefix=scylla-jmx-$SCYLLA_VERSION/ HEAD -o build/rpmbuild/SOURCES/scylla-jmx-$VERSION.tar
|
||||||
|
cp dist/redhat/scylla-jmx.spec.in $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
sed -i -e "s/@@VERSION@@/$SCYLLA_VERSION/g" $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
sed -i -e "s/@@RELEASE@@/$SCYLLA_RELEASE/g" $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
|
||||||
|
if [ "$OS" = "Fedora" ]; then
|
||||||
|
rpmbuild -bs --define "_topdir $RPMBUILD" $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
/usr/bin/mock rebuild --resultdir=`pwd`/build/rpms $RPMBUILD/SRPMS/scylla-jmx-$VERSION*.src.rpm
|
||||||
|
else
|
||||||
|
sudo yum-builddep -y $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
rpmbuild -ba --define "_topdir $RPMBUILD" $RPMBUILD/SPECS/scylla-jmx.spec
|
||||||
|
fi
|
75
dist/redhat/scylla-jmx.spec
vendored
75
dist/redhat/scylla-jmx.spec
vendored
@ -1,75 +0,0 @@
|
|||||||
Name: %{product}-jmx
|
|
||||||
Version: %{version}
|
|
||||||
Release: %{release}%{?dist}
|
|
||||||
Summary: Scylla JMX
|
|
||||||
Group: Applications/Databases
|
|
||||||
|
|
||||||
License: AGPLv3
|
|
||||||
URL: http://www.scylladb.com/
|
|
||||||
Source0: %{reloc_pkg}
|
|
||||||
|
|
||||||
BuildArch: noarch
|
|
||||||
BuildRequires: systemd-units
|
|
||||||
Requires: %{product}-server jre-1.8.0-headless
|
|
||||||
AutoReqProv: no
|
|
||||||
|
|
||||||
%description
|
|
||||||
|
|
||||||
|
|
||||||
%prep
|
|
||||||
%setup -q -n scylla-jmx
|
|
||||||
|
|
||||||
|
|
||||||
%build
|
|
||||||
|
|
||||||
%install
|
|
||||||
./install.sh --packaging --root "$RPM_BUILD_ROOT"
|
|
||||||
|
|
||||||
%pre
|
|
||||||
/usr/sbin/groupadd scylla 2> /dev/null || :
|
|
||||||
/usr/sbin/useradd -g scylla -s /sbin/nologin -r -d ${_sharedstatedir}/scylla scylla 2> /dev/null || :
|
|
||||||
ping -c1 `hostname` > /dev/null 2>&1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo
|
|
||||||
echo "**************************************************************"
|
|
||||||
echo "* WARNING: You need to add hostname on /etc/hosts, otherwise *"
|
|
||||||
echo "* scylla-jmx will not able to start up. *"
|
|
||||||
echo "**************************************************************"
|
|
||||||
echo
|
|
||||||
fi
|
|
||||||
|
|
||||||
%post
|
|
||||||
if [ $1 -eq 1 ] ; then
|
|
||||||
/usr/bin/systemctl preset scylla-jmx.service ||:
|
|
||||||
fi
|
|
||||||
|
|
||||||
/usr/bin/systemctl daemon-reload ||:
|
|
||||||
|
|
||||||
%preun
|
|
||||||
if [ $1 -eq 0 ] ; then
|
|
||||||
/usr/bin/systemctl --no-reload disable scylla-jmx.service ||:
|
|
||||||
/usr/bin/systemctl stop scylla-jmx.service ||:
|
|
||||||
fi
|
|
||||||
|
|
||||||
%postun
|
|
||||||
/usr/bin/systemctl daemon-reload ||:
|
|
||||||
|
|
||||||
%clean
|
|
||||||
rm -rf $RPM_BUILD_ROOT
|
|
||||||
|
|
||||||
|
|
||||||
%files
|
|
||||||
%defattr(-,root,root)
|
|
||||||
|
|
||||||
%config(noreplace) %{_sysconfdir}/sysconfig/scylla-jmx
|
|
||||||
%{_unitdir}/scylla-jmx.service
|
|
||||||
/opt/scylladb/jmx/scylla-jmx
|
|
||||||
/opt/scylladb/jmx/scylla-jmx-1.1.jar
|
|
||||||
/opt/scylladb/jmx/symlinks/scylla-jmx
|
|
||||||
%{_prefix}/lib/scylla/jmx/scylla-jmx
|
|
||||||
%{_prefix}/lib/scylla/jmx/scylla-jmx-1.1.jar
|
|
||||||
%{_prefix}/lib/scylla/jmx/symlinks/scylla-jmx
|
|
||||||
|
|
||||||
%changelog
|
|
||||||
* Fri Aug 7 2015 Takuya ASADA Takuya ASADA <syuu@cloudius-systems.com>
|
|
||||||
- inital version of scylla-tools.spec
|
|
80
dist/redhat/scylla-jmx.spec.in
vendored
Normal file
80
dist/redhat/scylla-jmx.spec.in
vendored
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
Name: scylla-jmx
|
||||||
|
Version: @@VERSION@@
|
||||||
|
Release: @@RELEASE@@%{?dist}
|
||||||
|
Summary: Scylla JMX
|
||||||
|
Group: Applications/Databases
|
||||||
|
|
||||||
|
License: AGPLv3
|
||||||
|
URL: http://www.scylladb.com/
|
||||||
|
Source0: %{name}-@@VERSION@@-@@RELEASE@@.tar
|
||||||
|
|
||||||
|
BuildArch: noarch
|
||||||
|
BuildRequires: maven systemd-units java-devel
|
||||||
|
Requires: scylla-server java-headless
|
||||||
|
|
||||||
|
%description
|
||||||
|
|
||||||
|
|
||||||
|
%prep
|
||||||
|
%setup -q
|
||||||
|
|
||||||
|
|
||||||
|
%build
|
||||||
|
mvn -B install
|
||||||
|
mkdir build
|
||||||
|
cp dist/common/systemd/scylla-jmx.service.in build/scylla-jmx.service
|
||||||
|
sed -i -e "s#@@SYSCONFDIR@@#/etc/sysconfig#g" build/scylla-jmx.service
|
||||||
|
|
||||||
|
%install
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
|
||||||
|
mkdir -p $RPM_BUILD_ROOT%{_unitdir}
|
||||||
|
mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/scylla/
|
||||||
|
|
||||||
|
install -m644 dist/common/sysconfig/scylla-jmx $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/
|
||||||
|
install -m644 build/*.service $RPM_BUILD_ROOT%{_unitdir}/
|
||||||
|
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla
|
||||||
|
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx
|
||||||
|
install -d -m755 $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks
|
||||||
|
install -m644 target/scylla-jmx-1.0.jar $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/
|
||||||
|
install -m755 scripts/scylla-jmx $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx
|
||||||
|
ln -sf /usr/bin/java $RPM_BUILD_ROOT%{_prefix}/lib/scylla/jmx/symlinks/scylla-jmx
|
||||||
|
|
||||||
|
%pre
|
||||||
|
/usr/sbin/groupadd scylla 2> /dev/null || :
|
||||||
|
/usr/sbin/useradd -g scylla -s /sbin/nologin -r -d ${_sharedstatedir}/scylla scylla 2> /dev/null || :
|
||||||
|
ping -c1 `hostname` > /dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo
|
||||||
|
echo "**************************************************************"
|
||||||
|
echo "* WARNING: You need to add hostname on /etc/hosts, otherwise *"
|
||||||
|
echo "* scylla-jmx will not able to start up. *"
|
||||||
|
echo "**************************************************************"
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
|
||||||
|
%post
|
||||||
|
%systemd_post scylla-jmx.service
|
||||||
|
|
||||||
|
%preun
|
||||||
|
%systemd_preun scylla-jmx.service
|
||||||
|
|
||||||
|
%postun
|
||||||
|
%systemd_postun
|
||||||
|
|
||||||
|
%clean
|
||||||
|
rm -rf $RPM_BUILD_ROOT
|
||||||
|
|
||||||
|
|
||||||
|
%files
|
||||||
|
%defattr(-,root,root)
|
||||||
|
|
||||||
|
%config(noreplace) %{_sysconfdir}/sysconfig/scylla-jmx
|
||||||
|
%{_unitdir}/scylla-jmx.service
|
||||||
|
%{_prefix}/lib/scylla/jmx/scylla-jmx
|
||||||
|
%{_prefix}/lib/scylla/jmx/scylla-jmx-1.0.jar
|
||||||
|
%{_prefix}/lib/scylla/jmx/symlinks/scylla-jmx
|
||||||
|
|
||||||
|
%changelog
|
||||||
|
* Fri Aug 7 2015 Takuya ASADA Takuya ASADA <syuu@cloudius-systems.com>
|
||||||
|
- inital version of scylla-tools.spec
|
53
dist/ubuntu/build_deb.sh
vendored
Executable file
53
dist/ubuntu/build_deb.sh
vendored
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
if [ ! -e dist/ubuntu/build_deb.sh ]; then
|
||||||
|
echo "run build_deb.sh in top of scylla dir"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e debian ] || [ -e build ] || [ -e target ] || [ -e m2 ] || [ -e dependency-reduced-pom.xml ]; then
|
||||||
|
rm -rf debian build target m2 dependency-reduced-pom.xml
|
||||||
|
fi
|
||||||
|
sudo apt-get -y update
|
||||||
|
if [ ! -f /usr/bin/git ]; then
|
||||||
|
sudo apt-get -y install git
|
||||||
|
fi
|
||||||
|
if [ ! -f /usr/bin/mk-build-deps ]; then
|
||||||
|
sudo apt-get -y install devscripts
|
||||||
|
fi
|
||||||
|
if [ ! -f /usr/bin/equivs-build ]; then
|
||||||
|
sudo apt-get -y install equivs
|
||||||
|
fi
|
||||||
|
if [ ! -f /usr/bin/lsb_release ]; then
|
||||||
|
sudo apt-get -y install lsb-release
|
||||||
|
fi
|
||||||
|
|
||||||
|
DISTRIBUTION=`lsb_release -i|awk '{print $3}'`
|
||||||
|
RELEASE=`lsb_release -r|awk '{print $2}'`
|
||||||
|
CODENAME=`lsb_release -c|awk '{print $2}'`
|
||||||
|
|
||||||
|
VERSION=$(./SCYLLA-VERSION-GEN)
|
||||||
|
SCYLLA_VERSION=$(cat build/SCYLLA-VERSION-FILE | sed 's/\.rc/~rc/')
|
||||||
|
SCYLLA_RELEASE=$(cat build/SCYLLA-RELEASE-FILE)
|
||||||
|
if [ "$SCYLLA_VERSION" = "development" ]; then
|
||||||
|
SCYLLA_VERSION=0development
|
||||||
|
fi
|
||||||
|
echo $VERSION > version
|
||||||
|
./scripts/git-archive-all --extra version --force-submodules --prefix scylla-jmx ../scylla-jmx_$SCYLLA_VERSION-$SCYLLA_RELEASE.orig.tar.gz
|
||||||
|
|
||||||
|
cp -a dist/ubuntu/debian debian
|
||||||
|
cp dist/ubuntu/changelog.in debian/changelog
|
||||||
|
cp dist/ubuntu/rules.in debian/rules
|
||||||
|
sed -i -e "s/@@VERSION@@/$SCYLLA_VERSION/g" debian/changelog
|
||||||
|
sed -i -e "s/@@RELEASE@@/$SCYLLA_RELEASE/g" debian/changelog
|
||||||
|
sed -i -e "s/@@CODENAME@@/$CODENAME/g" debian/changelog
|
||||||
|
if [ "$RELEASE" = "14.04" ]; then
|
||||||
|
sed -i -e "s/@@DH_INSTALLINIT@@/--upstart-only/g" debian/rules
|
||||||
|
else
|
||||||
|
sed -i -e "s/@@DH_INSTALLINIT@@//g" debian/rules
|
||||||
|
fi
|
||||||
|
cp dist/common/systemd/scylla-jmx.service.in debian/scylla-jmx.service
|
||||||
|
sed -i -e "s#@@SYSCONFDIR@@#/etc/default#g" debian/scylla-jmx.service
|
||||||
|
|
||||||
|
echo Y | sudo mk-build-deps -i -r
|
||||||
|
debuild -r fakeroot -us -uc
|
@ -1,4 +1,4 @@
|
|||||||
%{product}-jmx (%{version}-%{release}-%{revision}) %{codename}; urgency=medium
|
scylla-jmx (@@VERSION@@-@@RELEASE@@-ubuntu1) @@CODENAME@@; urgency=medium
|
||||||
|
|
||||||
* Initial release.
|
* Initial release.
|
||||||
|
|
14
dist/ubuntu/debian/control
vendored
Normal file
14
dist/ubuntu/debian/control
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Source: scylla-jmx
|
||||||
|
Maintainer: Takuya ASADA <syuu@scylladb.com>
|
||||||
|
Homepage: http://scylladb.com
|
||||||
|
Section: database
|
||||||
|
Priority: optional
|
||||||
|
Standards-Version: 3.9.5
|
||||||
|
Build-Depends: debhelper (>= 9), maven, default-jdk | java7-jdk | java8-jdk
|
||||||
|
|
||||||
|
Package: scylla-jmx
|
||||||
|
Architecture: all
|
||||||
|
Depends: ${shlibs:Depends}, ${misc:Depends}, default-jre-headless | java-runtime-headless, scylla-server
|
||||||
|
Description: Scylla JMX server binaries
|
||||||
|
Scylla is a highly scalable, eventually consistent, distributed,
|
||||||
|
partitioned row DB.
|
21
dist/ubuntu/debian/scylla-jmx.upstart
vendored
Normal file
21
dist/ubuntu/debian/scylla-jmx.upstart
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# scylla-jmx - ScyllaDB
|
||||||
|
#
|
||||||
|
# ScyllaDB
|
||||||
|
|
||||||
|
description "ScyllaDB jmx"
|
||||||
|
|
||||||
|
start on started scylla-server
|
||||||
|
stop on stopping scylla-server
|
||||||
|
|
||||||
|
umask 022
|
||||||
|
|
||||||
|
console log
|
||||||
|
|
||||||
|
setuid scylla
|
||||||
|
setgid scylla
|
||||||
|
|
||||||
|
script
|
||||||
|
. /etc/default/scylla-jmx
|
||||||
|
export SCYLLA_HOME SCYLLA_CONF
|
||||||
|
exec /usr/lib/scylla/jmx/scylla-jmx -l /usr/lib/scylla/jmx
|
||||||
|
end script
|
32
dist/ubuntu/rules.in
vendored
Executable file
32
dist/ubuntu/rules.in
vendored
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
|
||||||
|
DOC = $(CURDIR)/debian/scylla-jmx/usr/share/doc/scylla-jmx
|
||||||
|
DEST = $(CURDIR)/debian/scylla-jmx/usr/lib/scylla/jmx
|
||||||
|
M2_REPO= $(CURDIR)/m2
|
||||||
|
|
||||||
|
override_dh_auto_build:
|
||||||
|
mvn -B -Dmaven.repo.local=$(M2_REPO) install
|
||||||
|
|
||||||
|
override_dh_auto_clean:
|
||||||
|
rm -rf target m2
|
||||||
|
|
||||||
|
override_dh_auto_install:
|
||||||
|
mkdir -p $(CURDIR)/debian/scylla-jmx/etc/default/ && \
|
||||||
|
cp $(CURDIR)/dist/common/sysconfig/scylla-jmx \
|
||||||
|
$(CURDIR)/debian/scylla-jmx/etc/default/
|
||||||
|
|
||||||
|
mkdir -p $(DOC) && \
|
||||||
|
cp $(CURDIR)/*.md $(DOC)
|
||||||
|
cp $(CURDIR)/NOTICE $(DOC)
|
||||||
|
|
||||||
|
mkdir -p $(DEST)
|
||||||
|
cp $(CURDIR)/scripts/scylla-jmx $(DEST)
|
||||||
|
cp $(CURDIR)/target/scylla-jmx-1.0.jar $(DEST)
|
||||||
|
mkdir $(DEST)/symlinks
|
||||||
|
ln -sf /usr/bin/java $(DEST)/symlinks/scylla-jmx
|
||||||
|
|
||||||
|
override_dh_installinit:
|
||||||
|
dh_installinit --no-start @@DH_INSTALLINIT@@
|
||||||
|
|
||||||
|
%:
|
||||||
|
dh $@
|
@ -1,26 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# This file is open source software, licensed to you under the terms
|
|
||||||
# of the Apache License, Version 2.0 (the "License"). See the NOTICE file
|
|
||||||
# distributed with this work for additional information regarding copyright
|
|
||||||
# ownership. 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.
|
|
||||||
#
|
|
||||||
|
|
||||||
. /etc/os-release
|
|
||||||
|
|
||||||
if [ "$ID" = "ubuntu" ] || [ "$ID" = "debian" ]; then
|
|
||||||
apt -y install maven openjdk-8-jdk-headless
|
|
||||||
elif [ "$ID" = "fedora" ] || [ "$ID" = "centos" ]; then
|
|
||||||
dnf install -y maven java-1.8.0-openjdk-devel
|
|
||||||
fi
|
|
173
install.sh
173
install.sh
@ -1,173 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Copyright (C) 2019 ScyllaDB
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# This file is part of Scylla.
|
|
||||||
#
|
|
||||||
# Scylla is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Scylla is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
cat <<EOF
|
|
||||||
Usage: install.sh [options]
|
|
||||||
|
|
||||||
Options:
|
|
||||||
--root /path/to/root alternative install root (default /)
|
|
||||||
--prefix /prefix directory prefix (default /usr)
|
|
||||||
--nonroot shortcut of '--disttype nonroot'
|
|
||||||
--sysconfdir /etc/sysconfig specify sysconfig directory name
|
|
||||||
--packaging use install.sh for packaging
|
|
||||||
--without-systemd skip installing systemd units
|
|
||||||
--help this helpful message
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
root=/
|
|
||||||
sysconfdir=/etc/sysconfig
|
|
||||||
nonroot=false
|
|
||||||
packaging=false
|
|
||||||
without_systemd=false
|
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
"--root")
|
|
||||||
root="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
"--prefix")
|
|
||||||
prefix="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
"--nonroot")
|
|
||||||
nonroot=true
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
"--sysconfdir")
|
|
||||||
sysconfdir="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
"--packaging")
|
|
||||||
packaging=true
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
"--without-systemd")
|
|
||||||
without_systemd=true
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
"--help")
|
|
||||||
shift 1
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
check_usermode_support() {
|
|
||||||
user=$(systemctl --help|grep -e '--user')
|
|
||||||
[ -n "$user" ]
|
|
||||||
}
|
|
||||||
|
|
||||||
if ! $packaging; then
|
|
||||||
has_java=false
|
|
||||||
if [ -x /usr/bin/java ]; then
|
|
||||||
javaver=$(/usr/bin/java -version 2>&1|head -n1|cut -f 3 -d " ")
|
|
||||||
has_java=true
|
|
||||||
fi
|
|
||||||
if ! $has_java; then
|
|
||||||
echo "Please install openjdk-8, openjdk-11, or openjdk-17 before running install.sh."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$prefix" ]; then
|
|
||||||
if $nonroot; then
|
|
||||||
prefix=~/scylladb
|
|
||||||
else
|
|
||||||
prefix=/opt/scylladb
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
rprefix=$(realpath -m "$root/$prefix")
|
|
||||||
if ! $nonroot; then
|
|
||||||
retc="$root/etc"
|
|
||||||
rsysconfdir="$root/$sysconfdir"
|
|
||||||
rusr="$root/usr"
|
|
||||||
rsystemd="$rusr/lib/systemd/system"
|
|
||||||
else
|
|
||||||
retc="$rprefix/etc"
|
|
||||||
rsysconfdir="$rprefix/$sysconfdir"
|
|
||||||
rsystemd="$HOME/.config/systemd/user"
|
|
||||||
fi
|
|
||||||
|
|
||||||
install -d -m755 "$rsysconfdir"
|
|
||||||
if ! $without_systemd; then
|
|
||||||
install -d -m755 "$rsystemd"
|
|
||||||
fi
|
|
||||||
install -d -m755 "$rprefix/scripts" "$rprefix/jmx" "$rprefix/jmx/symlinks"
|
|
||||||
|
|
||||||
install -m644 dist/common/sysconfig/scylla-jmx -Dt "$rsysconfdir"
|
|
||||||
if ! $without_systemd; then
|
|
||||||
install -m644 dist/common/systemd/scylla-jmx.service -Dt "$rsystemd"
|
|
||||||
fi
|
|
||||||
if ! $nonroot && ! $without_systemd; then
|
|
||||||
if [ "$sysconfdir" != "/etc/sysconfig" ]; then
|
|
||||||
install -d -m755 "$retc"/systemd/system/scylla-jmx.service.d
|
|
||||||
cat << EOS > "$retc"/systemd/system/scylla-jmx.service.d/sysconfdir.conf
|
|
||||||
[Service]
|
|
||||||
EnvironmentFile=
|
|
||||||
EnvironmentFile=$sysconfdir/scylla-jmx
|
|
||||||
EOS
|
|
||||||
fi
|
|
||||||
elif ! $without_systemd; then
|
|
||||||
install -d -m755 "$rsystemd"/scylla-jmx.service.d
|
|
||||||
cat << EOS > "$rsystemd"/scylla-jmx.service.d/nonroot.conf
|
|
||||||
[Service]
|
|
||||||
EnvironmentFile=
|
|
||||||
EnvironmentFile=$retc/sysconfig/scylla-jmx
|
|
||||||
ExecStart=
|
|
||||||
ExecStart=$rprefix/jmx/scylla-jmx \$SCYLLA_JMX_PORT \$SCYLLA_API_PORT \$SCYLLA_API_ADDR \$SCYLLA_JMX_ADDR \$SCYLLA_JMX_FILE \$SCYLLA_JMX_LOCAL \$SCYLLA_JMX_REMOTE \$SCYLLA_JMX_DEBUG
|
|
||||||
User=
|
|
||||||
Group=
|
|
||||||
WorkingDirectory=$rprefix
|
|
||||||
EOS
|
|
||||||
fi
|
|
||||||
|
|
||||||
install -m644 scylla-jmx-1.1.jar "$rprefix/jmx"
|
|
||||||
install -m755 scylla-jmx "$rprefix/jmx"
|
|
||||||
ln -sf /usr/bin/java "$rprefix/jmx/symlinks/scylla-jmx"
|
|
||||||
if ! $nonroot; then
|
|
||||||
install -m755 -d "$rusr"/lib/scylla/jmx/symlinks
|
|
||||||
ln -srf "$rprefix"/jmx/scylla-jmx-1.1.jar "$rusr"/lib/scylla/jmx/
|
|
||||||
ln -srf "$rprefix"/jmx/scylla-jmx "$rusr"/lib/scylla/jmx/
|
|
||||||
ln -sf /usr/bin/java "$rusr"/lib/scylla/jmx/symlinks/scylla-jmx
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $nonroot; then
|
|
||||||
sed -i -e "s#/var/lib/scylla#$rprefix#g" "$rsysconfdir"/scylla-jmx
|
|
||||||
sed -i -e "s#/etc/scylla#$rprefix/etc/scylla#g" "$rsysconfdir"/scylla-jmx
|
|
||||||
sed -i -e "s#/opt/scylladb/jmx#$rprefix/jmx#g" "$rsysconfdir"/scylla-jmx
|
|
||||||
if ! $without_systemd && check_usermode_support; then
|
|
||||||
systemctl --user daemon-reload
|
|
||||||
fi
|
|
||||||
echo "Scylla-JMX non-root install completed."
|
|
||||||
elif ! $without_systemd && ! $packaging; then
|
|
||||||
systemctl --system daemon-reload
|
|
||||||
fi
|
|
128
pom.xml
128
pom.xml
@ -2,81 +2,97 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.scylladb.jmx</groupId>
|
||||||
<artifactId>scylla-jmx</artifactId>
|
<artifactId>scylla-jmx</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>it.cavallium.scylladb.jmx</groupId>
|
|
||||||
<artifactId>scylla-jmx-parent</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<relativePath>./scylla-jmx-parent/pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<name>Scylla JMX</name>
|
<name>Scylla JMX</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>it.cavallium.scylladb.jmx</groupId>
|
<groupId>org.yaml</groupId>
|
||||||
<artifactId>scylla-apiclient</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>1.1</version>
|
<version>1.16</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-common</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>javax.ws.rs-api</artifactId>
|
||||||
|
<version>2.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
<version>1.1.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish.jersey.core</groupId>
|
||||||
|
<artifactId>jersey-client</artifactId>
|
||||||
|
<version>2.22.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>1.7.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.6.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
<version>1.7.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13.1</version>
|
<version>4.8.2</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish</groupId>
|
||||||
|
<artifactId>javax.json</artifactId>
|
||||||
|
<version>1.0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>18.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.yammer.metrics</groupId>
|
||||||
|
<artifactId>metrics-core</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.collections</groupId>
|
||||||
|
<artifactId>google-collections</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mx4j</groupId>
|
||||||
|
<artifactId>mx4j</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.10.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>11</source>
|
|
||||||
<target>11</target>
|
|
||||||
<compilerArgs>
|
|
||||||
<arg>--add-exports</arg>
|
|
||||||
<arg>java.management/com.sun.jmx.mbeanserver=scylla.jmx</arg>
|
|
||||||
<arg>--add-exports</arg>
|
|
||||||
<arg>java.management/com.sun.jmx.interceptor=scylla.jmx</arg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>2.4.1</version>
|
||||||
<configuration>
|
|
||||||
<artifactSet>
|
|
||||||
<includes>
|
|
||||||
<include>*:*</include>
|
|
||||||
</includes>
|
|
||||||
<excludes>
|
|
||||||
<exclude>com.sun.activation:jakarta.activation</exclude>
|
|
||||||
</excludes>
|
|
||||||
</artifactSet>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>module-info.class</exclude>
|
|
||||||
<exclude>META-INF/versions/*/module-info.class</exclude>
|
|
||||||
<exclude>META-INF/*.SF</exclude>
|
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
|
||||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
|
||||||
<exclude>META-INF/*.MD</exclude>
|
|
||||||
<exclude>META-INF/*.md</exclude>
|
|
||||||
<exclude>META-INF/LICENSE</exclude>
|
|
||||||
<exclude>META-INF/LICENSE.txt</exclude>
|
|
||||||
<exclude>META-INF/NOTICE</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
|
@ -1,42 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
echo "build_deb.sh --reloc-pkg build/scylla-jmx-package.tar.gz"
|
|
||||||
echo " --reloc-pkg specify relocatable package path"
|
|
||||||
echo " --builddir specify Debian package build path"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
RELOC_PKG=build/scylla-jmx-package.tar.gz
|
|
||||||
BUILDDIR=build/debian
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
"--reloc-pkg")
|
|
||||||
RELOC_PKG=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
"--builddir")
|
|
||||||
BUILDDIR="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
RELOC_PKG=$(readlink -f $RELOC_PKG)
|
|
||||||
rm -rf "$BUILDDIR"/scylla-package "$BUILDDIR"/scylla-package.orig "$BUILDDIR"/debian
|
|
||||||
mkdir -p "$BUILDDIR"/scylla-package
|
|
||||||
tar -C "$BUILDDIR"/scylla-package -xpf $RELOC_PKG
|
|
||||||
cd "$BUILDDIR"/scylla-package
|
|
||||||
|
|
||||||
RELOC_PKG=$(readlink -f $RELOC_PKG)
|
|
||||||
|
|
||||||
mv scylla-jmx/debian debian
|
|
||||||
PKG_NAME=$(dpkg-parsechangelog --show-field Source)
|
|
||||||
# XXX: Drop revision number from version string.
|
|
||||||
# Since it always '1', this should be okay for now.
|
|
||||||
PKG_VERSION=$(dpkg-parsechangelog --show-field Version |sed -e 's/-1$//')
|
|
||||||
ln -fv $RELOC_PKG ../"$PKG_NAME"_"$PKG_VERSION".orig.tar.gz
|
|
||||||
debuild -rfakeroot -us -uc
|
|
@ -1,70 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
. /etc/os-release
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
echo "build_reloc.sh --clean --nodeps"
|
|
||||||
echo " --clean clean build directory"
|
|
||||||
echo " --nodeps skip installing dependencies"
|
|
||||||
echo " --version V product-version-release string (overriding SCYLLA-VERSION-GEN)"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
CLEAN=
|
|
||||||
NODEPS=
|
|
||||||
VERSION_OVERRIDE=
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
"--clean")
|
|
||||||
CLEAN=yes
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
"--nodeps")
|
|
||||||
NODEPS=yes
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
"--version")
|
|
||||||
VERSION_OVERRIDE="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
VERSION=$(./SCYLLA-VERSION-GEN ${VERSION_OVERRIDE:+ --version "$VERSION_OVERRIDE"})
|
|
||||||
# the former command should generate build/SCYLLA-PRODUCT-FILE and some other version
|
|
||||||
# related files
|
|
||||||
PRODUCT=`cat build/SCYLLA-PRODUCT-FILE`
|
|
||||||
DEST="build/$PRODUCT-jmx-$VERSION.noarch.tar.gz"
|
|
||||||
|
|
||||||
is_redhat_variant() {
|
|
||||||
[ -f /etc/redhat-release ]
|
|
||||||
}
|
|
||||||
is_debian_variant() {
|
|
||||||
[ -f /etc/debian_version ]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if [ ! -e reloc/build_reloc.sh ]; then
|
|
||||||
echo "run build_reloc.sh in top of scylla dir"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$CLEAN" = "yes" ]; then
|
|
||||||
rm -rf build target
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$DEST" ]; then
|
|
||||||
rm "$DEST"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$NODEPS" ]; then
|
|
||||||
sudo ./install-dependencies.sh
|
|
||||||
fi
|
|
||||||
|
|
||||||
mvn -B --file scylla-jmx-parent/pom.xml install
|
|
||||||
./SCYLLA-VERSION-GEN ${VERSION_OVERRIDE:+ --version "$VERSION_OVERRIDE"}
|
|
||||||
./dist/debian/debian_files_gen.py
|
|
||||||
scripts/create-relocatable-package.py "$DEST"
|
|
@ -1,52 +0,0 @@
|
|||||||
#!/bin/bash -e
|
|
||||||
|
|
||||||
print_usage() {
|
|
||||||
echo "build_rpm.sh --reloc-pkg build/scylla-jmx-package.tar.gz"
|
|
||||||
echo " --reloc-pkg specify relocatable package path"
|
|
||||||
echo " --builddir specify rpmbuild directory"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
RELOC_PKG=build/scylla-jmx-package.tar.gz
|
|
||||||
BUILDDIR=build/redhat
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
"--reloc-pkg")
|
|
||||||
RELOC_PKG=$2
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
"--builddir")
|
|
||||||
BUILDDIR="$2"
|
|
||||||
shift 2
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
print_usage
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
RELOC_PKG=$(readlink -f $RELOC_PKG)
|
|
||||||
RPMBUILD=$(readlink -f $BUILDDIR)
|
|
||||||
mkdir -p "$BUILDDIR"
|
|
||||||
tar -C "$BUILDDIR" -xpf $RELOC_PKG scylla-jmx/SCYLLA-RELEASE-FILE scylla-jmx/SCYLLA-RELOCATABLE-FILE scylla-jmx/SCYLLA-VERSION-FILE scylla-jmx/SCYLLA-PRODUCT-FILE scylla-jmx/dist/redhat
|
|
||||||
cd "$BUILDDIR"/scylla-jmx
|
|
||||||
|
|
||||||
RELOC_PKG_BASENAME=$(basename "$RELOC_PKG")
|
|
||||||
SCYLLA_VERSION=$(cat SCYLLA-VERSION-FILE)
|
|
||||||
SCYLLA_RELEASE=$(cat SCYLLA-RELEASE-FILE)
|
|
||||||
VERSION=$SCYLLA_VERSION-$SCYLLA_RELEASE
|
|
||||||
PRODUCT=$(cat SCYLLA-PRODUCT-FILE)
|
|
||||||
|
|
||||||
mkdir -p $RPMBUILD/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
|
|
||||||
|
|
||||||
ln -fv $RELOC_PKG $RPMBUILD/SOURCES/
|
|
||||||
|
|
||||||
parameters=(
|
|
||||||
-D"version $SCYLLA_VERSION"
|
|
||||||
-D"release $SCYLLA_RELEASE"
|
|
||||||
-D"product $PRODUCT"
|
|
||||||
-D"reloc_pkg $RELOC_PKG_BASENAME"
|
|
||||||
)
|
|
||||||
|
|
||||||
cp dist/redhat/scylla-jmx.spec $RPMBUILD/SPECS
|
|
||||||
# this rpm can be install on both fedora / centos7, so drop distribution name from the file name
|
|
||||||
rpmbuild -ba "${parameters[@]}" --define '_binary_payload w2.xzdio' --define "_topdir $RPMBUILD" --undefine "dist" $RPMBUILD/SPECS/scylla-jmx.spec
|
|
@ -1,64 +0,0 @@
|
|||||||
#!/usr/bin/python3
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright (C) 2018 ScyllaDB
|
|
||||||
#
|
|
||||||
|
|
||||||
#
|
|
||||||
# This file is part of Scylla.
|
|
||||||
#
|
|
||||||
# Scylla is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU Affero General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Scylla is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import io
|
|
||||||
import os
|
|
||||||
import tarfile
|
|
||||||
import pathlib
|
|
||||||
|
|
||||||
RELOC_PREFIX='scylla-jmx'
|
|
||||||
def reloc_add(self, name, arcname=None, recursive=True, *, filter=None):
|
|
||||||
if arcname:
|
|
||||||
return self.add(name, arcname="{}/{}".format(RELOC_PREFIX, arcname))
|
|
||||||
else:
|
|
||||||
return self.add(name, arcname="{}/{}".format(RELOC_PREFIX, name))
|
|
||||||
|
|
||||||
tarfile.TarFile.reloc_add = reloc_add
|
|
||||||
|
|
||||||
ap = argparse.ArgumentParser(description='Create a relocatable scylla package.')
|
|
||||||
ap.add_argument('dest',
|
|
||||||
help='Destination file (tar format)')
|
|
||||||
|
|
||||||
args = ap.parse_args()
|
|
||||||
|
|
||||||
output = args.dest
|
|
||||||
|
|
||||||
ar = tarfile.open(output, mode='w|gz')
|
|
||||||
# relocatable package format version = 2.2
|
|
||||||
with open('build/.relocatable_package_version', 'w') as f:
|
|
||||||
f.write('2.2\n')
|
|
||||||
ar.add('build/.relocatable_package_version', arcname='.relocatable_package_version')
|
|
||||||
|
|
||||||
pathlib.Path('build/SCYLLA-RELOCATABLE-FILE').touch()
|
|
||||||
ar.reloc_add('build/SCYLLA-RELOCATABLE-FILE', arcname='SCYLLA-RELOCATABLE-FILE')
|
|
||||||
ar.reloc_add('build/SCYLLA-RELEASE-FILE', arcname='SCYLLA-RELEASE-FILE')
|
|
||||||
ar.reloc_add('build/SCYLLA-VERSION-FILE', arcname='SCYLLA-VERSION-FILE')
|
|
||||||
ar.reloc_add('build/SCYLLA-PRODUCT-FILE', arcname='SCYLLA-PRODUCT-FILE')
|
|
||||||
ar.reloc_add('dist')
|
|
||||||
ar.reloc_add('install.sh')
|
|
||||||
ar.reloc_add('target/scylla-jmx-1.1.jar', arcname='scylla-jmx-1.1.jar')
|
|
||||||
ar.reloc_add('scripts/scylla-jmx', arcname='scylla-jmx')
|
|
||||||
ar.reloc_add('README.md')
|
|
||||||
ar.reloc_add('NOTICE')
|
|
||||||
ar.reloc_add('build/debian/debian', arcname='debian')
|
|
@ -1,18 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
#
|
#
|
||||||
# Copyright (C) 2015 Cloudius Systems, Ltd.
|
# Copyright (C) 2015 Cloudius Systems, Ltd.
|
||||||
|
|
||||||
JMX_PORT="7199"
|
JMX_PORT="7199"
|
||||||
JMX_ADDR=
|
API_ADDR=""
|
||||||
|
API_PORT=""
|
||||||
API_ADDR=
|
|
||||||
API_PORT=
|
|
||||||
|
|
||||||
CONF_FILE=""
|
CONF_FILE=""
|
||||||
DEBUG=""
|
DEBUG=""
|
||||||
PARAM_HELP="-h"
|
PARAM_HELP="-h"
|
||||||
PARAM_JMX_PORT="-jp"
|
PARAM_JMX_PORT="-jp"
|
||||||
PARAM_JMX_ADDR="-ja"
|
|
||||||
PARAM_API_PORT="-p"
|
PARAM_API_PORT="-p"
|
||||||
PARAM_ADDR="-a"
|
PARAM_ADDR="-a"
|
||||||
PARAM_LOCATION="-l"
|
PARAM_LOCATION="-l"
|
||||||
@ -24,11 +20,6 @@ ALLOW_DEBUG="-d"
|
|||||||
REMOTE=0
|
REMOTE=0
|
||||||
HOSTNAME=`hostname`
|
HOSTNAME=`hostname`
|
||||||
|
|
||||||
|
|
||||||
PROPERTIES=
|
|
||||||
JMX_AUTH=-Dcom.sun.management.jmxremote.authenticate=false
|
|
||||||
JMX_SSL=-Dcom.sun.management.jmxremote.ssl=false
|
|
||||||
|
|
||||||
print_help() {
|
print_help() {
|
||||||
cat <<HLPEND
|
cat <<HLPEND
|
||||||
|
|
||||||
@ -44,7 +35,6 @@ This script receives the following command line arguments:
|
|||||||
$PARAM_JMX_PORT <port> - The jmx port to open
|
$PARAM_JMX_PORT <port> - The jmx port to open
|
||||||
$PARAM_API_PORT <port> - The API port to connect to
|
$PARAM_API_PORT <port> - The API port to connect to
|
||||||
$PARAM_ADDR <address> - The API address to connect to
|
$PARAM_ADDR <address> - The API address to connect to
|
||||||
$PARAM_JMX_ADDR <address> - JMX bind address
|
|
||||||
$PARAM_FILE <file> - A configuration file to use
|
$PARAM_FILE <file> - A configuration file to use
|
||||||
$PARAM_LOCATION <location> - The location of the jmx proxy jar file
|
$PARAM_LOCATION <location> - The location of the jmx proxy jar file
|
||||||
$ALLOW_REMOTE - When set allow remote jmx connectivity
|
$ALLOW_REMOTE - When set allow remote jmx connectivity
|
||||||
@ -63,12 +53,12 @@ do
|
|||||||
API_ADDR="-Dapiaddress="$2
|
API_ADDR="-Dapiaddress="$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
"$PARAM_JMX_PORT")
|
"$PARAM_PORT")
|
||||||
JMX_PORT=$2
|
API_ADDR=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
"$PARAM_JMX_ADDR")
|
"$PARAM_JMX_PORT")
|
||||||
JMX_ADDR=-Dcom.sun.management.jmxremote.host=$2
|
JMX_PORT=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
"$PARAM_LOCATION")
|
"$PARAM_LOCATION")
|
||||||
@ -92,27 +82,6 @@ do
|
|||||||
DEBUG="-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:7690,server=y,suspend=n"
|
DEBUG="-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:7690,server=y,suspend=n"
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
-Dcom.sun.management.jmxremote.host=*)
|
|
||||||
JMX_ADDR=$1
|
|
||||||
HOSTNAME=${1:36}
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-Dcom.sun.management.jmxremote.authenticate=*)
|
|
||||||
JMX_AUTH=$1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-Dcom.sun.management.jmxremote.ssl=*)
|
|
||||||
JMX_SSL=$1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-Dcom.sun.management.jmxremote.local.only=*)
|
|
||||||
JMX_LOCAL=$1
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
-D*)
|
|
||||||
PROPERTIES="$PROPERTIES $1"
|
|
||||||
shift 1
|
|
||||||
;;
|
|
||||||
*)
|
*)
|
||||||
echo "Unknown parameter: $1"
|
echo "Unknown parameter: $1"
|
||||||
print_help
|
print_help
|
||||||
@ -120,24 +89,11 @@ do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $REMOTE -eq 0 ]; then
|
|
||||||
if [ -z $JMX_ADDR ]; then
|
if [ $REMOTE -eq 1 ]; then
|
||||||
JMX_ADDR=-Dcom.sun.management.jmxremote.host=localhost
|
REMOTE="-Djavax.management.builder.initial=com.scylladb.jmx.utils.APIBuilder -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMX_PORT -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=$HOSTNAME"
|
||||||
fi
|
|
||||||
HOSTNAME=localhost
|
|
||||||
else
|
else
|
||||||
if [ -z $JMX_LOCAL ]; then
|
REMOTE="-Dcassandra.jmx.local.port=$JMX_PORT"
|
||||||
JMX_LOCAL=-Dcom.sun.management.jmxremote.local.only=false
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$LOCATION_SCRIPTS"/symlinks/scylla-jmx $DEBUG \
|
exec "$LOCATION_SCRIPTS"/symlinks/scylla-jmx $API_ADDR $API_PORT $DEBUG $CONF_FILE $REMOTE -Xmx256m -XX:+UseSerialGC -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar $LOCATION/scylla-jmx-1.0.jar
|
||||||
$API_PORT $API_ADDR $CONF_FILE -Xmx256m -XX:+UseSerialGC \
|
|
||||||
-XX:+HeapDumpOnOutOfMemoryError \
|
|
||||||
$JMX_AUTH $JMX_SSL $JMX_ADDR $JMX_LOCAL \
|
|
||||||
--add-exports java.management/com.sun.jmx.mbeanserver=ALL-UNNAMED \
|
|
||||||
--add-exports java.management/com.sun.jmx.interceptor=ALL-UNNAMED \
|
|
||||||
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=$JMX_PORT \
|
|
||||||
-Djava.rmi.server.hostname=$HOSTNAME -Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \
|
|
||||||
-Djavax.management.builder.initial=com.scylladb.jmx.utils.APIBuilder \
|
|
||||||
$PROPERTIES -jar $LOCATION/scylla-jmx-1.1.jar
|
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<artifactId>scylla-apiclient</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<version>1.1</version>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<relativePath>../scylla-jmx-parent/pom.xml</relativePath>
|
|
||||||
<groupId>it.cavallium.scylladb.jmx</groupId>
|
|
||||||
<artifactId>scylla-jmx-parent</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<name>Scylla REST API client</name>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<jackson.version>2.14.0</jackson.version>
|
|
||||||
<jackson.databind.version>2.14.0</jackson.databind.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.parsson</groupId>
|
|
||||||
<artifactId>parsson</artifactId>
|
|
||||||
<version>1.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.yaml</groupId>
|
|
||||||
<artifactId>snakeyaml</artifactId>
|
|
||||||
<version>1.33</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.core</groupId>
|
|
||||||
<artifactId>jersey-common</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.ws.rs</groupId>
|
|
||||||
<artifactId>jakarta.ws.rs-api</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.core</groupId>
|
|
||||||
<artifactId>jersey-client</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish.jersey.inject</groupId>
|
|
||||||
<artifactId>jersey-hk2</artifactId>
|
|
||||||
<version>3.1.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.json</groupId>
|
|
||||||
<artifactId>jakarta.json-api</artifactId>
|
|
||||||
<version>2.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>31.1-jre</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>jakarta.activation</groupId>
|
|
||||||
<artifactId>jakarta.activation-api</artifactId>
|
|
||||||
<version>2.1.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-annotations</artifactId>
|
|
||||||
<version>${jackson.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
|
||||||
<artifactId>jackson-databind</artifactId>
|
|
||||||
<version>${jackson.databind.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
|
|
||||||
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
|
|
||||||
<version>2.14.1</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.10.1</version>
|
|
||||||
<configuration>
|
|
||||||
<release>11</release>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,15 +0,0 @@
|
|||||||
module scylla.apiclient {
|
|
||||||
exports com.scylladb.jmx.api;
|
|
||||||
exports com.scylladb.jmx.api.utils;
|
|
||||||
requires org.eclipse.parsson;
|
|
||||||
requires jakarta.ws.rs;
|
|
||||||
requires com.fasterxml.jackson.jakarta.rs.json;
|
|
||||||
requires jersey.client;
|
|
||||||
requires java.logging;
|
|
||||||
requires jakarta.json;
|
|
||||||
requires java.management;
|
|
||||||
requires org.yaml.snakeyaml;
|
|
||||||
requires com.google.common;
|
|
||||||
requires jersey.common;
|
|
||||||
requires jersey.hk2;
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>it.cavallium.scylladb.jmx</groupId>
|
|
||||||
<artifactId>scylla-jmx-parent</artifactId>
|
|
||||||
<version>1.1</version>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>../</module>
|
|
||||||
<module>../scylla-apiclient</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<name>Scylla JMX Parent</name>
|
|
||||||
|
|
||||||
<distributionManagement>
|
|
||||||
<repository>
|
|
||||||
<id>mchv-release-distribution</id>
|
|
||||||
<name>MCHV Release Apache Maven Packages Distribution</name>
|
|
||||||
<url>https://mvn.mchv.eu/repository/mchv</url>
|
|
||||||
</repository>
|
|
||||||
<snapshotRepository>
|
|
||||||
<id>mchv-snapshot-distribution</id>
|
|
||||||
<name>MCHV Snapshot Apache Maven Packages Distribution</name>
|
|
||||||
<url>https://mvn.mchv.eu/repository/mchv-snapshot</url>
|
|
||||||
</snapshotRepository>
|
|
||||||
</distributionManagement>
|
|
||||||
</project>
|
|
@ -3,62 +3,45 @@
|
|||||||
*/
|
*/
|
||||||
package com.scylladb.jmx.api;
|
package com.scylladb.jmx.api;
|
||||||
|
|
||||||
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
|
|
||||||
import jakarta.json.Json;
|
|
||||||
import jakarta.json.JsonArray;
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import jakarta.json.JsonReader;
|
|
||||||
import jakarta.json.JsonReaderFactory;
|
|
||||||
import jakarta.json.JsonString;
|
|
||||||
import jakarta.ws.rs.ProcessingException;
|
|
||||||
import jakarta.ws.rs.client.Client;
|
|
||||||
import jakarta.ws.rs.client.ClientBuilder;
|
|
||||||
import jakarta.ws.rs.client.Entity;
|
|
||||||
import jakarta.ws.rs.client.Invocation;
|
|
||||||
import jakarta.ws.rs.client.WebTarget;
|
|
||||||
import jakarta.ws.rs.core.MediaType;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import jakarta.ws.rs.core.Response;
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.lang.System.Logger.Level;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
|
import javax.json.Json;
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
import javax.json.JsonReader;
|
||||||
|
import javax.json.JsonReaderFactory;
|
||||||
|
import javax.json.JsonString;
|
||||||
import javax.management.openmbean.TabularData;
|
import javax.management.openmbean.TabularData;
|
||||||
import javax.management.openmbean.TabularDataSupport;
|
import javax.management.openmbean.TabularDataSupport;
|
||||||
|
import javax.ws.rs.ProcessingException;
|
||||||
|
import javax.ws.rs.client.Client;
|
||||||
|
import javax.ws.rs.client.ClientBuilder;
|
||||||
|
import javax.ws.rs.client.Entity;
|
||||||
|
import javax.ws.rs.client.Invocation;
|
||||||
|
import javax.ws.rs.client.WebTarget;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
import org.glassfish.jersey.client.ClientConfig;
|
import org.glassfish.jersey.client.ClientConfig;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.utils.SnapshotDetailsTabularData;
|
import com.scylladb.jmx.utils.EstimatedHistogram;
|
||||||
|
import com.scylladb.jmx.utils.SnapshotDetailsTabularData;
|
||||||
|
import com.yammer.metrics.core.HistogramValues;
|
||||||
|
|
||||||
public class APIClient {
|
public class APIClient {
|
||||||
private Map<String, CacheEntry> cache = new HashMap<String, CacheEntry>();
|
Map<String, CacheEntry> cache = new HashMap<String, CacheEntry>();
|
||||||
private final APIConfig config;
|
String getCacheKey(String key, MultivaluedMap<String, String> param, long duration) {
|
||||||
private final ClientConfig clientConfig;
|
|
||||||
private final Client client;
|
|
||||||
private JsonReaderFactory factory = Json.createReaderFactory(null);
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(APIClient.class.getName());
|
|
||||||
|
|
||||||
public APIClient(APIConfig config) {
|
|
||||||
this.config = config;
|
|
||||||
this.clientConfig = new ClientConfig();
|
|
||||||
clientConfig.register(new JacksonJsonProvider());
|
|
||||||
this.client = ClientBuilder.newClient(clientConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCacheKey(String key, MultivaluedMap<String, String> param, long duration) {
|
|
||||||
if (duration <= 0) {
|
if (duration <= 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -73,31 +56,43 @@ public class APIClient {
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStringFromCache(String key, long duration) {
|
String getStringFromCache(String key, long duration) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CacheEntry value = cache.get(key);
|
CacheEntry value = cache.get(key);
|
||||||
return (value != null && value.valid(duration)) ? value.stringValue() : null;
|
return (value!= null && value.valid(duration))? value.stringValue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JsonObject getJsonObjectFromCache(String key, long duration) {
|
JsonObject getJsonObjectFromCache(String key, long duration) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CacheEntry value = cache.get(key);
|
CacheEntry value = cache.get(key);
|
||||||
return (value != null && value.valid(duration)) ? value.jsonObject() : null;
|
return (value!= null && value.valid(duration))? value.jsonObject() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EstimatedHistogram getEstimatedHistogramFromCache(String key, long duration) {
|
||||||
|
if (key == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
CacheEntry value = cache.get(key);
|
||||||
|
return (value!= null && value.valid(duration))? value.getEstimatedHistogram() : null;
|
||||||
|
}
|
||||||
|
|
||||||
private String getBaseUrl() {
|
JsonReaderFactory factory = Json.createReaderFactory(null);
|
||||||
return config.getBaseUrl();
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(APIClient.class.getName());
|
||||||
|
|
||||||
|
public static String getBaseUrl() {
|
||||||
|
return APIConfig.getBaseUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Invocation.Builder get(String path, MultivaluedMap<String, String> queryParams) {
|
public Invocation.Builder get(String path, MultivaluedMap<String, String> queryParams) {
|
||||||
|
Client client = ClientBuilder.newClient( new ClientConfig());
|
||||||
WebTarget webTarget = client.target(getBaseUrl()).path(path);
|
WebTarget webTarget = client.target(getBaseUrl()).path(path);
|
||||||
if (queryParams != null) {
|
if (queryParams != null) {
|
||||||
for (Entry<String, List<String>> qp : queryParams.entrySet()) {
|
for (Entry<String, List<String>> qp : queryParams.entrySet()) {
|
||||||
for (String e : qp.getValue()) {
|
for (String e : qp.getValue()) {
|
||||||
webTarget = webTarget.queryParam(qp.getKey(), e);
|
webTarget = webTarget.queryParam(qp.getKey(), e);
|
||||||
}
|
}
|
||||||
@ -111,15 +106,10 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Response post(String path, MultivaluedMap<String, String> queryParams) {
|
public Response post(String path, MultivaluedMap<String, String> queryParams) {
|
||||||
return post(path, queryParams, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Response post(String path, MultivaluedMap<String, String> queryParams, Object object, String type) {
|
|
||||||
try {
|
try {
|
||||||
Response response = get(path, queryParams).post(Entity.entity(object, type));
|
Response response = get(path, queryParams).post(Entity.entity(null, MediaType.TEXT_PLAIN));
|
||||||
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
|
if (response.getStatus() != Response.Status.OK.getStatusCode() ) {
|
||||||
throw getException("Scylla API server HTTP POST to URL '" + path + "' failed",
|
throw getException("Scylla API server HTTP POST to URL '" + path + "' failed", response.readEntity(String.class));
|
||||||
response.readEntity(String.class));
|
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
} catch (ProcessingException e) {
|
} catch (ProcessingException e) {
|
||||||
@ -127,10 +117,6 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Response post(String path, MultivaluedMap<String, String> queryParams, Object object) {
|
|
||||||
return post(path, queryParams, object, MediaType.TEXT_PLAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void post(String path) {
|
public void post(String path) {
|
||||||
post(path, null);
|
post(path, null);
|
||||||
}
|
}
|
||||||
@ -158,18 +144,15 @@ public class APIClient {
|
|||||||
get(path, queryParams).delete();
|
get(path, queryParams).delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Response response = get(path).delete();
|
get(path).delete();
|
||||||
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
|
|
||||||
throw getException("Scylla API server HTTP delete to URL '" + path + "' failed",
|
|
||||||
response.readEntity(String.class));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(String path) {
|
public void delete(String path) {
|
||||||
delete(path, null);
|
delete(path, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRawValue(String string, MultivaluedMap<String, String> queryParams, long duration) {
|
public String getRawValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams, long duration) {
|
||||||
try {
|
try {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return "";
|
return "";
|
||||||
@ -185,8 +168,7 @@ public class APIClient {
|
|||||||
// TBD
|
// TBD
|
||||||
// We are currently not caching errors,
|
// We are currently not caching errors,
|
||||||
// it should be reconsider.
|
// it should be reconsider.
|
||||||
throw getException("Scylla API server HTTP GET to URL '" + string + "' failed",
|
throw getException("Scylla API server HTTP GET to URL '" + string + "' failed", response.readEntity(String.class));
|
||||||
response.readEntity(String.class));
|
|
||||||
}
|
}
|
||||||
res = response.readEntity(String.class);
|
res = response.readEntity(String.class);
|
||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
@ -198,7 +180,8 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRawValue(String string, MultivaluedMap<String, String> queryParams) {
|
public String getRawValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
return getRawValue(string, queryParams, 0);
|
return getRawValue(string, queryParams, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,19 +194,23 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getStringValue(String string, MultivaluedMap<String, String> queryParams) {
|
public String getStringValue(String string, MultivaluedMap<String, String> queryParams) {
|
||||||
return getRawValue(string, queryParams).replaceAll("^\"|\"$", "");
|
return getRawValue(string,
|
||||||
|
queryParams).replaceAll("^\"|\"$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStringValue(String string, MultivaluedMap<String, String> queryParams, long duration) {
|
public String getStringValue(String string, MultivaluedMap<String, String> queryParams, long duration) {
|
||||||
return getRawValue(string, queryParams, duration).replaceAll("^\"|\"$", "");
|
return getRawValue(string,
|
||||||
|
queryParams, duration).replaceAll("^\"|\"$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStringValue(String string) {
|
public String getStringValue(String string) {
|
||||||
return getStringValue(string, null);
|
return getStringValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonReader getReader(String string, MultivaluedMap<String, String> queryParams) {
|
public JsonReader getReader(String string,
|
||||||
return factory.createReader(new StringReader(getRawValue(string, queryParams)));
|
MultivaluedMap<String, String> queryParams) {
|
||||||
|
return factory.createReader(new StringReader(getRawValue(string,
|
||||||
|
queryParams)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonReader getReader(String string) {
|
public JsonReader getReader(String string) {
|
||||||
@ -235,7 +222,8 @@ public class APIClient {
|
|||||||
return val.toArray(new String[val.size()]);
|
return val.toArray(new String[val.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getIntValue(String string, MultivaluedMap<String, String> queryParams) {
|
public int getIntValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
return Integer.parseInt(getRawValue(string, queryParams));
|
return Integer.parseInt(getRawValue(string, queryParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,19 +231,6 @@ public class APIClient {
|
|||||||
return getIntValue(string, null);
|
return getIntValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> BiFunction<APIClient, String, T> getReader(Class<T> type) {
|
|
||||||
if (type == String.class) {
|
|
||||||
return (c, s) -> type.cast(c.getRawValue(s));
|
|
||||||
} else if (type == Integer.class) {
|
|
||||||
return (c, s) -> type.cast(c.getIntValue(s));
|
|
||||||
} else if (type == Double.class) {
|
|
||||||
return (c, s) -> type.cast(c.getDoubleValue(s));
|
|
||||||
} else if (type == Long.class) {
|
|
||||||
return (c, s) -> type.cast(c.getLongValue(s));
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException(type.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getBooleanValue(String string) {
|
public boolean getBooleanValue(String string) {
|
||||||
return Boolean.parseBoolean(getRawValue(string));
|
return Boolean.parseBoolean(getRawValue(string));
|
||||||
}
|
}
|
||||||
@ -264,7 +239,8 @@ public class APIClient {
|
|||||||
return Double.parseDouble(getRawValue(string));
|
return Double.parseDouble(getRawValue(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getListStrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public List<String> getListStrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
JsonArray arr = reader.readArray();
|
JsonArray arr = reader.readArray();
|
||||||
List<String> res = new ArrayList<String>(arr.size());
|
List<String> res = new ArrayList<String>(arr.size());
|
||||||
@ -319,7 +295,8 @@ public class APIClient {
|
|||||||
return join(arr, ",");
|
return join(arr, ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String mapToString(Map<String, String> mp, String pairJoin, String joiner) {
|
public static String mapToString(Map<String, String> mp, String pairJoin,
|
||||||
|
String joiner) {
|
||||||
String res = "";
|
String res = "";
|
||||||
if (mp != null) {
|
if (mp != null) {
|
||||||
for (String name : mp.keySet()) {
|
for (String name : mp.keySet()) {
|
||||||
@ -336,15 +313,19 @@ public class APIClient {
|
|||||||
return mapToString(mp, "=", ",");
|
return mapToString(mp, "=", ",");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean set_query_param(MultivaluedMap<String, String> queryParams, String key, String value) {
|
public static boolean set_query_param(
|
||||||
if (queryParams != null && key != null && value != null && !value.equals("")) {
|
MultivaluedMap<String, String> queryParams, String key, String value) {
|
||||||
|
if (queryParams != null && key != null && value != null
|
||||||
|
&& !value.equals("")) {
|
||||||
queryParams.add(key, value);
|
queryParams.add(key, value);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean set_bool_query_param(MultivaluedMap<String, String> queryParams, String key, boolean value) {
|
public static boolean set_bool_query_param(
|
||||||
|
MultivaluedMap<String, String> queryParams, String key,
|
||||||
|
boolean value) {
|
||||||
if (queryParams != null && key != null && value) {
|
if (queryParams != null && key != null && value) {
|
||||||
queryParams.add(key, "true");
|
queryParams.add(key, "true");
|
||||||
return true;
|
return true;
|
||||||
@ -363,7 +344,8 @@ public class APIClient {
|
|||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
if (obj.containsKey("key") && obj.containsKey("value")) {
|
if (obj.containsKey("key") && obj.containsKey("value")) {
|
||||||
map.put(obj.getString("key"), listStrFromJArr(obj.getJsonArray("value")));
|
map.put(obj.getString("key"),
|
||||||
|
listStrFromJArr(obj.getJsonArray("value")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
@ -385,7 +367,8 @@ public class APIClient {
|
|||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
if (obj.containsKey("key") && obj.containsKey("value")) {
|
if (obj.containsKey("key") && obj.containsKey("value")) {
|
||||||
map.put(listStrFromJArr(obj.getJsonArray("key")), listStrFromJArr(obj.getJsonArray("value")));
|
map.put(listStrFromJArr(obj.getJsonArray("key")),
|
||||||
|
listStrFromJArr(obj.getJsonArray("value")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.close();
|
reader.close();
|
||||||
@ -396,7 +379,8 @@ public class APIClient {
|
|||||||
return getMapListStrValue(string, null);
|
return getMapListStrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getSetStringValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Set<String> getSetStringValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
JsonArray arr = reader.readArray();
|
JsonArray arr = reader.readArray();
|
||||||
Set<String> res = new HashSet<String>();
|
Set<String> res = new HashSet<String>();
|
||||||
@ -411,13 +395,14 @@ public class APIClient {
|
|||||||
return getSetStringValue(string, null);
|
return getSetStringValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getMapStrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, String> getMapStrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
JsonArray arr = reader.readArray();
|
JsonArray arr = reader.readArray();
|
||||||
Map<String, String> map = new LinkedHashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
if (obj.containsKey("key") && obj.containsKey("value")) {
|
if (obj.containsKey("key") && obj.containsKey("value")) {
|
||||||
@ -432,7 +417,8 @@ public class APIClient {
|
|||||||
return getMapStrValue(string, null);
|
return getMapStrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getReverseMapStrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, String> getReverseMapStrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -449,11 +435,12 @@ public class APIClient {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getReverseMapStrValue(String string) {
|
public Map<String, String> getReverseMapStrValue(String string) {
|
||||||
return getReverseMapStrValue(string, null);
|
return getReverseMapStrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<InetAddress> getListInetAddressValue(String string, MultivaluedMap<String, String> queryParams) {
|
public List<InetAddress> getListInetAddressValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
List<String> vals = getListStrValue(string, queryParams);
|
List<String> vals = getListStrValue(string, queryParams);
|
||||||
List<InetAddress> res = new ArrayList<InetAddress>();
|
List<InetAddress> res = new ArrayList<InetAddress>();
|
||||||
for (String val : vals) {
|
for (String val : vals) {
|
||||||
@ -477,20 +464,22 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TabularDataSupport getSnapshotData(String key, JsonArray arr) {
|
private TabularDataSupport getSnapshotData(String key, JsonArray arr) {
|
||||||
TabularDataSupport data = new TabularDataSupport(SnapshotDetailsTabularData.TABULAR_TYPE);
|
TabularDataSupport data = new TabularDataSupport(
|
||||||
|
SnapshotDetailsTabularData.TABULAR_TYPE);
|
||||||
|
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
if (obj.containsKey("ks") && obj.containsKey("cf")) {
|
if (obj.containsKey("ks") && obj.containsKey("cf")) {
|
||||||
SnapshotDetailsTabularData.from(key, obj.getString("ks"), obj.getString("cf"), obj.getJsonNumber("total").longValue(),
|
SnapshotDetailsTabularData.from(key, obj.getString("ks"),
|
||||||
obj.getJsonNumber("live").longValue(), data);
|
obj.getString("cf"), obj.getJsonNumber("total").longValue(),
|
||||||
|
obj.getInt("live"), data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, TabularData> getMapStringSnapshotTabularDataValue(String string,
|
public Map<String, TabularData> getMapStringSnapshotTabularDataValue(
|
||||||
MultivaluedMap<String, String> queryParams) {
|
String string, MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -524,7 +513,8 @@ public class APIClient {
|
|||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
try {
|
try {
|
||||||
obj = arr.getJsonObject(i);
|
obj = arr.getJsonObject(i);
|
||||||
res.put(InetAddress.getByName(obj.getString("key")), Float.parseFloat(obj.getString("value")));
|
res.put(InetAddress.getByName(obj.getString("key")),
|
||||||
|
Float.parseFloat(obj.getString("value")));
|
||||||
} catch (UnknownHostException e) {
|
} catch (UnknownHostException e) {
|
||||||
logger.warning("Bad formatted address " + obj.getString("key"));
|
logger.warning("Bad formatted address " + obj.getString("key"));
|
||||||
}
|
}
|
||||||
@ -536,7 +526,8 @@ public class APIClient {
|
|||||||
return getMapInetAddressFloatValue(string, null);
|
return getMapInetAddressFloatValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Long> getMapStringLongValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, Long> getMapStringLongValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
Map<String, Long> res = new HashMap<String, Long>();
|
Map<String, Long> res = new HashMap<String, Long>();
|
||||||
|
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
@ -554,7 +545,8 @@ public class APIClient {
|
|||||||
return getMapStringLongValue(string, null);
|
return getMapStringLongValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] getLongArrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public long[] getLongArrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
JsonArray arr = reader.readArray();
|
JsonArray arr = reader.readArray();
|
||||||
long[] res = new long[arr.size()];
|
long[] res = new long[arr.size()];
|
||||||
@ -569,7 +561,8 @@ public class APIClient {
|
|||||||
return getLongArrValue(string, null);
|
return getLongArrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getMapStringIntegerValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, Integer> getMapStringIntegerValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
Map<String, Integer> res = new HashMap<String, Integer>();
|
Map<String, Integer> res = new HashMap<String, Integer>();
|
||||||
|
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
@ -587,7 +580,8 @@ public class APIClient {
|
|||||||
return getMapStringIntegerValue(string, null);
|
return getMapStringIntegerValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getIntArrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public int[] getIntArrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonReader reader = getReader(string, queryParams);
|
JsonReader reader = getReader(string, queryParams);
|
||||||
JsonArray arr = reader.readArray();
|
JsonArray arr = reader.readArray();
|
||||||
int[] res = new int[arr.size()];
|
int[] res = new int[arr.size()];
|
||||||
@ -602,7 +596,8 @@ public class APIClient {
|
|||||||
return getIntArrValue(string, null);
|
return getIntArrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Long> getListMapStringLongValue(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, Long> getListMapStringLongValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -635,7 +630,8 @@ public class APIClient {
|
|||||||
return getListMapStringLongValue(string, null);
|
return getListMapStringLongValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonArray getJsonArray(String string, MultivaluedMap<String, String> queryParams) {
|
public JsonArray getJsonArray(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -649,7 +645,8 @@ public class APIClient {
|
|||||||
return getJsonArray(string, null);
|
return getJsonArray(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Map<String, String>> getListMapStrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public List<Map<String, String>> getListMapStrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonArray arr = getJsonArray(string, queryParams);
|
JsonArray arr = getJsonArray(string, queryParams);
|
||||||
List<Map<String, String>> res = new ArrayList<Map<String, String>>();
|
List<Map<String, String>> res = new ArrayList<Map<String, String>>();
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
@ -667,7 +664,8 @@ public class APIClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject getJsonObj(String string, MultivaluedMap<String, String> queryParams, long duration) {
|
public JsonObject getJsonObj(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams, long duration) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -684,19 +682,61 @@ public class APIClient {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
public JsonObject getJsonObj(String string,
|
||||||
public JsonObject getJsonObj(String string, MultivaluedMap<String, String> queryParams) {
|
MultivaluedMap<String, String> queryParams) {
|
||||||
return getJsonObj(string, queryParams, 0);
|
return getJsonObj(string, queryParams, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long[] getEstimatedHistogramAsLongArrValue(String string, MultivaluedMap<String, String> queryParams) {
|
public static HistogramValues json2histogram(JsonObject obj) {
|
||||||
|
HistogramValues res = new HistogramValues();
|
||||||
|
res.count = obj.getJsonNumber("count").longValue();
|
||||||
|
res.max = obj.getJsonNumber("max").longValue();
|
||||||
|
res.min = obj.getJsonNumber("min").longValue();
|
||||||
|
res.sum = obj.getJsonNumber("sum").longValue();
|
||||||
|
res.variance = obj.getJsonNumber("variance").doubleValue();
|
||||||
|
res.mean = obj.getJsonNumber("mean").doubleValue();
|
||||||
|
JsonArray arr = obj.getJsonArray("sample");
|
||||||
|
if (arr != null) {
|
||||||
|
res.sample = new long[arr.size()];
|
||||||
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
|
res.sample[i] = arr.getJsonNumber(i).longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistogramValues getHistogramValue(String url,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
|
return json2histogram(getJsonObj(url, queryParams));
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistogramValues getHistogramValue(String url) {
|
||||||
|
return getHistogramValue(url, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EstimatedHistogram getEstimatedHistogram(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams, long duration) {
|
||||||
|
String key = getCacheKey(string, queryParams, duration);
|
||||||
|
EstimatedHistogram res = getEstimatedHistogramFromCache(key, duration);
|
||||||
|
if (res != null) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
res = new EstimatedHistogram(getEstimatedHistogramAsLongArrValue(string, queryParams));
|
||||||
|
if (duration > 0) {
|
||||||
|
cache.put(key, new CacheEntry(res));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
public long[] getEstimatedHistogramAsLongArrValue(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
JsonObject obj = getJsonObj(string, queryParams);
|
JsonObject obj = getJsonObj(string, queryParams);
|
||||||
JsonArray arr = obj.getJsonArray("buckets");
|
JsonArray arr = obj.getJsonArray("buckets");
|
||||||
if (arr == null) {
|
if (arr == null) {
|
||||||
return new long[0];
|
return new long[0];
|
||||||
}
|
}
|
||||||
long res[] = new long[arr.size()];
|
long res[] = new long[arr.size()];
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i< arr.size(); i++) {
|
||||||
res[i] = arr.getJsonNumber(i).longValue();
|
res[i] = arr.getJsonNumber(i).longValue();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -706,7 +746,8 @@ public class APIClient {
|
|||||||
return getEstimatedHistogramAsLongArrValue(string, null);
|
return getEstimatedHistogramAsLongArrValue(string, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Double> getMapStringDouble(String string, MultivaluedMap<String, String> queryParams) {
|
public Map<String, Double> getMapStringDouble(String string,
|
||||||
|
MultivaluedMap<String, String> queryParams) {
|
||||||
if (string.equals("")) {
|
if (string.equals("")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -734,7 +775,6 @@ public class APIClient {
|
|||||||
reader.close();
|
reader.close();
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Double> getMapStringDouble(String string) {
|
public Map<String, Double> getMapStringDouble(String string) {
|
||||||
return getMapStringDouble(string, null);
|
return getMapStringDouble(string, null);
|
||||||
}
|
}
|
@ -30,22 +30,23 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class APIConfig {
|
public class APIConfig {
|
||||||
private String address = "localhost";
|
static String address = "localhost";
|
||||||
private String port = "10000";
|
static String port = "10000";
|
||||||
|
|
||||||
public String getAddress() {
|
public static String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPort() {
|
public static String getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBaseUrl() {
|
public static String getBaseUrl() {
|
||||||
return "http://" + address + ":" + port;
|
return "http://" + address + ":"
|
||||||
|
+ port;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readFile(String name) {
|
public static void readFile(String name) {
|
||||||
System.out.println("Using config file: " + name);
|
System.out.println("Using config file: " + name);
|
||||||
InputStream input;
|
InputStream input;
|
||||||
try {
|
try {
|
||||||
@ -60,7 +61,7 @@ public class APIConfig {
|
|||||||
address = (String) map.get("api_address");
|
address = (String) map.get("api_address");
|
||||||
}
|
}
|
||||||
if (map.containsKey("api_port")) {
|
if (map.containsKey("api_port")) {
|
||||||
port = map.get("api_port").toString();
|
port = (String) map.get("api_port").toString();
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.err.println("fail reading from config file: " + name);
|
System.err.println("fail reading from config file: " + name);
|
||||||
@ -73,7 +74,7 @@ public class APIConfig {
|
|||||||
return varTmpDir.exists();
|
return varTmpDir.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean loadIfExists(String path, String name) {
|
public static boolean loadIfExists(String path, String name) {
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -83,21 +84,24 @@ public class APIConfig {
|
|||||||
readFile(path + name);
|
readFile(path + name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setConfig load the JMX proxy configuration The configuration hierarchy is
|
* setConfig load the JMX proxy configuration
|
||||||
* as follow: Command line argument takes precedence over everything Then
|
* The configuration hierarchy is as follow:
|
||||||
* configuration file in the command line (command line argument can replace
|
* Command line argument takes precedence over everything
|
||||||
* specific values in it. Then SCYLLA_CONF/scylla.yaml Then
|
* Then configuration file in the command line (command line
|
||||||
* SCYLLA_HOME/conf/scylla.yaml Then conf/scylla.yaml Then the default
|
* argument can replace specific values in it.
|
||||||
* values With file configuration, to make it clearer what is been used,
|
* Then SCYLLA_CONF/scylla.yaml
|
||||||
* only one file will be chosen with the highest precedence
|
* Then SCYLLA_HOME/conf/scylla.yaml
|
||||||
|
* Then conf/scylla.yaml
|
||||||
|
* Then the default values
|
||||||
|
* With file configuration, to make it clearer what is been used, only
|
||||||
|
* one file will be chosen with the highest precedence
|
||||||
*/
|
*/
|
||||||
public APIConfig() {
|
public static void setConfig() {
|
||||||
if (!System.getProperty("apiconfig", "").equals("")) {
|
if (!System.getProperty("apiconfig","").equals("")) {
|
||||||
readFile(System.getProperty("apiconfig"));
|
readFile(System.getProperty("apiconfig"));
|
||||||
} else if (!loadIfExists(System.getenv("SCYLLA_CONF"), "/scylla.yaml")
|
} else if (!loadIfExists(System.getenv("SCYLLA_CONF"), "/scylla.yaml") &&
|
||||||
&& !loadIfExists(System.getenv("SCYLLA_HOME"), "/conf/scylla.yaml")) {
|
!loadIfExists(System.getenv("SCYLLA_HOME"), "/conf/scylla.yaml")) {
|
||||||
loadIfExists("", "conf/scylla.yaml");
|
loadIfExists("", "conf/scylla.yaml");
|
||||||
}
|
}
|
||||||
|
|
@ -21,14 +21,15 @@
|
|||||||
|
|
||||||
package com.scylladb.jmx.api;
|
package com.scylladb.jmx.api;
|
||||||
|
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
import jakarta.json.JsonObject;
|
import com.scylladb.jmx.utils.EstimatedHistogram;
|
||||||
|
|
||||||
class CacheEntry {
|
public class CacheEntry {
|
||||||
private long time;
|
long time;
|
||||||
private Object value;
|
Object value;
|
||||||
|
|
||||||
public CacheEntry(Object res) {
|
CacheEntry(Object res) {
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
this.value = res;
|
this.value = res;
|
||||||
}
|
}
|
||||||
@ -41,6 +42,10 @@ class CacheEntry {
|
|||||||
return (String) value;
|
return (String) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EstimatedHistogram getEstimatedHistogram() {
|
||||||
|
return (EstimatedHistogram)value;
|
||||||
|
}
|
||||||
|
|
||||||
public JsonObject jsonObject() {
|
public JsonObject jsonObject() {
|
||||||
return (JsonObject) value;
|
return (JsonObject) value;
|
||||||
}
|
}
|
@ -3,75 +3,38 @@
|
|||||||
*/
|
*/
|
||||||
package com.scylladb.jmx.main;
|
package com.scylladb.jmx.main;
|
||||||
|
|
||||||
import static java.lang.management.ManagementFactory.getPlatformMBeanServer;
|
import com.scylladb.jmx.api.APIConfig;
|
||||||
import static java.util.Arrays.asList;
|
import com.scylladb.jmx.utils.RMIServerSocketFactoryImpl;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
|
|
||||||
import org.apache.cassandra.db.commitlog.CommitLog;
|
import org.apache.cassandra.db.commitlog.CommitLog;
|
||||||
import org.apache.cassandra.db.compaction.CompactionManager;
|
import org.apache.cassandra.db.compaction.CompactionManager;
|
||||||
import org.apache.cassandra.gms.FailureDetector;
|
|
||||||
import org.apache.cassandra.gms.Gossiper;
|
import org.apache.cassandra.gms.Gossiper;
|
||||||
|
import org.apache.cassandra.gms.FailureDetector;
|
||||||
import org.apache.cassandra.locator.EndpointSnitchInfo;
|
import org.apache.cassandra.locator.EndpointSnitchInfo;
|
||||||
import org.apache.cassandra.net.MessagingService;
|
import org.apache.cassandra.net.MessagingService;
|
||||||
import org.apache.cassandra.service.CacheService;
|
import org.apache.cassandra.service.CacheService;
|
||||||
import org.apache.cassandra.service.GCInspector;
|
import org.apache.cassandra.service.GCInspector;
|
||||||
import org.apache.cassandra.service.StorageProxy;
|
import org.apache.cassandra.service.StorageProxy;
|
||||||
import org.apache.cassandra.service.StorageService;
|
import org.apache.cassandra.service.StorageService;
|
||||||
import org.apache.cassandra.streaming.StreamManager;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.scylladb.jmx.api.APIConfig;
|
|
||||||
import com.scylladb.jmx.metrics.APIMBean;
|
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
private static APIConfig config;
|
|
||||||
private static APIClient client;
|
|
||||||
|
|
||||||
public static synchronized APIConfig getApiConfig() {
|
|
||||||
if (config == null) {
|
|
||||||
config = new APIConfig();
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized APIClient getApiClient() {
|
|
||||||
if (client == null) {
|
|
||||||
client = new APIClient(getApiConfig());
|
|
||||||
}
|
|
||||||
return client;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.out.printf("Java %s%n", System.getProperty("java.version"));
|
APIConfig.setConfig();
|
||||||
System.out.printf("Connecting to %s%n", getApiConfig().getBaseUrl());
|
System.out.println("Connecting to " + APIConfig.getBaseUrl());
|
||||||
System.out.println("Starting the JMX server");
|
System.out.println("Starting the JMX server");
|
||||||
|
RMIServerSocketFactoryImpl.maybeInitJmx();
|
||||||
MBeanServer server = getPlatformMBeanServer();
|
StorageService.getInstance();
|
||||||
for (Class<? extends APIMBean> clazz : asList(StorageService.class, StorageProxy.class, MessagingService.class,
|
StorageProxy.getInstance();
|
||||||
CommitLog.class, Gossiper.class, EndpointSnitchInfo.class, FailureDetector.class, CacheService.class,
|
MessagingService.getInstance();
|
||||||
CompactionManager.class, GCInspector.class, StreamManager.class)) {
|
CommitLog.getInstance();
|
||||||
Constructor<? extends APIMBean> c = clazz.getDeclaredConstructor(APIClient.class);
|
Gossiper.getInstance();
|
||||||
APIMBean m = c.newInstance(getApiClient());
|
EndpointSnitchInfo.getInstance();
|
||||||
server.registerMBean(m, null);
|
FailureDetector.getInstance();
|
||||||
}
|
CacheService.getInstance();
|
||||||
|
CompactionManager.getInstance();
|
||||||
try {
|
GCInspector.register();
|
||||||
// forces check for dynamically created mbeans
|
Thread.sleep(Long.MAX_VALUE);
|
||||||
server.queryNames(null, null);
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
// ignore this. Just means we started before scylla.
|
|
||||||
}
|
|
||||||
|
|
||||||
String jmxPort = System.getProperty("com.sun.management.jmxremote.port");
|
|
||||||
System.out.println("JMX is enabled to receive remote connections on port: " + jmxPort);
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
Thread.sleep(Long.MAX_VALUE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,195 +0,0 @@
|
|||||||
package com.scylladb.jmx.metrics;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import javax.management.BadAttributeValueExpException;
|
|
||||||
import javax.management.BadBinaryOpValueExpException;
|
|
||||||
import javax.management.BadStringOperationException;
|
|
||||||
import javax.management.InstanceAlreadyExistsException;
|
|
||||||
import javax.management.InstanceNotFoundException;
|
|
||||||
import javax.management.InvalidApplicationException;
|
|
||||||
import javax.management.MBeanRegistration;
|
|
||||||
import javax.management.MBeanRegistrationException;
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.QueryExp;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base type for MBeans in scylla-jmx. Wraps auto naming and {@link APIClient}
|
|
||||||
* holding.
|
|
||||||
*
|
|
||||||
* @author calle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class APIMBean implements MBeanRegistration {
|
|
||||||
protected final APIClient client;
|
|
||||||
protected final String mbeanName;
|
|
||||||
|
|
||||||
public APIMBean(APIClient client) {
|
|
||||||
this(null, client);
|
|
||||||
}
|
|
||||||
|
|
||||||
public APIMBean(String mbeanName, APIClient client) {
|
|
||||||
this.mbeanName = mbeanName;
|
|
||||||
this.client = client;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to add/remove dynamically created MBeans from a server
|
|
||||||
* instance.
|
|
||||||
*
|
|
||||||
* @param server
|
|
||||||
* The {@link MBeanServer} to check
|
|
||||||
* @param all
|
|
||||||
* All {@link ObjectName}s that should be bound
|
|
||||||
* @param predicate
|
|
||||||
* {@link QueryExp} predicate to filter relevant object names.
|
|
||||||
* @param generator
|
|
||||||
* {@link Function} to create a new MBean instance for a given
|
|
||||||
* {@link ObjectName}
|
|
||||||
* @return
|
|
||||||
* @throws MalformedObjectNameException
|
|
||||||
*/
|
|
||||||
public static boolean checkRegistration(JmxMBeanServer server, Set<ObjectName> all,
|
|
||||||
EnumSet<RegistrationMode> mode, final Predicate<ObjectName> predicate,
|
|
||||||
Function<ObjectName, Object> generator) throws MalformedObjectNameException {
|
|
||||||
Set<ObjectName> registered = queryNames(server, predicate);
|
|
||||||
if (mode.contains(RegistrationMode.Remove)) {
|
|
||||||
for (ObjectName name : registered) {
|
|
||||||
if (!all.contains(name)) {
|
|
||||||
try {
|
|
||||||
server.getMBeanServerInterceptor().unregisterMBean(name);
|
|
||||||
} catch (MBeanRegistrationException | InstanceNotFoundException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int added = 0;
|
|
||||||
if (mode.contains(RegistrationMode.Add)) {
|
|
||||||
for (ObjectName name : all) {
|
|
||||||
if (!registered.contains(name)) {
|
|
||||||
try {
|
|
||||||
server.getMBeanServerInterceptor().registerMBean(generator.apply(name), name);
|
|
||||||
added++;
|
|
||||||
} catch (InstanceAlreadyExistsException | MBeanRegistrationException
|
|
||||||
| NotCompliantMBeanException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return added > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper method to query {@link ObjectName}s from an {@link MBeanServer}
|
|
||||||
* based on {@link Predicate}
|
|
||||||
*
|
|
||||||
* @param server
|
|
||||||
* @param predicate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static Set<ObjectName> queryNames(JmxMBeanServer server, final Predicate<ObjectName> predicate) {
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
Set<ObjectName> registered = server.queryNames(null, new QueryExp() {
|
|
||||||
@Override
|
|
||||||
public void setMBeanServer(MBeanServer s) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(ObjectName name) throws BadStringOperationException, BadBinaryOpValueExpException,
|
|
||||||
BadAttributeValueExpException, InvalidApplicationException {
|
|
||||||
return predicate.test(name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return registered;
|
|
||||||
}
|
|
||||||
|
|
||||||
JmxMBeanServer server;
|
|
||||||
ObjectName name;
|
|
||||||
|
|
||||||
protected final ObjectName getBoundName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out an {@link ObjectName} for this object based on either
|
|
||||||
* contructor parameter, static field, or just package/class name.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* @throws MalformedObjectNameException
|
|
||||||
*/
|
|
||||||
protected ObjectName generateName() throws MalformedObjectNameException {
|
|
||||||
String mbeanName = this.mbeanName;
|
|
||||||
if (mbeanName == null) {
|
|
||||||
Field f;
|
|
||||||
try {
|
|
||||||
f = getClass().getDeclaredField("MBEAN_NAME");
|
|
||||||
f.setAccessible(true);
|
|
||||||
mbeanName = (String) f.get(null);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mbeanName == null) {
|
|
||||||
for (Class<?> c : getClass().getInterfaces()) {
|
|
||||||
Field f;
|
|
||||||
try {
|
|
||||||
f = c.getDeclaredField("OBJECT_NAME");
|
|
||||||
f.setAccessible(true);
|
|
||||||
mbeanName = (String) f.get(null);
|
|
||||||
break;
|
|
||||||
} catch (Throwable t) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mbeanName == null) {
|
|
||||||
String name = getClass().getName();
|
|
||||||
int i = name.lastIndexOf('.');
|
|
||||||
mbeanName = name.substring(0, i) + ":type=" + name.substring(i + 1);
|
|
||||||
}
|
|
||||||
return new ObjectName(mbeanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Keeps track of bound server and optionally generates an
|
|
||||||
* {@link ObjectName} for this instance.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
|
|
||||||
if (this.server != null) {
|
|
||||||
throw new IllegalStateException("Can only exist in a single MBeanServer");
|
|
||||||
}
|
|
||||||
this.server = (JmxMBeanServer) server;
|
|
||||||
if (name == null) {
|
|
||||||
name = generateName();
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postRegister(Boolean registrationDone) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void preDeregister() throws Exception {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postDeregister() {
|
|
||||||
assert server != null;
|
|
||||||
assert name != null;
|
|
||||||
this.server = null;
|
|
||||||
this.name = null;
|
|
||||||
}
|
|
||||||
}
|
|
399
src/main/java/com/scylladb/jmx/metrics/APIMetrics.java
Normal file
399
src/main/java/com/scylladb/jmx/metrics/APIMetrics.java
Normal file
@ -0,0 +1,399 @@
|
|||||||
|
package com.scylladb.jmx.metrics;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.yammer.metrics.core.APIMetricsRegistry;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
import com.yammer.metrics.core.Gauge;
|
||||||
|
import com.yammer.metrics.core.Histogram;
|
||||||
|
import com.yammer.metrics.core.Meter;
|
||||||
|
import com.yammer.metrics.core.MetricName;
|
||||||
|
import com.yammer.metrics.core.Timer;
|
||||||
|
import com.yammer.metrics.reporting.JmxReporter;
|
||||||
|
import com.yammer.metrics.core.APIMeter;
|
||||||
|
|
||||||
|
public class APIMetrics {
|
||||||
|
private static final APIMetricsRegistry DEFAULT_REGISTRY = new APIMetricsRegistry();
|
||||||
|
private static final Thread SHUTDOWN_HOOK = new Thread() {
|
||||||
|
public void run() {
|
||||||
|
JmxReporter.shutdownDefault();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static {
|
||||||
|
JmxReporter.startDefault(DEFAULT_REGISTRY);
|
||||||
|
Runtime.getRuntime().addShutdownHook(SHUTDOWN_HOOK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private APIMetrics() { /* unused */
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
||||||
|
* given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param metric
|
||||||
|
* the metric
|
||||||
|
* @param <T>
|
||||||
|
* the type of the value returned by the metric
|
||||||
|
* @return {@code metric}
|
||||||
|
*/
|
||||||
|
public static <T> Gauge<T> newGauge(Class<?> klass, String name,
|
||||||
|
Gauge<T> metric) {
|
||||||
|
return DEFAULT_REGISTRY.newGauge(klass, name, metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
||||||
|
* given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param metric
|
||||||
|
* the metric
|
||||||
|
* @param <T>
|
||||||
|
* the type of the value returned by the metric
|
||||||
|
* @return {@code metric}
|
||||||
|
*/
|
||||||
|
public static <T> Gauge<T> newGauge(Class<?> klass, String name,
|
||||||
|
String scope, Gauge<T> metric) {
|
||||||
|
return DEFAULT_REGISTRY.newGauge(klass, name, scope, metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a new {@link com.yammer.metrics.core.Gauge}, registers it under the
|
||||||
|
* given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param metric
|
||||||
|
* the metric
|
||||||
|
* @param <T>
|
||||||
|
* the type of the value returned by the metric
|
||||||
|
* @return {@code metric}
|
||||||
|
*/
|
||||||
|
public static <T> Gauge<T> newGauge(MetricName metricName, Gauge<T> metric) {
|
||||||
|
return DEFAULT_REGISTRY.newGauge(metricName, metric);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Counter} and registers it
|
||||||
|
* under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
||||||
|
*/
|
||||||
|
public static Counter newCounter(String url, Class<?> klass, String name) {
|
||||||
|
return DEFAULT_REGISTRY.newCounter(url, klass, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Counter} and registers it
|
||||||
|
* under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
||||||
|
*/
|
||||||
|
public static Counter newCounter(String url, Class<?> klass, String name,
|
||||||
|
String scope) {
|
||||||
|
return DEFAULT_REGISTRY.newCounter(url, klass, name, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Counter} and registers it
|
||||||
|
* under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Counter}
|
||||||
|
*/
|
||||||
|
public static Counter newCounter(String url, MetricName metricName) {
|
||||||
|
return DEFAULT_REGISTRY.newCounter(url, metricName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Histogram} and registers it
|
||||||
|
* under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, Class<?> klass,
|
||||||
|
String name, boolean biased) {
|
||||||
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, biased);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Histogram} and registers it
|
||||||
|
* under the given class, name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, Class<?> klass,
|
||||||
|
String name, String scope, boolean biased) {
|
||||||
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, scope, biased);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Histogram} and registers it
|
||||||
|
* under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, MetricName metricName,
|
||||||
|
boolean biased) {
|
||||||
|
return DEFAULT_REGISTRY.newHistogram(url, metricName, biased);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} and
|
||||||
|
* registers it under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, Class<?> klass, String name) {
|
||||||
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} and
|
||||||
|
* registers it under the given class, name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, Class<?> klass,
|
||||||
|
String name, String scope) {
|
||||||
|
return DEFAULT_REGISTRY.newHistogram(url, klass, name, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new non-biased {@link com.yammer.metrics.core.Histogram} and
|
||||||
|
* registers it under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Histogram}
|
||||||
|
*/
|
||||||
|
public static Histogram newHistogram(String url, MetricName metricName) {
|
||||||
|
return newHistogram(url, metricName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Meter} and registers it
|
||||||
|
* under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
||||||
|
*/
|
||||||
|
public static APIMeter newMeter(String url, Class<?> klass, String name,
|
||||||
|
String eventType, TimeUnit unit) {
|
||||||
|
return DEFAULT_REGISTRY.newMeter(url, klass, name, eventType, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Meter} and registers it
|
||||||
|
* under the given class, name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
||||||
|
*/
|
||||||
|
public static APIMeter newMeter(String url, Class<?> klass, String name,
|
||||||
|
String scope, String eventType, TimeUnit unit) {
|
||||||
|
return DEFAULT_REGISTRY.newMeter(url, klass, name, scope, eventType,
|
||||||
|
unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.Meter} and registers it
|
||||||
|
* under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link com.yammer.metrics.core.Meter}
|
||||||
|
*/
|
||||||
|
public static APIMeter newMeter(String url, MetricName metricName,
|
||||||
|
String eventType, TimeUnit unit) {
|
||||||
|
return DEFAULT_REGISTRY.newMeter(url, metricName, eventType, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
||||||
|
* under the given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
||||||
|
*/
|
||||||
|
public static Timer newTimer(String url, Class<?> klass, String name,
|
||||||
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, durationUnit, rateUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
||||||
|
* under the given class and name, measuring elapsed time in milliseconds
|
||||||
|
* and invocations per second.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
||||||
|
*/
|
||||||
|
public static Timer newTimer(String url, Class<?> klass, String name) {
|
||||||
|
return DEFAULT_REGISTRY.newTimer(url, klass, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
||||||
|
* under the given class, name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
||||||
|
*/
|
||||||
|
public static Timer newTimer(String url, Class<?> klass, String name, String scope,
|
||||||
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, scope, durationUnit,
|
||||||
|
rateUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
||||||
|
* under the given class, name, and scope, measuring elapsed time in
|
||||||
|
* milliseconds and invocations per second.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
||||||
|
*/
|
||||||
|
public static Timer newTimer(String url, Class<?> klass, String name, String scope) {
|
||||||
|
return DEFAULT_REGISTRY.newTimer(url, klass, name, scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link com.yammer.metrics.core.APITimer} and registers it
|
||||||
|
* under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link com.yammer.metrics.core.APITimer}
|
||||||
|
*/
|
||||||
|
public static Timer newTimer(String url, MetricName metricName, TimeUnit durationUnit,
|
||||||
|
TimeUnit rateUnit) {
|
||||||
|
return DEFAULT_REGISTRY.newTimer(url, metricName, durationUnit, rateUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the (static) default registry.
|
||||||
|
*
|
||||||
|
* @return the metrics registry
|
||||||
|
*/
|
||||||
|
public static APIMetricsRegistry defaultRegistry() {
|
||||||
|
return DEFAULT_REGISTRY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down all thread pools for the default registry.
|
||||||
|
*/
|
||||||
|
public static void shutdown() {
|
||||||
|
DEFAULT_REGISTRY.shutdown();
|
||||||
|
JmxReporter.shutdownDefault();
|
||||||
|
Runtime.getRuntime().removeShutdownHook(SHUTDOWN_HOOK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -15,10 +15,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
/*
|
||||||
import javax.management.ObjectName;
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
package com.scylladb.jmx.metrics;
|
||||||
|
|
||||||
|
import com.yammer.metrics.core.MetricName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MetricNameFactory that generates default MetricName of metrics.
|
* MetricNameFactory that generates default MetricName of metrics.
|
||||||
@ -38,14 +43,19 @@ public class DefaultNameFactory implements MetricNameFactory {
|
|||||||
this.scope = scope;
|
this.scope = scope;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public MetricName createMetricName(String metricName) {
|
||||||
public ObjectName createMetricName(String metricName) throws MalformedObjectNameException {
|
|
||||||
return createMetricName(type, metricName, scope);
|
return createMetricName(type, metricName, scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ObjectName createMetricName(String type, String name, String scope)
|
public static MetricName createMetricName(String type, String metricName,
|
||||||
throws MalformedObjectNameException {
|
String scope) {
|
||||||
StringBuilder nameBuilder = new StringBuilder();
|
return new MetricName(GROUP_NAME, type, metricName, scope,
|
||||||
|
createDefaultMBeanName(type, metricName, scope));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String createDefaultMBeanName(String type, String name,
|
||||||
|
String scope) {
|
||||||
|
final StringBuilder nameBuilder = new StringBuilder();
|
||||||
nameBuilder.append(GROUP_NAME);
|
nameBuilder.append(GROUP_NAME);
|
||||||
nameBuilder.append(":type=");
|
nameBuilder.append(":type=");
|
||||||
nameBuilder.append(type);
|
nameBuilder.append(type);
|
||||||
@ -57,6 +67,6 @@ public class DefaultNameFactory implements MetricNameFactory {
|
|||||||
nameBuilder.append(",name=");
|
nameBuilder.append(",name=");
|
||||||
nameBuilder.append(name);
|
nameBuilder.append(name);
|
||||||
}
|
}
|
||||||
return new ObjectName(nameBuilder.toString());
|
return nameBuilder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,26 +15,23 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simplified version of {@link Metrics} naming factory paradigm, simply
|
|
||||||
* generating {@link ObjectName} and nothing more.
|
|
||||||
*
|
|
||||||
* @author calle
|
|
||||||
*
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
*/
|
*/
|
||||||
public interface MetricNameFactory {
|
|
||||||
|
package com.scylladb.jmx.metrics;
|
||||||
|
|
||||||
|
import com.yammer.metrics.core.MetricName;
|
||||||
|
|
||||||
|
public interface MetricNameFactory
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Create a qualified name from given metric name.
|
* Create a qualified name from given metric name.
|
||||||
*
|
*
|
||||||
* @param metricName
|
* @param metricName part of qualified name.
|
||||||
* part of qualified name.
|
|
||||||
* @return new String with given metric name.
|
* @return new String with given metric name.
|
||||||
* @throws MalformedObjectNameException
|
|
||||||
*/
|
*/
|
||||||
ObjectName createMetricName(String metricName) throws MalformedObjectNameException;
|
MetricName createMetricName(String metricName);
|
||||||
}
|
}
|
@ -1,137 +0,0 @@
|
|||||||
package com.scylladb.jmx.metrics;
|
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Predicate;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import javax.management.InstanceNotFoundException;
|
|
||||||
import javax.management.MBeanRegistrationException;
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.Metrics;
|
|
||||||
import org.apache.cassandra.metrics.MetricsRegistry;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Base type for MBeans containing {@link Metrics}.
|
|
||||||
*
|
|
||||||
* @author calle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public abstract class MetricsMBean extends APIMBean {
|
|
||||||
private static final Map<JmxMBeanServer, Map<String, Integer>> registered = new HashMap<>();
|
|
||||||
private static final Object registrationLock = new Object();
|
|
||||||
|
|
||||||
private final Collection<Metrics> metrics;
|
|
||||||
|
|
||||||
public MetricsMBean(APIClient client, Metrics... metrics) {
|
|
||||||
this(null, client, metrics);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricsMBean(String mbeanName, APIClient client, Metrics... metrics) {
|
|
||||||
this(mbeanName, client, asList(metrics));
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricsMBean(String mbeanName, APIClient client, Collection<Metrics> metrics) {
|
|
||||||
super(mbeanName, client);
|
|
||||||
this.metrics = metrics;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Predicate<ObjectName> getTypePredicate() {
|
|
||||||
String domain = name.getDomain();
|
|
||||||
String type = name.getKeyProperty("type");
|
|
||||||
return n -> {
|
|
||||||
return domain.equals(n.getDomain()) && type.equals(n.getKeyProperty("type"));
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Has to be called with registrationLock hold
|
|
||||||
private static boolean shouldRegisterGlobals(JmxMBeanServer server, String domainAndType, boolean reversed) {
|
|
||||||
Map<String, Integer> serverMap = registered.get(server);
|
|
||||||
if (serverMap == null) {
|
|
||||||
assert !reversed;
|
|
||||||
serverMap = new HashMap<>();
|
|
||||||
serverMap.put(domainAndType, 1);
|
|
||||||
registered.put(server, serverMap);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Integer count = serverMap.get(domainAndType);
|
|
||||||
if (count == null) {
|
|
||||||
assert !reversed;
|
|
||||||
serverMap.put(domainAndType, 1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (reversed) {
|
|
||||||
--count;
|
|
||||||
if (count == 0) {
|
|
||||||
serverMap.remove(domainAndType);
|
|
||||||
if (serverMap.isEmpty()) {
|
|
||||||
registered.remove(server);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
serverMap.put(domainAndType, count);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
serverMap.put(domainAndType, count + 1);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void register(MetricsRegistry registry, JmxMBeanServer server, boolean reversed) throws MalformedObjectNameException {
|
|
||||||
// Check if we're the first/last of our type bound/removed.
|
|
||||||
synchronized (registrationLock) {
|
|
||||||
boolean registerGlobals = shouldRegisterGlobals(server, name.getDomain() + ":" + name.getKeyProperty("type"), reversed);
|
|
||||||
if (registerGlobals) {
|
|
||||||
for (Metrics m : metrics) {
|
|
||||||
m.registerGlobals(registry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (Metrics m : metrics) {
|
|
||||||
m.register(registry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
|
|
||||||
// Get name etc.
|
|
||||||
name = super.preRegister(server, name);
|
|
||||||
// Register all metrics in server
|
|
||||||
register(new MetricsRegistry(client, (JmxMBeanServer) server), (JmxMBeanServer) server, false);
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void postDeregister() {
|
|
||||||
// We're officially unbound. Remove all metrics we added.
|
|
||||||
try {
|
|
||||||
register(new MetricsRegistry(client, server) {
|
|
||||||
// Unbind instead of bind. Yes.
|
|
||||||
@Override
|
|
||||||
public void register(Supplier<MetricMBean> s, ObjectName... objectNames) {
|
|
||||||
for (ObjectName name : objectNames) {
|
|
||||||
try {
|
|
||||||
server.getMBeanServerInterceptor().unregisterMBean(name);
|
|
||||||
} catch (MBeanRegistrationException | InstanceNotFoundException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, server, true);
|
|
||||||
} catch (MalformedObjectNameException e) {
|
|
||||||
// TODO : log?
|
|
||||||
}
|
|
||||||
super.postDeregister();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
package com.scylladb.jmx.metrics;
|
|
||||||
|
|
||||||
import static com.scylladb.jmx.metrics.RegistrationMode.Remove;
|
|
||||||
import static com.scylladb.jmx.metrics.RegistrationMode.Wait;
|
|
||||||
import static java.util.EnumSet.allOf;
|
|
||||||
import static java.util.EnumSet.of;
|
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.concurrent.locks.Lock;
|
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
|
||||||
|
|
||||||
import javax.management.OperationsException;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper type to do optional locking for registration. Allows for
|
|
||||||
* per-bind-point locks and registration, instead of per-type or per-instance
|
|
||||||
* locks which may be misguiding, since for example one instance can be bound to
|
|
||||||
* many MBeanServers etc.
|
|
||||||
*
|
|
||||||
* Also allows for polled checks, i.e. try-lock and either wait or skip. Wait,
|
|
||||||
* because we probably should not repeat things hidden by this type too often,
|
|
||||||
* and skip because for example a periodic task checking can just skip if a
|
|
||||||
* user-initiated registration check is being done.
|
|
||||||
*
|
|
||||||
* @author calle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
public abstract class RegistrationChecker {
|
|
||||||
private final Lock lock = new ReentrantLock();
|
|
||||||
|
|
||||||
public static final EnumSet<RegistrationMode> REMOVE_NO_WAIT = of(Remove);
|
|
||||||
public static final EnumSet<RegistrationMode> ADD_AND_REMOVE = allOf(RegistrationMode.class);
|
|
||||||
|
|
||||||
public final void reap(APIClient client, JmxMBeanServer server) throws OperationsException, UnknownHostException {
|
|
||||||
check(client, server, REMOVE_NO_WAIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void check(APIClient client, JmxMBeanServer server) throws OperationsException, UnknownHostException {
|
|
||||||
check(client, server, ADD_AND_REMOVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void check(APIClient client, JmxMBeanServer server, EnumSet<RegistrationMode> mode)
|
|
||||||
throws OperationsException, UnknownHostException {
|
|
||||||
if (!lock.tryLock()) {
|
|
||||||
if (mode.contains(Wait)) {
|
|
||||||
// someone is doing update.
|
|
||||||
// since this is jmx, and sloppy, we'll just
|
|
||||||
// assume that once he is done, things are
|
|
||||||
// good enough.
|
|
||||||
lock.lock();
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
doCheck(client, server, mode);
|
|
||||||
} finally {
|
|
||||||
lock.unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void doCheck(APIClient client, JmxMBeanServer server, EnumSet<RegistrationMode> mode)
|
|
||||||
throws OperationsException, UnknownHostException;
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.scylladb.jmx.metrics;
|
|
||||||
|
|
||||||
public enum RegistrationMode {
|
|
||||||
Wait, Add, Remove,
|
|
||||||
}
|
|
@ -3,20 +3,6 @@ package com.scylladb.jmx.utils;
|
|||||||
* Copyright 2016 ScyllaDB
|
* Copyright 2016 ScyllaDB
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import static com.scylladb.jmx.main.Main.getApiClient;
|
|
||||||
import static com.sun.jmx.mbeanserver.Util.wildmatch;
|
|
||||||
import static java.util.logging.Level.SEVERE;
|
|
||||||
import static javax.management.MBeanServerDelegate.DELEGATE_NAME;
|
|
||||||
|
|
||||||
import java.security.AccessController;
|
|
||||||
import java.security.PrivilegedActionException;
|
|
||||||
import java.security.PrivilegedExceptionAction;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of Scylla.
|
* This file is part of Scylla.
|
||||||
*
|
*
|
||||||
@ -34,463 +20,22 @@ import java.util.logging.Logger;
|
|||||||
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import javax.management.DynamicMBean;
|
|
||||||
import javax.management.InstanceAlreadyExistsException;
|
|
||||||
import javax.management.InstanceNotFoundException;
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MBeanServerBuilder;
|
|
||||||
import javax.management.MBeanServerDelegate;
|
import javax.management.MBeanServerDelegate;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.QueryExp;
|
|
||||||
import javax.management.RuntimeOperationsException;
|
|
||||||
|
|
||||||
import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
|
import mx4j.server.ChainedMBeanServerBuilder;
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
import com.sun.jmx.mbeanserver.NamedObject;
|
|
||||||
import com.sun.jmx.mbeanserver.Repository;
|
|
||||||
|
|
||||||
/**
|
public class APIBuilder extends ChainedMBeanServerBuilder {
|
||||||
* This class purposly knows way to much of the inner workings
|
public APIBuilder() {
|
||||||
* of Oracle JDK MBeanServer workings, and pervert it for
|
super(new mx4j.server.MX4JMBeanServerBuilder());
|
||||||
* performance sakes. It is not portable to other MBean implementations.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("restriction")
|
|
||||||
public class APIBuilder extends MBeanServerBuilder {
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(APIBuilder.class.getName());
|
|
||||||
|
|
||||||
private static class TableRepository extends Repository {
|
|
||||||
private static final Logger logger = Logger.getLogger(TableRepository.class.getName());
|
|
||||||
|
|
||||||
private final Repository wrapped;
|
|
||||||
|
|
||||||
private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
|
|
||||||
|
|
||||||
private final Map<TableMetricParams, DynamicMBean> tableMBeans = new HashMap<>();
|
|
||||||
|
|
||||||
private static boolean isTableMetricName(ObjectName name) {
|
|
||||||
return isTableMetricDomain(name.getDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isTableMetricDomain(String domain) {
|
|
||||||
return TableMetricParams.TABLE_METRICS_DOMAIN.equals(domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TableRepository(String defaultDomain, final Repository repository) {
|
|
||||||
super(defaultDomain);
|
|
||||||
wrapped = repository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultDomain() {
|
|
||||||
return wrapped.getDefaultDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(final ObjectName name) {
|
|
||||||
if (!isTableMetricName(name)) {
|
|
||||||
return wrapped.contains(name);
|
|
||||||
} else {
|
|
||||||
lock.readLock().lock();
|
|
||||||
try {
|
|
||||||
return tableMBeans.containsKey(new TableMetricParams(name));
|
|
||||||
} finally {
|
|
||||||
lock.readLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getDomains() {
|
|
||||||
final String[] domains = wrapped.getDomains();
|
|
||||||
if (tableMBeans.isEmpty()) {
|
|
||||||
return domains;
|
|
||||||
}
|
|
||||||
final String[] res = new String[domains.length + 1];
|
|
||||||
System.arraycopy(domains, 0, res, 0, domains.length);
|
|
||||||
res[domains.length] = TableMetricParams.TABLE_METRICS_DOMAIN;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getCount() {
|
|
||||||
lock.readLock().lock();
|
|
||||||
try {
|
|
||||||
return wrapped.getCount() + tableMBeans.size();
|
|
||||||
} finally {
|
|
||||||
lock.readLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addMBean(final DynamicMBean bean, final ObjectName name, final RegistrationContext ctx)
|
|
||||||
throws InstanceAlreadyExistsException {
|
|
||||||
if (!isTableMetricName(name)) {
|
|
||||||
wrapped.addMBean(bean, name, ctx);
|
|
||||||
} else {
|
|
||||||
final TableMetricParams key = new TableMetricParams(name);
|
|
||||||
lock.writeLock().lock();
|
|
||||||
try {
|
|
||||||
if (tableMBeans.containsKey(key)) {
|
|
||||||
throw new InstanceAlreadyExistsException(name.toString());
|
|
||||||
}
|
|
||||||
tableMBeans.put(key, bean);
|
|
||||||
if (ctx == null) return;
|
|
||||||
try {
|
|
||||||
ctx.registering();
|
|
||||||
} catch (RuntimeOperationsException x) {
|
|
||||||
throw x;
|
|
||||||
} catch (RuntimeException x) {
|
|
||||||
throw new RuntimeOperationsException(x);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove(final ObjectName name, final RegistrationContext ctx) throws InstanceNotFoundException {
|
|
||||||
if (!isTableMetricName(name)) {
|
|
||||||
wrapped.remove(name, ctx);
|
|
||||||
} else {
|
|
||||||
final TableMetricParams key = new TableMetricParams(name);
|
|
||||||
lock.writeLock().lock();
|
|
||||||
try {
|
|
||||||
if (tableMBeans.remove(key) == null) {
|
|
||||||
throw new InstanceNotFoundException(name.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
ctx.unregistered();
|
|
||||||
} catch (Exception x) {
|
|
||||||
logger.log(SEVERE, "Unexpected error.", x);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.writeLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DynamicMBean retrieve(final ObjectName name) {
|
|
||||||
if (!isTableMetricName(name)) {
|
|
||||||
return wrapped.retrieve(name);
|
|
||||||
} else {
|
|
||||||
lock.readLock().lock();
|
|
||||||
try {
|
|
||||||
return tableMBeans.get(new TableMetricParams(name));
|
|
||||||
} finally {
|
|
||||||
lock.readLock().unlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAll(final Set<NamedObject> res) {
|
|
||||||
for (Map.Entry<TableMetricParams, DynamicMBean> e : tableMBeans.entrySet()) {
|
|
||||||
try {
|
|
||||||
res.add(new NamedObject(e.getKey().toName(), e.getValue()));
|
|
||||||
} catch (MalformedObjectNameException e1) {
|
|
||||||
// This should never happen
|
|
||||||
logger.log(SEVERE, "Unexpected error.", e1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAllMatching(final Set<NamedObject> res,
|
|
||||||
final ObjectNamePattern pattern) {
|
|
||||||
for (Map.Entry<TableMetricParams, DynamicMBean> e : tableMBeans.entrySet()) {
|
|
||||||
try {
|
|
||||||
ObjectName name = e.getKey().toName();
|
|
||||||
if (pattern.matchKeys(name)) {
|
|
||||||
res.add(new NamedObject(name, e.getValue()));
|
|
||||||
}
|
|
||||||
} catch (MalformedObjectNameException e1) {
|
|
||||||
// This should never happen
|
|
||||||
logger.log(SEVERE, "Unexpected error.", e1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Set<NamedObject> query(final ObjectName pattern, final QueryExp query) {
|
|
||||||
Set<NamedObject> res = wrapped.query(pattern, query);
|
|
||||||
ObjectName name;
|
|
||||||
if (pattern == null ||
|
|
||||||
pattern.getCanonicalName().length() == 0 ||
|
|
||||||
pattern.equals(ObjectName.WILDCARD)) {
|
|
||||||
name = ObjectName.WILDCARD;
|
|
||||||
} else {
|
|
||||||
name = pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
lock.readLock().lock();
|
|
||||||
try {
|
|
||||||
// If pattern is not a pattern, retrieve this mbean !
|
|
||||||
if (!name.isPattern() && isTableMetricName(name)) {
|
|
||||||
final DynamicMBean bean = tableMBeans.get(new TableMetricParams(name));
|
|
||||||
if (bean != null) {
|
|
||||||
res.add(new NamedObject(name, bean));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// All names in all domains
|
|
||||||
if (name == ObjectName.WILDCARD) {
|
|
||||||
addAll(res);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String canonical_key_property_list_string =
|
|
||||||
name.getCanonicalKeyPropertyListString();
|
|
||||||
|
|
||||||
final boolean allNames =
|
|
||||||
(canonical_key_property_list_string.length()==0);
|
|
||||||
final ObjectNamePattern namePattern =
|
|
||||||
(allNames?null:new ObjectNamePattern(name));
|
|
||||||
|
|
||||||
// All names in default domain
|
|
||||||
if (name.getDomain().length() == 0) {
|
|
||||||
if (isTableMetricDomain(getDefaultDomain())) {
|
|
||||||
if (allNames) {
|
|
||||||
addAll(res);
|
|
||||||
} else {
|
|
||||||
addAllMatching(res, namePattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!name.isDomainPattern()) {
|
|
||||||
if (isTableMetricDomain(getDefaultDomain())) {
|
|
||||||
if (allNames) {
|
|
||||||
addAll(res);
|
|
||||||
} else {
|
|
||||||
addAllMatching(res, namePattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pattern matching in the domain name (*, ?)
|
|
||||||
final String dom2Match = name.getDomain();
|
|
||||||
if (wildmatch(TableMetricParams.TABLE_METRICS_DOMAIN, dom2Match)) {
|
|
||||||
if (allNames) {
|
|
||||||
addAll(res);
|
|
||||||
} else {
|
|
||||||
addAllMatching(res, namePattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
lock.readLock().unlock();
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final static class ObjectNamePattern {
|
public MBeanServer newMBeanServer(String defaultDomain, MBeanServer outer,
|
||||||
private final String[] keys;
|
MBeanServerDelegate delegate) {
|
||||||
private final String[] values;
|
APIMBeanServer extern = new APIMBeanServer();
|
||||||
private final String properties;
|
MBeanServer nested = getMBeanServerBuilder().newMBeanServer(
|
||||||
private final boolean isPropertyListPattern;
|
defaultDomain, outer == null ? extern : outer, delegate);
|
||||||
private final boolean isPropertyValuePattern;
|
extern.setMBeanServer(nested);
|
||||||
|
return extern;
|
||||||
/**
|
|
||||||
* The ObjectName pattern against which ObjectNames are matched.
|
|
||||||
**/
|
|
||||||
public final ObjectName pattern;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a new ObjectNamePattern object from an ObjectName pattern.
|
|
||||||
* @param pattern The ObjectName pattern under examination.
|
|
||||||
**/
|
|
||||||
public ObjectNamePattern(ObjectName pattern) {
|
|
||||||
this(pattern.isPropertyListPattern(),
|
|
||||||
pattern.isPropertyValuePattern(),
|
|
||||||
pattern.getCanonicalKeyPropertyListString(),
|
|
||||||
pattern.getKeyPropertyList(),
|
|
||||||
pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Builds a new ObjectNamePattern object from an ObjectName pattern
|
|
||||||
* constituents.
|
|
||||||
* @param propertyListPattern pattern.isPropertyListPattern().
|
|
||||||
* @param propertyValuePattern pattern.isPropertyValuePattern().
|
|
||||||
* @param canonicalProps pattern.getCanonicalKeyPropertyListString().
|
|
||||||
* @param keyPropertyList pattern.getKeyPropertyList().
|
|
||||||
* @param pattern The ObjectName pattern under examination.
|
|
||||||
**/
|
|
||||||
ObjectNamePattern(boolean propertyListPattern,
|
|
||||||
boolean propertyValuePattern,
|
|
||||||
String canonicalProps,
|
|
||||||
Map<String,String> keyPropertyList,
|
|
||||||
ObjectName pattern) {
|
|
||||||
this.isPropertyListPattern = propertyListPattern;
|
|
||||||
this.isPropertyValuePattern = propertyValuePattern;
|
|
||||||
this.properties = canonicalProps;
|
|
||||||
final int len = keyPropertyList.size();
|
|
||||||
this.keys = new String[len];
|
|
||||||
this.values = new String[len];
|
|
||||||
int i = 0;
|
|
||||||
for (Map.Entry<String,String> entry : keyPropertyList.entrySet()) {
|
|
||||||
keys[i] = entry.getKey();
|
|
||||||
values[i] = entry.getValue();
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
this.pattern = pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the given ObjectName matches the ObjectName pattern
|
|
||||||
* for which this object has been built.
|
|
||||||
* WARNING: domain name is not considered here because it is supposed
|
|
||||||
* not to be wildcard when called. PropertyList is also
|
|
||||||
* supposed not to be zero-length.
|
|
||||||
* @param name The ObjectName we want to match against the pattern.
|
|
||||||
* @return true if <code>name</code> matches the pattern.
|
|
||||||
**/
|
|
||||||
public boolean matchKeys(ObjectName name) {
|
|
||||||
// If key property value pattern but not key property list
|
|
||||||
// pattern, then the number of key properties must be equal
|
|
||||||
//
|
|
||||||
if (isPropertyValuePattern &&
|
|
||||||
!isPropertyListPattern &&
|
|
||||||
(name.getKeyPropertyList().size() != keys.length)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If key property value pattern or key property list pattern,
|
|
||||||
// then every property inside pattern should exist in name
|
|
||||||
//
|
|
||||||
if (isPropertyValuePattern || isPropertyListPattern) {
|
|
||||||
for (int i = keys.length - 1; i >= 0 ; i--) {
|
|
||||||
// Find value in given object name for key at current
|
|
||||||
// index in receiver
|
|
||||||
//
|
|
||||||
String v = name.getKeyProperty(keys[i]);
|
|
||||||
// Did we find a value for this key ?
|
|
||||||
//
|
|
||||||
if (v == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// If this property is ok (same key, same value), go to next
|
|
||||||
//
|
|
||||||
if (isPropertyValuePattern &&
|
|
||||||
pattern.isPropertyValuePattern(keys[i])) {
|
|
||||||
// wildmatch key property values
|
|
||||||
// values[i] is the pattern;
|
|
||||||
// v is the string
|
|
||||||
if (wildmatch(v,values[i])) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (v.equals(values[i])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no pattern, then canonical names must be equal
|
|
||||||
//
|
|
||||||
final String p1 = name.getCanonicalKeyPropertyListString();
|
|
||||||
final String p2 = properties;
|
|
||||||
return (p1.equals(p2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public static class TableMetricParams {
|
|
||||||
public static final String TABLE_METRICS_DOMAIN = "org.apache.cassandra.metrics";
|
|
||||||
|
|
||||||
private final ObjectName name;
|
|
||||||
|
|
||||||
public TableMetricParams(ObjectName name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObjectName toName() throws MalformedObjectNameException {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean equal(Object a, Object b) {
|
|
||||||
return (a == null) ? b == null : a.equals(b);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof TableMetricParams)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
TableMetricParams oo = (TableMetricParams) o;
|
|
||||||
return equal(name.getKeyProperty("keyspace"), oo.name.getKeyProperty("keyspace"))
|
|
||||||
&& equal(name.getKeyProperty("scope"), oo.name.getKeyProperty("scope"))
|
|
||||||
&& equal(name.getKeyProperty("name"), oo.name.getKeyProperty("name"))
|
|
||||||
&& equal(name.getKeyProperty("type"), oo.name.getKeyProperty("type"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int hash(Object o) {
|
|
||||||
return o == null ? 0 : o.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int safeAdd(int ... nums) {
|
|
||||||
long res = 0;
|
|
||||||
for (int n : nums) {
|
|
||||||
res = (res + n) % Integer.MAX_VALUE;
|
|
||||||
}
|
|
||||||
return (int)res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return safeAdd(hash(name.getKeyProperty("keyspace")),
|
|
||||||
hash(name.getKeyProperty("scope")),
|
|
||||||
hash(name.getKeyProperty("name")),
|
|
||||||
hash(name.getKeyProperty("type")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MBeanServer newMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate) {
|
|
||||||
// It is important to set |interceptors| to true while creating the
|
|
||||||
// JmxMBeanSearver. It is required for calls to
|
|
||||||
// JmxMBeanServer.setMBeanServerInterceptor() to be allowed.
|
|
||||||
JmxMBeanServer nested = (JmxMBeanServer) JmxMBeanServer.newMBeanServer(defaultDomain, outer, delegate, true);
|
|
||||||
// This is not very clean, we depend on knowledge of how the Sun/Oracle
|
|
||||||
// MBean chain looks internally. But we need haxxor support, so
|
|
||||||
// lets replace the interceptor.
|
|
||||||
// Note: Removed reflection gunk to eliminate jdk9+ warnings on
|
|
||||||
// execution. Also, if we can get by without reflection, it is
|
|
||||||
// better.
|
|
||||||
final DefaultMBeanServerInterceptor interceptor = new DefaultMBeanServerInterceptor(outer != null ? outer : nested,
|
|
||||||
delegate, nested.getMBeanInstantiator(),
|
|
||||||
new TableRepository(defaultDomain, new Repository(defaultDomain)));
|
|
||||||
nested.setMBeanServerInterceptor(interceptor);
|
|
||||||
final MBeanServerDelegate d = nested.getMBeanServerDelegate();
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Interceptor needs the delegate present. Normally done
|
|
||||||
// by inaccessible method in JmxMBeanServer
|
|
||||||
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
|
|
||||||
public Object run() throws Exception {
|
|
||||||
interceptor.registerMBean(d, DELEGATE_NAME);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (PrivilegedActionException e) {
|
|
||||||
logger.log(SEVERE, "Unexpected error.", e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new APIMBeanServer(getApiClient(), nested);
|
|
||||||
}
|
|
||||||
}
|
|
103
src/main/java/com/scylladb/jmx/utils/APIMBeanIntrospector.java
Normal file
103
src/main/java/com/scylladb/jmx/utils/APIMBeanIntrospector.java
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
package com.scylladb.jmx.utils;
|
||||||
|
/**
|
||||||
|
* Copyright (C) The MX4J Contributors.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This software is distributed under the terms of the MX4J License version 1.0.
|
||||||
|
* See the terms of the MX4J License in the documentation provided with this software.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modified by ScyllaDB
|
||||||
|
* Copyright 2016 ScyllaDB
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of Scylla.
|
||||||
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import javax.management.MBeanInfo;
|
||||||
|
|
||||||
|
import mx4j.server.MBeanIntrospector;
|
||||||
|
import mx4j.server.MBeanMetaData;
|
||||||
|
|
||||||
|
public class APIMBeanIntrospector extends MBeanIntrospector {
|
||||||
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(APIMBeanIntrospector.class.getName());
|
||||||
|
|
||||||
|
public boolean isMBeanCompliant(MBeanMetaData metadata) {
|
||||||
|
Class info = metadata.getMBeanInterface();
|
||||||
|
if (info != null) {
|
||||||
|
String cn = info.getName();
|
||||||
|
if (cn != null) {
|
||||||
|
if (cn.endsWith("MXBean")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.isMBeanCompliant(metadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apiIntrospectStandardMBean(MBeanMetaData metadata) {
|
||||||
|
try {
|
||||||
|
Class[] cArg = new Class[1];
|
||||||
|
cArg[0] = MBeanMetaData.class;
|
||||||
|
Method met = MBeanIntrospector.class
|
||||||
|
.getDeclaredMethod("introspectStandardMBean", cArg);
|
||||||
|
met.setAccessible(true);
|
||||||
|
met.invoke((MBeanIntrospector) this, metadata);
|
||||||
|
} catch (NoSuchMethodException | SecurityException
|
||||||
|
| IllegalAccessException | IllegalArgumentException
|
||||||
|
| InvocationTargetException e) {
|
||||||
|
logger.warning("Failed setting mbean info " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apiIntrospect(MBeanMetaData metadata) {
|
||||||
|
apiIntrospectStandardMBean(metadata);
|
||||||
|
Class[] cArg = new Class[1];
|
||||||
|
cArg[0] = MBeanMetaData.class;
|
||||||
|
try {
|
||||||
|
Method met = MBeanIntrospector.class
|
||||||
|
.getDeclaredMethod("createStandardMBeanInfo", cArg);
|
||||||
|
met.setAccessible(true);
|
||||||
|
Object info = met.invoke((MBeanIntrospector) this, metadata);
|
||||||
|
metadata.setMBeanInfo((MBeanInfo) info);
|
||||||
|
} catch (IllegalAccessException | NoSuchMethodException
|
||||||
|
| SecurityException | IllegalArgumentException
|
||||||
|
| InvocationTargetException e) {
|
||||||
|
logger.warning("Failed setting mbean info" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void introspect(MBeanMetaData metadata) {
|
||||||
|
Class<?> mx_mbean = null;
|
||||||
|
for (Class<?> it : metadata.getMBean().getClass().getInterfaces()) {
|
||||||
|
if (it.getName().endsWith("MXBean")) {
|
||||||
|
mx_mbean = it;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mx_mbean != null) {
|
||||||
|
metadata.setMBeanInterface(mx_mbean);
|
||||||
|
apiIntrospect(metadata);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.introspect(metadata);
|
||||||
|
}
|
||||||
|
}
|
@ -1,327 +1,134 @@
|
|||||||
package com.scylladb.jmx.utils;
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
/**
|
||||||
import static java.util.concurrent.Executors.newScheduledThreadPool;
|
* Copyright 2016 ScyllaDB
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
*/
|
||||||
|
/*
|
||||||
import java.io.ObjectInputStream;
|
* This file is part of Scylla.
|
||||||
import java.net.UnknownHostException;
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Hashtable;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.management.Attribute;
|
|
||||||
import javax.management.AttributeList;
|
|
||||||
import javax.management.AttributeNotFoundException;
|
|
||||||
import javax.management.InstanceAlreadyExistsException;
|
|
||||||
import javax.management.InstanceNotFoundException;
|
|
||||||
import javax.management.IntrospectionException;
|
|
||||||
import javax.management.InvalidAttributeValueException;
|
|
||||||
import javax.management.ListenerNotFoundException;
|
|
||||||
import javax.management.MBeanException;
|
|
||||||
import javax.management.MBeanInfo;
|
|
||||||
import javax.management.MBeanRegistrationException;
|
|
||||||
import javax.management.MBeanServer;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
|
||||||
import javax.management.NotificationFilter;
|
|
||||||
import javax.management.NotificationListener;
|
|
||||||
import javax.management.ObjectInstance;
|
|
||||||
import javax.management.ObjectName;
|
import javax.management.ObjectName;
|
||||||
import javax.management.OperationsException;
|
|
||||||
import javax.management.QueryExp;
|
import javax.management.QueryExp;
|
||||||
import javax.management.ReflectionException;
|
|
||||||
import javax.management.loading.ClassLoaderRepository;
|
|
||||||
|
|
||||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||||
import org.apache.cassandra.metrics.StreamingMetrics;
|
import org.apache.cassandra.metrics.StreamingMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import mx4j.server.ChainedMBeanServer;
|
||||||
import com.scylladb.jmx.metrics.RegistrationChecker;
|
import mx4j.server.MX4JMBeanServer;
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
import mx4j.util.Utils;
|
||||||
|
|
||||||
@SuppressWarnings("restriction")
|
public class APIMBeanServer extends ChainedMBeanServer {
|
||||||
public class APIMBeanServer implements MBeanServer {
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
@SuppressWarnings("unused")
|
.getLogger(APIMBeanServer.class.getName());
|
||||||
private static final Logger logger = Logger.getLogger(APIMBeanServer.class.getName());
|
|
||||||
private static final ScheduledExecutorService executor = newScheduledThreadPool(1);
|
|
||||||
|
|
||||||
private final RegistrationChecker columnFamilyStoreChecker = ColumnFamilyStore.createRegistrationChecker();
|
public static void log(String str) {
|
||||||
private final RegistrationChecker streamingMetricsChecker = StreamingMetrics.createRegistrationChecker();
|
logger.finest(str);
|
||||||
|
|
||||||
private final APIClient client;
|
|
||||||
private final JmxMBeanServer server;
|
|
||||||
|
|
||||||
public APIMBeanServer(APIClient client, JmxMBeanServer server) {
|
|
||||||
this.client = client;
|
|
||||||
this.server = server;
|
|
||||||
|
|
||||||
executor.scheduleWithFixedDelay(() -> {
|
|
||||||
for (RegistrationChecker c : asList(columnFamilyStoreChecker, streamingMetricsChecker)) {
|
|
||||||
try {
|
|
||||||
c.reap(client, server);
|
|
||||||
} catch (OperationsException | UnknownHostException e) {
|
|
||||||
// TODO: log?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 1, 5, MINUTES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectInstance prepareForRemote(final ObjectInstance i) {
|
public void setMBeanServer(MBeanServer server) {
|
||||||
return new ObjectInstance(prepareForRemote(i.getObjectName()), i.getClassName());
|
if (server != null) {
|
||||||
}
|
try {
|
||||||
|
Field f = server.getClass().getDeclaredField("introspector");
|
||||||
private static ObjectName prepareForRemote(final ObjectName n) {
|
f.setAccessible(true);
|
||||||
/*
|
f.set(server, new APIMBeanIntrospector());
|
||||||
* ObjectName.getInstance has changed in JDK (micro) updates so it no longer applies
|
} catch (Exception e) {
|
||||||
* overridable methods -> wrong name published.
|
logger.warning(
|
||||||
* Fix by doing explicit ObjectName instansiation.
|
"Failed setting new interceptor" + e.getMessage());
|
||||||
*/
|
}
|
||||||
try {
|
|
||||||
return new ObjectName(n.getCanonicalName());
|
|
||||||
} catch (MalformedObjectNameException e) {
|
|
||||||
throw new IllegalArgumentException(n.toString());
|
|
||||||
}
|
}
|
||||||
}
|
super.setMBeanServer(server);
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
|
|
||||||
InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException {
|
|
||||||
return prepareForRemote(server.createMBean(className, name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ObjectName apiNormalizeObjectName(ObjectName name) {
|
||||||
public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName)
|
try {
|
||||||
throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
|
Class[] cArg = new Class[1];
|
||||||
NotCompliantMBeanException, InstanceNotFoundException {
|
cArg[0] = ObjectName.class;
|
||||||
return prepareForRemote(server.createMBean(className, name, loaderName));
|
Method met = MX4JMBeanServer.class
|
||||||
}
|
.getDeclaredMethod("normalizeObjectName", cArg);
|
||||||
|
met.setAccessible(true);
|
||||||
@Override
|
return (ObjectName) met.invoke((MX4JMBeanServer) getMBeanServer(),
|
||||||
public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature)
|
name);
|
||||||
throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException,
|
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
|
||||||
NotCompliantMBeanException {
|
// TODO Auto-generated catch block
|
||||||
return prepareForRemote(server.createMBean(className, name, params, signature));
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params,
|
|
||||||
String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException,
|
|
||||||
MBeanException, NotCompliantMBeanException, InstanceNotFoundException {
|
|
||||||
return prepareForRemote(server.createMBean(className, name, loaderName, params, signature));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectInstance registerMBean(Object object, ObjectName name)
|
|
||||||
throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
|
|
||||||
return prepareForRemote(server.registerMBean(object, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException {
|
|
||||||
server.unregisterMBean(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return prepareForRemote(server.getObjectInstance(name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
|
public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
|
||||||
checkRegistrations(name);
|
if (name == null) {
|
||||||
return server.queryNames(name, query).stream().map(n -> prepareForRemote(n)).collect(Collectors.toSet());
|
ColumnFamilyStore.checkRegistration();
|
||||||
}
|
StreamingMetrics.checkRegistration();
|
||||||
|
return super.queryNames(name, query);
|
||||||
@Override
|
|
||||||
public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.queryMBeans(name, query).stream().map(i -> prepareForRemote(i)).collect(Collectors.toSet());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRegistered(ObjectName name) {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.isRegistered(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getMBeanCount() {
|
|
||||||
return server.getMBeanCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getAttribute(ObjectName name, String attribute)
|
|
||||||
throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.getAttribute(name, attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AttributeList getAttributes(ObjectName name, String[] attributes)
|
|
||||||
throws InstanceNotFoundException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.getAttributes(name, attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException,
|
|
||||||
AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
server.setAttribute(name, attribute);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AttributeList setAttributes(ObjectName name, AttributeList attributes)
|
|
||||||
throws InstanceNotFoundException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.setAttributes(name, attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
|
|
||||||
throws InstanceNotFoundException, MBeanException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.invoke(name, operationName, params, signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDefaultDomain() {
|
|
||||||
return server.getDefaultDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String[] getDomains() {
|
|
||||||
return server.getDomains();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
|
|
||||||
Object handback) throws InstanceNotFoundException {
|
|
||||||
server.addNotificationListener(name, listener, filter, handback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter,
|
|
||||||
Object handback) throws InstanceNotFoundException {
|
|
||||||
server.addNotificationListener(name, listener, filter, handback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeNotificationListener(ObjectName name, ObjectName listener)
|
|
||||||
throws InstanceNotFoundException, ListenerNotFoundException {
|
|
||||||
server.removeNotificationListener(name, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter,
|
|
||||||
Object handback) throws InstanceNotFoundException, ListenerNotFoundException {
|
|
||||||
server.removeNotificationListener(name, listener, filter, handback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeNotificationListener(ObjectName name, NotificationListener listener)
|
|
||||||
throws InstanceNotFoundException, ListenerNotFoundException {
|
|
||||||
server.removeNotificationListener(name, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
|
|
||||||
Object handback) throws InstanceNotFoundException, ListenerNotFoundException {
|
|
||||||
server.removeNotificationListener(name, listener, filter, handback);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MBeanInfo getMBeanInfo(ObjectName name)
|
|
||||||
throws InstanceNotFoundException, IntrospectionException, ReflectionException {
|
|
||||||
checkRegistrations(name);
|
|
||||||
return server.getMBeanInfo(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException {
|
|
||||||
return server.isInstanceOf(name, className);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object instantiate(String className) throws ReflectionException, MBeanException {
|
|
||||||
return server.instantiate(className);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object instantiate(String className, ObjectName loaderName)
|
|
||||||
throws ReflectionException, MBeanException, InstanceNotFoundException {
|
|
||||||
return server.instantiate(className, loaderName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object instantiate(String className, Object[] params, String[] signature)
|
|
||||||
throws ReflectionException, MBeanException {
|
|
||||||
return server.instantiate(className, params, signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature)
|
|
||||||
throws ReflectionException, MBeanException, InstanceNotFoundException {
|
|
||||||
return server.instantiate(className, loaderName, params, signature);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public ObjectInputStream deserialize(ObjectName name, byte[] data)
|
|
||||||
throws InstanceNotFoundException, OperationsException {
|
|
||||||
return server.deserialize(name, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public ObjectInputStream deserialize(String className, byte[] data)
|
|
||||||
throws OperationsException, ReflectionException {
|
|
||||||
return server.deserialize(className, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Deprecated
|
|
||||||
public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data)
|
|
||||||
throws InstanceNotFoundException, OperationsException, ReflectionException {
|
|
||||||
return server.deserialize(className, loaderName, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException {
|
|
||||||
return server.getClassLoaderFor(mbeanName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException {
|
|
||||||
return server.getClassLoader(loaderName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ClassLoaderRepository getClassLoaderRepository() {
|
|
||||||
return server.getClassLoaderRepository();
|
|
||||||
}
|
|
||||||
|
|
||||||
static final Pattern tables = Pattern.compile("^\\*?((Index)?ColumnFamil(ies|y)|(Index)?(Table(s)?)?)$");
|
|
||||||
|
|
||||||
private void checkRegistrations(ObjectName name) {
|
|
||||||
if (name != null && server.isRegistered(name)) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
if (name.getCanonicalKeyPropertyListString()
|
||||||
try {
|
.contains("ColumnFamilies")) {
|
||||||
String type = name != null ? name.getKeyProperty("type") : null;
|
ColumnFamilyStore.checkRegistration();
|
||||||
if (type == null || tables.matcher(type).matches()) {
|
} else if (name.getCanonicalKeyPropertyListString()
|
||||||
columnFamilyStoreChecker.check(client, server);
|
.contains("Stream")) {
|
||||||
}
|
StreamingMetrics.checkRegistration();
|
||||||
if (type == null || StreamingMetrics.TYPE_NAME.equals(type)) {
|
|
||||||
streamingMetricsChecker.check(client, server);
|
|
||||||
}
|
|
||||||
} catch (OperationsException | UnknownHostException e) {
|
|
||||||
// TODO: log
|
|
||||||
}
|
}
|
||||||
|
ObjectName no = apiNormalizeObjectName(name);
|
||||||
|
Hashtable patternProps = no.getKeyPropertyList();
|
||||||
|
boolean paternFound = false;
|
||||||
|
for (Iterator j = patternProps.entrySet().iterator(); j.hasNext();) {
|
||||||
|
Map.Entry entry = (Map.Entry) j.next();
|
||||||
|
String patternValue = (String) entry.getValue();
|
||||||
|
if (patternValue.contains("*")) {
|
||||||
|
paternFound = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (paternFound) {
|
||||||
|
Set<ObjectName> res = new HashSet<ObjectName>();
|
||||||
|
for (ObjectName q : (Set<ObjectName>) super.queryNames(null,query)) {
|
||||||
|
if (Utils.wildcardMatch(name.getDomain(), q.getDomain())) {
|
||||||
|
Hashtable props = q.getKeyPropertyList();
|
||||||
|
boolean found = true;
|
||||||
|
for (Iterator j = patternProps.entrySet().iterator(); j
|
||||||
|
.hasNext();) {
|
||||||
|
Map.Entry entry = (Map.Entry) j.next();
|
||||||
|
String patternKey = (String) entry.getKey();
|
||||||
|
String patternValue = (String) entry.getValue();
|
||||||
|
if (props.containsKey(patternKey)) {
|
||||||
|
if (!Utils.wildcardMatch(patternValue,
|
||||||
|
props.get(patternKey).toString())) {
|
||||||
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
found = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
res.add(q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return super.queryNames(name, query);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,18 +0,0 @@
|
|||||||
package com.scylladb.jmx.utils;
|
|
||||||
|
|
||||||
import jakarta.xml.bind.annotation.adapters.XmlAdapter;
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class DateXmlAdapter extends XmlAdapter<String, Date> {
|
|
||||||
@Override
|
|
||||||
public String marshal(Date v) throws Exception {
|
|
||||||
return Instant.ofEpochMilli(v.getTime()).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Date unmarshal(String v) throws Exception {
|
|
||||||
return new Date(Instant.parse(v).toEpochMilli());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
315
src/main/java/com/scylladb/jmx/utils/EstimatedHistogram.java
Normal file
315
src/main/java/com/scylladb/jmx/utils/EstimatedHistogram.java
Normal file
@ -0,0 +1,315 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.concurrent.atomic.AtomicLongArray;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
public class EstimatedHistogram {
|
||||||
|
/**
|
||||||
|
* The series of values to which the counts in `buckets` correspond: 1, 2,
|
||||||
|
* 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, etc. Thus, a `buckets` of [0, 0, 1,
|
||||||
|
* 10] would mean we had seen one value of 3 and 10 values of 4.
|
||||||
|
*
|
||||||
|
* The series starts at 1 and grows by 1.2 each time (rounding and removing
|
||||||
|
* duplicates). It goes from 1 to around 36M by default (creating 90+1
|
||||||
|
* buckets), which will give us timing resolution from microseconds to 36
|
||||||
|
* seconds, with less precision as the numbers get larger.
|
||||||
|
*
|
||||||
|
* Each bucket represents values from (previous bucket offset, current
|
||||||
|
* offset].
|
||||||
|
*/
|
||||||
|
private final long[] bucketOffsets;
|
||||||
|
|
||||||
|
// buckets is one element longer than bucketOffsets -- the last element is
|
||||||
|
// values greater than the last offset
|
||||||
|
final AtomicLongArray buckets;
|
||||||
|
|
||||||
|
public EstimatedHistogram() {
|
||||||
|
this(90);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EstimatedHistogram(int bucketCount) {
|
||||||
|
bucketOffsets = newOffsets(bucketCount);
|
||||||
|
buckets = new AtomicLongArray(bucketOffsets.length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EstimatedHistogram(long[] offsets, long[] bucketData) {
|
||||||
|
assert bucketData.length == offsets.length + 1;
|
||||||
|
bucketOffsets = offsets;
|
||||||
|
buckets = new AtomicLongArray(bucketData);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public EstimatedHistogram(long[] bucketData) {
|
||||||
|
bucketOffsets = newOffsets(bucketData.length - 1);
|
||||||
|
buckets = new AtomicLongArray(bucketData);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long[] newOffsets(int size) {
|
||||||
|
if (size <= 0) {
|
||||||
|
return new long[0];
|
||||||
|
}
|
||||||
|
long[] result = new long[size];
|
||||||
|
long last = 1;
|
||||||
|
result[0] = last;
|
||||||
|
for (int i = 1; i < size; i++) {
|
||||||
|
long next = Math.round(last * 1.2);
|
||||||
|
if (next == last)
|
||||||
|
next++;
|
||||||
|
result[i] = next;
|
||||||
|
last = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the histogram values corresponding to each bucket index
|
||||||
|
*/
|
||||||
|
public long[] getBucketOffsets() {
|
||||||
|
return bucketOffsets;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increments the count of the bucket closest to n, rounding UP.
|
||||||
|
*
|
||||||
|
* @param n
|
||||||
|
*/
|
||||||
|
public void add(long n) {
|
||||||
|
int index = Arrays.binarySearch(bucketOffsets, n);
|
||||||
|
if (index < 0) {
|
||||||
|
// inexact match, take the first bucket higher than n
|
||||||
|
index = -index - 1;
|
||||||
|
}
|
||||||
|
// else exact match; we're good
|
||||||
|
buckets.incrementAndGet(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the count in the given bucket
|
||||||
|
*/
|
||||||
|
long get(int bucket) {
|
||||||
|
return buckets.get(bucket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param reset
|
||||||
|
* zero out buckets afterwards if true
|
||||||
|
* @return a long[] containing the current histogram buckets
|
||||||
|
*/
|
||||||
|
public long[] getBuckets(boolean reset) {
|
||||||
|
final int len = buckets.length();
|
||||||
|
long[] rv = new long[len];
|
||||||
|
|
||||||
|
if (reset)
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
rv[i] = buckets.getAndSet(i, 0L);
|
||||||
|
else
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
rv[i] = buckets.get(i);
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the smallest value that could have been added to this histogram
|
||||||
|
*/
|
||||||
|
public long min() {
|
||||||
|
for (int i = 0; i < buckets.length(); i++) {
|
||||||
|
if (buckets.get(i) > 0)
|
||||||
|
return i == 0 ? 0 : 1 + bucketOffsets[i - 1];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the largest value that could have been added to this histogram.
|
||||||
|
* If the histogram overflowed, returns Long.MAX_VALUE.
|
||||||
|
*/
|
||||||
|
public long max() {
|
||||||
|
int lastBucket = buckets.length() - 1;
|
||||||
|
if (buckets.get(lastBucket) > 0)
|
||||||
|
return Long.MAX_VALUE;
|
||||||
|
|
||||||
|
for (int i = lastBucket - 1; i >= 0; i--) {
|
||||||
|
if (buckets.get(i) > 0)
|
||||||
|
return bucketOffsets[i];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param percentile
|
||||||
|
* @return estimated value at given percentile
|
||||||
|
*/
|
||||||
|
public long percentile(double percentile) {
|
||||||
|
assert percentile >= 0 && percentile <= 1.0;
|
||||||
|
int lastBucket = buckets.length() - 1;
|
||||||
|
if (buckets.get(lastBucket) > 0)
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unable to compute when histogram overflowed");
|
||||||
|
|
||||||
|
long pcount = (long) Math.floor(count() * percentile);
|
||||||
|
if (pcount == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
long elements = 0;
|
||||||
|
for (int i = 0; i < lastBucket; i++) {
|
||||||
|
elements += buckets.get(i);
|
||||||
|
if (elements >= pcount)
|
||||||
|
return bucketOffsets[i];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the mean histogram value (average of bucket offsets, weighted by
|
||||||
|
* count)
|
||||||
|
* @throws IllegalStateException
|
||||||
|
* if any values were greater than the largest bucket threshold
|
||||||
|
*/
|
||||||
|
public long mean() {
|
||||||
|
int lastBucket = buckets.length() - 1;
|
||||||
|
if (buckets.get(lastBucket) > 0)
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Unable to compute ceiling for max when histogram overflowed");
|
||||||
|
|
||||||
|
long elements = 0;
|
||||||
|
long sum = 0;
|
||||||
|
for (int i = 0; i < lastBucket; i++) {
|
||||||
|
long bCount = buckets.get(i);
|
||||||
|
elements += bCount;
|
||||||
|
sum += bCount * bucketOffsets[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return (long) Math.ceil((double) sum / elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the total number of non-zero values
|
||||||
|
*/
|
||||||
|
public long count() {
|
||||||
|
long sum = 0L;
|
||||||
|
for (int i = 0; i < buckets.length(); i++)
|
||||||
|
sum += buckets.get(i);
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this histogram has overflowed -- that is, a value larger
|
||||||
|
* than our largest bucket could bound was added
|
||||||
|
*/
|
||||||
|
public boolean isOverflowed() {
|
||||||
|
return buckets.get(buckets.length() - 1) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* log.debug() every record in the histogram
|
||||||
|
*
|
||||||
|
* @param log
|
||||||
|
*/
|
||||||
|
public void log(Logger log) {
|
||||||
|
// only print overflow if there is any
|
||||||
|
int nameCount;
|
||||||
|
if (buckets.get(buckets.length() - 1) == 0)
|
||||||
|
nameCount = buckets.length() - 1;
|
||||||
|
else
|
||||||
|
nameCount = buckets.length();
|
||||||
|
String[] names = new String[nameCount];
|
||||||
|
|
||||||
|
int maxNameLength = 0;
|
||||||
|
for (int i = 0; i < nameCount; i++) {
|
||||||
|
names[i] = nameOfRange(bucketOffsets, i);
|
||||||
|
maxNameLength = Math.max(maxNameLength, names[i].length());
|
||||||
|
}
|
||||||
|
|
||||||
|
// emit log records
|
||||||
|
String formatstr = "%" + maxNameLength + "s: %d";
|
||||||
|
for (int i = 0; i < nameCount; i++) {
|
||||||
|
long count = buckets.get(i);
|
||||||
|
// sort-of-hack to not print empty ranges at the start that are only
|
||||||
|
// used to demarcate the
|
||||||
|
// first populated range. for code clarity we don't omit this record
|
||||||
|
// from the maxNameLength
|
||||||
|
// calculation, and accept the unnecessary whitespace prefixes that
|
||||||
|
// will occasionally occur
|
||||||
|
if (i == 0 && count == 0)
|
||||||
|
continue;
|
||||||
|
log.debug(String.format(formatstr, names[i], count));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String nameOfRange(long[] bucketOffsets, int index) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
appendRange(sb, bucketOffsets, index);
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendRange(StringBuilder sb, long[] bucketOffsets,
|
||||||
|
int index) {
|
||||||
|
sb.append("[");
|
||||||
|
if (index == 0)
|
||||||
|
if (bucketOffsets[0] > 0)
|
||||||
|
// by original definition, this histogram is for values greater
|
||||||
|
// than zero only;
|
||||||
|
// if values of 0 or less are required, an entry of lb-1 must be
|
||||||
|
// inserted at the start
|
||||||
|
sb.append("1");
|
||||||
|
else
|
||||||
|
sb.append("-Inf");
|
||||||
|
else
|
||||||
|
sb.append(bucketOffsets[index - 1] + 1);
|
||||||
|
sb.append("..");
|
||||||
|
if (index == bucketOffsets.length)
|
||||||
|
sb.append("Inf");
|
||||||
|
else
|
||||||
|
sb.append(bucketOffsets[index]);
|
||||||
|
sb.append("]");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!(o instanceof EstimatedHistogram))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
EstimatedHistogram that = (EstimatedHistogram) o;
|
||||||
|
return Arrays.equals(getBucketOffsets(), that.getBucketOffsets())
|
||||||
|
&& Arrays.equals(getBuckets(false), that.getBuckets(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getBucketOffsets(), getBuckets(false));
|
||||||
|
}
|
||||||
|
}
|
@ -22,59 +22,71 @@
|
|||||||
* Modified by Cloudius Systems
|
* Modified by Cloudius Systems
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.scylladb.jmx.api.utils;
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils
|
||||||
|
{
|
||||||
private static final double KB = 1024d;
|
private static final double KB = 1024d;
|
||||||
private static final double MB = 1024 * 1024d;
|
private static final double MB = 1024*1024d;
|
||||||
private static final double GB = 1024 * 1024 * 1024d;
|
private static final double GB = 1024*1024*1024d;
|
||||||
private static final double TB = 1024 * 1024 * 1024 * 1024d;
|
private static final double TB = 1024*1024*1024*1024d;
|
||||||
|
|
||||||
private static final DecimalFormat df = new DecimalFormat("#.##");
|
private static final DecimalFormat df = new DecimalFormat("#.##");
|
||||||
|
|
||||||
|
|
||||||
public static String stringifyFileSize(double value) {
|
public static String stringifyFileSize(double value)
|
||||||
|
{
|
||||||
double d;
|
double d;
|
||||||
if (value >= TB) {
|
if ( value >= TB )
|
||||||
|
{
|
||||||
d = value / TB;
|
d = value / TB;
|
||||||
String val = df.format(d);
|
String val = df.format(d);
|
||||||
return val + " TB";
|
return val + " TB";
|
||||||
} else if (value >= GB) {
|
}
|
||||||
|
else if ( value >= GB )
|
||||||
|
{
|
||||||
d = value / GB;
|
d = value / GB;
|
||||||
String val = df.format(d);
|
String val = df.format(d);
|
||||||
return val + " GB";
|
return val + " GB";
|
||||||
} else if (value >= MB) {
|
}
|
||||||
|
else if ( value >= MB )
|
||||||
|
{
|
||||||
d = value / MB;
|
d = value / MB;
|
||||||
String val = df.format(d);
|
String val = df.format(d);
|
||||||
return val + " MB";
|
return val + " MB";
|
||||||
} else if (value >= KB) {
|
}
|
||||||
|
else if ( value >= KB )
|
||||||
|
{
|
||||||
d = value / KB;
|
d = value / KB;
|
||||||
String val = df.format(d);
|
String val = df.format(d);
|
||||||
return val + " KB";
|
return val + " KB";
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
String val = df.format(value);
|
String val = df.format(value);
|
||||||
return val + " bytes";
|
return val + " bytes";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the size of a directory in bytes
|
* Get the size of a directory in bytes
|
||||||
*
|
* @param directory The directory for which we need size.
|
||||||
* @param directory
|
|
||||||
* The directory for which we need size.
|
|
||||||
* @return The size of the directory
|
* @return The size of the directory
|
||||||
*/
|
*/
|
||||||
public static long folderSize(File directory) {
|
public static long folderSize(File directory)
|
||||||
|
{
|
||||||
long length = 0;
|
long length = 0;
|
||||||
for (File file : directory.listFiles()) {
|
for (File file : directory.listFiles())
|
||||||
if (file.isFile()) {
|
{
|
||||||
|
if (file.isFile())
|
||||||
length += file.length();
|
length += file.length();
|
||||||
} else {
|
else
|
||||||
length += folderSize(file);
|
length += folderSize(file);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -22,42 +22,47 @@
|
|||||||
* Modified by Cloudius Systems
|
* Modified by Cloudius Systems
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.scylladb.jmx.api.utils;
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
public class Pair<T1, T2> {
|
public class Pair<T1, T2>
|
||||||
|
{
|
||||||
public final T1 left;
|
public final T1 left;
|
||||||
public final T2 right;
|
public final T2 right;
|
||||||
|
|
||||||
protected Pair(T1 left, T2 right) {
|
protected Pair(T1 left, T2 right)
|
||||||
|
{
|
||||||
this.left = left;
|
this.left = left;
|
||||||
this.right = right;
|
this.right = right;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int hashCode() {
|
public final int hashCode()
|
||||||
|
{
|
||||||
int hashCode = 31 + (left == null ? 0 : left.hashCode());
|
int hashCode = 31 + (left == null ? 0 : left.hashCode());
|
||||||
return 31 * hashCode + (right == null ? 0 : right.hashCode());
|
return 31*hashCode + (right == null ? 0 : right.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final boolean equals(Object o) {
|
public final boolean equals(Object o)
|
||||||
if (!(o instanceof Pair)) {
|
{
|
||||||
|
if(!(o instanceof Pair))
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
Pair that = (Pair) o;
|
Pair that = (Pair)o;
|
||||||
// handles nulls properly
|
// handles nulls properly
|
||||||
return Objects.equal(left, that.left) && Objects.equal(right, that.right);
|
return Objects.equal(left, that.left) && Objects.equal(right, that.right);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return "(" + left + "," + right + ")";
|
return "(" + left + "," + right + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <X, Y> Pair<X, Y> create(X x, Y y) {
|
public static <X, Y> Pair<X, Y> create(X x, Y y)
|
||||||
|
{
|
||||||
return new Pair<X, Y>(x, y);
|
return new Pair<X, Y>(x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2016 ScyllaDB
|
||||||
|
*
|
||||||
|
* Modified by ScyllaDB
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.net.*;
|
||||||
|
import java.rmi.registry.LocateRegistry;
|
||||||
|
import java.rmi.server.RMIServerSocketFactory;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.management.remote.JMXConnectorServer;
|
||||||
|
import javax.management.remote.JMXServiceURL;
|
||||||
|
import javax.management.remote.rmi.RMIConnectorServer;
|
||||||
|
import javax.net.ServerSocketFactory;
|
||||||
|
|
||||||
|
public class RMIServerSocketFactoryImpl implements RMIServerSocketFactory {
|
||||||
|
public static JMXConnectorServer jmxServer = null;
|
||||||
|
|
||||||
|
public static void maybeInitJmx() {
|
||||||
|
System.setProperty("javax.management.builder.initial", "com.scylladb.jmx.utils.APIBuilder");
|
||||||
|
System.setProperty("mx4j.strict.mbean.interface", "no");
|
||||||
|
|
||||||
|
String jmxPort = System
|
||||||
|
.getProperty("com.sun.management.jmxremote.port");
|
||||||
|
|
||||||
|
if (jmxPort == null) {
|
||||||
|
System.out.println(
|
||||||
|
"JMX is not enabled to receive remote connections.");
|
||||||
|
|
||||||
|
jmxPort = System.getProperty("cassandra.jmx.local.port", "7199");
|
||||||
|
String address = System.getProperty("jmx.address", "localhost");
|
||||||
|
if (address.equals("localhost")) {
|
||||||
|
System.setProperty("java.rmi.server.hostname",
|
||||||
|
InetAddress.getLoopbackAddress().getHostAddress());
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
System.setProperty("java.rmi.server.hostname",
|
||||||
|
InetAddress.getByName(address).getHostAddress());
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
RMIServerSocketFactory serverFactory = new RMIServerSocketFactoryImpl();
|
||||||
|
LocateRegistry.createRegistry(Integer.valueOf(jmxPort), null,
|
||||||
|
serverFactory);
|
||||||
|
|
||||||
|
StringBuffer url = new StringBuffer();
|
||||||
|
url.append("service:jmx:");
|
||||||
|
url.append("rmi://").append(address).append("/jndi/");
|
||||||
|
url.append("rmi://").append(address).append(":").append(jmxPort)
|
||||||
|
.append("/jmxrmi");
|
||||||
|
System.out.println(url);
|
||||||
|
Map env = new HashMap();
|
||||||
|
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE,
|
||||||
|
serverFactory);
|
||||||
|
|
||||||
|
jmxServer = new RMIConnectorServer(
|
||||||
|
new JMXServiceURL(url.toString()), env,
|
||||||
|
ManagementFactory.getPlatformMBeanServer());
|
||||||
|
|
||||||
|
jmxServer.start();
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(
|
||||||
|
"Error starting local jmx server: " + e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println(
|
||||||
|
"JMX is enabled to receive remote connections on port: "
|
||||||
|
+ jmxPort);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerSocket createServerSocket(final int pPort) throws IOException {
|
||||||
|
return ServerSocketFactory.getDefault().createServerSocket(pPort, 0,
|
||||||
|
InetAddress.getLoopbackAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (obj == this) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj.getClass().equals(getClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
return RMIServerSocketFactoryImpl.class.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.scylladb.jmx.utils;
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 ScyllaDB
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Scylla.
|
||||||
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* RecentEstimatedHistogram In the (deprecated) 'recent' functionality, each
|
||||||
|
* call to get the values cleans the value.
|
||||||
|
*
|
||||||
|
* The RecentEstimatedHistogram support recent call to EstimatedHistogram.
|
||||||
|
* It holds the latest total values and a call to getBuckets return the delta.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class RecentEstimatedHistogram extends EstimatedHistogram {
|
||||||
|
public RecentEstimatedHistogram() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentEstimatedHistogram(int bucketCount) {
|
||||||
|
super(bucketCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RecentEstimatedHistogram(long[] offsets, long[] bucketData) {
|
||||||
|
super(offsets, bucketData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the current buckets to new value and return the delta from the last
|
||||||
|
* getBuckets call
|
||||||
|
*
|
||||||
|
* @param bucketData
|
||||||
|
* - new bucket value
|
||||||
|
* @return a long[] containing the current histogram difference buckets
|
||||||
|
*/
|
||||||
|
public long[] getBuckets(long[] bucketData) {
|
||||||
|
if (bucketData.length == 0) {
|
||||||
|
return new long[0];
|
||||||
|
}
|
||||||
|
final int len = buckets.length();
|
||||||
|
long[] rv = new long[len];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
rv[i] = bucketData[i];
|
||||||
|
rv[i] -= buckets.getAndSet(i, bucketData[i]);
|
||||||
|
}
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
@ -20,27 +20,21 @@
|
|||||||
*
|
*
|
||||||
* Modified by Cloudius Systems
|
* Modified by Cloudius Systems
|
||||||
*/
|
*/
|
||||||
package com.scylladb.jmx.api.utils;
|
package com.scylladb.jmx.utils;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.management.openmbean.*;
|
||||||
import javax.management.openmbean.CompositeDataSupport;
|
|
||||||
import javax.management.openmbean.CompositeType;
|
|
||||||
import javax.management.openmbean.OpenDataException;
|
|
||||||
import javax.management.openmbean.OpenType;
|
|
||||||
import javax.management.openmbean.SimpleType;
|
|
||||||
import javax.management.openmbean.TabularDataSupport;
|
|
||||||
import javax.management.openmbean.TabularType;
|
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
public class SnapshotDetailsTabularData {
|
public class SnapshotDetailsTabularData {
|
||||||
|
|
||||||
private static final String[] ITEM_NAMES = new String[] { "Snapshot name", "Keyspace name", "Column family name",
|
private static final String[] ITEM_NAMES = new String[] { "Snapshot name",
|
||||||
"True size", "Size on disk" };
|
"Keyspace name", "Column family name", "True size", "Size on disk" };
|
||||||
|
|
||||||
private static final String[] ITEM_DESCS = new String[] { "snapshot_name", "keyspace_name", "columnfamily_name",
|
private static final String[] ITEM_DESCS = new String[] { "snapshot_name",
|
||||||
"TrueDiskSpaceUsed", "TotalDiskSpaceUsed" };
|
"keyspace_name", "columnfamily_name", "TrueDiskSpaceUsed",
|
||||||
|
"TotalDiskSpaceUsed" };
|
||||||
|
|
||||||
private static final String TYPE_NAME = "SnapshotDetails";
|
private static final String TYPE_NAME = "SnapshotDetails";
|
||||||
|
|
||||||
@ -54,22 +48,28 @@ public class SnapshotDetailsTabularData {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
ITEM_TYPES = new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
|
ITEM_TYPES = new OpenType[] { SimpleType.STRING, SimpleType.STRING,
|
||||||
SimpleType.STRING };
|
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING };
|
||||||
|
|
||||||
COMPOSITE_TYPE = new CompositeType(TYPE_NAME, ROW_DESC, ITEM_NAMES, ITEM_DESCS, ITEM_TYPES);
|
COMPOSITE_TYPE = new CompositeType(TYPE_NAME, ROW_DESC, ITEM_NAMES,
|
||||||
|
ITEM_DESCS, ITEM_TYPES);
|
||||||
|
|
||||||
TABULAR_TYPE = new TabularType(TYPE_NAME, ROW_DESC, COMPOSITE_TYPE, ITEM_NAMES);
|
TABULAR_TYPE = new TabularType(TYPE_NAME, ROW_DESC, COMPOSITE_TYPE,
|
||||||
|
ITEM_NAMES);
|
||||||
} catch (OpenDataException e) {
|
} catch (OpenDataException e) {
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void from(final String snapshot, final String ks, final String cf,
|
public static void from(final String snapshot, final String ks,
|
||||||
Map.Entry<String, Pair<Long, Long>> snapshotDetail, TabularDataSupport result) {
|
final String cf,
|
||||||
|
Map.Entry<String, Pair<Long, Long>> snapshotDetail,
|
||||||
|
TabularDataSupport result) {
|
||||||
try {
|
try {
|
||||||
final String totalSize = FileUtils.stringifyFileSize(snapshotDetail.getValue().left);
|
final String totalSize = FileUtils.stringifyFileSize(snapshotDetail
|
||||||
final String liveSize = FileUtils.stringifyFileSize(snapshotDetail.getValue().right);
|
.getValue().left);
|
||||||
|
final String liveSize = FileUtils.stringifyFileSize(snapshotDetail
|
||||||
|
.getValue().right);
|
||||||
result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
|
result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
|
||||||
new Object[] { snapshot, ks, cf, liveSize, totalSize }));
|
new Object[] { snapshot, ks, cf, liveSize, totalSize }));
|
||||||
} catch (OpenDataException e) {
|
} catch (OpenDataException e) {
|
||||||
@ -77,8 +77,8 @@ public class SnapshotDetailsTabularData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void from(final String snapshot, final String ks, final String cf, long total, long live,
|
public static void from(final String snapshot, final String ks,
|
||||||
TabularDataSupport result) {
|
final String cf, long total, long live, TabularDataSupport result) {
|
||||||
try {
|
try {
|
||||||
final String totalSize = FileUtils.stringifyFileSize(total);
|
final String totalSize = FileUtils.stringifyFileSize(total);
|
||||||
final String liveSize = FileUtils.stringifyFileSize(live);
|
final String liveSize = FileUtils.stringifyFileSize(live);
|
29
src/main/java/com/yammer/metrics/core/APICounter.java
Normal file
29
src/main/java/com/yammer/metrics/core/APICounter.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
|
||||||
|
public class APICounter extends Counter {
|
||||||
|
String url;
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
|
||||||
|
public APICounter(String _url) {
|
||||||
|
super();
|
||||||
|
url = _url;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Returns the counter's current value.
|
||||||
|
*
|
||||||
|
* @return the counter's current value
|
||||||
|
*/
|
||||||
|
public long count() {
|
||||||
|
return c.getLongValue(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
215
src/main/java/com/yammer/metrics/core/APIHistogram.java
Normal file
215
src/main/java/com/yammer/metrics/core/APIHistogram.java
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.yammer.metrics.stats.Sample;
|
||||||
|
import com.yammer.metrics.stats.Snapshot;
|
||||||
|
|
||||||
|
public class APIHistogram extends Histogram {
|
||||||
|
Field countField;
|
||||||
|
Field minField;
|
||||||
|
Field maxField;
|
||||||
|
Field sumField;
|
||||||
|
Field varianceField;
|
||||||
|
Field sampleField;
|
||||||
|
|
||||||
|
long last_update = 0;
|
||||||
|
static final long UPDATE_INTERVAL = 50;
|
||||||
|
long updateInterval;
|
||||||
|
String url;
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
|
||||||
|
private void setFields() {
|
||||||
|
try {
|
||||||
|
minField = Histogram.class.getDeclaredField("min");
|
||||||
|
minField.setAccessible(true);
|
||||||
|
maxField = Histogram.class.getDeclaredField("max");
|
||||||
|
maxField.setAccessible(true);
|
||||||
|
sumField = Histogram.class.getDeclaredField("sum");
|
||||||
|
sumField.setAccessible(true);
|
||||||
|
varianceField = Histogram.class.getDeclaredField("variance");
|
||||||
|
varianceField.setAccessible(true);
|
||||||
|
sampleField = Histogram.class.getDeclaredField("sample");
|
||||||
|
sampleField.setAccessible(true);
|
||||||
|
countField = Histogram.class.getDeclaredField("count");
|
||||||
|
countField.setAccessible(true);
|
||||||
|
try {
|
||||||
|
getCount().set(0);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
// There's no reason to get here
|
||||||
|
// and there's nothing we can do even if we would
|
||||||
|
}
|
||||||
|
} catch (NoSuchFieldException | SecurityException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicLong getMin() throws IllegalArgumentException,
|
||||||
|
IllegalAccessException {
|
||||||
|
return (AtomicLong) minField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicLong getMax() throws IllegalArgumentException,
|
||||||
|
IllegalAccessException {
|
||||||
|
return (AtomicLong) maxField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicLong getSum() throws IllegalArgumentException,
|
||||||
|
IllegalAccessException {
|
||||||
|
return (AtomicLong) sumField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AtomicLong getCount() throws IllegalArgumentException,
|
||||||
|
IllegalAccessException {
|
||||||
|
return (AtomicLong) countField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public AtomicReference<double[]> getVariance()
|
||||||
|
throws IllegalArgumentException, IllegalAccessException {
|
||||||
|
return (AtomicReference<double[]>) varianceField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample getSample() throws IllegalArgumentException,
|
||||||
|
IllegalAccessException {
|
||||||
|
return (Sample) sampleField.get(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIHistogram(String url, Sample sample) {
|
||||||
|
super(sample);
|
||||||
|
setFields();
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIHistogram(String url, SampleType type, long updateInterval) {
|
||||||
|
super(type);
|
||||||
|
setFields();
|
||||||
|
this.url = url;
|
||||||
|
this.updateInterval = updateInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIHistogram(String url, SampleType type) {
|
||||||
|
this(url, type, UPDATE_INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateValue(HistogramValues vals) {
|
||||||
|
try {
|
||||||
|
if (vals.sample != null) {
|
||||||
|
for (long v : vals.sample) {
|
||||||
|
getSample().update(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getCount().set(vals.count);
|
||||||
|
getMax().set(vals.max);
|
||||||
|
getMin().set(vals.min);
|
||||||
|
getSum().set(vals.sum);
|
||||||
|
double[] newValue = new double[2];
|
||||||
|
newValue[0] = vals.mean;
|
||||||
|
newValue[1] = vals.variance;
|
||||||
|
getVariance().getAndSet(newValue);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
if (url == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
if (now - last_update < UPDATE_INTERVAL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
last_update = now;
|
||||||
|
clear();
|
||||||
|
JsonObject obj = c.getJsonObj(url, null);
|
||||||
|
if (obj.containsKey("hist")) {
|
||||||
|
updateValue(APIClient.json2histogram(obj.getJsonObject("hist")));
|
||||||
|
} else {
|
||||||
|
updateValue(APIClient.json2histogram(obj));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of values recorded.
|
||||||
|
*
|
||||||
|
* @return the number of values recorded
|
||||||
|
*/
|
||||||
|
public long count() {
|
||||||
|
update();
|
||||||
|
return super.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.yammer.metrics.core.Summarizable#max()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double max() {
|
||||||
|
update();
|
||||||
|
return super.max();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.yammer.metrics.core.Summarizable#min()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double min() {
|
||||||
|
update();
|
||||||
|
return super.min();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.yammer.metrics.core.Summarizable#mean()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double mean() {
|
||||||
|
update();
|
||||||
|
return super.mean();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.yammer.metrics.core.Summarizable#stdDev()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double stdDev() {
|
||||||
|
update();
|
||||||
|
return super.stdDev();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see com.yammer.metrics.core.Summarizable#sum()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public double sum() {
|
||||||
|
update();
|
||||||
|
return super.sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Snapshot getSnapshot() {
|
||||||
|
update();
|
||||||
|
return super.getSnapshot();
|
||||||
|
}
|
||||||
|
}
|
113
src/main/java/com/yammer/metrics/core/APIMeter.java
Normal file
113
src/main/java/com/yammer/metrics/core/APIMeter.java
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 ScyllaDB
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Scylla.
|
||||||
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Modified by ScyllaDB
|
||||||
|
*/
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
|
||||||
|
public class APIMeter extends Meter {
|
||||||
|
public final static long CACHE_DURATION = 1000;
|
||||||
|
|
||||||
|
String url;
|
||||||
|
String eventType;
|
||||||
|
TimeUnit rateUnit;
|
||||||
|
APIClient c = new APIClient();
|
||||||
|
long count;
|
||||||
|
double oneMinuteRate;
|
||||||
|
double fiveMinuteRate;
|
||||||
|
double fifteenMinuteRate;
|
||||||
|
double meanRate;
|
||||||
|
|
||||||
|
public APIMeter(String url, ScheduledExecutorService tickThread,
|
||||||
|
String eventType, TimeUnit rateUnit) {
|
||||||
|
super(tickThread, eventType, rateUnit, Clock.defaultClock());
|
||||||
|
super.stop();
|
||||||
|
this.url = url;
|
||||||
|
this.eventType = eventType;
|
||||||
|
this.rateUnit = rateUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromJson(JsonObject obj) {
|
||||||
|
JsonArray rates = obj.getJsonArray("rates");
|
||||||
|
int i = 0;
|
||||||
|
oneMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
fiveMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
fifteenMinuteRate = rates.getJsonNumber(i++).doubleValue();
|
||||||
|
meanRate = obj.getJsonNumber("mean_rate").doubleValue();
|
||||||
|
count = obj.getJsonNumber("count").longValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update_fields() {
|
||||||
|
if (url != null) {
|
||||||
|
fromJson(c.getJsonObj(url, null, CACHE_DURATION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimeUnit rateUnit() {
|
||||||
|
return rateUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String eventType() {
|
||||||
|
return eventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count() {
|
||||||
|
update_fields();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fifteenMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return fifteenMinuteRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fiveMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return fiveMinuteRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double meanRate() {
|
||||||
|
update_fields();
|
||||||
|
return meanRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double oneMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return oneMinuteRate;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
384
src/main/java/com/yammer/metrics/core/APIMetricsRegistry.java
Normal file
384
src/main/java/com/yammer/metrics/core/APIMetricsRegistry.java
Normal file
@ -0,0 +1,384 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.yammer.metrics.core.APICounter;
|
||||||
|
import com.yammer.metrics.core.APIMeter;
|
||||||
|
import com.yammer.metrics.core.Clock;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
import com.yammer.metrics.core.Meter;
|
||||||
|
import com.yammer.metrics.core.Metric;
|
||||||
|
import com.yammer.metrics.core.MetricName;
|
||||||
|
import com.yammer.metrics.core.MetricsRegistry;
|
||||||
|
import com.yammer.metrics.core.ThreadPools;
|
||||||
|
import com.yammer.metrics.core.Histogram.SampleType;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class APIMetricsRegistry extends MetricsRegistry {
|
||||||
|
Field fieldMetrics;
|
||||||
|
Field fieldClock;
|
||||||
|
Field fieldThreadPool;
|
||||||
|
|
||||||
|
public APIMetricsRegistry() {
|
||||||
|
try {
|
||||||
|
fieldMetrics = MetricsRegistry.class.getDeclaredField("metrics");
|
||||||
|
fieldMetrics.setAccessible(true);
|
||||||
|
fieldClock = MetricsRegistry.class.getDeclaredField("clock");
|
||||||
|
fieldClock.setAccessible(true);
|
||||||
|
fieldThreadPool = MetricsRegistry.class
|
||||||
|
.getDeclaredField("threadPools");
|
||||||
|
fieldThreadPool.setAccessible(true);
|
||||||
|
} catch (NoSuchFieldException | SecurityException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ThreadPools getThreadPools() {
|
||||||
|
try {
|
||||||
|
return (ThreadPools) fieldThreadPool.get(this);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Clock getClock() {
|
||||||
|
try {
|
||||||
|
return (Clock) fieldClock.get(this);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ConcurrentMap<MetricName, Metric> getMetrics() {
|
||||||
|
try {
|
||||||
|
return (ConcurrentMap<MetricName, Metric>) fieldMetrics.get(this);
|
||||||
|
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Counter} and registers it under the given class and
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link Counter}
|
||||||
|
*/
|
||||||
|
public Counter newCounter(String url, Class<?> klass, String name) {
|
||||||
|
return newCounter(url, klass, name, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Counter} and registers it under the given class and
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link Counter}
|
||||||
|
*/
|
||||||
|
public Counter newCounter(String url, Class<?> klass, String name,
|
||||||
|
String scope) {
|
||||||
|
return newCounter(url, createName(klass, name, scope));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Counter} and registers it under the given metric
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link Counter}
|
||||||
|
*/
|
||||||
|
public Counter newCounter(String url, MetricName metricName) {
|
||||||
|
return getOrAdd(metricName, new APICounter(url));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Meter} and registers it under the given class and
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link Meter}
|
||||||
|
*/
|
||||||
|
public APIMeter newMeter(String url, Class<?> klass, String name,
|
||||||
|
String eventType, TimeUnit unit) {
|
||||||
|
return newMeter(url, klass, name, null, eventType, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Meter} and registers it under the given class, name,
|
||||||
|
* and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link Meter}
|
||||||
|
*/
|
||||||
|
public APIMeter newMeter(String url, Class<?> klass, String name,
|
||||||
|
String scope, String eventType, TimeUnit unit) {
|
||||||
|
return newMeter(url, createName(klass, name, scope), eventType, unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScheduledExecutorService newMeterTickThreadPool() {
|
||||||
|
return getThreadPools().newScheduledThreadPool(2, "meter-tick");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Meter} and registers it under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link Meter}
|
||||||
|
*/
|
||||||
|
public APIMeter newMeter(String url, MetricName metricName, String eventType,
|
||||||
|
TimeUnit unit) {
|
||||||
|
final Metric existingMetric = getMetrics().get(metricName);
|
||||||
|
if (existingMetric != null) {
|
||||||
|
return (APIMeter) existingMetric;
|
||||||
|
}
|
||||||
|
return getOrAdd(metricName, new APIMeter(url, newMeterTickThreadPool(),
|
||||||
|
eventType, unit));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link APISettableMeter} and registers it under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param eventType
|
||||||
|
* the plural name of the type of events the meter is measuring
|
||||||
|
* (e.g., {@code "requests"})
|
||||||
|
* @param unit
|
||||||
|
* the rate unit of the new meter
|
||||||
|
* @return a new {@link Meter}
|
||||||
|
*/
|
||||||
|
public Meter newSettableMeter(MetricName metricName, String eventType,
|
||||||
|
TimeUnit unit) {
|
||||||
|
final Metric existingMetric = getMetrics().get(metricName);
|
||||||
|
if (existingMetric != null) {
|
||||||
|
return (Meter) existingMetric;
|
||||||
|
}
|
||||||
|
return getOrAdd(metricName, new APISettableMeter(newMeterTickThreadPool(),
|
||||||
|
eventType, unit, getClock()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Histogram} and registers it under the given class
|
||||||
|
* and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link Histogram}
|
||||||
|
*/
|
||||||
|
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||||
|
boolean biased) {
|
||||||
|
return newHistogram(url, klass, name, null, biased);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Histogram} and registers it under the given class,
|
||||||
|
* name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link Histogram}
|
||||||
|
*/
|
||||||
|
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||||
|
String scope, boolean biased) {
|
||||||
|
return newHistogram(url, createName(klass, name, scope), biased);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new non-biased {@link Histogram} and registers it under the
|
||||||
|
* given class and name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link Histogram}
|
||||||
|
*/
|
||||||
|
public Histogram newHistogram(String url, Class<?> klass, String name) {
|
||||||
|
return newHistogram(url, klass, name, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new non-biased {@link Histogram} and registers it under the
|
||||||
|
* given class, name, and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link Histogram}
|
||||||
|
*/
|
||||||
|
public Histogram newHistogram(String url, Class<?> klass, String name,
|
||||||
|
String scope) {
|
||||||
|
return newHistogram(url, klass, name, scope, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Histogram} and registers it under the given metric
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param biased
|
||||||
|
* whether or not the histogram should be biased
|
||||||
|
* @return a new {@link Histogram}
|
||||||
|
*/
|
||||||
|
public Histogram newHistogram(String url, MetricName metricName,
|
||||||
|
boolean biased) {
|
||||||
|
return getOrAdd(metricName, new APIHistogram(url,
|
||||||
|
biased ? SampleType.BIASED : SampleType.UNIFORM));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Timer} and registers it under the given class and
|
||||||
|
* name, measuring elapsed time in milliseconds and invocations per second.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @return a new {@link Timer}
|
||||||
|
*/
|
||||||
|
public Timer newTimer(String url, Class<?> klass, String name) {
|
||||||
|
return newTimer(url, klass, name, null, TimeUnit.MILLISECONDS,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Timer} and registers it under the given class and
|
||||||
|
* name.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link Timer}
|
||||||
|
*/
|
||||||
|
public Timer newTimer(String url, Class<?> klass, String name,
|
||||||
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
return newTimer(url, klass, name, null, durationUnit, rateUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Timer} and registers it under the given class, name,
|
||||||
|
* and scope, measuring elapsed time in milliseconds and invocations per
|
||||||
|
* second.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @return a new {@link Timer}
|
||||||
|
*/
|
||||||
|
public Timer newTimer(String url, Class<?> klass, String name, String scope) {
|
||||||
|
return newTimer(url, klass, name, scope, TimeUnit.MILLISECONDS,
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Timer} and registers it under the given class, name,
|
||||||
|
* and scope.
|
||||||
|
*
|
||||||
|
* @param klass
|
||||||
|
* the class which owns the metric
|
||||||
|
* @param name
|
||||||
|
* the name of the metric
|
||||||
|
* @param scope
|
||||||
|
* the scope of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link Timer}
|
||||||
|
*/
|
||||||
|
public Timer newTimer(String url, Class<?> klass, String name,
|
||||||
|
String scope, TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
return newTimer(url, createName(klass, name, scope), durationUnit,
|
||||||
|
rateUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Timer} and registers it under the given metric name.
|
||||||
|
*
|
||||||
|
* @param metricName
|
||||||
|
* the name of the metric
|
||||||
|
* @param durationUnit
|
||||||
|
* the duration scale unit of the new timer
|
||||||
|
* @param rateUnit
|
||||||
|
* the rate scale unit of the new timer
|
||||||
|
* @return a new {@link Timer}
|
||||||
|
*/
|
||||||
|
public Timer newTimer(String url, MetricName metricName,
|
||||||
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
final Metric existingMetric = getMetrics().get(metricName);
|
||||||
|
if (existingMetric != null) {
|
||||||
|
return (Timer) existingMetric;
|
||||||
|
}
|
||||||
|
return getOrAdd(metricName, new APITimer(url, newMeterTickThreadPool(),
|
||||||
|
durationUnit, rateUnit));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
src/main/java/com/yammer/metrics/core/APISettableMeter.java
Normal file
49
src/main/java/com/yammer/metrics/core/APISettableMeter.java
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 ScyllaDB
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* This file is part of Scylla.
|
||||||
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class APISettableMeter extends Meter {
|
||||||
|
|
||||||
|
public APISettableMeter(ScheduledExecutorService tickThread,
|
||||||
|
String eventType, TimeUnit rateUnit, Clock clock) {
|
||||||
|
super(tickThread, eventType, rateUnit, clock);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Meter doesn't have a set value method.
|
||||||
|
// to mimic it, we clear the old value and set it to a new one.
|
||||||
|
// This is safe because the only this method would be used
|
||||||
|
// to update the values
|
||||||
|
public long set(long new_value) {
|
||||||
|
long res = super.count();
|
||||||
|
mark(-res);
|
||||||
|
mark(new_value);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
super.tick();
|
||||||
|
}
|
||||||
|
}
|
134
src/main/java/com/yammer/metrics/core/APITimer.java
Normal file
134
src/main/java/com/yammer/metrics/core/APITimer.java
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package com.yammer.metrics.core;
|
||||||
|
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.yammer.metrics.core.Histogram.SampleType;
|
||||||
|
import com.yammer.metrics.stats.Snapshot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A timer metric which aggregates timing durations and provides duration
|
||||||
|
* statistics, plus throughput statistics via {@link Meter}.
|
||||||
|
*/
|
||||||
|
public class APITimer extends Timer {
|
||||||
|
public final static long CACHE_DURATION = 1000;
|
||||||
|
|
||||||
|
final TimeUnit durationUnit, rateUnit;
|
||||||
|
final APIMeter meter;
|
||||||
|
final APIHistogram histogram;
|
||||||
|
APIClient c = new APIClient();
|
||||||
|
|
||||||
|
private double convertFromNS(double ns) {
|
||||||
|
return ns / TimeUnit.NANOSECONDS.convert(1, durationUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
String url;
|
||||||
|
|
||||||
|
public APITimer(String url, ScheduledExecutorService tickThread,
|
||||||
|
TimeUnit durationUnit, TimeUnit rateUnit) {
|
||||||
|
super(tickThread, durationUnit, rateUnit);
|
||||||
|
super.stop();
|
||||||
|
this.url = url;
|
||||||
|
this.durationUnit = durationUnit;
|
||||||
|
this.rateUnit = rateUnit;
|
||||||
|
meter = new APIMeter(null, tickThread, "calls", rateUnit);
|
||||||
|
histogram = new APIHistogram(null, SampleType.BIASED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fromJson(JsonObject obj) {
|
||||||
|
meter.fromJson(obj.getJsonObject("meter"));
|
||||||
|
histogram.updateValue(APIClient.json2histogram(obj.getJsonObject("hist")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update_fields() {
|
||||||
|
if (url != null) {
|
||||||
|
fromJson(c.getJsonObj(url, null, CACHE_DURATION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double max() {
|
||||||
|
update_fields();
|
||||||
|
return convertFromNS(histogram.max());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double min() {
|
||||||
|
update_fields();
|
||||||
|
return convertFromNS(histogram.min());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double mean() {
|
||||||
|
update_fields();
|
||||||
|
return convertFromNS(histogram.mean());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double stdDev() {
|
||||||
|
update_fields();
|
||||||
|
return convertFromNS(histogram.stdDev());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double sum() {
|
||||||
|
update_fields();
|
||||||
|
return convertFromNS(histogram.sum());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Snapshot getSnapshot() {
|
||||||
|
update_fields();
|
||||||
|
return histogram.getSnapshot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimeUnit rateUnit() {
|
||||||
|
update_fields();
|
||||||
|
return meter.rateUnit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String eventType() {
|
||||||
|
update_fields();
|
||||||
|
return meter.eventType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long count() {
|
||||||
|
update_fields();
|
||||||
|
return meter.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fifteenMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return meter.fifteenMinuteRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double fiveMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return meter.fiveMinuteRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double meanRate() {
|
||||||
|
update_fields();
|
||||||
|
return meter.meanRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double oneMinuteRate() {
|
||||||
|
update_fields();
|
||||||
|
return meter.oneMinuteRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
src/main/java/com/yammer/metrics/core/HistogramValues.java
Normal file
11
src/main/java/com/yammer/metrics/core/HistogramValues.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.yammer.metrics.core;
|
||||||
|
|
||||||
|
public class HistogramValues {
|
||||||
|
public long count;
|
||||||
|
public long min;
|
||||||
|
public long max;
|
||||||
|
public long sum;
|
||||||
|
public double variance;
|
||||||
|
public double mean;
|
||||||
|
public long sample[];
|
||||||
|
}
|
@ -1,16 +0,0 @@
|
|||||||
module scylla.jmx {
|
|
||||||
opens com.scylladb.jmx.utils;
|
|
||||||
exports com.scylladb.jmx.utils;
|
|
||||||
opens com.scylladb.jmx.main;
|
|
||||||
exports com.scylladb.jmx.main;
|
|
||||||
opens com.scylladb.jmx.metrics;
|
|
||||||
exports com.scylladb.jmx.metrics;
|
|
||||||
requires java.logging;
|
|
||||||
requires java.management;
|
|
||||||
requires scylla.apiclient;
|
|
||||||
requires jakarta.json;
|
|
||||||
requires jakarta.ws.rs;
|
|
||||||
requires com.google.common;
|
|
||||||
requires jakarta.xml.bind;
|
|
||||||
requires com.fasterxml.jackson.annotation;
|
|
||||||
}
|
|
@ -23,146 +23,63 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.db;
|
package org.apache.cassandra.db;
|
||||||
|
|
||||||
import static jakarta.json.Json.createObjectBuilder;
|
import java.lang.management.ManagementFactory;
|
||||||
import static java.lang.String.valueOf;
|
import java.net.ConnectException;
|
||||||
import static java.util.Arrays.asList;
|
import java.util.*;
|
||||||
import static java.util.stream.Collectors.toMap;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import jakarta.json.Json;
|
import javax.json.JsonArray;
|
||||||
import jakarta.json.JsonArray;
|
import javax.json.JsonObject;
|
||||||
import jakarta.json.JsonObject;
|
import javax.management.*;
|
||||||
import jakarta.json.JsonObjectBuilder;
|
|
||||||
import jakarta.json.JsonReader;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
|
||||||
import java.util.concurrent.Executors;
|
|
||||||
import java.util.concurrent.Future;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.OperationsException;
|
|
||||||
import javax.management.openmbean.CompositeData;
|
import javax.management.openmbean.CompositeData;
|
||||||
import javax.management.openmbean.CompositeDataSupport;
|
|
||||||
import javax.management.openmbean.CompositeType;
|
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.openmbean.OpenDataException;
|
||||||
import javax.management.openmbean.OpenType;
|
import javax.ws.rs.ProcessingException;
|
||||||
import javax.management.openmbean.SimpleType;
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
import javax.management.openmbean.TabularDataSupport;
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
import javax.management.openmbean.TabularType;
|
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.TableMetrics;
|
import org.apache.cassandra.metrics.ColumnFamilyMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.scylladb.jmx.metrics.MetricsMBean;
|
|
||||||
import com.scylladb.jmx.metrics.RegistrationChecker;
|
|
||||||
import com.scylladb.jmx.metrics.RegistrationMode;
|
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
|
||||||
public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStoreMBean {
|
public class ColumnFamilyStore implements ColumnFamilyStoreMBean {
|
||||||
private static final Logger logger = Logger.getLogger(ColumnFamilyStore.class.getName());
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
@SuppressWarnings("unused")
|
.getLogger(ColumnFamilyStore.class.getName());
|
||||||
private final String type;
|
private APIClient c = new APIClient();
|
||||||
private final String keyspace;
|
private String type;
|
||||||
private final String name;
|
private String keyspace;
|
||||||
private static final String[] COUNTER_NAMES = new String[]{"raw", "count", "error", "string"};
|
private String name;
|
||||||
private static final String[] COUNTER_DESCS = new String[]
|
private String mbeanName;
|
||||||
{ "partition key in raw hex bytes", // Table name and comments match Cassandra, we will use the partition key
|
private ObjectName nameObj;
|
||||||
"value of this partition for given sampler",
|
private static APIClient s_c = new APIClient();
|
||||||
"value is within the error bounds plus or minus of this",
|
static final int INTERVAL = 1000; // update every 1second
|
||||||
"the partition key turned into a human readable format" };
|
public ColumnFamilyMetrics metric;
|
||||||
private static final CompositeType COUNTER_COMPOSITE_TYPE;
|
|
||||||
private static final TabularType COUNTER_TYPE;
|
|
||||||
|
|
||||||
private static final String[] SAMPLER_NAMES = new String[]{"cardinality", "partitions"};
|
private static Map<String, ColumnFamilyStore> cf = new HashMap<String, ColumnFamilyStore>();
|
||||||
private static final String[] SAMPLER_DESCS = new String[]
|
private static Timer timer = new Timer("Column Family");
|
||||||
{ "cardinality of partitions",
|
|
||||||
"list of counter results" };
|
|
||||||
|
|
||||||
private static final String SAMPLING_RESULTS_NAME = "SAMPLING_RESULTS";
|
|
||||||
private static final CompositeType SAMPLING_RESULT;
|
|
||||||
|
|
||||||
public static final String SNAPSHOT_TRUNCATE_PREFIX = "truncated";
|
|
||||||
public static final String SNAPSHOT_DROP_PREFIX = "dropped";
|
|
||||||
private JsonObject tableSamplerResult = null;
|
|
||||||
|
|
||||||
private Future<JsonObject> futureTableSamperResult = null;
|
|
||||||
private ExecutorService service = null;
|
|
||||||
|
|
||||||
static
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
OpenType<?>[] counterTypes = new OpenType[] { SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING };
|
|
||||||
COUNTER_COMPOSITE_TYPE = new CompositeType(SAMPLING_RESULTS_NAME, SAMPLING_RESULTS_NAME, COUNTER_NAMES, COUNTER_DESCS, counterTypes);
|
|
||||||
COUNTER_TYPE = new TabularType(SAMPLING_RESULTS_NAME, SAMPLING_RESULTS_NAME, COUNTER_COMPOSITE_TYPE, COUNTER_NAMES);
|
|
||||||
|
|
||||||
OpenType<?>[] samplerTypes = new OpenType[] { SimpleType.LONG, COUNTER_TYPE };
|
|
||||||
SAMPLING_RESULT = new CompositeType(SAMPLING_RESULTS_NAME, SAMPLING_RESULTS_NAME, SAMPLER_NAMES, SAMPLER_DESCS, samplerTypes);
|
|
||||||
} catch (OpenDataException e)
|
|
||||||
{
|
|
||||||
throw Throwables.propagate(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected synchronized void startTableSampling(MultivaluedMap<String, String> queryParams) {
|
|
||||||
if (futureTableSamperResult != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
futureTableSamperResult = service.submit(() -> {
|
|
||||||
tableSamplerResult = client.getJsonObj("column_family/toppartitions/" + getCFName(), queryParams);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Wait until the action is completed
|
|
||||||
* It is safe to call this method multiple times
|
|
||||||
*/
|
|
||||||
public synchronized void waitUntilSamplingCompleted() {
|
|
||||||
try {
|
|
||||||
if (futureTableSamperResult != null) {
|
|
||||||
futureTableSamperResult.get();
|
|
||||||
futureTableSamperResult = null;
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
futureTableSamperResult = null;
|
|
||||||
throw new RuntimeException("Failed getting table statistics", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static final Set<String> TYPE_NAMES = new HashSet<>(asList("ColumnFamilies", "IndexTables", "Tables"));
|
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnFamilyStore(APIClient client, String type, String keyspace, String name) {
|
public static void register_mbeans() {
|
||||||
super(client,
|
TimerTask taskToExecute = new CheckRegistration();
|
||||||
new TableMetrics(keyspace, name, false /* hardcoded for now */));
|
timer.schedule(taskToExecute, 100, INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ColumnFamilyStore(String type, String keyspace, String name) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.keyspace = keyspace;
|
this.keyspace = keyspace;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
service = Executors.newSingleThreadExecutor();
|
mbeanName = getName(type, keyspace, name);
|
||||||
}
|
try {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
public ColumnFamilyStore(APIClient client, ObjectName name) {
|
nameObj = new ObjectName(mbeanName);
|
||||||
this(client, name.getKeyProperty("type"), name.getKeyProperty("keyspace"), name.getKeyProperty("columnfamily"));
|
mbs.registerMBean(this, nameObj);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
metric = new ColumnFamilyMetrics(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** true if this CFS contains secondary index data */
|
/** true if this CFS contains secondary index data */
|
||||||
@ -182,96 +99,444 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
return keyspace + ":" + name;
|
return keyspace + ":" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectName getName(String type, String keyspace, String name) throws MalformedObjectNameException {
|
private static String getName(String type, String keyspace, String name) {
|
||||||
return new ObjectName(
|
return "org.apache.cassandra.db:type=" + type + ",keyspace=" + keyspace
|
||||||
"org.apache.cassandra.db:type=" + type + ",keyspace=" + keyspace + ",columnfamily=" + name);
|
+ ",columnfamily=" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegistrationChecker createRegistrationChecker() {
|
public static boolean checkRegistration() {
|
||||||
return new RegistrationChecker() {
|
try {
|
||||||
@Override
|
JsonArray mbeans = s_c.getJsonArray("/column_family/");
|
||||||
protected void doCheck(APIClient client, JmxMBeanServer server, EnumSet<RegistrationMode> mode)
|
Set<String> all_cf = new HashSet<String>();
|
||||||
throws OperationsException {
|
for (int i = 0; i < mbeans.size(); i++) {
|
||||||
JsonArray mbeans = client.getJsonArray("/column_family/");
|
JsonObject mbean = mbeans.getJsonObject(i);
|
||||||
Set<ObjectName> all = new HashSet<ObjectName>();
|
String name = getName(mbean.getString("type"),
|
||||||
for (int i = 0; i < mbeans.size(); i++) {
|
mbean.getString("ks"), mbean.getString("cf"));
|
||||||
JsonObject mbean = mbeans.getJsonObject(i);
|
if (!cf.containsKey(name)) {
|
||||||
all.add(getName(mbean.getString("type"), mbean.getString("ks"), mbean.getString("cf")));
|
ColumnFamilyStore cfs = new ColumnFamilyStore(
|
||||||
}
|
mbean.getString("type"), mbean.getString("ks"),
|
||||||
checkRegistration(server, all, mode,
|
mbean.getString("cf"));
|
||||||
n -> TYPE_NAMES.contains(n.getKeyProperty("type")), n -> new ColumnFamilyStore(client, n));
|
cf.put(name, cfs);
|
||||||
}
|
}
|
||||||
};
|
all_cf.add(name);
|
||||||
}
|
}
|
||||||
|
// removing deleted column family
|
||||||
|
Iterator<String> i = cf.keySet().iterator();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
String n = i.next();
|
||||||
|
if (!all_cf.contains(n)) {
|
||||||
|
cf.get(n).unregister();
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Instead of waiting for the object to be removed by the mbean server,
|
||||||
|
* do it explicitly
|
||||||
|
*/
|
||||||
|
private void unregister() {
|
||||||
|
mbeanName = getName(type, keyspace, name);
|
||||||
|
try {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
mbs.unregisterMBean(nameObj);
|
||||||
|
metric = null;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class CheckRegistration extends TimerTask {
|
||||||
|
private int missed_response = 0;
|
||||||
|
// After MAX_RETRY retry we assume the API is not available
|
||||||
|
// and the jmx will shutdown
|
||||||
|
private static final int MAX_RETRY = 30;
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
if (checkRegistration()) {
|
||||||
|
missed_response = 0;
|
||||||
|
} else {
|
||||||
|
if (missed_response++ > MAX_RETRY) {
|
||||||
|
System.err.println("API is not available, JMX is shuting down");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignoring exceptions, will retry on the next interval
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the name of the column family
|
* @return the name of the column family
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public String getColumnFamilyName() {
|
public String getColumnFamilyName() {
|
||||||
log(" getColumnFamilyName()");
|
log(" getColumnFamilyName()");
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total amount of data stored in the memtable, including column
|
||||||
|
* related overhead.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableOnHeapSize
|
||||||
|
* @return The size in bytes.
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMemtableDataSize() {
|
||||||
|
log(" getMemtableDataSize()");
|
||||||
|
return c.getLongValue("/column_family/metrics/memtable_on_heap_size/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total number of columns present in the memtable.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableColumnsCount
|
||||||
|
* @return The number of columns.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMemtableColumnsCount() {
|
||||||
|
log(" getMemtableColumnsCount()");
|
||||||
|
return metric.memtableColumnsCount.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of times that a flush has resulted in the memtable
|
||||||
|
* being switched out.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableSwitchCount
|
||||||
|
* @return the number of memtable switches
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getMemtableSwitchCount() {
|
||||||
|
log(" getMemtableSwitchCount()");
|
||||||
|
return c.getIntValue("/column_family/metrics/memtable_switch_count/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentSSTablesPerRead
|
||||||
|
* @return a histogram of the number of sstable data files accessed per
|
||||||
|
* read: reading this property resets it
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentSSTablesPerReadHistogram() {
|
||||||
|
log(" getRecentSSTablesPerReadHistogram()");
|
||||||
|
return metric.getRecentSSTablesPerRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#sstablesPerReadHistogram
|
||||||
|
* @return a histogram of the number of sstable data files accessed per read
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getSSTablesPerReadHistogram() {
|
||||||
|
log(" getSSTablesPerReadHistogram()");
|
||||||
|
return metric.sstablesPerRead.getBuckets(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return the number of read operations on this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getReadCount() {
|
||||||
|
log(" getReadCount()");
|
||||||
|
return c.getIntValue("/column_family/metrics/read/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return total read latency (divide by getReadCount() for average)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalReadLatencyMicros() {
|
||||||
|
log(" getTotalReadLatencyMicros()");
|
||||||
|
return c.getLongValue("/column_family/metrics/read_latency/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getLifetimeReadLatencyHistogramMicros() {
|
||||||
|
log(" getLifetimeReadLatencyHistogramMicros()");
|
||||||
|
return metric.readLatency.totalLatencyHistogram.getBuckets(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentReadLatencyHistogramMicros() {
|
||||||
|
log(" getRecentReadLatencyHistogramMicros()");
|
||||||
|
return metric.readLatency.getRecentLatencyHistogram();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return average latency per read operation since the last call
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentReadLatencyMicros() {
|
||||||
|
log(" getRecentReadLatencyMicros()");
|
||||||
|
return metric.readLatency.getRecentLatency();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return the number of write operations on this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getWriteCount() {
|
||||||
|
log(" getWriteCount()");
|
||||||
|
return c.getLongValue("/column_family/metrics/write/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return total write latency (divide by getReadCount() for average)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalWriteLatencyMicros() {
|
||||||
|
log(" getTotalWriteLatencyMicros()");
|
||||||
|
return c.getLongValue("/column_family/metrics/write_latency/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getLifetimeWriteLatencyHistogramMicros() {
|
||||||
|
log(" getLifetimeWriteLatencyHistogramMicros()");
|
||||||
|
return metric.writeLatency.totalLatencyHistogram.getBuckets(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentWriteLatencyHistogramMicros() {
|
||||||
|
log(" getRecentWriteLatencyHistogramMicros()");
|
||||||
|
return metric.writeLatency.getRecentLatencyHistogram();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return average latency per write operation since the last call
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentWriteLatencyMicros() {
|
||||||
|
log(" getRecentWriteLatencyMicros()");
|
||||||
|
return metric.writeLatency.getRecentLatency();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#pendingFlushes
|
||||||
|
* @return the estimated number of tasks pending for this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getPendingTasks() {
|
||||||
|
log(" getPendingTasks()");
|
||||||
|
return c.getIntValue("/column_family/metrics/pending_flushes/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveSSTableCount
|
||||||
|
* @return the number of SSTables on disk for this CF
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getLiveSSTableCount() {
|
||||||
|
log(" getLiveSSTableCount()");
|
||||||
|
return c.getIntValue("/column_family/metrics/live_ss_table_count/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveDiskSpaceUsed
|
||||||
|
* @return disk space used by SSTables belonging to this CF
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getLiveDiskSpaceUsed() {
|
||||||
|
log(" getLiveDiskSpaceUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/live_disk_space_used/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#totalDiskSpaceUsed
|
||||||
|
* @return total disk space used by SSTables belonging to this CF, including
|
||||||
|
* obsolete ones waiting to be GC'd
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalDiskSpaceUsed() {
|
||||||
|
log(" getTotalDiskSpaceUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/total_disk_space_used/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* force a major compaction of this column family
|
* force a major compaction of this column family
|
||||||
*/
|
*/
|
||||||
public void forceMajorCompaction() throws ExecutionException, InterruptedException {
|
public void forceMajorCompaction()
|
||||||
|
throws ExecutionException, InterruptedException {
|
||||||
log(" forceMajorCompaction() throws ExecutionException, InterruptedException");
|
log(" forceMajorCompaction() throws ExecutionException, InterruptedException");
|
||||||
client.post("column_family/major_compaction/" + getCFName());
|
c.post("column_family/major_compaction/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#minRowSize
|
||||||
|
* @return the size of the smallest compacted row
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMinRowSize() {
|
||||||
|
log(" getMinRowSize()");
|
||||||
|
return c.getLongValue("/column_family/metrics/min_row_size/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#maxRowSize
|
||||||
|
* @return the size of the largest compacted row
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMaxRowSize() {
|
||||||
|
log(" getMaxRowSize()");
|
||||||
|
return c.getLongValue("/column_family/metrics/max_row_size/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#meanRowSize
|
||||||
|
* @return the average row size across all the sstables
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMeanRowSize() {
|
||||||
|
log(" getMeanRowSize()");
|
||||||
|
return c.getLongValue("/column_family/metrics/mean_row_size/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalsePositives
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterFalsePositives() {
|
||||||
|
log(" getBloomFilterFalsePositives()");
|
||||||
|
return c.getLongValue("/column_family/metrics/bloom_filter_false_positives/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalsePositives
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRecentBloomFilterFalsePositives() {
|
||||||
|
log(" getRecentBloomFilterFalsePositives()");
|
||||||
|
return c.getLongValue("/column_family/metrics/recent_bloom_filter_false_positives/" +getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalseRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getBloomFilterFalseRatio() {
|
||||||
|
log(" getBloomFilterFalseRatio()");
|
||||||
|
return c.getDoubleValue("/column_family/metrics/bloom_filter_false_ratio/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalseRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentBloomFilterFalseRatio() {
|
||||||
|
log(" getRecentBloomFilterFalseRatio()");
|
||||||
|
return c.getDoubleValue("/column_family/metrics/recent_bloom_filter_false_ratio/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterDiskSpaceUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterDiskSpaceUsed() {
|
||||||
|
log(" getBloomFilterDiskSpaceUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/bloom_filter_disk_space_used/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterOffHeapMemoryUsed() {
|
||||||
|
log(" getBloomFilterOffHeapMemoryUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/bloom_filter_off_heap_memory_used/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#indexSummaryOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getIndexSummaryOffHeapMemoryUsed() {
|
||||||
|
log(" getIndexSummaryOffHeapMemoryUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/index_summary_off_heap_memory_used/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionMetadataOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompressionMetadataOffHeapMemoryUsed() {
|
||||||
|
log(" getCompressionMetadataOffHeapMemoryUsed()");
|
||||||
|
return c.getLongValue("/column_family/metrics/compression_metadata_off_heap_memory_used/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the minimum number of sstables in queue before compaction kicks off
|
* Gets the minimum number of sstables in queue before compaction kicks off
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getMinimumCompactionThreshold() {
|
public int getMinimumCompactionThreshold() {
|
||||||
log(" getMinimumCompactionThreshold()");
|
log(" getMinimumCompactionThreshold()");
|
||||||
return client.getIntValue("column_family/minimum_compaction/" + getCFName());
|
return c.getIntValue("column_family/minimum_compaction/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the minimum number of sstables in queue before compaction kicks off
|
* Sets the minimum number of sstables in queue before compaction kicks off
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setMinimumCompactionThreshold(int threshold) {
|
public void setMinimumCompactionThreshold(int threshold) {
|
||||||
log(" setMinimumCompactionThreshold(int threshold)");
|
log(" setMinimumCompactionThreshold(int threshold)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("value", Integer.toString(threshold));
|
queryParams.add("value", Integer.toString(threshold));
|
||||||
client.post("column_family/minimum_compaction/" + getCFName(), queryParams);
|
c.post("column_family/minimum_compaction/" + getCFName(), queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the maximum number of sstables in queue before compaction kicks off
|
* Gets the maximum number of sstables in queue before compaction kicks off
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getMaximumCompactionThreshold() {
|
public int getMaximumCompactionThreshold() {
|
||||||
log(" getMaximumCompactionThreshold()");
|
log(" getMaximumCompactionThreshold()");
|
||||||
return client.getIntValue("column_family/maximum_compaction/" + getCFName());
|
return c.getIntValue("column_family/maximum_compaction/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum and maximum number of SSTables in queue before
|
* Sets the maximum and maximum number of SSTables in queue before
|
||||||
* compaction kicks off
|
* compaction kicks off
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setCompactionThresholds(int minThreshold, int maxThreshold) {
|
public void setCompactionThresholds(int minThreshold, int maxThreshold) {
|
||||||
log(" setCompactionThresholds(int minThreshold, int maxThreshold)");
|
log(" setCompactionThresholds(int minThreshold, int maxThreshold)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("minimum", Integer.toString(minThreshold));
|
queryParams.add("minimum", Integer.toString(minThreshold));
|
||||||
queryParams.add("maximum", Integer.toString(maxThreshold));
|
queryParams.add("maximum", Integer.toString(maxThreshold));
|
||||||
client.post("column_family/compaction" + getCFName(), queryParams);
|
c.post("column_family/compaction" + getCFName(), queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum number of sstables in queue before compaction kicks off
|
* Sets the maximum number of sstables in queue before compaction kicks off
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setMaximumCompactionThreshold(int threshold) {
|
public void setMaximumCompactionThreshold(int threshold) {
|
||||||
log(" setMaximumCompactionThreshold(int threshold)");
|
log(" setMaximumCompactionThreshold(int threshold)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("value", Integer.toString(threshold));
|
queryParams.add("value", Integer.toString(threshold));
|
||||||
client.post("column_family/maximum_compaction/" + getCFName(), queryParams);
|
c.post("column_family/maximum_compaction/" + getCFName(), queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,7 +549,7 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
log(" setCompactionStrategyClass(String className)");
|
log(" setCompactionStrategyClass(String className)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("class_name", className);
|
queryParams.add("class_name", className);
|
||||||
client.post("column_family/compaction_strategy/" + getCFName(), queryParams);
|
c.post("column_family/compaction_strategy/" + getCFName(), queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,16 +557,17 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
*/
|
*/
|
||||||
public String getCompactionStrategyClass() {
|
public String getCompactionStrategyClass() {
|
||||||
log(" getCompactionStrategyClass()");
|
log(" getCompactionStrategyClass()");
|
||||||
return client.getStringValue("column_family/compaction_strategy/" + getCFName());
|
return c.getStringValue(
|
||||||
|
"column_family/compaction_strategy/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the compression parameters
|
* Get the compression parameters
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, String> getCompressionParameters() {
|
public Map<String, String> getCompressionParameters() {
|
||||||
log(" getCompressionParameters()");
|
log(" getCompressionParameters()");
|
||||||
return client.getMapStrValue("column_family/compression_parameters/" + getCFName());
|
return c.getMapStrValue(
|
||||||
|
"column_family/compression_parameters/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -310,49 +576,73 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
* @param opts
|
* @param opts
|
||||||
* map of string names to values
|
* map of string names to values
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setCompressionParameters(Map<String, String> opts) {
|
public void setCompressionParameters(Map<String, String> opts) {
|
||||||
log(" setCompressionParameters(Map<String,String> opts)");
|
log(" setCompressionParameters(Map<String,String> opts)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("opts", APIClient.mapToString(opts));
|
queryParams.add("opts", APIClient.mapToString(opts));
|
||||||
client.post("column_family/compression_parameters/" + getCFName(), queryParams);
|
c.post("column_family/compression_parameters/" + getCFName(),
|
||||||
|
queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new crc check chance
|
* Set new crc check chance
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setCrcCheckChance(double crcCheckChance) {
|
public void setCrcCheckChance(double crcCheckChance) {
|
||||||
log(" setCrcCheckChance(double crcCheckChance)");
|
log(" setCrcCheckChance(double crcCheckChance)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("check_chance", Double.toString(crcCheckChance));
|
queryParams.add("check_chance", Double.toString(crcCheckChance));
|
||||||
client.post("column_family/crc_check_chance/" + getCFName(), queryParams);
|
c.post("column_family/crc_check_chance/" + getCFName(), queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAutoCompactionDisabled() {
|
public boolean isAutoCompactionDisabled() {
|
||||||
log(" isAutoCompactionDisabled()");
|
log(" isAutoCompactionDisabled()");
|
||||||
return !client.getBooleanValue("column_family/autocompaction/" + getCFName());
|
return c.getBooleanValue("column_family/autocompaction/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Number of tombstoned cells retreived during the last slicequery */
|
/** Number of tombstoned cells retreived during the last slicequery */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getTombstonesPerSlice() {
|
public double getTombstonesPerSlice() {
|
||||||
log(" getTombstonesPerSlice()");
|
log(" getTombstonesPerSlice()");
|
||||||
return client.getDoubleValue("");
|
return c.getDoubleValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Number of live cells retreived during the last slicequery */
|
/** Number of live cells retreived during the last slicequery */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public double getLiveCellsPerSlice() {
|
public double getLiveCellsPerSlice() {
|
||||||
log(" getLiveCellsPerSlice()");
|
log(" getLiveCellsPerSlice()");
|
||||||
return client.getDoubleValue("");
|
return c.getDoubleValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long estimateKeys() {
|
public long estimateKeys() {
|
||||||
log(" estimateKeys()");
|
log(" estimateKeys()");
|
||||||
return client.getLongValue("column_family/estimate_keys/" + getCFName());
|
return c.getLongValue("column_family/estimate_keys/" + getCFName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedRowSizeHistogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getEstimatedRowSizeHistogram() {
|
||||||
|
log(" getEstimatedRowSizeHistogram()");
|
||||||
|
return metric.estimatedRowSizeHistogram.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedColumnCountHistogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getEstimatedColumnCountHistogram() {
|
||||||
|
log(" getEstimatedColumnCountHistogram()");
|
||||||
|
return metric.estimatedColumnCountHistogram.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getCompressionRatio() {
|
||||||
|
log(" getCompressionRatio()");
|
||||||
|
return c.getDoubleValue("/column_family/metrics/compression_ratio/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -360,10 +650,9 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
*
|
*
|
||||||
* @return list of the index names
|
* @return list of the index names
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public List<String> getBuiltIndexes() {
|
public List<String> getBuiltIndexes() {
|
||||||
log(" getBuiltIndexes()");
|
log(" getBuiltIndexes()");
|
||||||
return client.getListStrValue("column_family/built_indexes/" + getCFName());
|
return c.getListStrValue("column_family/built_indexes/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -372,49 +661,30 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
* @param key
|
* @param key
|
||||||
* @return list of filenames containing the key
|
* @return list of filenames containing the key
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public List<String> getSSTablesForKey(String key) {
|
public List<String> getSSTablesForKey(String key) {
|
||||||
log(" getSSTablesForKey(String key)");
|
log(" getSSTablesForKey(String key)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("key", key);
|
queryParams.add("key", key);
|
||||||
return client.getListStrValue("column_family/sstables/by_key/" + getCFName(), queryParams);
|
return c.getListStrValue("column_family/sstables/by_key/" + getCFName(),
|
||||||
|
queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a list of filenames that contain the given key on this node
|
|
||||||
* @param key
|
|
||||||
* @param hexFormat if key is in hex string format
|
|
||||||
* @return list of filenames containing the key
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public List<String> getSSTablesForKey(String key, boolean hexFormat)
|
|
||||||
{
|
|
||||||
log(" getSSTablesForKey(String key)");
|
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
|
||||||
queryParams.add("key", key);
|
|
||||||
if (hexFormat) {
|
|
||||||
queryParams.add("format", "hex");
|
|
||||||
}
|
|
||||||
return client.getListStrValue("column_family/sstables/by_key/" + getCFName(), queryParams);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Scan through Keyspace/ColumnFamily's data directory determine which
|
* Scan through Keyspace/ColumnFamily's data directory determine which
|
||||||
* SSTables should be loaded and load them
|
* SSTables should be loaded and load them
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void loadNewSSTables() {
|
public void loadNewSSTables() {
|
||||||
log(" loadNewSSTables()");
|
log(" loadNewSSTables()");
|
||||||
client.post("column_family/sstable/" + getCFName());
|
c.post("column_family/sstable/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the number of SSTables in L0. Always return 0 if Leveled
|
* @return the number of SSTables in L0. Always return 0 if Leveled
|
||||||
* compaction is not enabled.
|
* compaction is not enabled.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getUnleveledSSTables() {
|
public int getUnleveledSSTables() {
|
||||||
log(" getUnleveledSSTables()");
|
log(" getUnleveledSSTables()");
|
||||||
return client.getIntValue("column_family/sstables/unleveled/" + getCFName());
|
return c.getIntValue("column_family/sstables/unleveled/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -422,10 +692,10 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
* used. array index corresponds to level(int[0] is for level 0,
|
* used. array index corresponds to level(int[0] is for level 0,
|
||||||
* ...).
|
* ...).
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int[] getSSTableCountPerLevel() {
|
public int[] getSSTableCountPerLevel() {
|
||||||
log(" getSSTableCountPerLevel()");
|
log(" getSSTableCountPerLevel()");
|
||||||
int[] res = client.getIntArrValue("column_family/sstables/per_level/" + getCFName());
|
int[] res = c.getIntArrValue(
|
||||||
|
"column_family/sstables/per_level/" + getCFName());
|
||||||
if (res.length == 0) {
|
if (res.length == 0) {
|
||||||
// no sstable count
|
// no sstable count
|
||||||
// should return null
|
// should return null
|
||||||
@ -440,20 +710,18 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
*
|
*
|
||||||
* @return ratio
|
* @return ratio
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public double getDroppableTombstoneRatio() {
|
public double getDroppableTombstoneRatio() {
|
||||||
log(" getDroppableTombstoneRatio()");
|
log(" getDroppableTombstoneRatio()");
|
||||||
return client.getDoubleValue("column_family/droppable_ratio/" + getCFName());
|
return c.getDoubleValue("column_family/droppable_ratio/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the size of SSTables in "snapshots" subdirectory which aren't
|
* @return the size of SSTables in "snapshots" subdirectory which aren't
|
||||||
* live anymore
|
* live anymore
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public long trueSnapshotsSize() {
|
public long trueSnapshotsSize() {
|
||||||
log(" trueSnapshotsSize()");
|
log(" trueSnapshotsSize()");
|
||||||
return client.getLongValue("column_family/metrics/snapshots_size/" + getCFName());
|
return c.getLongValue("column_family/metrics/snapshots_size/" + getCFName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getKeyspace() {
|
public String getKeyspace() {
|
||||||
@ -461,104 +729,48 @@ public class ColumnFamilyStore extends MetricsMBean implements ColumnFamilyStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTableName() {
|
public long getRangeCount() {
|
||||||
log(" getTableName()");
|
log("getRangeCount()");
|
||||||
return name;
|
return metric.rangeLatency.latency.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forceMajorCompaction(boolean splitOutput) throws ExecutionException, InterruptedException {
|
public long getTotalRangeLatencyMicros() {
|
||||||
log(" forceMajorCompaction(boolean) throws ExecutionException, InterruptedException");
|
log("getTotalRangeLatencyMicros()");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
return metric.rangeLatency.totalLatency.count();
|
||||||
queryParams.putSingle("value", valueOf(splitOutput));
|
|
||||||
client.post("column_family/major_compaction/" + getCFName(), queryParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompactionParametersJson(String options) {
|
public long[] getLifetimeRangeLatencyHistogramMicros() {
|
||||||
log(" setCompactionParametersJson");
|
log("getLifetimeRangeLatencyHistogramMicros()");
|
||||||
JsonReader reader = Json.createReaderFactory(null).createReader(new StringReader(options));
|
return metric.rangeLatency.totalLatencyHistogram.getBuckets(false);
|
||||||
setCompactionParameters(
|
|
||||||
reader.readObject().entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.toString())));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getCompactionParametersJson() {
|
public long[] getRecentRangeLatencyHistogramMicros() {
|
||||||
log(" getCompactionParametersJson");
|
log("getRecentRangeLatencyHistogramMicros()");
|
||||||
JsonObjectBuilder b = createObjectBuilder();
|
return metric.rangeLatency.getRecentLatencyHistogram();
|
||||||
getCompactionParameters().forEach(b::add);
|
|
||||||
return b.build().toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCompactionParameters(Map<String, String> options) {
|
public double getRecentRangeLatencyMicros() {
|
||||||
for (Map.Entry<String, String> e : options.entrySet()) {
|
log("getRecentRangeLatencyMicros()");
|
||||||
// See below
|
return metric.rangeLatency.getRecentLatency();
|
||||||
if ("class".equals(e.getKey())) {
|
|
||||||
setCompactionStrategyClass(e.getValue());
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(e.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getCompactionParameters() {
|
public void beginLocalSampling(String sampler, int capacity) {
|
||||||
// We only currently support class. Here could have been a call that can
|
|
||||||
// be expanded only on the server side, but that raises controversy.
|
|
||||||
// Lets add some technical debt instead.
|
|
||||||
return Collections.singletonMap("class", getCompactionStrategyClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCompactionDiskSpaceCheckEnabled() {
|
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" isCompactionDiskSpaceCheckEnabled()");
|
log("beginLocalSampling()");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void compactionDiskSpaceCheck(boolean enable) {
|
public CompositeData finishLocalSampling(String sampler, int count)
|
||||||
|
throws OpenDataException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" compactionDiskSpaceCheck()");
|
log("finishLocalSampling()");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void beginLocalSampling(String sampler_base, int capacity) {
|
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
|
||||||
queryParams.add("capacity", Integer.toString(capacity));
|
|
||||||
if (sampler_base.contains(":")) {
|
|
||||||
String[] parts = sampler_base.split(":");
|
|
||||||
queryParams.add("duration", parts[1]);
|
|
||||||
} else {
|
|
||||||
queryParams.add("duration", "10000");
|
|
||||||
}
|
|
||||||
startTableSampling(queryParams);
|
|
||||||
log(" beginLocalSampling()");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompositeData finishLocalSampling(String samplerType, int count) throws OpenDataException {
|
|
||||||
log(" finishLocalSampling()");
|
|
||||||
|
|
||||||
waitUntilSamplingCompleted();
|
|
||||||
|
|
||||||
TabularDataSupport result = new TabularDataSupport(COUNTER_TYPE);
|
|
||||||
|
|
||||||
JsonArray counters = tableSamplerResult.getJsonArray((samplerType.equalsIgnoreCase("reads")) ? "read" : "write");
|
|
||||||
long cardinality = tableSamplerResult.getJsonNumber((samplerType.equalsIgnoreCase("reads")) ? "read_cardinality" : "write_cardinality").longValue();
|
|
||||||
long size = 0;
|
|
||||||
if (counters != null) {
|
|
||||||
size = (count > counters.size()) ? counters.size() : count;
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
JsonObject counter = counters.getJsonObject(i);
|
|
||||||
result.put(new CompositeDataSupport(COUNTER_COMPOSITE_TYPE, COUNTER_NAMES,
|
|
||||||
new Object[] { counter.getString("partition"), // raw
|
|
||||||
counter.getJsonNumber("count").longValue(), // count
|
|
||||||
counter.getJsonNumber("error").longValue(), // error
|
|
||||||
counter.getString("partition") })); // string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new CompositeDataSupport(SAMPLING_RESULT, SAMPLER_NAMES, new Object[] { cardinality, result });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.db;
|
package org.apache.cassandra.db;
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
@ -28,28 +27,263 @@ import javax.management.openmbean.OpenDataException;
|
|||||||
/**
|
/**
|
||||||
* The MBean interface for ColumnFamilyStore
|
* The MBean interface for ColumnFamilyStore
|
||||||
*/
|
*/
|
||||||
public interface ColumnFamilyStoreMBean {
|
public interface ColumnFamilyStoreMBean
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* @return the name of the column family
|
* @return the name of the column family
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public String getColumnFamilyName();
|
public String getColumnFamilyName();
|
||||||
|
|
||||||
public String getTableName();
|
/**
|
||||||
|
* Returns the total amount of data stored in the memtable, including
|
||||||
|
* column related overhead.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableOnHeapSize
|
||||||
|
* @return The size in bytes.
|
||||||
|
* @deprecated
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMemtableDataSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the total number of columns present in the memtable.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableColumnsCount
|
||||||
|
* @return The number of columns.
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMemtableColumnsCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of times that a flush has resulted in the
|
||||||
|
* memtable being switched out.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#memtableSwitchCount
|
||||||
|
* @return the number of memtable switches
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getMemtableSwitchCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentSSTablesPerRead
|
||||||
|
* @return a histogram of the number of sstable data files accessed per read: reading this property resets it
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentSSTablesPerReadHistogram();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#sstablesPerReadHistogram
|
||||||
|
* @return a histogram of the number of sstable data files accessed per read
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getSSTablesPerReadHistogram();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return the number of read operations on this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getReadCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return total read latency (divide by getReadCount() for average)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalReadLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getLifetimeReadLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentReadLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#readLatency
|
||||||
|
* @return average latency per read operation since the last call
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentReadLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return the number of write operations on this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getWriteCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return total write latency (divide by getReadCount() for average)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalWriteLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getLifetimeWriteLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentWriteLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#writeLatency
|
||||||
|
* @return average latency per write operation since the last call
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentWriteLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#rangeLatency
|
||||||
|
* @return the number of range slice operations on this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRangeCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#rangeLatency
|
||||||
|
* @return total range slice latency (divide by getRangeCount() for average)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalRangeLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#rangeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getLifetimeRangeLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#rangeLatency
|
||||||
|
* @return an array representing the latency histogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getRecentRangeLatencyHistogramMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#rangeLatency
|
||||||
|
* @return average latency per range slice operation since the last call
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentRangeLatencyMicros();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#pendingFlushes
|
||||||
|
* @return the estimated number of tasks pending for this column family
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getPendingTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveSSTableCount
|
||||||
|
* @return the number of SSTables on disk for this CF
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getLiveSSTableCount();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#liveDiskSpaceUsed
|
||||||
|
* @return disk space used by SSTables belonging to this CF
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getLiveDiskSpaceUsed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#totalDiskSpaceUsed
|
||||||
|
* @return total disk space used by SSTables belonging to this CF, including obsolete ones waiting to be GC'd
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalDiskSpaceUsed();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* force a major compaction of this column family
|
* force a major compaction of this column family
|
||||||
*
|
|
||||||
* @param splitOutput
|
|
||||||
* true if the output of the major compaction should be split in
|
|
||||||
* several sstables
|
|
||||||
*/
|
*/
|
||||||
public void forceMajorCompaction(boolean splitOutput) throws ExecutionException, InterruptedException;
|
public void forceMajorCompaction() throws ExecutionException, InterruptedException;
|
||||||
|
|
||||||
// NOT even default-throw implementing
|
/**
|
||||||
// forceCompactionForTokenRange
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#minRowSize
|
||||||
// as this is clearly a misplaced method that should not be in the mbean interface
|
* @return the size of the smallest compacted row
|
||||||
// (uses internal cassandra types)
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMinRowSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#maxRowSize
|
||||||
|
* @return the size of the largest compacted row
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMaxRowSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#meanRowSize
|
||||||
|
* @return the average row size across all the sstables
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getMeanRowSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalsePositives
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterFalsePositives();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalsePositives
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRecentBloomFilterFalsePositives();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterFalseRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getBloomFilterFalseRatio();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#recentBloomFilterFalseRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentBloomFilterFalseRatio();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterDiskSpaceUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterDiskSpaceUsed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#bloomFilterOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getBloomFilterOffHeapMemoryUsed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#indexSummaryOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getIndexSummaryOffHeapMemoryUsed();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionMetadataOffHeapMemoryUsed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompressionMetadataOffHeapMemoryUsed();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the minimum number of sstables in queue before compaction kicks off
|
* Gets the minimum number of sstables in queue before compaction kicks off
|
||||||
@ -67,8 +301,7 @@ public interface ColumnFamilyStoreMBean {
|
|||||||
public int getMaximumCompactionThreshold();
|
public int getMaximumCompactionThreshold();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the maximum and maximum number of SSTables in queue before
|
* Sets the maximum and maximum number of SSTables in queue before compaction kicks off
|
||||||
* compaction kicks off
|
|
||||||
*/
|
*/
|
||||||
public void setCompactionThresholds(int minThreshold, int maxThreshold);
|
public void setCompactionThresholds(int minThreshold, int maxThreshold);
|
||||||
|
|
||||||
@ -78,44 +311,26 @@ public interface ColumnFamilyStoreMBean {
|
|||||||
public void setMaximumCompactionThreshold(int threshold);
|
public void setMaximumCompactionThreshold(int threshold);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the compaction parameters locally for this node
|
* Sets the compaction strategy by class name
|
||||||
*
|
* @param className the name of the compaction strategy class
|
||||||
* Note that this will be set until an ALTER with compaction = {..} is
|
|
||||||
* executed or the node is restarted
|
|
||||||
*
|
|
||||||
* @param options
|
|
||||||
* compaction options with the same syntax as when doing ALTER
|
|
||||||
* ... WITH compaction = {..}
|
|
||||||
*/
|
*/
|
||||||
public void setCompactionParametersJson(String options);
|
public void setCompactionStrategyClass(String className);
|
||||||
|
|
||||||
public String getCompactionParametersJson();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the compaction parameters locally for this node
|
* Gets the compaction strategy class name
|
||||||
*
|
|
||||||
* Note that this will be set until an ALTER with compaction = {..} is
|
|
||||||
* executed or the node is restarted
|
|
||||||
*
|
|
||||||
* @param options
|
|
||||||
* compaction options map
|
|
||||||
*/
|
*/
|
||||||
public void setCompactionParameters(Map<String, String> options);
|
public String getCompactionStrategyClass();
|
||||||
|
|
||||||
public Map<String, String> getCompactionParameters();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the compression parameters
|
* Get the compression parameters
|
||||||
*/
|
*/
|
||||||
public Map<String, String> getCompressionParameters();
|
public Map<String,String> getCompressionParameters();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the compression parameters
|
* Set the compression parameters
|
||||||
*
|
* @param opts map of string names to values
|
||||||
* @param opts
|
|
||||||
* map of string names to values
|
|
||||||
*/
|
*/
|
||||||
public void setCompressionParameters(Map<String, String> opts);
|
public void setCompressionParameters(Map<String,String> opts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new crc check chance
|
* Set new crc check chance
|
||||||
@ -124,92 +339,81 @@ public interface ColumnFamilyStoreMBean {
|
|||||||
|
|
||||||
public boolean isAutoCompactionDisabled();
|
public boolean isAutoCompactionDisabled();
|
||||||
|
|
||||||
|
/** Number of tombstoned cells retreived during the last slicequery */
|
||||||
|
@Deprecated
|
||||||
|
public double getTombstonesPerSlice();
|
||||||
|
|
||||||
|
/** Number of live cells retreived during the last slicequery */
|
||||||
|
@Deprecated
|
||||||
|
public double getLiveCellsPerSlice();
|
||||||
|
|
||||||
public long estimateKeys();
|
public long estimateKeys();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedRowSizeHistogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getEstimatedRowSizeHistogram();
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#estimatedColumnCountHistogram
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long[] getEstimatedColumnCountHistogram();
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.ColumnFamilyMetrics#compressionRatio
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getCompressionRatio();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of the names of the built column indexes for current store
|
* Returns a list of the names of the built column indexes for current store
|
||||||
*
|
|
||||||
* @return list of the index names
|
* @return list of the index names
|
||||||
*/
|
*/
|
||||||
public List<String> getBuiltIndexes();
|
public List<String> getBuiltIndexes();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of filenames that contain the given key on this node
|
* Returns a list of filenames that contain the given key on this node
|
||||||
*
|
|
||||||
* @param key
|
* @param key
|
||||||
* @return list of filenames containing the key
|
* @return list of filenames containing the key
|
||||||
*/
|
*/
|
||||||
public List<String> getSSTablesForKey(String key);
|
public List<String> getSSTablesForKey(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of filenames that contain the given key on this node
|
* Scan through Keyspace/ColumnFamily's data directory
|
||||||
* @param key
|
* determine which SSTables should be loaded and load them
|
||||||
* @param hexFormat if key is in hex string format
|
|
||||||
* @return list of filenames containing the key
|
|
||||||
*/
|
|
||||||
public List<String> getSSTablesForKey(String key, boolean hexFormat);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scan through Keyspace/ColumnFamily's data directory determine which
|
|
||||||
* SSTables should be loaded and load them
|
|
||||||
*/
|
*/
|
||||||
public void loadNewSSTables();
|
public void loadNewSSTables();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the number of SSTables in L0. Always return 0 if Leveled
|
* @return the number of SSTables in L0. Always return 0 if Leveled compaction is not enabled.
|
||||||
* compaction is not enabled.
|
|
||||||
*/
|
*/
|
||||||
public int getUnleveledSSTables();
|
public int getUnleveledSSTables();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return sstable count for each level. null unless leveled compaction is
|
* @return sstable count for each level. null unless leveled compaction is used.
|
||||||
* used. array index corresponds to level(int[0] is for level 0,
|
* array index corresponds to level(int[0] is for level 0, ...).
|
||||||
* ...).
|
|
||||||
*/
|
*/
|
||||||
public int[] getSSTableCountPerLevel();
|
public int[] getSSTableCountPerLevel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return sstable fanout size for level compaction strategy.
|
* Get the ratio of droppable tombstones to real columns (and non-droppable tombstones)
|
||||||
*/
|
|
||||||
default public int getLevelFanoutSize() {
|
|
||||||
// TODO: implement for real. This is sort of default.
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the ratio of droppable tombstones to real columns (and non-droppable
|
|
||||||
* tombstones)
|
|
||||||
*
|
|
||||||
* @return ratio
|
* @return ratio
|
||||||
*/
|
*/
|
||||||
public double getDroppableTombstoneRatio();
|
public double getDroppableTombstoneRatio();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the size of SSTables in "snapshots" subdirectory which aren't
|
* @return the size of SSTables in "snapshots" subdirectory which aren't live anymore
|
||||||
* live anymore
|
|
||||||
*/
|
*/
|
||||||
public long trueSnapshotsSize();
|
public long trueSnapshotsSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* begin sampling for a specific sampler with a given capacity. The
|
* begin sampling for a specific sampler with a given capacity. The cardinality may
|
||||||
* cardinality may be larger than the capacity, but depending on the use
|
* be larger than the capacity, but depending on the use case it may affect its accuracy
|
||||||
* case it may affect its accuracy
|
|
||||||
*/
|
*/
|
||||||
public void beginLocalSampling(String sampler, int capacity);
|
public void beginLocalSampling(String sampler, int capacity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return top <i>count</i> items for the sampler since beginLocalSampling
|
* @return top <i>count</i> items for the sampler since beginLocalSampling was called
|
||||||
* was called
|
|
||||||
*/
|
*/
|
||||||
public CompositeData finishLocalSampling(String sampler, int count) throws OpenDataException;
|
public CompositeData finishLocalSampling(String sampler, int count) throws OpenDataException;
|
||||||
|
|
||||||
/*
|
|
||||||
* Is Compaction space check enabled
|
|
||||||
*/
|
|
||||||
public boolean isCompactionDiskSpaceCheckEnabled();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Enable/Disable compaction space check
|
|
||||||
*/
|
|
||||||
public void compactionDiskSpaceCheck(boolean enable);
|
|
||||||
}
|
}
|
||||||
|
@ -22,39 +22,85 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.db.commitlog;
|
package org.apache.cassandra.db.commitlog;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import javax.management.MBeanServer;
|
||||||
import java.util.Map;
|
import javax.management.ObjectName;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.CommitLogMetrics;
|
import org.apache.cassandra.metrics.CommitLogMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.MetricsMBean;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Commit Log tracks every write operation into the system. The aim of the commit log is to be able to
|
* Commit Log tracks every write operation into the system. The aim of the commit log is to be able to
|
||||||
* successfully recover data that was not stored to disk via the Memtable.
|
* successfully recover data that was not stored to disk via the Memtable.
|
||||||
*/
|
*/
|
||||||
public class CommitLog extends MetricsMBean implements CommitLogMBean {
|
public class CommitLog implements CommitLogMBean {
|
||||||
|
|
||||||
|
CommitLogMetrics metrics = new CommitLogMetrics();
|
||||||
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
.getLogger(CommitLog.class.getName());
|
.getLogger(CommitLog.class.getName());
|
||||||
|
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommitLog(APIClient client) {
|
private static final CommitLog instance = new CommitLog();
|
||||||
super("org.apache.cassandra.db:type=Commitlog", client, new CommitLogMetrics());
|
|
||||||
|
public static CommitLog getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CommitLog() {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
try {
|
||||||
|
mbs.registerMBean(this,
|
||||||
|
new ObjectName("org.apache.cassandra.db:type=Commitlog"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of completed tasks
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#completedTasks
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompletedTasks() {
|
||||||
|
log(" getCompletedTasks()");
|
||||||
|
return metrics.completedTasks.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of tasks waiting to be executed
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#pendingTasks
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getPendingTasks() {
|
||||||
|
log(" getPendingTasks()");
|
||||||
|
return metrics.pendingTasks.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current size used by all the commitlog segments.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#totalCommitLogSize
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalCommitlogSize() {
|
||||||
|
log(" getTotalCommitlogSize()");
|
||||||
|
return metrics.totalCommitLogSize.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recover a single file.
|
* Recover a single file.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void recover(String path) throws IOException {
|
public void recover(String path) throws IOException {
|
||||||
log(" recover(String path) throws IOException");
|
log(" recover(String path) throws IOException");
|
||||||
}
|
}
|
||||||
@ -63,10 +109,9 @@ public class CommitLog extends MetricsMBean implements CommitLogMBean {
|
|||||||
* @return file names (not full paths) of active commit log segments
|
* @return file names (not full paths) of active commit log segments
|
||||||
* (segments containing unflushed data)
|
* (segments containing unflushed data)
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public List<String> getActiveSegmentNames() {
|
public List<String> getActiveSegmentNames() {
|
||||||
log(" getActiveSegmentNames()");
|
log(" getActiveSegmentNames()");
|
||||||
List<String> lst = client.getListStrValue("/commitlog/segments/active");
|
List<String> lst = c.getListStrValue("/commitlog/segments/active");
|
||||||
Set<String> set = new HashSet<String>();
|
Set<String> set = new HashSet<String>();
|
||||||
for (String l : lst) {
|
for (String l : lst) {
|
||||||
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
||||||
@ -79,10 +124,9 @@ public class CommitLog extends MetricsMBean implements CommitLogMBean {
|
|||||||
* @return Files which are pending for archival attempt. Does NOT include
|
* @return Files which are pending for archival attempt. Does NOT include
|
||||||
* failed archive attempts.
|
* failed archive attempts.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public List<String> getArchivingSegmentNames() {
|
public List<String> getArchivingSegmentNames() {
|
||||||
log(" getArchivingSegmentNames()");
|
log(" getArchivingSegmentNames()");
|
||||||
List<String> lst = client.getListStrValue("/commitlog/segments/archiving");
|
List<String> lst = c.getListStrValue("/commitlog/segments/archiving");
|
||||||
Set<String> set = new HashSet<String>();
|
Set<String> set = new HashSet<String>();
|
||||||
for (String l : lst) {
|
for (String l : lst) {
|
||||||
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
String name = l.substring(l.lastIndexOf("/") + 1, l.length());
|
||||||
@ -95,54 +139,35 @@ public class CommitLog extends MetricsMBean implements CommitLogMBean {
|
|||||||
public String getArchiveCommand() {
|
public String getArchiveCommand() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" getArchiveCommand()");
|
log(" getArchiveCommand()");
|
||||||
return client.getStringValue("");
|
return c.getStringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRestoreCommand() {
|
public String getRestoreCommand() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" getRestoreCommand()");
|
log(" getRestoreCommand()");
|
||||||
return client.getStringValue("");
|
return c.getStringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRestoreDirectories() {
|
public String getRestoreDirectories() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" getRestoreDirectories()");
|
log(" getRestoreDirectories()");
|
||||||
return client.getStringValue("");
|
return c.getStringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getRestorePointInTime() {
|
public long getRestorePointInTime() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" getRestorePointInTime()");
|
log(" getRestorePointInTime()");
|
||||||
return client.getLongValue("");
|
return c.getLongValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getRestorePrecision() {
|
public String getRestorePrecision() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
log(" getRestorePrecision()");
|
log(" getRestorePrecision()");
|
||||||
return client.getStringValue("");
|
return c.getStringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getActiveContentSize() {
|
|
||||||
// scylla does not compress commit log, so this is equivalent
|
|
||||||
return getActiveOnDiskSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getActiveOnDiskSize() {
|
|
||||||
return client.getLongValue("/commitlog/metrics/total_commit_log_size");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Double> getActiveSegmentCompressionRatios() {
|
|
||||||
HashMap<String, Double> res = new HashMap<>();
|
|
||||||
for (String name : getActiveSegmentNames()) {
|
|
||||||
res.put(name, 1.0);
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,9 +19,32 @@ package org.apache.cassandra.db.commitlog;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface CommitLogMBean {
|
public interface CommitLogMBean {
|
||||||
|
/**
|
||||||
|
* Get the number of completed tasks
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#completedTasks
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompletedTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of tasks waiting to be executed
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#pendingTasks
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getPendingTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current size used by all the commitlog segments.
|
||||||
|
*
|
||||||
|
* @see org.apache.cassandra.metrics.CommitLogMetrics#totalCommitLogSize
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalCommitlogSize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command to execute to archive a commitlog segment. Blank to disabled.
|
* Command to execute to archive a commitlog segment. Blank to disabled.
|
||||||
*/
|
*/
|
||||||
@ -69,21 +92,4 @@ public interface CommitLogMBean {
|
|||||||
* failed archive attempts.
|
* failed archive attempts.
|
||||||
*/
|
*/
|
||||||
public List<String> getArchivingSegmentNames();
|
public List<String> getArchivingSegmentNames();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The size of the mutations in all active commit log segments
|
|
||||||
* (uncompressed).
|
|
||||||
*/
|
|
||||||
public long getActiveContentSize();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The space taken on disk by the commit log (compressed).
|
|
||||||
*/
|
|
||||||
public long getActiveOnDiskSize();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return A map between active log segments and the compression ratio
|
|
||||||
* achieved for each.
|
|
||||||
*/
|
|
||||||
public Map<String, Double> getActiveSegmentCompressionRatios();
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.db.compaction;
|
package org.apache.cassandra.db.compaction;
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
import javax.json.JsonArray;
|
||||||
import jakarta.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
import javax.management.openmbean.CompositeDataSupport;
|
import javax.management.openmbean.CompositeDataSupport;
|
||||||
import javax.management.openmbean.CompositeType;
|
import javax.management.openmbean.CompositeType;
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.openmbean.OpenDataException;
|
||||||
@ -36,11 +36,13 @@ import javax.management.openmbean.TabularType;
|
|||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
|
||||||
public class CompactionHistoryTabularData {
|
public class CompactionHistoryTabularData {
|
||||||
private static final String[] ITEM_NAMES = new String[] { "id", "keyspace_name", "columnfamily_name",
|
private static final String[] ITEM_NAMES = new String[] { "id",
|
||||||
"compacted_at", "bytes_in", "bytes_out", "rows_merged" };
|
"keyspace_name", "columnfamily_name", "compacted_at", "bytes_in",
|
||||||
|
"bytes_out", "rows_merged" };
|
||||||
|
|
||||||
private static final String[] ITEM_DESCS = new String[] { "time uuid", "keyspace name", "column family name",
|
private static final String[] ITEM_DESCS = new String[] { "time uuid",
|
||||||
"compaction finished at", "total bytes in", "total bytes out", "total rows merged" };
|
"keyspace name", "column family name", "compaction finished at",
|
||||||
|
"total bytes in", "total bytes out", "total rows merged" };
|
||||||
|
|
||||||
private static final String TYPE_NAME = "CompactionHistory";
|
private static final String TYPE_NAME = "CompactionHistory";
|
||||||
|
|
||||||
@ -54,18 +56,22 @@ public class CompactionHistoryTabularData {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
ITEM_TYPES = new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG,
|
ITEM_TYPES = new OpenType[] { SimpleType.STRING, SimpleType.STRING,
|
||||||
SimpleType.LONG, SimpleType.LONG, SimpleType.STRING };
|
SimpleType.STRING, SimpleType.LONG, SimpleType.LONG,
|
||||||
|
SimpleType.LONG, SimpleType.STRING };
|
||||||
|
|
||||||
COMPOSITE_TYPE = new CompositeType(TYPE_NAME, ROW_DESC, ITEM_NAMES, ITEM_DESCS, ITEM_TYPES);
|
COMPOSITE_TYPE = new CompositeType(TYPE_NAME, ROW_DESC, ITEM_NAMES,
|
||||||
|
ITEM_DESCS, ITEM_TYPES);
|
||||||
|
|
||||||
TABULAR_TYPE = new TabularType(TYPE_NAME, ROW_DESC, COMPOSITE_TYPE, ITEM_NAMES);
|
TABULAR_TYPE = new TabularType(TYPE_NAME, ROW_DESC, COMPOSITE_TYPE,
|
||||||
|
ITEM_NAMES);
|
||||||
} catch (OpenDataException e) {
|
} catch (OpenDataException e) {
|
||||||
throw Throwables.propagate(e);
|
throw Throwables.propagate(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TabularData from(JsonArray resultSet) throws OpenDataException {
|
public static TabularData from(JsonArray resultSet)
|
||||||
|
throws OpenDataException {
|
||||||
TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
|
TabularDataSupport result = new TabularDataSupport(TABULAR_TYPE);
|
||||||
for (int i = 0; i < resultSet.size(); i++) {
|
for (int i = 0; i < resultSet.size(); i++) {
|
||||||
JsonObject row = resultSet.getJsonObject(i);
|
JsonObject row = resultSet.getJsonObject(i);
|
||||||
@ -85,13 +91,15 @@ public class CompactionHistoryTabularData {
|
|||||||
if (m > 0) {
|
if (m > 0) {
|
||||||
sb.append(',');
|
sb.append(',');
|
||||||
}
|
}
|
||||||
sb.append(entry.getString("key")).append(':').append(entry.getString("value"));
|
sb.append(entry.getString("key")).append(':')
|
||||||
|
.append(entry.getString("value"));
|
||||||
|
|
||||||
}
|
}
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
}
|
}
|
||||||
result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
|
result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES,
|
||||||
new Object[] { id, ksName, cfName, compactedAt, bytesIn, bytesOut, sb.toString() }));
|
new Object[] { id, ksName, cfName, compactedAt, bytesIn,
|
||||||
|
bytesOut, sb.toString() }));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -17,23 +17,24 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.db.compaction;
|
package org.apache.cassandra.db.compaction;
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
import java.lang.management.ManagementFactory;
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
|
import javax.json.JsonArray;
|
||||||
|
import javax.json.JsonObject;
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.openmbean.OpenDataException;
|
||||||
import javax.management.openmbean.TabularData;
|
import javax.management.openmbean.TabularData;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.CompactionMetrics;
|
import org.apache.cassandra.metrics.CompactionMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.MetricsMBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton which manages a private executor of ongoing compactions.
|
* A singleton which manages a private executor of ongoing compactions.
|
||||||
@ -48,24 +49,37 @@ import com.scylladb.jmx.metrics.MetricsMBean;
|
|||||||
*
|
*
|
||||||
* Modified by Cloudius Systems
|
* Modified by Cloudius Systems
|
||||||
*/
|
*/
|
||||||
public class CompactionManager extends MetricsMBean implements CompactionManagerMBean {
|
public class CompactionManager implements CompactionManagerMBean {
|
||||||
public static final String MBEAN_OBJECT_NAME = "org.apache.cassandra.db:type=CompactionManager";
|
public static final String MBEAN_OBJECT_NAME = "org.apache.cassandra.db:type=CompactionManager";
|
||||||
private static final Logger logger = Logger.getLogger(CompactionManager.class.getName());
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(CompactionManager.class.getName());
|
||||||
|
public static final CompactionManager instance;
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
CompactionMetrics metrics = new CompactionMetrics();
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompactionManager(APIClient client) {
|
static {
|
||||||
super(MBEAN_OBJECT_NAME, client, new CompactionMetrics());
|
instance = new CompactionManager();
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
try {
|
||||||
|
mbs.registerMBean(instance, new ObjectName(MBEAN_OBJECT_NAME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompactionManager getInstance() {
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** List of running compaction objects. */
|
/** List of running compaction objects. */
|
||||||
@Override
|
|
||||||
public List<Map<String, String>> getCompactions() {
|
public List<Map<String, String>> getCompactions() {
|
||||||
log(" getCompactions()");
|
log(" getCompactions()");
|
||||||
List<Map<String, String>> results = new ArrayList<Map<String, String>>();
|
List<Map<String, String>> results = new ArrayList<Map<String, String>>();
|
||||||
JsonArray compactions = client.getJsonArray("compaction_manager/compactions");
|
JsonArray compactions = c.getJsonArray("compaction_manager/compactions");
|
||||||
for (int i = 0; i < compactions.size(); i++) {
|
for (int i = 0; i < compactions.size(); i++) {
|
||||||
JsonObject compaction = compactions.getJsonObject(i);
|
JsonObject compaction = compactions.getJsonObject(i);
|
||||||
Map<String, String> result = new HashMap<String, String>();
|
Map<String, String> result = new HashMap<String, String>();
|
||||||
@ -75,30 +89,67 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
result.put("keyspace", compaction.getString("ks"));
|
result.put("keyspace", compaction.getString("ks"));
|
||||||
result.put("columnfamily", compaction.getString("cf"));
|
result.put("columnfamily", compaction.getString("cf"));
|
||||||
result.put("unit", compaction.getString("unit"));
|
result.put("unit", compaction.getString("unit"));
|
||||||
result.put("compactionId", (compaction.containsKey("id"))? compaction.getString("id") : "<none>");
|
|
||||||
results.add(result);
|
results.add(result);
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** List of running compaction summary strings. */
|
/** List of running compaction summary strings. */
|
||||||
@Override
|
|
||||||
public List<String> getCompactionSummary() {
|
public List<String> getCompactionSummary() {
|
||||||
log(" getCompactionSummary()");
|
log(" getCompactionSummary()");
|
||||||
return client.getListStrValue("compaction_manager/compaction_summary");
|
return c.getListStrValue("compaction_manager/compaction_summary");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** compaction history **/
|
/** compaction history **/
|
||||||
@Override
|
|
||||||
public TabularData getCompactionHistory() {
|
public TabularData getCompactionHistory() {
|
||||||
log(" getCompactionHistory()");
|
log(" getCompactionHistory()");
|
||||||
try {
|
try {
|
||||||
return CompactionHistoryTabularData.from(client.getJsonArray("/compaction_manager/compaction_history"));
|
return CompactionHistoryTabularData.from(c.getJsonArray("/compaction_manager/compaction_history"));
|
||||||
} catch (OpenDataException e) {
|
} catch (OpenDataException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#pendingTasks
|
||||||
|
* @return estimated number of compactions remaining to perform
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getPendingTasks() {
|
||||||
|
log(" getPendingTasks()");
|
||||||
|
return metrics.pendingTasks.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#completedTasks
|
||||||
|
* @return number of completed compactions since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompletedTasks() {
|
||||||
|
log(" getCompletedTasks()");
|
||||||
|
return metrics.completedTasks.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#bytesCompacted
|
||||||
|
* @return total number of bytes compacted since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalBytesCompacted() {
|
||||||
|
log(" getTotalBytesCompacted()");
|
||||||
|
return metrics.bytesCompacted.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#totalCompactionsCompleted
|
||||||
|
* @return total number of compactions since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalCompactionsCompleted() {
|
||||||
|
log(" getTotalCompactionsCompleted()");
|
||||||
|
return metrics.totalCompactionsCompleted.count();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers the compaction of user specified sstables. You can specify files
|
* Triggers the compaction of user specified sstables. You can specify files
|
||||||
* from various keyspaces and columnfamilies. If you do so, user defined
|
* from various keyspaces and columnfamilies. If you do so, user defined
|
||||||
@ -110,12 +161,11 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* contain keyspace and columnfamily name in path(for 2.1+) or
|
* contain keyspace and columnfamily name in path(for 2.1+) or
|
||||||
* file name itself.
|
* file name itself.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void forceUserDefinedCompaction(String dataFiles) {
|
public void forceUserDefinedCompaction(String dataFiles) {
|
||||||
log(" forceUserDefinedCompaction(String dataFiles)");
|
log(" forceUserDefinedCompaction(String dataFiles)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("dataFiles", dataFiles);
|
queryParams.add("dataFiles", dataFiles);
|
||||||
client.post("compaction_manager/force_user_defined_compaction", queryParams);
|
c.post("compaction_manager/force_user_defined_compaction", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,21 +175,23 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* the type of compaction to stop. Can be one of: - COMPACTION -
|
* the type of compaction to stop. Can be one of: - COMPACTION -
|
||||||
* VALIDATION - CLEANUP - SCRUB - INDEX_BUILD
|
* VALIDATION - CLEANUP - SCRUB - INDEX_BUILD
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void stopCompaction(String type) {
|
public void stopCompaction(String type) {
|
||||||
log(" stopCompaction(String type)");
|
log(" stopCompaction(String type)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("type", type);
|
queryParams.add("type", type);
|
||||||
client.post("compaction_manager/stop_compaction", queryParams);
|
c.post("compaction_manager/stop_compaction", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns core size of compaction thread pool
|
* Returns core size of compaction thread pool
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getCoreCompactorThreads() {
|
public int getCoreCompactorThreads() {
|
||||||
log(" getCoreCompactorThreads()");
|
log(" getCoreCompactorThreads()");
|
||||||
return client.getIntValue("");
|
/**
|
||||||
|
* Core size pool is meaningless, we still wants to return a valid reponse,
|
||||||
|
* just in case someone will try to call this method.
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,7 +200,6 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setCoreCompactorThreads(int number) {
|
public void setCoreCompactorThreads(int number) {
|
||||||
log(" setCoreCompactorThreads(int number)");
|
log(" setCoreCompactorThreads(int number)");
|
||||||
}
|
}
|
||||||
@ -156,10 +207,13 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
/**
|
/**
|
||||||
* Returns maximum size of compaction thread pool
|
* Returns maximum size of compaction thread pool
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getMaximumCompactorThreads() {
|
public int getMaximumCompactorThreads() {
|
||||||
log(" getMaximumCompactorThreads()");
|
log(" getMaximumCompactorThreads()");
|
||||||
return client.getIntValue("");
|
/**
|
||||||
|
* Core size pool is meaningless, we still wants to return a valid reponse,
|
||||||
|
* just in case someone will try to call this method.
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,7 +222,6 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setMaximumCompactorThreads(int number) {
|
public void setMaximumCompactorThreads(int number) {
|
||||||
log(" setMaximumCompactorThreads(int number)");
|
log(" setMaximumCompactorThreads(int number)");
|
||||||
}
|
}
|
||||||
@ -176,10 +229,13 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
/**
|
/**
|
||||||
* Returns core size of validation thread pool
|
* Returns core size of validation thread pool
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getCoreValidationThreads() {
|
public int getCoreValidationThreads() {
|
||||||
log(" getCoreValidationThreads()");
|
log(" getCoreValidationThreads()");
|
||||||
return client.getIntValue("");
|
/**
|
||||||
|
* Core validation size pool is meaningless, we still wants to return a valid reponse,
|
||||||
|
* just in case someone will try to call this method.
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -188,7 +244,6 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setCoreValidationThreads(int number) {
|
public void setCoreValidationThreads(int number) {
|
||||||
log(" setCoreValidationThreads(int number)");
|
log(" setCoreValidationThreads(int number)");
|
||||||
}
|
}
|
||||||
@ -196,10 +251,13 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
/**
|
/**
|
||||||
* Returns size of validator thread pool
|
* Returns size of validator thread pool
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public int getMaximumValidatorThreads() {
|
public int getMaximumValidatorThreads() {
|
||||||
log(" getMaximumValidatorThreads()");
|
log(" getMaximumValidatorThreads()");
|
||||||
return client.getIntValue("");
|
/**
|
||||||
|
* Core validation size pool is meaningless, we still wants to return a valid reponse,
|
||||||
|
* just in case someone will try to call this method.
|
||||||
|
*/
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,19 +266,8 @@ public class CompactionManager extends MetricsMBean implements CompactionManager
|
|||||||
* @param number
|
* @param number
|
||||||
* New maximum of validator threads
|
* New maximum of validator threads
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void setMaximumValidatorThreads(int number) {
|
public void setMaximumValidatorThreads(int number) {
|
||||||
log(" setMaximumValidatorThreads(int number)");
|
log(" setMaximumValidatorThreads(int number)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stopCompactionById(String compactionId) {
|
|
||||||
// scylla does not have neither compaction ids nor the file described
|
|
||||||
// in:
|
|
||||||
// "Ids can be found in the transaction log files whose name starts with
|
|
||||||
// compaction_, located in the table transactions folder"
|
|
||||||
// (nodetool)
|
|
||||||
// TODO: throw?
|
|
||||||
log(" stopCompactionById");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.cassandra.db.compaction;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.management.openmbean.TabularData;
|
import javax.management.openmbean.TabularData;
|
||||||
|
|
||||||
public interface CompactionManagerMBean {
|
public interface CompactionManagerMBean {
|
||||||
@ -32,6 +31,34 @@ public interface CompactionManagerMBean {
|
|||||||
/** compaction history **/
|
/** compaction history **/
|
||||||
public TabularData getCompactionHistory();
|
public TabularData getCompactionHistory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#pendingTasks
|
||||||
|
* @return estimated number of compactions remaining to perform
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public int getPendingTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#completedTasks
|
||||||
|
* @return number of completed compactions since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getCompletedTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#bytesCompacted
|
||||||
|
* @return total number of bytes compacted since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalBytesCompacted();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CompactionMetrics#totalCompactionsCompleted
|
||||||
|
* @return total number of compactions since server [re]start
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getTotalCompactionsCompleted();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers the compaction of user specified sstables. You can specify files
|
* Triggers the compaction of user specified sstables. You can specify files
|
||||||
* from various keyspaces and columnfamilies. If you do so, user defined
|
* from various keyspaces and columnfamilies. If you do so, user defined
|
||||||
@ -43,37 +70,15 @@ public interface CompactionManagerMBean {
|
|||||||
*/
|
*/
|
||||||
public void forceUserDefinedCompaction(String dataFiles);
|
public void forceUserDefinedCompaction(String dataFiles);
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers the cleanup of user specified sstables.
|
|
||||||
* You can specify files from various keyspaces and columnfamilies.
|
|
||||||
* If you do so, cleanup is performed each file individually
|
|
||||||
*
|
|
||||||
* @param dataFiles a comma separated list of sstable file to cleanup.
|
|
||||||
* must contain keyspace and columnfamily name in path(for 2.1+) or file name itself.
|
|
||||||
*/
|
|
||||||
default public void forceUserDefinedCleanup(String dataFiles) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop all running compaction-like tasks having the provided {@code type}.
|
* Stop all running compaction-like tasks having the provided {@code type}.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* the type of compaction to stop. Can be one of: - COMPACTION -
|
* the type of compaction to stop. Can be one of: - COMPACTION -
|
||||||
* VALIDATION - CLEANUP - SCRUB - INDEX_BUILD
|
* VALIDATION - CLEANUP - SCRUB - INDEX_BUILD
|
||||||
*/
|
*/
|
||||||
public void stopCompaction(String type);
|
public void stopCompaction(String type);
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop an individual running compaction using the compactionId.
|
|
||||||
*
|
|
||||||
* @param compactionId
|
|
||||||
* Compaction ID of compaction to stop. Such IDs can be found in
|
|
||||||
* the transaction log files whose name starts with compaction_,
|
|
||||||
* located in the table transactions folder.
|
|
||||||
*/
|
|
||||||
public void stopCompactionById(String compactionId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns core size of compaction thread pool
|
* Returns core size of compaction thread pool
|
||||||
*/
|
*/
|
||||||
@ -81,7 +86,7 @@ public interface CompactionManagerMBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows user to resize maximum size of the compaction thread pool.
|
* Allows user to resize maximum size of the compaction thread pool.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@ -94,7 +99,7 @@ public interface CompactionManagerMBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows user to resize maximum size of the compaction thread pool.
|
* Allows user to resize maximum size of the compaction thread pool.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@ -107,7 +112,7 @@ public interface CompactionManagerMBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows user to resize maximum size of the compaction thread pool.
|
* Allows user to resize maximum size of the compaction thread pool.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* New maximum of compaction threads
|
* New maximum of compaction threads
|
||||||
*/
|
*/
|
||||||
@ -120,7 +125,7 @@ public interface CompactionManagerMBean {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows user to resize maximum size of the validator thread pool.
|
* Allows user to resize maximum size of the validator thread pool.
|
||||||
*
|
*
|
||||||
* @param number
|
* @param number
|
||||||
* New maximum of validator threads
|
* New maximum of validator threads
|
||||||
*/
|
*/
|
||||||
|
@ -24,12 +24,31 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.gms;
|
package org.apache.cassandra.gms;
|
||||||
|
|
||||||
public enum ApplicationState {
|
public enum ApplicationState
|
||||||
STATUS, LOAD, SCHEMA, DC, RACK, RELEASE_VERSION, REMOVAL_COORDINATOR, INTERNAL_IP, RPC_ADDRESS, X_11_PADDING, // padding
|
{
|
||||||
// specifically
|
STATUS,
|
||||||
// for
|
LOAD,
|
||||||
// 1.1
|
SCHEMA,
|
||||||
SEVERITY, NET_VERSION, HOST_ID, TOKENS,
|
DC,
|
||||||
|
RACK,
|
||||||
|
RELEASE_VERSION,
|
||||||
|
REMOVAL_COORDINATOR,
|
||||||
|
INTERNAL_IP,
|
||||||
|
RPC_ADDRESS,
|
||||||
|
X_11_PADDING, // padding specifically for 1.1
|
||||||
|
SEVERITY,
|
||||||
|
NET_VERSION,
|
||||||
|
HOST_ID,
|
||||||
|
TOKENS,
|
||||||
// pad to allow adding new states to existing cluster
|
// pad to allow adding new states to existing cluster
|
||||||
X1, X2, X3, X4, X5, X6, X7, X8, X9, X10,
|
X1,
|
||||||
|
X2,
|
||||||
|
X3,
|
||||||
|
X4,
|
||||||
|
X5,
|
||||||
|
X6,
|
||||||
|
X7,
|
||||||
|
X8,
|
||||||
|
X9,
|
||||||
|
X10,
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ public class EndpointState {
|
|||||||
ApplicationState[] applicationValues;
|
ApplicationState[] applicationValues;
|
||||||
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
.getLogger(EndpointState.class.getName());
|
.getLogger(EndpointState.class.getName());
|
||||||
|
|
||||||
EndpointState(HeartBeatState initialHbState) {
|
EndpointState(HeartBeatState initialHbState) {
|
||||||
applicationValues = ApplicationState.values();
|
applicationValues = ApplicationState.values();
|
||||||
hbState = initialHbState;
|
hbState = initialHbState;
|
||||||
@ -102,8 +101,8 @@ public class EndpointState {
|
|||||||
isAlive = alive;
|
isAlive = alive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EndpointState: HeartBeatState = " + hbState + ", AppStateMap = " + applicationState;
|
return "EndpointState: HeartBeatState = " + hbState + ", AppStateMap = "
|
||||||
|
+ applicationState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,155 +24,117 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.gms;
|
package org.apache.cassandra.gms;
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
import java.lang.management.ManagementFactory;
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import jakarta.json.JsonValue;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.management.openmbean.CompositeData;
|
import javax.json.JsonArray;
|
||||||
import javax.management.openmbean.CompositeDataSupport;
|
import javax.json.JsonObject;
|
||||||
import javax.management.openmbean.CompositeType;
|
import javax.management.MBeanServer;
|
||||||
import javax.management.openmbean.OpenDataException;
|
import javax.management.ObjectName;
|
||||||
import javax.management.openmbean.OpenType;
|
|
||||||
import javax.management.openmbean.SimpleType;
|
|
||||||
import javax.management.openmbean.TabularData;
|
|
||||||
import javax.management.openmbean.TabularDataSupport;
|
|
||||||
import javax.management.openmbean.TabularType;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.APIMBean;
|
|
||||||
|
|
||||||
public class FailureDetector extends APIMBean implements FailureDetectorMBean {
|
public class FailureDetector implements FailureDetectorMBean {
|
||||||
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=FailureDetector";
|
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=FailureDetector";
|
||||||
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
.getLogger(FailureDetector.class.getName());
|
.getLogger(FailureDetector.class.getName());
|
||||||
|
|
||||||
public FailureDetector(APIClient c) {
|
private APIClient c = new APIClient();
|
||||||
super(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static final FailureDetector instance = new FailureDetector();
|
||||||
|
|
||||||
|
public static FailureDetector getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private FailureDetector() {
|
||||||
|
// Register this instance with JMX
|
||||||
|
try {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
mbs.registerMBean(this, new ObjectName(MBEAN_NAME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void dumpInterArrivalTimes() {
|
public void dumpInterArrivalTimes() {
|
||||||
log(" dumpInterArrivalTimes()");
|
log(" dumpInterArrivalTimes()");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPhiConvictThreshold(double phi) {
|
public void setPhiConvictThreshold(double phi) {
|
||||||
log(" setPhiConvictThreshold(double phi)");
|
log(" setPhiConvictThreshold(double phi)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getPhiConvictThreshold() {
|
public double getPhiConvictThreshold() {
|
||||||
log(" getPhiConvictThreshold()");
|
log(" getPhiConvictThreshold()");
|
||||||
return client.getDoubleValue("/failure_detector/phi");
|
return c.getDoubleValue("/failure_detector/phi");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAllEndpointStates() {
|
public String getAllEndpointStates() {
|
||||||
log(" getAllEndpointStates()");
|
log(" getAllEndpointStates()");
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Map.Entry<String, EndpointState> entry : getEndpointStateMap().entrySet()) {
|
for (Map.Entry<String, EndpointState> entry : getEndpointStateMap().entrySet())
|
||||||
|
{
|
||||||
sb.append('/').append(entry.getKey()).append("\n");
|
sb.append('/').append(entry.getKey()).append("\n");
|
||||||
appendEndpointState(sb, entry.getValue());
|
appendEndpointState(sb, entry.getValue());
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendEndpointState(StringBuilder sb, EndpointState endpointState) {
|
private void appendEndpointState(StringBuilder sb, EndpointState endpointState)
|
||||||
|
{
|
||||||
sb.append(" generation:").append(endpointState.getHeartBeatState().getGeneration()).append("\n");
|
sb.append(" generation:").append(endpointState.getHeartBeatState().getGeneration()).append("\n");
|
||||||
sb.append(" heartbeat:").append(endpointState.getHeartBeatState().getHeartBeatVersion()).append("\n");
|
sb.append(" heartbeat:").append(endpointState.getHeartBeatState().getHeartBeatVersion()).append("\n");
|
||||||
for (Map.Entry<ApplicationState, String> state : endpointState.applicationState.entrySet()) {
|
for (Map.Entry<ApplicationState, String> state : endpointState.applicationState.entrySet())
|
||||||
if (state.getKey() == ApplicationState.TOKENS) {
|
{
|
||||||
|
if (state.getKey() == ApplicationState.TOKENS)
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
sb.append(" ").append(state.getKey()).append(":").append(state.getValue()).append("\n");
|
sb.append(" ").append(state.getKey()).append(":").append(state.getValue()).append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, EndpointState> getEndpointStateMap() {
|
public Map<String, EndpointState> getEndpointStateMap() {
|
||||||
Map<String, EndpointState> res = new HashMap<String, EndpointState>();
|
Map<String, EndpointState> res = new HashMap<String, EndpointState>();
|
||||||
JsonArray arr = client.getJsonArray("/failure_detector/endpoints");
|
JsonArray arr = c.getJsonArray("/failure_detector/endpoints");
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
EndpointState ep = new EndpointState(new HeartBeatState(obj.getInt("generation"), obj.getInt("version")));
|
EndpointState ep = new EndpointState(new HeartBeatState(obj.getInt("generation"), obj.getInt("version")));
|
||||||
ep.setAliave(obj.getBoolean("is_alive"));
|
ep.setAliave(obj.getBoolean("is_alive"));
|
||||||
ep.setUpdateTimestamp(obj.getJsonNumber("update_time").longValue());
|
ep.setUpdateTimestamp(obj.getJsonNumber("update_time").longValue());
|
||||||
JsonArray states = obj.getJsonArray("application_state");
|
JsonArray states = obj.getJsonArray("application_state");
|
||||||
if (states != null) {
|
for (int j = 0; j < states.size(); j++) {
|
||||||
for (int j = 0; j < states.size(); j++) {
|
JsonObject state = states.getJsonObject(j);
|
||||||
JsonObject state = states.getJsonObject(j);
|
ep.addApplicationState(state.getInt("application_state"), state.getString("value"));
|
||||||
ep.addApplicationState(state.getInt("application_state"), state.getString("value"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res.put(obj.getString("addrs"), ep);
|
res.put(obj.getString("addrs"), ep);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEndpointState(String address) throws UnknownHostException {
|
public String getEndpointState(String address) throws UnknownHostException {
|
||||||
log(" getEndpointState(String address) throws UnknownHostException");
|
log(" getEndpointState(String address) throws UnknownHostException");
|
||||||
return client.getStringValue("/failure_detector/endpoints/states/" + address);
|
return c.getStringValue("/failure_detector/endpoints/states/" + address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, String> getSimpleStates() {
|
public Map<String, String> getSimpleStates() {
|
||||||
log(" getSimpleStates()");
|
log(" getSimpleStates()");
|
||||||
return client.getMapStrValue("/failure_detector/simple_states");
|
return c.getMapStrValue("/failure_detector/simple_states");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getDownEndpointCount() {
|
public int getDownEndpointCount() {
|
||||||
log(" getDownEndpointCount()");
|
log(" getDownEndpointCount()");
|
||||||
return client.getIntValue("/failure_detector/count/endpoint/down");
|
return c.getIntValue("/failure_detector/count/endpoint/down");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getUpEndpointCount() {
|
public int getUpEndpointCount() {
|
||||||
log(" getUpEndpointCount()");
|
log(" getUpEndpointCount()");
|
||||||
return client.getIntValue("/failure_detector/count/endpoint/up");
|
return c.getIntValue("/failure_detector/count/endpoint/up");
|
||||||
}
|
}
|
||||||
|
|
||||||
// From origin:
|
|
||||||
// this is useless except to provide backwards compatibility in
|
|
||||||
// phi_convict_threshold,
|
|
||||||
// because everyone seems pretty accustomed to the default of 8, and users
|
|
||||||
// who have
|
|
||||||
// already tuned their phi_convict_threshold for their own environments
|
|
||||||
// won't need to
|
|
||||||
// change.
|
|
||||||
private final double PHI_FACTOR = 1.0 / Math.log(10.0); // 0.434...
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TabularData getPhiValues() throws OpenDataException {
|
|
||||||
final CompositeType ct = new CompositeType("Node", "Node", new String[] { "Endpoint", "PHI" },
|
|
||||||
new String[] { "IP of the endpoint", "PHI value" },
|
|
||||||
new OpenType[] { SimpleType.STRING, SimpleType.DOUBLE });
|
|
||||||
final TabularDataSupport results = new TabularDataSupport(
|
|
||||||
new TabularType("PhiList", "PhiList", ct, new String[] { "Endpoint" }));
|
|
||||||
final JsonArray arr = client.getJsonArray("/failure_detector/endpoint_phi_values");
|
|
||||||
|
|
||||||
for (JsonValue v : arr) {
|
|
||||||
JsonObject o = (JsonObject) v;
|
|
||||||
String endpoint = o.getString("endpoint");
|
|
||||||
double phi = Double.parseDouble(o.getString("phi"));
|
|
||||||
|
|
||||||
if (phi != Double.MIN_VALUE) {
|
|
||||||
// returned values are scaled by PHI_FACTOR so that the are on
|
|
||||||
// the same scale as PhiConvictThreshold
|
|
||||||
final CompositeData data = new CompositeDataSupport(ct, new String[] { "Endpoint", "PHI" },
|
|
||||||
new Object[] { endpoint, phi * PHI_FACTOR });
|
|
||||||
results.put(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,8 @@ package org.apache.cassandra.gms;
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.management.openmbean.OpenDataException;
|
public interface FailureDetectorMBean
|
||||||
import javax.management.openmbean.TabularData;
|
{
|
||||||
|
|
||||||
public interface FailureDetectorMBean {
|
|
||||||
public void dumpInterArrivalTimes();
|
public void dumpInterArrivalTimes();
|
||||||
|
|
||||||
public void setPhiConvictThreshold(double phi);
|
public void setPhiConvictThreshold(double phi);
|
||||||
@ -39,6 +37,4 @@ public interface FailureDetectorMBean {
|
|||||||
public int getDownEndpointCount();
|
public int getDownEndpointCount();
|
||||||
|
|
||||||
public int getUpEndpointCount();
|
public int getUpEndpointCount();
|
||||||
|
|
||||||
public TabularData getPhiValues() throws OpenDataException;
|
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,15 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.gms;
|
package org.apache.cassandra.gms;
|
||||||
|
|
||||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
import java.lang.management.ManagementFactory;
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.APIMBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module is responsible for Gossiping information for the local endpoint.
|
* This module is responsible for Gossiping information for the local endpoint.
|
||||||
@ -46,43 +48,57 @@ import com.scylladb.jmx.metrics.APIMBean;
|
|||||||
* node as down in the Failure Detector.
|
* node as down in the Failure Detector.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Gossiper extends APIMBean implements GossiperMBean {
|
public class Gossiper implements GossiperMBean {
|
||||||
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=Gossiper";
|
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=Gossiper";
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(Gossiper.class.getName());
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(Gossiper.class.getName());
|
||||||
|
|
||||||
public Gossiper(APIClient c) {
|
private APIClient c = new APIClient();
|
||||||
super(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private static final Gossiper instance = new Gossiper();
|
||||||
|
|
||||||
|
public static Gossiper getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Gossiper() {
|
||||||
|
|
||||||
|
// Register this instance with JMX
|
||||||
|
try {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
mbs.registerMBean(this, new ObjectName(MBEAN_NAME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long getEndpointDowntime(String address) throws UnknownHostException {
|
public long getEndpointDowntime(String address) throws UnknownHostException {
|
||||||
log(" getEndpointDowntime(String address) throws UnknownHostException");
|
log(" getEndpointDowntime(String address) throws UnknownHostException");
|
||||||
return client.getLongValue("gossiper/downtime/" + address);
|
return c.getLongValue("gossiper/downtime/" + address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public int getCurrentGenerationNumber(String address)
|
||||||
public int getCurrentGenerationNumber(String address) throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
log(" getCurrentGenerationNumber(String address) throws UnknownHostException");
|
log(" getCurrentGenerationNumber(String address) throws UnknownHostException");
|
||||||
return client.getIntValue("gossiper/generation_number/" + address);
|
return c.getIntValue("gossiper/generation_number/" + address);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void unsafeAssassinateEndpoint(String address)
|
||||||
public void unsafeAssassinateEndpoint(String address) throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
log(" unsafeAssassinateEndpoint(String address) throws UnknownHostException");
|
log(" unsafeAssassinateEndpoint(String address) throws UnknownHostException");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("unsafe", "True");
|
queryParams.add("unsafe", "True");
|
||||||
client.post("gossiper/assassinate/" + address, queryParams);
|
c.post("gossiper/assassinate/" + address, queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void assassinateEndpoint(String address) throws UnknownHostException {
|
public void assassinateEndpoint(String address) throws UnknownHostException {
|
||||||
log(" assassinateEndpoint(String address) throws UnknownHostException");
|
log(" assassinateEndpoint(String address) throws UnknownHostException");
|
||||||
client.post("gossiper/assassinate/" + address, null);
|
c.post("gossiper/assassinate/" + address, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -19,13 +19,12 @@ package org.apache.cassandra.gms;
|
|||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
public interface GossiperMBean {
|
public interface GossiperMBean
|
||||||
|
{
|
||||||
public long getEndpointDowntime(String address) throws UnknownHostException;
|
public long getEndpointDowntime(String address) throws UnknownHostException;
|
||||||
|
|
||||||
public int getCurrentGenerationNumber(String address) throws UnknownHostException;
|
public int getCurrentGenerationNumber(String address) throws UnknownHostException;
|
||||||
|
|
||||||
public void unsafeAssassinateEndpoint(String address) throws UnknownHostException;
|
public void unsafeAssassinateEndpoint(String address) throws UnknownHostException;
|
||||||
|
|
||||||
public void assassinateEndpoint(String address) throws UnknownHostException;
|
|
||||||
|
|
||||||
}
|
}
|
@ -58,8 +58,8 @@ class HeartBeatState {
|
|||||||
version = Integer.MAX_VALUE;
|
version = Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("HeartBeat: generation = %d, version = %d", generation, version);
|
return String.format("HeartBeat: generation = %d, version = %d",
|
||||||
|
generation, version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,29 +17,43 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.locator;
|
package org.apache.cassandra.locator;
|
||||||
|
|
||||||
import static java.util.Collections.singletonMap;
|
import java.lang.management.ManagementFactory;
|
||||||
|
|
||||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.APIMBean;
|
|
||||||
|
|
||||||
public class EndpointSnitchInfo extends APIMBean implements EndpointSnitchInfoMBean {
|
public class EndpointSnitchInfo implements EndpointSnitchInfoMBean {
|
||||||
public static final String MBEAN_NAME = "org.apache.cassandra.db:type=EndpointSnitchInfo";
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
private static final Logger logger = Logger.getLogger(EndpointSnitchInfo.class.getName());
|
.getLogger(EndpointSnitchInfo.class.getName());
|
||||||
|
|
||||||
public EndpointSnitchInfo(APIClient c) {
|
private APIClient c = new APIClient();
|
||||||
super(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final EndpointSnitchInfo instance = new EndpointSnitchInfo();
|
||||||
|
|
||||||
|
public static EndpointSnitchInfo getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private EndpointSnitchInfo() {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
try {
|
||||||
|
mbs.registerMBean(this, new ObjectName(
|
||||||
|
"org.apache.cassandra.db:type=EndpointSnitchInfo"));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Rack name depending on the respective snitch used, given the
|
* Provides the Rack name depending on the respective snitch used, given the
|
||||||
* host name/ip
|
* host name/ip
|
||||||
@ -50,9 +64,12 @@ public class EndpointSnitchInfo extends APIMBean implements EndpointSnitchInfoMB
|
|||||||
@Override
|
@Override
|
||||||
public String getRack(String host) throws UnknownHostException {
|
public String getRack(String host) throws UnknownHostException {
|
||||||
log("getRack(String host) throws UnknownHostException");
|
log("getRack(String host) throws UnknownHostException");
|
||||||
MultivaluedMap<String, String> queryParams = host != null ? new MultivaluedHashMap<String, String>(
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
singletonMap("host", InetAddress.getByName(host).getHostAddress())) : null;
|
if (host == null) {
|
||||||
return client.getStringValue("/snitch/rack", queryParams, 10000);
|
host = InetAddress.getLoopbackAddress().getHostAddress();
|
||||||
|
}
|
||||||
|
queryParams.add("host", host);
|
||||||
|
return c.getStringValue("/snitch/rack", queryParams, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,9 +82,12 @@ public class EndpointSnitchInfo extends APIMBean implements EndpointSnitchInfoMB
|
|||||||
@Override
|
@Override
|
||||||
public String getDatacenter(String host) throws UnknownHostException {
|
public String getDatacenter(String host) throws UnknownHostException {
|
||||||
log(" getDatacenter(String host) throws UnknownHostException");
|
log(" getDatacenter(String host) throws UnknownHostException");
|
||||||
MultivaluedMap<String, String> queryParams = host != null ? new MultivaluedHashMap<String, String>(
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
singletonMap("host", InetAddress.getByName(host).getHostAddress())) : null;
|
if (host == null) {
|
||||||
return client.getStringValue("/snitch/datacenter", queryParams, 10000);
|
host = InetAddress.getLoopbackAddress().getHostAddress();
|
||||||
|
}
|
||||||
|
queryParams.add("host", host);
|
||||||
|
return c.getStringValue("/snitch/datacenter", queryParams, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,16 +98,7 @@ public class EndpointSnitchInfo extends APIMBean implements EndpointSnitchInfoMB
|
|||||||
@Override
|
@Override
|
||||||
public String getSnitchName() {
|
public String getSnitchName() {
|
||||||
log(" getSnitchName()");
|
log(" getSnitchName()");
|
||||||
return client.getStringValue("/snitch/name");
|
return c.getStringValue("/snitch/name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRack() {
|
|
||||||
return client.getStringValue("/snitch/rack", null, 10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDatacenter() {
|
|
||||||
return client.getStringValue("/snitch/datacenter", null, 10000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,40 +22,25 @@ import java.net.UnknownHostException;
|
|||||||
/**
|
/**
|
||||||
* MBean exposing standard Snitch info
|
* MBean exposing standard Snitch info
|
||||||
*/
|
*/
|
||||||
public interface EndpointSnitchInfoMBean {
|
public interface EndpointSnitchInfoMBean
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Provides the Rack name depending on the respective snitch used, given the
|
* Provides the Rack name depending on the respective snitch used, given the host name/ip
|
||||||
* host name/ip
|
|
||||||
*
|
|
||||||
* @param host
|
* @param host
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
public String getRack(String host) throws UnknownHostException;
|
public String getRack(String host) throws UnknownHostException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the Datacenter name depending on the respective snitch used,
|
* Provides the Datacenter name depending on the respective snitch used, given the hostname/ip
|
||||||
* given the hostname/ip
|
|
||||||
*
|
|
||||||
* @param host
|
* @param host
|
||||||
* @throws UnknownHostException
|
* @throws UnknownHostException
|
||||||
*/
|
*/
|
||||||
public String getDatacenter(String host) throws UnknownHostException;
|
public String getDatacenter(String host) throws UnknownHostException;
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the Rack name depending on the respective snitch used for this
|
|
||||||
* node
|
|
||||||
*/
|
|
||||||
public String getRack();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides the Datacenter name depending on the respective snitch used for
|
|
||||||
* this node
|
|
||||||
*/
|
|
||||||
public String getDatacenter();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides the snitch name of the cluster
|
* Provides the snitch name of the cluster
|
||||||
*
|
|
||||||
* @return Snitch name
|
* @return Snitch name
|
||||||
*/
|
*/
|
||||||
public String getSnitchName();
|
public String getSnitchName();
|
||||||
|
@ -25,20 +25,34 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.yammer.metrics.core.*;
|
||||||
|
|
||||||
// TODO: In StorageProxy
|
|
||||||
public class CASClientRequestMetrics extends ClientRequestMetrics {
|
public class CASClientRequestMetrics extends ClientRequestMetrics {
|
||||||
|
|
||||||
public CASClientRequestMetrics(String scope, String url) {
|
public final Histogram contention;
|
||||||
super(scope, url);
|
/* Used only for write */
|
||||||
|
public final Counter conditionNotMet;
|
||||||
|
|
||||||
|
public final Counter unfinishedCommit;
|
||||||
|
|
||||||
|
public CASClientRequestMetrics(String url, String scope) {
|
||||||
|
super(url, scope);
|
||||||
|
contention = APIMetrics.newHistogram(url + "contention",
|
||||||
|
factory.createMetricName("ContentionHistogram"), true);
|
||||||
|
conditionNotMet = APIMetrics.newCounter(url + "condition_not_met",
|
||||||
|
factory.createMetricName("ConditionNotMet"));
|
||||||
|
unfinishedCommit = APIMetrics.newCounter(url + "unfinished_commit",
|
||||||
|
factory.createMetricName("UnfinishedCommit"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void release() {
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
super.release();
|
||||||
super.register(registry);
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
registry.register(() -> registry.histogram(uri + "/contention", true), names("ContentionHistogram"));
|
factory.createMetricName("ContentionHistogram"));
|
||||||
registry.register(() -> registry.counter(uri + "/condition_not_met"), names("ConditionNotMet"));
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
registry.register(() -> registry.counter(uri + "/unfinished_commit"), names("UnfinishedCommit"));
|
factory.createMetricName("ConditionNotMet"));
|
||||||
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("UnfinishedCommit"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,20 +23,44 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.yammer.metrics.core.Gauge;
|
||||||
|
import com.yammer.metrics.core.APIMeter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics for {@code ICache}.
|
* Metrics for {@code ICache}.
|
||||||
*/
|
*/
|
||||||
public class CacheMetrics implements Metrics {
|
public class CacheMetrics {
|
||||||
|
/** Cache capacity in bytes */
|
||||||
|
public final Gauge<Long> capacity;
|
||||||
|
/** Total number of cache hits */
|
||||||
|
public final APIMeter hits;
|
||||||
|
/** Total number of cache requests */
|
||||||
|
public final APIMeter requests;
|
||||||
|
/** cache hit rate */
|
||||||
|
public final Gauge<Double> hitRate;
|
||||||
|
/** Total size of cache, in bytes */
|
||||||
|
public final Gauge<Long> size;
|
||||||
|
/** Total number of cache entries */
|
||||||
|
public final Gauge<Integer> entries;
|
||||||
|
|
||||||
private final String type;
|
private final AtomicLong lastRequests = new AtomicLong(0);
|
||||||
private final String url;
|
private final AtomicLong lastHits = new AtomicLong(0);
|
||||||
|
|
||||||
private String compose(String value) {
|
private APIClient c = new APIClient();
|
||||||
return "/cache_service/metrics/" + url + "/" + value;
|
|
||||||
|
private String getURL(String url, String value) {
|
||||||
|
if (url == null || value == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return "/cache_service/metrics/" + url + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create metrics for given cache.
|
* Create metrics for given cache.
|
||||||
*
|
*
|
||||||
@ -46,21 +70,70 @@ public class CacheMetrics implements Metrics {
|
|||||||
* Cache to measure metrics
|
* Cache to measure metrics
|
||||||
*/
|
*/
|
||||||
public CacheMetrics(String type, final String url) {
|
public CacheMetrics(String type, final String url) {
|
||||||
this.type = type;
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
|
||||||
MetricNameFactory factory = new DefaultNameFactory("Cache", type);
|
MetricNameFactory factory = new DefaultNameFactory("Cache", type);
|
||||||
|
|
||||||
registry.register(() -> registry.gauge(compose("capacity")), factory.createMetricName("Capacity"));
|
|
||||||
registry.register(() -> registry.meter(compose("hits_moving_avrage")), factory.createMetricName("Hits"));
|
|
||||||
registry.register(() -> registry.meter(compose("requests_moving_avrage")),
|
|
||||||
factory.createMetricName("Requests"));
|
|
||||||
|
|
||||||
registry.register(() -> registry.gauge(Double.class, compose("hit_rate")), factory.createMetricName("HitRate"));
|
capacity = APIMetrics.newGauge(factory.createMetricName("Capacity"),
|
||||||
registry.register(() -> registry.gauge(compose("size")), factory.createMetricName("Size"));
|
new Gauge<Long>() {
|
||||||
registry.register(() -> registry.gauge(Integer.class, compose("entries")), factory.createMetricName("Entries"));
|
String u = getURL(url, "/capacity");
|
||||||
|
public Long value() {
|
||||||
|
if (u == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return c.getLongValue(u);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
hits = APIMetrics.newMeter(getURL(url, "/hits_moving_avrage"), factory.createMetricName("Hits"), "hits",
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
requests = APIMetrics.newMeter(getURL(url, "/requests_moving_avrage"), factory.createMetricName("Requests"),
|
||||||
|
"requests", TimeUnit.SECONDS);
|
||||||
|
hitRate = APIMetrics.newGauge(factory.createMetricName("HitRate"),
|
||||||
|
new Gauge<Double>() {
|
||||||
|
String u = getURL(url, "/hit_rate");
|
||||||
|
@Override
|
||||||
|
public Double value() {
|
||||||
|
if (u == null) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return c.getDoubleValue(u);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
size = APIMetrics.newGauge(factory.createMetricName("Size"),
|
||||||
|
new Gauge<Long>() {
|
||||||
|
String u = getURL(url, "/size");
|
||||||
|
public Long value() {
|
||||||
|
if (u == null) {
|
||||||
|
return 0L;
|
||||||
|
}
|
||||||
|
return c.getLongValue(u);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
entries = APIMetrics.newGauge(factory.createMetricName("Entries"),
|
||||||
|
new Gauge<Integer>() {
|
||||||
|
String u = getURL(url, "/entries");
|
||||||
|
public Integer value() {
|
||||||
|
if (u == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return c.getIntValue(u);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for backward compatibility
|
||||||
|
@Deprecated
|
||||||
|
public double getRecentHitRate() {
|
||||||
|
long r = requests.count();
|
||||||
|
long h = hits.count();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return ((double)(h - lastHits.get())) / (r - lastRequests.get());
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
lastRequests.set(r);
|
||||||
|
lastHits.set(h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,17 +27,52 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.yammer.metrics.Metrics;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
import com.yammer.metrics.core.Meter;
|
||||||
|
|
||||||
public class ClientRequestMetrics extends LatencyMetrics {
|
public class ClientRequestMetrics extends LatencyMetrics {
|
||||||
public ClientRequestMetrics(String scope, String url) {
|
@Deprecated
|
||||||
super("ClientRequest", scope, url);
|
public static final Counter readTimeouts = Metrics
|
||||||
|
.newCounter(DefaultNameFactory.createMetricName(
|
||||||
|
"ClientRequestMetrics", "ReadTimeouts", null));
|
||||||
|
@Deprecated
|
||||||
|
public static final Counter writeTimeouts = Metrics
|
||||||
|
.newCounter(DefaultNameFactory.createMetricName(
|
||||||
|
"ClientRequestMetrics", "WriteTimeouts", null));
|
||||||
|
@Deprecated
|
||||||
|
public static final Counter readUnavailables = Metrics
|
||||||
|
.newCounter(DefaultNameFactory.createMetricName(
|
||||||
|
"ClientRequestMetrics", "ReadUnavailables", null));
|
||||||
|
@Deprecated
|
||||||
|
public static final Counter writeUnavailables = Metrics
|
||||||
|
.newCounter(DefaultNameFactory.createMetricName(
|
||||||
|
"ClientRequestMetrics", "WriteUnavailables", null));
|
||||||
|
|
||||||
|
public final Meter timeouts;
|
||||||
|
public final Meter unavailables;
|
||||||
|
|
||||||
|
public ClientRequestMetrics(String url, String scope) {
|
||||||
|
super(url, "ClientRequest", scope);
|
||||||
|
|
||||||
|
timeouts = APIMetrics.newMeter(url + "/timeouts_rates",
|
||||||
|
factory.createMetricName("Timeouts"), "timeouts",
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
unavailables = APIMetrics.newMeter(url + "/unavailables_rates",
|
||||||
|
factory.createMetricName("Unavailables"), "unavailables",
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void release() {
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
super.release();
|
||||||
super.register(registry);
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
registry.register(() -> registry.meter(uri + "/timeouts_rates"), names("Timeouts"));
|
factory.createMetricName("Timeouts"));
|
||||||
registry.register(() -> registry.meter(uri + "/unavailables_rates"), names("Unavailables"));
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("Unavailables"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,576 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2015 Cloudius Systems
|
||||||
|
*
|
||||||
|
* Modified by Cloudius Systems
|
||||||
|
*/
|
||||||
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.apache.cassandra.db.ColumnFamilyStore;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.scylladb.jmx.utils.RecentEstimatedHistogram;
|
||||||
|
import com.yammer.metrics.Metrics;
|
||||||
|
import com.yammer.metrics.core.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Metrics for {@link ColumnFamilyStore}.
|
||||||
|
*/
|
||||||
|
public class ColumnFamilyMetrics {
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
/**
|
||||||
|
* Total amount of data stored in the memtable that resides on-heap,
|
||||||
|
* including column related overhead and overwritten rows.
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> memtableOnHeapSize;
|
||||||
|
/**
|
||||||
|
* Total amount of data stored in the memtable that resides off-heap,
|
||||||
|
* including column related overhead and overwritten rows.
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> memtableOffHeapSize;
|
||||||
|
/**
|
||||||
|
* Total amount of live data stored in the memtable, excluding any data
|
||||||
|
* structure overhead
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> memtableLiveDataSize;
|
||||||
|
/**
|
||||||
|
* Total amount of data stored in the memtables (2i and pending flush
|
||||||
|
* memtables included) that resides on-heap.
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> allMemtablesOnHeapSize;
|
||||||
|
/**
|
||||||
|
* Total amount of data stored in the memtables (2i and pending flush
|
||||||
|
* memtables included) that resides off-heap.
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> allMemtablesOffHeapSize;
|
||||||
|
/**
|
||||||
|
* Total amount of live data stored in the memtables (2i and pending flush
|
||||||
|
* memtables included) that resides off-heap, excluding any data structure
|
||||||
|
* overhead
|
||||||
|
*/
|
||||||
|
public final Gauge<Long> allMemtablesLiveDataSize;
|
||||||
|
/** Total number of columns present in the memtable. */
|
||||||
|
public final Gauge<Long> memtableColumnsCount;
|
||||||
|
/** Number of times flush has resulted in the memtable being switched out. */
|
||||||
|
public final Counter memtableSwitchCount;
|
||||||
|
/** Current compression ratio for all SSTables */
|
||||||
|
public final Gauge<Double> compressionRatio;
|
||||||
|
/** Histogram of estimated row size (in bytes). */
|
||||||
|
public final Gauge<long[]> estimatedRowSizeHistogram;
|
||||||
|
/** Approximate number of keys in table. */
|
||||||
|
public final Gauge<Long> estimatedRowCount;
|
||||||
|
/** Histogram of estimated number of columns. */
|
||||||
|
public final Gauge<long[]> estimatedColumnCountHistogram;
|
||||||
|
/** Histogram of the number of sstable data files accessed per read */
|
||||||
|
public final ColumnFamilyHistogram sstablesPerReadHistogram;
|
||||||
|
/** (Local) read metrics */
|
||||||
|
public final LatencyMetrics readLatency;
|
||||||
|
/** (Local) range slice metrics */
|
||||||
|
public final LatencyMetrics rangeLatency;
|
||||||
|
/** (Local) write metrics */
|
||||||
|
public final LatencyMetrics writeLatency;
|
||||||
|
/** Estimated number of tasks pending for this column family */
|
||||||
|
public final Counter pendingFlushes;
|
||||||
|
/** Estimate of number of pending compactios for this CF */
|
||||||
|
public final Gauge<Integer> pendingCompactions;
|
||||||
|
/** Number of SSTables on disk for this CF */
|
||||||
|
public final Gauge<Integer> liveSSTableCount;
|
||||||
|
/** Disk space used by SSTables belonging to this CF */
|
||||||
|
public final Counter liveDiskSpaceUsed;
|
||||||
|
/**
|
||||||
|
* Total disk space used by SSTables belonging to this CF, including
|
||||||
|
* obsolete ones waiting to be GC'd
|
||||||
|
*/
|
||||||
|
public final Counter totalDiskSpaceUsed;
|
||||||
|
/** Size of the smallest compacted row */
|
||||||
|
public final Gauge<Long> minRowSize;
|
||||||
|
/** Size of the largest compacted row */
|
||||||
|
public final Gauge<Long> maxRowSize;
|
||||||
|
/** Size of the smallest compacted row */
|
||||||
|
public final Gauge<Long> meanRowSize;
|
||||||
|
/** Number of false positives in bloom filter */
|
||||||
|
public final Gauge<Long> bloomFilterFalsePositives;
|
||||||
|
/** Number of false positives in bloom filter from last read */
|
||||||
|
public final Gauge<Long> recentBloomFilterFalsePositives;
|
||||||
|
/** False positive ratio of bloom filter */
|
||||||
|
public final Gauge<Double> bloomFilterFalseRatio;
|
||||||
|
/** False positive ratio of bloom filter from last read */
|
||||||
|
public final Gauge<Double> recentBloomFilterFalseRatio;
|
||||||
|
/** Disk space used by bloom filter */
|
||||||
|
public final Gauge<Long> bloomFilterDiskSpaceUsed;
|
||||||
|
/** Off heap memory used by bloom filter */
|
||||||
|
public final Gauge<Long> bloomFilterOffHeapMemoryUsed;
|
||||||
|
/** Off heap memory used by index summary */
|
||||||
|
public final Gauge<Long> indexSummaryOffHeapMemoryUsed;
|
||||||
|
/** Off heap memory used by compression meta data */
|
||||||
|
public final Gauge<Long> compressionMetadataOffHeapMemoryUsed;
|
||||||
|
/** Key cache hit rate for this CF */
|
||||||
|
public final Gauge<Double> keyCacheHitRate;
|
||||||
|
/** Tombstones scanned in queries on this CF */
|
||||||
|
public final ColumnFamilyHistogram tombstoneScannedHistogram;
|
||||||
|
/** Live cells scanned in queries on this CF */
|
||||||
|
public final ColumnFamilyHistogram liveScannedHistogram;
|
||||||
|
/** Column update time delta on this CF */
|
||||||
|
public final ColumnFamilyHistogram colUpdateTimeDeltaHistogram;
|
||||||
|
/** Disk space used by snapshot files which */
|
||||||
|
public final Gauge<Long> trueSnapshotsSize;
|
||||||
|
/** Row cache hits, but result out of range */
|
||||||
|
public final Counter rowCacheHitOutOfRange;
|
||||||
|
/** Number of row cache hits */
|
||||||
|
public final Counter rowCacheHit;
|
||||||
|
/** Number of row cache misses */
|
||||||
|
public final Counter rowCacheMiss;
|
||||||
|
/** CAS Prepare metrics */
|
||||||
|
public final LatencyMetrics casPrepare;
|
||||||
|
/** CAS Propose metrics */
|
||||||
|
public final LatencyMetrics casPropose;
|
||||||
|
/** CAS Commit metrics */
|
||||||
|
public final LatencyMetrics casCommit;
|
||||||
|
|
||||||
|
public final Timer coordinatorReadLatency;
|
||||||
|
public final Timer coordinatorScanLatency;
|
||||||
|
|
||||||
|
/** Time spent waiting for free memtable space, either on- or off-heap */
|
||||||
|
public final Timer waitingOnFreeMemtableSpace;
|
||||||
|
|
||||||
|
private final MetricNameFactory factory;
|
||||||
|
private static final MetricNameFactory globalNameFactory = new AllColumnFamilyMetricNameFactory();
|
||||||
|
|
||||||
|
public final Counter speculativeRetries;
|
||||||
|
|
||||||
|
// for backward compatibility
|
||||||
|
@Deprecated
|
||||||
|
public final EstimatedHistogramWrapper sstablesPerRead;
|
||||||
|
// it should not be called directly
|
||||||
|
@Deprecated
|
||||||
|
protected final RecentEstimatedHistogram recentSSTablesPerRead = new RecentEstimatedHistogram(35);
|
||||||
|
private String cfName;
|
||||||
|
|
||||||
|
public final static LatencyMetrics globalReadLatency = new LatencyMetrics(
|
||||||
|
"/column_family/metrics/read_latency", globalNameFactory, "Read");
|
||||||
|
public final static LatencyMetrics globalWriteLatency = new LatencyMetrics(
|
||||||
|
"/column_family/metrics/write_latency", globalNameFactory, "Write");
|
||||||
|
public final static LatencyMetrics globalRangeLatency = new LatencyMetrics(
|
||||||
|
"/column_family/metrics/range_latency", globalNameFactory, "Range");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stores metrics that will be rolled into a single global metric
|
||||||
|
*/
|
||||||
|
public final static ConcurrentMap<String, Set<Metric>> allColumnFamilyMetrics = Maps
|
||||||
|
.newConcurrentMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores all metric names created that can be used when unregistering
|
||||||
|
*/
|
||||||
|
public final static Set<String> all = Sets.newHashSet();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates metrics for given {@link ColumnFamilyStore}.
|
||||||
|
*
|
||||||
|
* @param cfs
|
||||||
|
* ColumnFamilyStore to measure metrics
|
||||||
|
*/
|
||||||
|
public ColumnFamilyMetrics(final ColumnFamilyStore cfs) {
|
||||||
|
factory = new ColumnFamilyMetricNameFactory(cfs);
|
||||||
|
cfName = cfs.getCFName();
|
||||||
|
memtableColumnsCount = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/memtable_columns_count",
|
||||||
|
"MemtableColumnsCount");
|
||||||
|
memtableOnHeapSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/memtable_on_heap_size",
|
||||||
|
"MemtableOnHeapSize");
|
||||||
|
memtableOffHeapSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/memtable_off_heap_size",
|
||||||
|
"MemtableOffHeapSize");
|
||||||
|
memtableLiveDataSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/memtable_live_data_size",
|
||||||
|
"MemtableLiveDataSize");
|
||||||
|
allMemtablesOnHeapSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/all_memtables_on_heap_size",
|
||||||
|
"AllMemtablesHeapSize");
|
||||||
|
allMemtablesOffHeapSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/all_memtables_off_heap_size",
|
||||||
|
"AllMemtablesOffHeapSize");
|
||||||
|
allMemtablesLiveDataSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/all_memtables_live_data_size",
|
||||||
|
"AllMemtablesLiveDataSize");
|
||||||
|
memtableSwitchCount = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/memtable_switch_count",
|
||||||
|
"MemtableSwitchCount");
|
||||||
|
estimatedRowSizeHistogram = Metrics.newGauge(
|
||||||
|
factory.createMetricName("EstimatedRowSizeHistogram"),
|
||||||
|
new Gauge<long[]>() {
|
||||||
|
public long[] value() {
|
||||||
|
return c.getEstimatedHistogramAsLongArrValue("/column_family/metrics/estimated_row_size_histogram/"
|
||||||
|
+ cfName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
estimatedRowCount= Metrics.newGauge(
|
||||||
|
factory.createMetricName("EstimatedRowCount"),
|
||||||
|
new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
return c.getLongValue("/column_family/metrics/estimated_row_count/"
|
||||||
|
+ cfName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
estimatedColumnCountHistogram = Metrics.newGauge(
|
||||||
|
factory.createMetricName("EstimatedColumnCountHistogram"),
|
||||||
|
new Gauge<long[]>() {
|
||||||
|
public long[] value() {
|
||||||
|
return c.getEstimatedHistogramAsLongArrValue("/column_family/metrics/estimated_column_count_histogram/"
|
||||||
|
+ cfName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sstablesPerReadHistogram = createColumnFamilyHistogram(
|
||||||
|
"/column_family/metrics/sstables_per_read_histogram",
|
||||||
|
"SSTablesPerReadHistogram");
|
||||||
|
compressionRatio = createColumnFamilyGauge("CompressionRatio",
|
||||||
|
new Gauge<Double>() {
|
||||||
|
public Double value() {
|
||||||
|
return c.getDoubleValue("/column_family/metrics/compression_ratio/"
|
||||||
|
+ cfName);
|
||||||
|
}
|
||||||
|
}, new Gauge<Double>() // global gauge
|
||||||
|
{
|
||||||
|
public Double value() {
|
||||||
|
return c.getDoubleValue("/column_family/metrics/compression_ratio/");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
readLatency = new LatencyMetrics("/column_family/metrics/read_latency",
|
||||||
|
cfName, factory, "Read");
|
||||||
|
writeLatency = new LatencyMetrics(
|
||||||
|
"/column_family/metrics/write_latency", cfName, factory,
|
||||||
|
"Write");
|
||||||
|
rangeLatency = new LatencyMetrics(
|
||||||
|
"/column_family/metrics/range_latency", cfName, factory,
|
||||||
|
"Range");
|
||||||
|
pendingFlushes = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/pending_flushes", "PendingFlushes");
|
||||||
|
pendingCompactions = createColumnFamilyGaugeInt(
|
||||||
|
"/column_family/metrics/pending_compactions",
|
||||||
|
"PendingCompactions");
|
||||||
|
liveSSTableCount = createColumnFamilyGaugeInt(
|
||||||
|
"/column_family/metrics/live_ss_table_count",
|
||||||
|
"LiveSSTableCount");
|
||||||
|
liveDiskSpaceUsed = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/live_disk_space_used",
|
||||||
|
"LiveDiskSpaceUsed");
|
||||||
|
totalDiskSpaceUsed = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/total_disk_space_used",
|
||||||
|
"TotalDiskSpaceUsed");
|
||||||
|
minRowSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/min_row_size", "MinRowSize");
|
||||||
|
maxRowSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/max_row_size", "MaxRowSize");
|
||||||
|
meanRowSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/mean_row_size", "MeanRowSize");
|
||||||
|
bloomFilterFalsePositives = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/bloom_filter_false_positives",
|
||||||
|
"BloomFilterFalsePositives");
|
||||||
|
recentBloomFilterFalsePositives = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/recent_bloom_filter_false_positives",
|
||||||
|
"RecentBloomFilterFalsePositives");
|
||||||
|
bloomFilterFalseRatio = createColumnFamilyGaugeDouble(
|
||||||
|
"/column_family/metrics/bloom_filter_false_ratio",
|
||||||
|
"BloomFilterFalseRatio");
|
||||||
|
recentBloomFilterFalseRatio = createColumnFamilyGaugeDouble(
|
||||||
|
"/column_family/metrics/recent_bloom_filter_false_ratio",
|
||||||
|
"RecentBloomFilterFalseRatio");
|
||||||
|
bloomFilterDiskSpaceUsed = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/bloom_filter_disk_space_used",
|
||||||
|
"BloomFilterDiskSpaceUsed");
|
||||||
|
bloomFilterOffHeapMemoryUsed = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/bloom_filter_off_heap_memory_used",
|
||||||
|
"BloomFilterOffHeapMemoryUsed");
|
||||||
|
indexSummaryOffHeapMemoryUsed = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/index_summary_off_heap_memory_used",
|
||||||
|
"IndexSummaryOffHeapMemoryUsed");
|
||||||
|
compressionMetadataOffHeapMemoryUsed = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/compression_metadata_off_heap_memory_used",
|
||||||
|
"CompressionMetadataOffHeapMemoryUsed");
|
||||||
|
speculativeRetries = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/speculative_retries",
|
||||||
|
"SpeculativeRetries");
|
||||||
|
keyCacheHitRate = Metrics.newGauge(
|
||||||
|
factory.createMetricName("KeyCacheHitRate"),
|
||||||
|
new Gauge<Double>() {
|
||||||
|
@Override
|
||||||
|
public Double value() {
|
||||||
|
return c.getDoubleValue("/column_family/metrics/key_cache_hit_rate/"
|
||||||
|
+ cfName);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tombstoneScannedHistogram = createColumnFamilyHistogram(
|
||||||
|
"/column_family/metrics/tombstone_scanned_histogram",
|
||||||
|
"TombstoneScannedHistogram");
|
||||||
|
liveScannedHistogram = createColumnFamilyHistogram(
|
||||||
|
"/column_family/metrics/live_scanned_histogram",
|
||||||
|
"LiveScannedHistogram");
|
||||||
|
colUpdateTimeDeltaHistogram = createColumnFamilyHistogram(
|
||||||
|
"/column_family/metrics/col_update_time_delta_histogram",
|
||||||
|
"ColUpdateTimeDeltaHistogram");
|
||||||
|
coordinatorReadLatency = APIMetrics.newTimer("/column_family/metrics/coordinator/read/" + cfName,
|
||||||
|
factory.createMetricName("CoordinatorReadLatency"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
|
coordinatorScanLatency = APIMetrics.newTimer("/column_family/metrics/coordinator/scan/" + cfName,
|
||||||
|
factory.createMetricName("CoordinatorScanLatency"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
|
waitingOnFreeMemtableSpace = APIMetrics.newTimer("/column_family/metrics/waiting_on_free_memtable/" + cfName,
|
||||||
|
factory.createMetricName("WaitingOnFreeMemtableSpace"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
trueSnapshotsSize = createColumnFamilyGauge(
|
||||||
|
"/column_family/metrics/snapshots_size", "SnapshotsSize");
|
||||||
|
rowCacheHitOutOfRange = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/row_cache_hit_out_of_range",
|
||||||
|
"RowCacheHitOutOfRange");
|
||||||
|
rowCacheHit = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/row_cache_hit", "RowCacheHit");
|
||||||
|
rowCacheMiss = createColumnFamilyCounter(
|
||||||
|
"/column_family/metrics/row_cache_miss", "RowCacheMiss");
|
||||||
|
|
||||||
|
casPrepare = new LatencyMetrics("/column_family/metrics/cas_prepare/"
|
||||||
|
+ cfName, factory, "CasPrepare");
|
||||||
|
casPropose = new LatencyMetrics("/column_family/metrics/cas_propose/"
|
||||||
|
+ cfName, factory, "CasPropose");
|
||||||
|
casCommit = new LatencyMetrics("/column_family/metrics/cas_commit/"
|
||||||
|
+ cfName, factory, "CasCommit");
|
||||||
|
sstablesPerRead = new EstimatedHistogramWrapper("/column_family/metrics/sstables_per_read_histogram/" + cfName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Release all associated metrics.
|
||||||
|
*/
|
||||||
|
public void release() {
|
||||||
|
for (String name : all) {
|
||||||
|
allColumnFamilyMetrics.get(name).remove(
|
||||||
|
Metrics.defaultRegistry().allMetrics()
|
||||||
|
.get(factory.createMetricName(name)));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName(name));
|
||||||
|
}
|
||||||
|
readLatency.release();
|
||||||
|
writeLatency.release();
|
||||||
|
rangeLatency.release();
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("EstimatedRowSizeHistogram"));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("EstimatedColumnCountHistogram"));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("KeyCacheHitRate"));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("CoordinatorReadLatency"));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("CoordinatorScanLatency"));
|
||||||
|
Metrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName("WaitingOnFreeMemtableSpace"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a gauge that will be part of a merged version of all column
|
||||||
|
* families. The global gauge will merge each CF gauge by adding their
|
||||||
|
* values
|
||||||
|
*/
|
||||||
|
protected Gauge<Double> createColumnFamilyGaugeDouble(final String url,
|
||||||
|
final String name) {
|
||||||
|
Gauge<Double> gauge = new Gauge<Double>() {
|
||||||
|
public Double value() {
|
||||||
|
return c.getDoubleValue(url + "/" + cfName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return createColumnFamilyGauge(url, name, gauge);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a gauge that will be part of a merged version of all column
|
||||||
|
* families. The global gauge will merge each CF gauge by adding their
|
||||||
|
* values
|
||||||
|
*/
|
||||||
|
protected Gauge<Long> createColumnFamilyGauge(final String url, final String name) {
|
||||||
|
Gauge<Long> gauge = new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
return (long)c.getDoubleValue(url + "/" + cfName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return createColumnFamilyGauge(url, name, gauge);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a gauge that will be part of a merged version of all column
|
||||||
|
* families. The global gauge will merge each CF gauge by adding their
|
||||||
|
* values
|
||||||
|
*/
|
||||||
|
protected Gauge<Integer> createColumnFamilyGaugeInt(final String url,
|
||||||
|
final String name) {
|
||||||
|
Gauge<Integer> gauge = new Gauge<Integer>() {
|
||||||
|
public Integer value() {
|
||||||
|
return (int)c.getDoubleValue(url + "/" + cfName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return createColumnFamilyGauge(url, name, gauge);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a gauge that will be part of a merged version of all column
|
||||||
|
* families. The global gauge will merge each CF gauge by adding their
|
||||||
|
* values
|
||||||
|
*/
|
||||||
|
protected <T extends Number> Gauge<T> createColumnFamilyGauge(final String url,
|
||||||
|
final String name, Gauge<T> gauge) {
|
||||||
|
return createColumnFamilyGauge(name, gauge, new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
// This is an optimiztion, call once for all column families
|
||||||
|
// instead
|
||||||
|
// of iterating over all of them
|
||||||
|
return c.getLongValue(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a gauge that will be part of a merged version of all column
|
||||||
|
* families. The global gauge is defined as the globalGauge parameter
|
||||||
|
*/
|
||||||
|
protected <G, T> Gauge<T> createColumnFamilyGauge(String name,
|
||||||
|
Gauge<T> gauge, Gauge<G> globalGauge) {
|
||||||
|
Gauge<T> cfGauge = APIMetrics.newGauge(factory.createMetricName(name),
|
||||||
|
gauge);
|
||||||
|
if (register(name, cfGauge)) {
|
||||||
|
Metrics.newGauge(globalNameFactory.createMetricName(name),
|
||||||
|
globalGauge);
|
||||||
|
}
|
||||||
|
return cfGauge;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a counter that will also have a global counter thats the sum of
|
||||||
|
* all counters across different column families
|
||||||
|
*/
|
||||||
|
protected Counter createColumnFamilyCounter(final String url, final String name) {
|
||||||
|
Counter cfCounter = APIMetrics.newCounter(url + "/" + cfName,
|
||||||
|
factory.createMetricName(name));
|
||||||
|
if (register(name, cfCounter)) {
|
||||||
|
Metrics.newGauge(globalNameFactory.createMetricName(name),
|
||||||
|
new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
// This is an optimiztion, call once for all column
|
||||||
|
// families instead
|
||||||
|
// of iterating over all of them
|
||||||
|
return c.getLongValue(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return cfCounter;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a histogram-like interface that will register both a CF, keyspace
|
||||||
|
* and global level histogram and forward any updates to both
|
||||||
|
*/
|
||||||
|
protected ColumnFamilyHistogram createColumnFamilyHistogram(String url,
|
||||||
|
String name) {
|
||||||
|
Histogram cfHistogram = APIMetrics.newHistogram(url + "/" + cfName,
|
||||||
|
factory.createMetricName(name), true);
|
||||||
|
register(name, cfHistogram);
|
||||||
|
|
||||||
|
// TBD add keyspace and global histograms
|
||||||
|
// keyspaceHistogram,
|
||||||
|
// Metrics.newHistogram(globalNameFactory.createMetricName(name),
|
||||||
|
// true));
|
||||||
|
return new ColumnFamilyHistogram(cfHistogram, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a metric to be removed when unloading CF.
|
||||||
|
*
|
||||||
|
* @return true if first time metric with that name has been registered
|
||||||
|
*/
|
||||||
|
private boolean register(String name, Metric metric) {
|
||||||
|
boolean ret = allColumnFamilyMetrics.putIfAbsent(name,
|
||||||
|
new HashSet<Metric>()) == null;
|
||||||
|
allColumnFamilyMetrics.get(name).add(metric);
|
||||||
|
all.add(name);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getRecentSSTablesPerRead() {
|
||||||
|
return recentSSTablesPerRead
|
||||||
|
.getBuckets(sstablesPerRead.getBuckets(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ColumnFamilyHistogram {
|
||||||
|
public final Histogram[] all;
|
||||||
|
public final Histogram cf;
|
||||||
|
|
||||||
|
private ColumnFamilyHistogram(Histogram cf, Histogram keyspace,
|
||||||
|
Histogram global) {
|
||||||
|
this.cf = cf;
|
||||||
|
this.all = new Histogram[] { cf, keyspace, global };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ColumnFamilyMetricNameFactory implements MetricNameFactory {
|
||||||
|
private final String keyspaceName;
|
||||||
|
private final String columnFamilyName;
|
||||||
|
private final boolean isIndex;
|
||||||
|
|
||||||
|
ColumnFamilyMetricNameFactory(ColumnFamilyStore cfs) {
|
||||||
|
this.keyspaceName = cfs.getKeyspace();
|
||||||
|
this.columnFamilyName = cfs.getColumnFamilyName();
|
||||||
|
isIndex = cfs.isIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MetricName createMetricName(String metricName) {
|
||||||
|
String groupName = ColumnFamilyMetrics.class.getPackage().getName();
|
||||||
|
String type = isIndex ? "IndexColumnFamily" : "ColumnFamily";
|
||||||
|
|
||||||
|
StringBuilder mbeanName = new StringBuilder();
|
||||||
|
mbeanName.append(groupName).append(":");
|
||||||
|
mbeanName.append("type=").append(type);
|
||||||
|
mbeanName.append(",keyspace=").append(keyspaceName);
|
||||||
|
mbeanName.append(",scope=").append(columnFamilyName);
|
||||||
|
mbeanName.append(",name=").append(metricName);
|
||||||
|
return new MetricName(groupName, type, metricName, keyspaceName
|
||||||
|
+ "." + columnFamilyName, mbeanName.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class AllColumnFamilyMetricNameFactory implements MetricNameFactory {
|
||||||
|
public MetricName createMetricName(String metricName) {
|
||||||
|
String groupName = ColumnFamilyMetrics.class.getPackage().getName();
|
||||||
|
StringBuilder mbeanName = new StringBuilder();
|
||||||
|
mbeanName.append(groupName).append(":");
|
||||||
|
mbeanName.append("type=ColumnFamily");
|
||||||
|
mbeanName.append(",name=").append(metricName);
|
||||||
|
return new MetricName(groupName, "ColumnFamily", metricName, "all",
|
||||||
|
mbeanName.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,38 +23,65 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.yammer.metrics.core.Gauge;
|
||||||
|
import com.yammer.metrics.core.Timer;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics for commit log
|
* Metrics for commit log
|
||||||
*/
|
*/
|
||||||
public class CommitLogMetrics implements Metrics {
|
public class CommitLogMetrics {
|
||||||
public CommitLogMetrics() {
|
public static final MetricNameFactory factory = new DefaultNameFactory(
|
||||||
}
|
"CommitLog");
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
|
||||||
@Override
|
/** Number of completed tasks */
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
public final Gauge<Long> completedTasks;
|
||||||
MetricNameFactory factory = new DefaultNameFactory("CommitLog");
|
/** Number of pending tasks */
|
||||||
/** Number of completed tasks */
|
public final Gauge<Long> pendingTasks;
|
||||||
registry.register(() -> registry.gauge("/commitlog/metrics/completed_tasks"),
|
/** Current size used by all the commit log segments */
|
||||||
factory.createMetricName("CompletedTasks"));
|
public final Gauge<Long> totalCommitLogSize;
|
||||||
/** Number of pending tasks */
|
/**
|
||||||
registry.register(() -> registry.gauge("/commitlog/metrics/pending_tasks"),
|
* Time spent waiting for a CLS to be allocated - under normal conditions
|
||||||
factory.createMetricName("PendingTasks"));
|
* this should be zero
|
||||||
/** Current size used by all the commit log segments */
|
*/
|
||||||
registry.register(() -> registry.gauge("/commitlog/metrics/total_commit_log_size"),
|
public final Timer waitingOnSegmentAllocation;
|
||||||
factory.createMetricName("TotalCommitLogSize"));
|
/**
|
||||||
/**
|
* The time spent waiting on CL sync; for Periodic this is only occurs when
|
||||||
* Time spent waiting for a CLS to be allocated - under normal
|
* the sync is lagging its sync interval
|
||||||
* conditions this should be zero
|
*/
|
||||||
*/
|
public final Timer waitingOnCommit;
|
||||||
registry.register(() -> registry.timer("/commitlog/metrics/waiting_on_segment_allocation"),
|
|
||||||
factory.createMetricName("WaitingOnSegmentAllocation"));
|
public CommitLogMetrics() {
|
||||||
/**
|
completedTasks = APIMetrics.newGauge(
|
||||||
* The time spent waiting on CL sync; for Periodic this is only occurs
|
factory.createMetricName("CompletedTasks"), new Gauge<Long>() {
|
||||||
* when the sync is lagging its sync interval
|
public Long value() {
|
||||||
*/
|
return c.getLongValue("/commitlog/metrics/completed_tasks");
|
||||||
registry.register(() -> registry.timer("/commitlog/metrics/waiting_on_commit"),
|
}
|
||||||
factory.createMetricName("WaitingOnCommit"));
|
});
|
||||||
|
pendingTasks = APIMetrics.newGauge(
|
||||||
|
factory.createMetricName("PendingTasks"), new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
return c.getLongValue("/commitlog/metrics/pending_tasks");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
totalCommitLogSize = APIMetrics.newGauge(
|
||||||
|
factory.createMetricName("TotalCommitLogSize"),
|
||||||
|
new Gauge<Long>() {
|
||||||
|
public Long value() {
|
||||||
|
return c.getLongValue("/commitlog/metrics/total_commit_log_size");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
waitingOnSegmentAllocation = APIMetrics.newTimer("/commit_log/metrics/waiting_on_segment_allocation",
|
||||||
|
factory.createMetricName("WaitingOnSegmentAllocation"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
|
waitingOnCommit = APIMetrics.newTimer("/commit_log/metrics/waiting_on_commit",
|
||||||
|
factory.createMetricName("WaitingOnCommit"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,54 +23,52 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
import java.util.concurrent.TimeUnit;
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
import com.yammer.metrics.core.Gauge;
|
||||||
|
import com.yammer.metrics.core.APIMeter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics for compaction.
|
* Metrics for compaction.
|
||||||
*/
|
*/
|
||||||
public class CompactionMetrics implements Metrics {
|
public class CompactionMetrics {
|
||||||
|
public static final MetricNameFactory factory = new DefaultNameFactory(
|
||||||
|
"Compaction");
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
/** Estimated number of compactions remaining to perform */
|
||||||
|
public final Gauge<Integer> pendingTasks;
|
||||||
|
/** Number of completed compactions since server [re]start */
|
||||||
|
public final Gauge<Long> completedTasks;
|
||||||
|
/** Total number of compactions since server [re]start */
|
||||||
|
public final APIMeter totalCompactionsCompleted;
|
||||||
|
/** Total number of bytes compacted since server [re]start */
|
||||||
|
public final Counter bytesCompacted;
|
||||||
|
|
||||||
public CompactionMetrics() {
|
public CompactionMetrics() {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
pendingTasks = APIMetrics.newGauge(
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
factory.createMetricName("PendingTasks"), new Gauge<Integer>() {
|
||||||
MetricNameFactory factory = new DefaultNameFactory("Compaction");
|
public Integer value() {
|
||||||
/** Estimated number of compactions remaining to perform */
|
return c.getIntValue("/compaction_manager/metrics/pending_tasks");
|
||||||
registry.register(() -> registry.gauge(Integer.class, "/compaction_manager/metrics/pending_tasks"),
|
}
|
||||||
factory.createMetricName("PendingTasks"));
|
});
|
||||||
/** Number of completed compactions since server [re]start */
|
completedTasks = APIMetrics.newGauge(
|
||||||
registry.register(() -> registry.gauge("/compaction_manager/metrics/completed_tasks"),
|
factory.createMetricName("CompletedTasks"), new Gauge<Long>() {
|
||||||
factory.createMetricName("CompletedTasks"));
|
public Long value() {
|
||||||
/** Total number of compactions since server [re]start */
|
return c.getLongValue("/compaction_manager/metrics/completed_tasks");
|
||||||
registry.register(() -> registry.meter("/compaction_manager/metrics/total_compactions_completed"),
|
}
|
||||||
factory.createMetricName("TotalCompactionsCompleted"));
|
});
|
||||||
/** Total number of bytes compacted since server [re]start */
|
totalCompactionsCompleted = APIMetrics.newMeter(
|
||||||
registry.register(() -> registry.meter("/compaction_manager/metrics/bytes_compacted"),
|
"/compaction_manager/metrics/total_compactions_completed",
|
||||||
|
factory.createMetricName("TotalCompactionsCompleted"),
|
||||||
|
"compaction completed", TimeUnit.SECONDS);
|
||||||
|
bytesCompacted = APIMetrics.newCounter(
|
||||||
|
"/compaction_manager/metrics/bytes_compacted",
|
||||||
factory.createMetricName("BytesCompacted"));
|
factory.createMetricName("BytesCompacted"));
|
||||||
|
|
||||||
registry.register(() -> registry.gauge((client) -> {
|
|
||||||
Map<String, Map<String, Integer>> result = new HashMap<>();
|
|
||||||
JsonArray compactions = client.getJsonArray("compaction_manager/metrics/pending_tasks_by_table");
|
|
||||||
|
|
||||||
for (int i = 0; i < compactions.size(); i++) {
|
|
||||||
JsonObject c = compactions.getJsonObject(i);
|
|
||||||
|
|
||||||
String ks = c.getString("ks");
|
|
||||||
String cf = c.getString("cf");
|
|
||||||
|
|
||||||
if (!result.containsKey(ks)) {
|
|
||||||
result.put(ks, new HashMap<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Integer> map = result.get(ks);
|
|
||||||
map.put(cf, (int)(c.getJsonNumber("task").longValue()));
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}), factory.createMetricName("PendingTasksByTableName"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,27 +24,42 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.apache.cassandra.net.MessagingService;
|
import org.apache.cassandra.net.MessagingService;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.yammer.metrics.core.APIMeter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics for dropped messages by verb.
|
* Metrics for dropped messages by verb.
|
||||||
*/
|
*/
|
||||||
public class DroppedMessageMetrics implements Metrics {
|
public class DroppedMessageMetrics {
|
||||||
private final MessagingService.Verb verb;
|
/** Number of dropped messages */
|
||||||
|
public final APIMeter dropped;
|
||||||
|
|
||||||
|
private long lastDropped = 0;
|
||||||
|
|
||||||
public DroppedMessageMetrics(MessagingService.Verb verb) {
|
public DroppedMessageMetrics(MessagingService.Verb verb) {
|
||||||
this.verb = verb;
|
MetricNameFactory factory = new DefaultNameFactory("DroppedMessage",
|
||||||
|
verb.toString());
|
||||||
|
dropped = (APIMeter) APIMetrics.newMeter(null,
|
||||||
|
factory.createMetricName("Dropped"), "dropped",
|
||||||
|
TimeUnit.SECONDS);
|
||||||
|
dropped.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Deprecated
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
public int getRecentlyDropped() {
|
||||||
MetricNameFactory factory = new DefaultNameFactory("DroppedMessage", verb.toString());
|
long currentDropped = dropped.count();
|
||||||
/** Number of dropped messages */
|
long recentlyDropped = currentDropped - lastDropped;
|
||||||
// TODO: this API url does not exist. Add meter calls for verbs.
|
lastDropped = currentDropped;
|
||||||
registry.register(() -> registry.meter("/messaging_service/messages/dropped/" + verb),
|
return (int) recentlyDropped;
|
||||||
factory.createMetricName("Dropped"));
|
}
|
||||||
|
|
||||||
|
public APIMeter getMeter() {
|
||||||
|
return dropped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
package org.apache.cassandra.metrics;
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2015 ScyllaDB
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Scylla.
|
||||||
|
*
|
||||||
|
* Scylla is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Scylla is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
|
import com.scylladb.jmx.api.APIClient;
|
||||||
|
import com.scylladb.jmx.utils.EstimatedHistogram;
|
||||||
|
|
||||||
|
public class EstimatedHistogramWrapper {
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
private String url;
|
||||||
|
private MultivaluedMap<String, String> queryParams;
|
||||||
|
private static final int DURATION = 50;
|
||||||
|
private int duration;
|
||||||
|
public EstimatedHistogramWrapper(String url, MultivaluedMap<String, String> queryParams, int duration) {
|
||||||
|
this.url = url;
|
||||||
|
this.queryParams = queryParams;
|
||||||
|
this.duration = duration;
|
||||||
|
|
||||||
|
}
|
||||||
|
public EstimatedHistogramWrapper(String url) {
|
||||||
|
this(url, null, DURATION);
|
||||||
|
|
||||||
|
}
|
||||||
|
public EstimatedHistogramWrapper(String url, int duration) {
|
||||||
|
this(url, null, duration);
|
||||||
|
|
||||||
|
}
|
||||||
|
public EstimatedHistogram get() {
|
||||||
|
return c.getEstimatedHistogram(url, queryParams, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getBuckets(boolean reset) {
|
||||||
|
return get().getBuckets(reset);
|
||||||
|
}
|
||||||
|
}
|
@ -23,19 +23,41 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import com.google.common.collect.ImmutableList;
|
||||||
import javax.management.ObjectName;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.scylladb.jmx.utils.RecentEstimatedHistogram;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
import com.yammer.metrics.core.Timer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics about latencies
|
* Metrics about latencies
|
||||||
*/
|
*/
|
||||||
public class LatencyMetrics implements Metrics {
|
public class LatencyMetrics {
|
||||||
protected final MetricNameFactory[] factories;
|
/** Latency */
|
||||||
|
public final Timer latency;
|
||||||
|
/** Total latency in micro sec */
|
||||||
|
public final Counter totalLatency;
|
||||||
|
|
||||||
|
/** parent metrics to replicate any updates to **/
|
||||||
|
private List<LatencyMetrics> parents = Lists.newArrayList();
|
||||||
|
|
||||||
|
protected final MetricNameFactory factory;
|
||||||
protected final String namePrefix;
|
protected final String namePrefix;
|
||||||
protected final String uri;
|
|
||||||
protected final String param;
|
@Deprecated public EstimatedHistogramWrapper totalLatencyHistogram;
|
||||||
|
/*
|
||||||
|
* It should not be called directly, use the getRecentLatencyHistogram
|
||||||
|
*/
|
||||||
|
@Deprecated protected final RecentEstimatedHistogram recentLatencyHistogram = new RecentEstimatedHistogram();
|
||||||
|
|
||||||
|
protected long lastLatency;
|
||||||
|
protected long lastOpCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create LatencyMetrics with given group, type, and scope. Name prefix for
|
* Create LatencyMetrics with given group, type, and scope. Name prefix for
|
||||||
@ -46,8 +68,8 @@ public class LatencyMetrics implements Metrics {
|
|||||||
* @param scope
|
* @param scope
|
||||||
* Scope
|
* Scope
|
||||||
*/
|
*/
|
||||||
public LatencyMetrics(String type, String scope, String uri) {
|
public LatencyMetrics(String url, String type, String scope) {
|
||||||
this(type, "", scope, uri, null);
|
this(url, type, "", scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,35 +83,83 @@ public class LatencyMetrics implements Metrics {
|
|||||||
* @param scope
|
* @param scope
|
||||||
* Scope of metrics
|
* Scope of metrics
|
||||||
*/
|
*/
|
||||||
public LatencyMetrics(String type, String namePrefix, String scope, String uri, String param) {
|
public LatencyMetrics(String url, String type, String namePrefix,
|
||||||
this(namePrefix, uri, param, new DefaultNameFactory(type, scope));
|
String scope) {
|
||||||
|
this(url, new DefaultNameFactory(type, scope), namePrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LatencyMetrics(String namePrefix, String uri, MetricNameFactory... factories) {
|
/**
|
||||||
this(namePrefix, uri, null, factories);
|
* Create LatencyMetrics with given group, type, prefix to append to each
|
||||||
|
* metric name, and scope.
|
||||||
|
*
|
||||||
|
* @param factory
|
||||||
|
* MetricName factory to use
|
||||||
|
* @param namePrefix
|
||||||
|
* Prefix to append to each metric name
|
||||||
|
*/
|
||||||
|
public LatencyMetrics(String url, MetricNameFactory factory,
|
||||||
|
String namePrefix) {
|
||||||
|
this(url, null, factory, namePrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LatencyMetrics(String namePrefix, String uri, String param, MetricNameFactory... factories) {
|
public LatencyMetrics(String url, String paramName,
|
||||||
this.factories = factories;
|
MetricNameFactory factory, String namePrefix) {
|
||||||
|
this.factory = factory;
|
||||||
this.namePrefix = namePrefix;
|
this.namePrefix = namePrefix;
|
||||||
this.uri = uri;
|
|
||||||
this.param = param;
|
paramName = (paramName == null)? "" : "/" + paramName;
|
||||||
|
latency = APIMetrics.newTimer(url + "/moving_average_histogram" + paramName,
|
||||||
|
factory.createMetricName(namePrefix + "Latency"),
|
||||||
|
TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
|
||||||
|
totalLatency = APIMetrics.newCounter(url + paramName,
|
||||||
|
factory.createMetricName(namePrefix + "TotalLatency"));
|
||||||
|
totalLatencyHistogram = new EstimatedHistogramWrapper(url + "/estimated_histogram" + paramName);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ObjectName[] names(String suffix) throws MalformedObjectNameException {
|
/**
|
||||||
return Arrays.stream(factories).map(f -> {
|
* Create LatencyMetrics with given group, type, prefix to append to each
|
||||||
try {
|
* metric name, and scope. Any updates to this will also run on parent
|
||||||
return f.createMetricName(namePrefix + suffix);
|
*
|
||||||
} catch (MalformedObjectNameException e) {
|
* @param factory
|
||||||
throw new RuntimeException(e); // dung...
|
* MetricName factory to use
|
||||||
}
|
* @param namePrefix
|
||||||
}).toArray(size -> new ObjectName[size]);
|
* Prefix to append to each metric name
|
||||||
|
* @param parents
|
||||||
|
* any amount of parents to replicate updates to
|
||||||
|
*/
|
||||||
|
public LatencyMetrics(String url, MetricNameFactory factory,
|
||||||
|
String namePrefix, LatencyMetrics... parents) {
|
||||||
|
this(url, factory, namePrefix);
|
||||||
|
this.parents.addAll(ImmutableList.copyOf(parents));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** takes nanoseconds **/
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
public void addNano(long nanos) {
|
||||||
String paramName = (param == null) ? "" : "/" + param;
|
// the object is only updated from the API
|
||||||
registry.register(() -> registry.timer(uri + "/moving_average_histogram" + paramName), names("Latency"));
|
}
|
||||||
registry.register(() -> registry.counter(uri + paramName), names("TotalLatency"));
|
|
||||||
|
public void release() {
|
||||||
|
APIMetrics.defaultRegistry()
|
||||||
|
.removeMetric(factory.createMetricName(namePrefix + "Latency"));
|
||||||
|
APIMetrics.defaultRegistry().removeMetric(
|
||||||
|
factory.createMetricName(namePrefix + "TotalLatency"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public synchronized double getRecentLatency() {
|
||||||
|
long ops = latency.count();
|
||||||
|
long n = totalLatency.count();
|
||||||
|
if (ops == lastOpCount)
|
||||||
|
return 0;
|
||||||
|
try {
|
||||||
|
return ((double) n - lastLatency) / (ops - lastOpCount);
|
||||||
|
} finally {
|
||||||
|
lastLatency = n;
|
||||||
|
lastOpCount = ops;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public long[] getRecentLatencyHistogram() {
|
||||||
|
return recentLatencyHistogram.getBuckets(totalLatencyHistogram.getBuckets(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
package org.apache.cassandra.metrics;
|
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action interface for any type that encapsulates n metrics.
|
|
||||||
*
|
|
||||||
* @author calle
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface Metrics {
|
|
||||||
/**
|
|
||||||
* Implementors should issue
|
|
||||||
* {@link MetricsRegistry#register(java.util.function.Supplier, javax.management.ObjectName...)}
|
|
||||||
* for every {@link Metrics} they generate. This method is called in both
|
|
||||||
* bind (create) and unbind (remove) phase, so an appropriate use of
|
|
||||||
* {@link Function} binding is advisable.
|
|
||||||
*
|
|
||||||
* @param registry
|
|
||||||
* @throws MalformedObjectNameException
|
|
||||||
*/
|
|
||||||
void register(MetricsRegistry registry) throws MalformedObjectNameException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as {{@link #register(MetricsRegistry)}, but for {@link Metric}s that
|
|
||||||
* are "global" (i.e. static - not bound to an individual bean instance.
|
|
||||||
* This method is called whenever the first encapsulating MBean is
|
|
||||||
* added/removed from a {@link MBeanServer}.
|
|
||||||
*
|
|
||||||
* @param registry
|
|
||||||
* @throws MalformedObjectNameException
|
|
||||||
*/
|
|
||||||
default void registerGlobals(MetricsRegistry registry) throws MalformedObjectNameException {
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,813 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.cassandra.metrics;
|
|
||||||
|
|
||||||
import static com.scylladb.jmx.api.APIClient.getReader;
|
|
||||||
import static java.lang.Math.floor;
|
|
||||||
import static java.util.logging.Level.SEVERE;
|
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
|
||||||
import jakarta.json.JsonNumber;
|
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.management.InstanceAlreadyExistsException;
|
|
||||||
import javax.management.MBeanRegistrationException;
|
|
||||||
import javax.management.MBeanServer;
|
|
||||||
import javax.management.NotCompliantMBeanException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Makes integrating 3.0 metrics API with 2.0.
|
|
||||||
* <p>
|
|
||||||
* The 3.0 API comes with poor JMX integration
|
|
||||||
* </p>
|
|
||||||
*/
|
|
||||||
public class MetricsRegistry {
|
|
||||||
private static final long CACHE_DURATION = 1000;
|
|
||||||
private static final long UPDATE_INTERVAL = 50;
|
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(MetricsRegistry.class.getName());
|
|
||||||
|
|
||||||
private final APIClient client;
|
|
||||||
private final JmxMBeanServer mBeanServer;
|
|
||||||
|
|
||||||
public MetricsRegistry(APIClient client, JmxMBeanServer mBeanServer) {
|
|
||||||
this.client = client;
|
|
||||||
this.mBeanServer = mBeanServer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricsRegistry(MetricsRegistry other) {
|
|
||||||
this(other.client, other.mBeanServer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricMBean gauge(String url) {
|
|
||||||
return gauge(Long.class, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> MetricMBean gauge(Class<T> type, final String url) {
|
|
||||||
return gauge(getReader(type), url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> MetricMBean gauge(final BiFunction<APIClient, String, T> function, final String url) {
|
|
||||||
return gauge(c -> function.apply(c, url));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> MetricMBean gauge(final Function<APIClient, T> function) {
|
|
||||||
return gauge(() -> function.apply(client));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JmxGauge implements JmxGaugeMBean {
|
|
||||||
private final Supplier<?> function;
|
|
||||||
|
|
||||||
public JmxGauge(Supplier<?> function) {
|
|
||||||
this.function = function;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getValue() {
|
|
||||||
return function.get();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> MetricMBean gauge(final Supplier<T> function) {
|
|
||||||
return new JmxGauge(function);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default approach to register is to actually register/add to
|
|
||||||
* {@link MBeanServer} For unbind phase, override here.
|
|
||||||
*
|
|
||||||
* @param bean
|
|
||||||
* @param objectNames
|
|
||||||
*/
|
|
||||||
public void register(Supplier<MetricMBean> f, ObjectName... objectNames) {
|
|
||||||
MetricMBean bean = f.get();
|
|
||||||
for (ObjectName name : objectNames) {
|
|
||||||
try {
|
|
||||||
mBeanServer.getMBeanServerInterceptor().registerMBean(bean, name);
|
|
||||||
} catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
|
|
||||||
logger.log(SEVERE, "Could not register mbean", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JmxCounter implements JmxCounterMBean {
|
|
||||||
private final String url;
|
|
||||||
|
|
||||||
public JmxCounter(String url) {
|
|
||||||
super();
|
|
||||||
this.url = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getCount() {
|
|
||||||
return client.getLongValue(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricMBean counter(final String url) {
|
|
||||||
if (url != null) {
|
|
||||||
return new JmxCounter(url);
|
|
||||||
}
|
|
||||||
return new JmxCounter(url) {
|
|
||||||
@Override
|
|
||||||
public long getCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private abstract class IntermediatelyUpdated {
|
|
||||||
private final long interval;
|
|
||||||
private final Supplier<JsonObject> supplier;
|
|
||||||
private long lastUpdate;
|
|
||||||
|
|
||||||
public IntermediatelyUpdated(String url, long interval) {
|
|
||||||
this.supplier = () -> client.getJsonObj(url, null);
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IntermediatelyUpdated(Supplier<JsonObject> supplier, long interval) {
|
|
||||||
this.supplier = supplier;
|
|
||||||
this.interval = interval;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void update(JsonObject obj);
|
|
||||||
|
|
||||||
public final void update() {
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
if (now - lastUpdate < interval) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JsonObject obj = supplier.get();
|
|
||||||
update(obj);
|
|
||||||
} finally {
|
|
||||||
lastUpdate = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Meter {
|
|
||||||
public final long count;
|
|
||||||
public final double oneMinuteRate;
|
|
||||||
public final double fiveMinuteRate;
|
|
||||||
public final double fifteenMinuteRate;
|
|
||||||
public final double meanRate;
|
|
||||||
|
|
||||||
public Meter(long count, double oneMinuteRate, double fiveMinuteRate, double fifteenMinuteRate,
|
|
||||||
double meanRate) {
|
|
||||||
this.count = count;
|
|
||||||
this.oneMinuteRate = oneMinuteRate;
|
|
||||||
this.fiveMinuteRate = fiveMinuteRate;
|
|
||||||
this.fifteenMinuteRate = fifteenMinuteRate;
|
|
||||||
this.meanRate = meanRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Meter() {
|
|
||||||
this(0, 0, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Meter(JsonObject obj) {
|
|
||||||
JsonArray rates = obj.getJsonArray("rates");
|
|
||||||
oneMinuteRate = rates.getJsonNumber(0).doubleValue();
|
|
||||||
fiveMinuteRate = rates.getJsonNumber(1).doubleValue();
|
|
||||||
fifteenMinuteRate = rates.getJsonNumber(2).doubleValue();
|
|
||||||
meanRate = obj.getJsonNumber("mean_rate").doubleValue();
|
|
||||||
count = obj.getJsonNumber("count").longValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final TimeUnit RATE_UNIT = TimeUnit.SECONDS;
|
|
||||||
private static final TimeUnit DURATION_UNIT = TimeUnit.MICROSECONDS;
|
|
||||||
private static final TimeUnit API_DURATION_UNIT = TimeUnit.MICROSECONDS;
|
|
||||||
private static final double DURATION_FACTOR = 1.0 / API_DURATION_UNIT.convert(1, DURATION_UNIT);
|
|
||||||
|
|
||||||
private static double toDuration(double micro) {
|
|
||||||
return micro * DURATION_FACTOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String unitString(TimeUnit u) {
|
|
||||||
String s = u.toString().toLowerCase(Locale.US);
|
|
||||||
return s.substring(0, s.length() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JmxMeter extends IntermediatelyUpdated implements JmxMeterMBean {
|
|
||||||
private Meter meter = new Meter();
|
|
||||||
|
|
||||||
public JmxMeter(String url, long interval) {
|
|
||||||
super(url, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
public JmxMeter(Supplier<JsonObject> supplier, long interval) {
|
|
||||||
super(supplier, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(JsonObject obj) {
|
|
||||||
meter = new Meter(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getCount() {
|
|
||||||
update();
|
|
||||||
return meter.count;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMeanRate() {
|
|
||||||
update();
|
|
||||||
return meter.meanRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getOneMinuteRate() {
|
|
||||||
update();
|
|
||||||
return meter.oneMinuteRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getFiveMinuteRate() {
|
|
||||||
update();
|
|
||||||
return meter.fiveMinuteRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getFifteenMinuteRate() {
|
|
||||||
update();
|
|
||||||
return meter.fifteenMinuteRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRateUnit() {
|
|
||||||
return "event/" + unitString(RATE_UNIT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricMBean meter(String url) {
|
|
||||||
return new JmxMeter(url, CACHE_DURATION);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long[] asLongArray(JsonArray a) {
|
|
||||||
return a.getValuesAs(JsonNumber.class).stream().mapToLong(n -> n.longValue()).toArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static interface Samples {
|
|
||||||
default double getValue(double quantile) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
default long[] getValues() {
|
|
||||||
return new long[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class BufferSamples implements Samples {
|
|
||||||
private final long[] samples;
|
|
||||||
|
|
||||||
public BufferSamples(long[] samples) {
|
|
||||||
this.samples = samples;
|
|
||||||
Arrays.sort(this.samples);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] getValues() {
|
|
||||||
return samples;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue(double quantile) {
|
|
||||||
if (quantile < 0.0 || quantile > 1.0) {
|
|
||||||
throw new IllegalArgumentException(quantile + " is not in [0..1]");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (samples.length == 0) {
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
final double pos = quantile * (samples.length + 1);
|
|
||||||
|
|
||||||
if (pos < 1) {
|
|
||||||
return samples[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos >= samples.length) {
|
|
||||||
return samples[samples.length - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
final double lower = samples[(int) pos - 1];
|
|
||||||
final double upper = samples[(int) pos];
|
|
||||||
return lower + (pos - floor(pos)) * (upper - lower);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Histogram {
|
|
||||||
private final long count;
|
|
||||||
private final long min;
|
|
||||||
private final long max;
|
|
||||||
private final double mean;
|
|
||||||
private final double stdDev;
|
|
||||||
|
|
||||||
private final Samples samples;
|
|
||||||
|
|
||||||
public Histogram(long count, long min, long max, double mean, double stdDev, Samples samples) {
|
|
||||||
this.count = count;
|
|
||||||
this.min = min;
|
|
||||||
this.max = max;
|
|
||||||
this.mean = mean;
|
|
||||||
this.stdDev = stdDev;
|
|
||||||
this.samples = samples;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Histogram() {
|
|
||||||
this(0, 0, 0, 0, 0, new Samples() {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public Histogram(JsonObject obj) {
|
|
||||||
this(obj.getJsonNumber("count").longValue(), obj.getJsonNumber("min").longValue(),
|
|
||||||
obj.getJsonNumber("max").longValue(), obj.getJsonNumber("mean").doubleValue(),
|
|
||||||
obj.getJsonNumber("variance").doubleValue(), new BufferSamples(getValues(obj)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Histogram(EstimatedHistogram h) {
|
|
||||||
this(h.count(), h.min(), h.max(), h.mean(), 0, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long[] getValues(JsonObject obj) {
|
|
||||||
JsonArray arr = obj.getJsonArray("sample");
|
|
||||||
if (arr != null) {
|
|
||||||
return asLongArray(arr);
|
|
||||||
}
|
|
||||||
return new long[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public long[] getValues() {
|
|
||||||
return samples.getValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Origin (and previous iterations of scylla-jxm)
|
|
||||||
// uses biased/ExponentiallyDecaying measurements
|
|
||||||
// for the history & quantile resolution.
|
|
||||||
// However, for use that is just gobbletigook, since
|
|
||||||
// we, at occasions of being asked, and when certain time
|
|
||||||
// has passed, ask the actual scylla server for a
|
|
||||||
// "values" buffer. A buffer with no information whatsoever
|
|
||||||
// on how said values correlate to actual sampling
|
|
||||||
// time.
|
|
||||||
// So, applying time weights at this level is just
|
|
||||||
// wrong. We can just as well treat this as a uniform
|
|
||||||
// distribution.
|
|
||||||
// Obvious improvement: Send time/value tuples instead.
|
|
||||||
public double getValue(double quantile) {
|
|
||||||
return samples.getValue(quantile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCount() {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMin() {
|
|
||||||
return min;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getMax() {
|
|
||||||
return max;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getMean() {
|
|
||||||
return mean;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getStdDev() {
|
|
||||||
return stdDev;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class EstimatedHistogram implements Samples {
|
|
||||||
/**
|
|
||||||
* The series of values to which the counts in `buckets` correspond: 1,
|
|
||||||
* 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, etc. Thus, a `buckets` of
|
|
||||||
* [0, 0, 1, 10] would mean we had seen one value of 3 and 10 values of
|
|
||||||
* 4.
|
|
||||||
*
|
|
||||||
* The series starts at 1 and grows by 1.2 each time (rounding and
|
|
||||||
* removing duplicates). It goes from 1 to around 36M by default
|
|
||||||
* (creating 90+1 buckets), which will give us timing resolution from
|
|
||||||
* microseconds to 36 seconds, with less precision as the numbers get
|
|
||||||
* larger.
|
|
||||||
*
|
|
||||||
* Each bucket represents values from (previous bucket offset, current
|
|
||||||
* offset].
|
|
||||||
*/
|
|
||||||
private final long[] bucketOffsets;
|
|
||||||
// buckets is one element longer than bucketOffsets -- the last element
|
|
||||||
// is
|
|
||||||
// values greater than the last offset
|
|
||||||
private long[] buckets;
|
|
||||||
|
|
||||||
public EstimatedHistogram(JsonObject obj) {
|
|
||||||
this(asLongArray(obj.getJsonArray("bucket_offsets")), asLongArray(obj.getJsonArray("buckets")));
|
|
||||||
}
|
|
||||||
|
|
||||||
public EstimatedHistogram(long[] offsets, long[] bucketData) {
|
|
||||||
assert bucketData.length == offsets.length + 1;
|
|
||||||
bucketOffsets = offsets;
|
|
||||||
buckets = bucketData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the smallest value that could have been added to this
|
|
||||||
* histogram
|
|
||||||
*/
|
|
||||||
public long min() {
|
|
||||||
for (int i = 0; i < buckets.length; i++) {
|
|
||||||
if (buckets[i] > 0) {
|
|
||||||
return i == 0 ? 0 : 1 + bucketOffsets[i - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the largest value that could have been added to this
|
|
||||||
* histogram. If the histogram overflowed, returns
|
|
||||||
* Long.MAX_VALUE.
|
|
||||||
*/
|
|
||||||
public long max() {
|
|
||||||
int lastBucket = buckets.length - 1;
|
|
||||||
if (buckets[lastBucket] > 0) {
|
|
||||||
return Long.MAX_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = lastBucket - 1; i >= 0; i--) {
|
|
||||||
if (buckets[i] > 0) {
|
|
||||||
return bucketOffsets[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] getValues() {
|
|
||||||
return buckets;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param percentile
|
|
||||||
* @return estimated value at given percentile
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public double getValue(double percentile) {
|
|
||||||
assert percentile >= 0 && percentile <= 1.0;
|
|
||||||
int lastBucket = buckets.length - 1;
|
|
||||||
if (buckets[lastBucket] > 0) {
|
|
||||||
throw new IllegalStateException("Unable to compute when histogram overflowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
long pcount = (long) Math.floor(count() * percentile);
|
|
||||||
if (pcount == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
long elements = 0;
|
|
||||||
for (int i = 0; i < lastBucket; i++) {
|
|
||||||
elements += buckets[i];
|
|
||||||
if (elements >= pcount) {
|
|
||||||
return bucketOffsets[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the mean histogram value (average of bucket offsets, weighted
|
|
||||||
* by count)
|
|
||||||
* @throws IllegalStateException
|
|
||||||
* if any values were greater than the largest bucket
|
|
||||||
* threshold
|
|
||||||
*/
|
|
||||||
public long mean() {
|
|
||||||
int lastBucket = buckets.length - 1;
|
|
||||||
if (buckets[lastBucket] > 0) {
|
|
||||||
throw new IllegalStateException("Unable to compute ceiling for max when histogram overflowed");
|
|
||||||
}
|
|
||||||
|
|
||||||
long elements = 0;
|
|
||||||
long sum = 0;
|
|
||||||
for (int i = 0; i < lastBucket; i++) {
|
|
||||||
long bCount = buckets[i];
|
|
||||||
elements += bCount;
|
|
||||||
sum += bCount * bucketOffsets[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (long) Math.ceil((double) sum / elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the total number of non-zero values
|
|
||||||
*/
|
|
||||||
public long count() {
|
|
||||||
return Arrays.stream(buckets).sum();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if this histogram has overflowed -- that is, a value
|
|
||||||
* larger than our largest bucket could bound was added
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public boolean isOverflowed() {
|
|
||||||
return buckets[buckets.length - 1] > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JmxHistogram extends IntermediatelyUpdated implements JmxHistogramMBean {
|
|
||||||
private Histogram histogram = new Histogram();
|
|
||||||
|
|
||||||
public JmxHistogram(String url, long interval) {
|
|
||||||
super(url, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(JsonObject obj) {
|
|
||||||
if (obj.containsKey("hist")) {
|
|
||||||
obj = obj.getJsonObject("hist");
|
|
||||||
}
|
|
||||||
if (obj.containsKey("buckets")) {
|
|
||||||
histogram = new Histogram(new EstimatedHistogram(obj));
|
|
||||||
} else {
|
|
||||||
histogram = new Histogram(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getCount() {
|
|
||||||
update();
|
|
||||||
return histogram.getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getMin() {
|
|
||||||
update();
|
|
||||||
return histogram.getMin();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getMax() {
|
|
||||||
update();
|
|
||||||
return histogram.getMax();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMean() {
|
|
||||||
update();
|
|
||||||
return histogram.getMean();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getStdDev() {
|
|
||||||
update();
|
|
||||||
return histogram.getStdDev();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get50thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get75thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.75);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get95thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.95);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get98thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.98);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get99thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.99);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get999thPercentile() {
|
|
||||||
update();
|
|
||||||
return histogram.getValue(.999);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] values() {
|
|
||||||
update();
|
|
||||||
return histogram.getValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricMBean histogram(String url, boolean considerZeroes) {
|
|
||||||
return new JmxHistogram(url, UPDATE_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JmxTimer extends JmxMeter implements JmxTimerMBean {
|
|
||||||
private Histogram histogram = new Histogram();
|
|
||||||
|
|
||||||
public JmxTimer(String url, long interval) {
|
|
||||||
super(url, interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void update(JsonObject obj) {
|
|
||||||
// TODO: this is not atomic.
|
|
||||||
super.update(obj.getJsonObject("meter"));
|
|
||||||
histogram = new Histogram(obj.getJsonObject("hist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMin() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getMin());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMax() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getMax());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getMean() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getMean());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getStdDev() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getStdDev());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get50thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.5));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get75thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.75));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get95thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.95));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get98thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.98));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get99thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.99));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double get999thPercentile() {
|
|
||||||
update();
|
|
||||||
return toDuration(histogram.getValue(.999));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long[] values() {
|
|
||||||
update();
|
|
||||||
return histogram.getValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDurationUnit() {
|
|
||||||
update();
|
|
||||||
return DURATION_UNIT.toString().toLowerCase(Locale.US);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MetricMBean timer(String url) {
|
|
||||||
return new JmxTimer(url, UPDATE_INTERVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface MetricMBean {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static interface JmxGaugeMBean extends MetricMBean {
|
|
||||||
Object getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface JmxHistogramMBean extends MetricMBean {
|
|
||||||
long getCount();
|
|
||||||
|
|
||||||
long getMin();
|
|
||||||
|
|
||||||
long getMax();
|
|
||||||
|
|
||||||
double getMean();
|
|
||||||
|
|
||||||
double getStdDev();
|
|
||||||
|
|
||||||
double get50thPercentile();
|
|
||||||
|
|
||||||
double get75thPercentile();
|
|
||||||
|
|
||||||
double get95thPercentile();
|
|
||||||
|
|
||||||
double get98thPercentile();
|
|
||||||
|
|
||||||
double get99thPercentile();
|
|
||||||
|
|
||||||
double get999thPercentile();
|
|
||||||
|
|
||||||
long[] values();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface JmxCounterMBean extends MetricMBean {
|
|
||||||
long getCount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface JmxMeterMBean extends MetricMBean {
|
|
||||||
long getCount();
|
|
||||||
|
|
||||||
double getMeanRate();
|
|
||||||
|
|
||||||
double getOneMinuteRate();
|
|
||||||
|
|
||||||
double getFiveMinuteRate();
|
|
||||||
|
|
||||||
double getFifteenMinuteRate();
|
|
||||||
|
|
||||||
String getRateUnit();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface JmxTimerMBean extends JmxMeterMBean {
|
|
||||||
double getMin();
|
|
||||||
|
|
||||||
double getMax();
|
|
||||||
|
|
||||||
double getMean();
|
|
||||||
|
|
||||||
double getStdDev();
|
|
||||||
|
|
||||||
double get50thPercentile();
|
|
||||||
|
|
||||||
double get75thPercentile();
|
|
||||||
|
|
||||||
double get95thPercentile();
|
|
||||||
|
|
||||||
double get98thPercentile();
|
|
||||||
|
|
||||||
double get99thPercentile();
|
|
||||||
|
|
||||||
double get999thPercentile();
|
|
||||||
|
|
||||||
long[] values();
|
|
||||||
|
|
||||||
String getDurationUnit();
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,21 +23,27 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
|
import com.yammer.metrics.core.Counter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics related to Storage.
|
* Metrics related to Storage.
|
||||||
*/
|
*/
|
||||||
public class StorageMetrics implements Metrics {
|
public class StorageMetrics {
|
||||||
@Override
|
private static final MetricNameFactory factory = new DefaultNameFactory(
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
"Storage");
|
||||||
MetricNameFactory factory = new DefaultNameFactory("Storage");
|
|
||||||
registry.register(() -> registry.counter("/storage_service/metrics/load"), factory.createMetricName("Load"));
|
public static final Counter load = APIMetrics.newCounter(
|
||||||
registry.register(() -> registry.counter("/storage_service/metrics/exceptions"),
|
"/storage_service/metrics/load", factory.createMetricName("Load"));
|
||||||
factory.createMetricName("Exceptions"));
|
public static final Counter exceptions = APIMetrics.newCounter(
|
||||||
registry.register(() -> registry.counter("/storage_service/metrics/hints_in_progress"),
|
"/storage_service/metrics/exceptions",
|
||||||
factory.createMetricName("TotalHintsInProgress"));
|
factory.createMetricName("Exceptions"));
|
||||||
registry.register(() -> registry.counter("/storage_service/metrics/total_hints"),
|
public static final Counter totalHintsInProgress = APIMetrics.newCounter(
|
||||||
factory.createMetricName("TotalHints"));
|
"/storage_service/metrics/hints_in_progress",
|
||||||
}
|
factory.createMetricName("TotalHintsInProgress"));
|
||||||
|
public static final Counter totalHints = APIMetrics.newCounter(
|
||||||
|
"/storage_service/metrics/total_hints",
|
||||||
|
factory.createMetricName("TotalHints"));
|
||||||
}
|
}
|
||||||
|
@ -23,89 +23,84 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.metrics;
|
package org.apache.cassandra.metrics;
|
||||||
|
|
||||||
import static java.util.Arrays.asList;
|
|
||||||
import static org.apache.cassandra.metrics.DefaultNameFactory.createMetricName;
|
|
||||||
|
|
||||||
import jakarta.json.JsonArray;
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.util.HashMap;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
import javax.json.JsonArray;
|
||||||
import javax.management.ObjectName;
|
|
||||||
import javax.management.OperationsException;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.APIMBean;
|
import com.scylladb.jmx.metrics.APIMetrics;
|
||||||
import com.scylladb.jmx.metrics.RegistrationChecker;
|
import com.scylladb.jmx.metrics.DefaultNameFactory;
|
||||||
import com.scylladb.jmx.metrics.RegistrationMode;
|
import com.scylladb.jmx.metrics.MetricNameFactory;
|
||||||
import com.sun.jmx.mbeanserver.JmxMBeanServer;
|
import com.yammer.metrics.core.Counter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metrics for streaming.
|
* Metrics for streaming.
|
||||||
*/
|
*/
|
||||||
public class StreamingMetrics {
|
public class StreamingMetrics
|
||||||
|
{
|
||||||
public static final String TYPE_NAME = "Streaming";
|
public static final String TYPE_NAME = "Streaming";
|
||||||
|
private static final Map<String, StreamingMetrics> instances = new HashMap<String, StreamingMetrics>();
|
||||||
|
static final int INTERVAL = 1000; //update every 1second
|
||||||
|
|
||||||
private static final HashSet<ObjectName> globalNames;
|
private static Timer timer = new Timer("Streaming Metrics");
|
||||||
|
|
||||||
static {
|
public static final Counter activeStreamsOutbound = APIMetrics.newCounter("/stream_manager/metrics/outbound", DefaultNameFactory.createMetricName(TYPE_NAME, "ActiveOutboundStreams", null));
|
||||||
|
public static final Counter totalIncomingBytes = APIMetrics.newCounter("/stream_manager/metrics/incoming", DefaultNameFactory.createMetricName(TYPE_NAME, "TotalIncomingBytes", null));
|
||||||
|
public static final Counter totalOutgoingBytes = APIMetrics.newCounter("/stream_manager/metrics/outgoing", DefaultNameFactory.createMetricName(TYPE_NAME, "TotalOutgoingBytes", null));
|
||||||
|
public final Counter incomingBytes;
|
||||||
|
public final Counter outgoingBytes;
|
||||||
|
private static APIClient s_c = new APIClient();
|
||||||
|
|
||||||
|
public static void register_mbeans() {
|
||||||
|
TimerTask taskToExecute = new CheckRegistration();
|
||||||
|
timer.scheduleAtFixedRate(taskToExecute, 100, INTERVAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StreamingMetrics(final InetAddress peer)
|
||||||
|
{
|
||||||
|
MetricNameFactory factory = new DefaultNameFactory("Streaming", peer.getHostAddress().replaceAll(":", "."));
|
||||||
|
incomingBytes = APIMetrics.newCounter("/stream_manager/metrics/incoming/" + peer,factory.createMetricName("IncomingBytes"));
|
||||||
|
outgoingBytes= APIMetrics.newCounter("/stream_manager/metrics/outgoing/" + peer, factory.createMetricName("OutgoingBytes"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkRegistration() {
|
||||||
try {
|
try {
|
||||||
globalNames = new HashSet<ObjectName>(asList(createMetricName(TYPE_NAME, "ActiveOutboundStreams", null),
|
JsonArray streams = s_c.getJsonArray("/stream_manager/");
|
||||||
createMetricName(TYPE_NAME, "TotalIncomingBytes", null),
|
Set<String> all = new HashSet<String>();
|
||||||
createMetricName(TYPE_NAME, "TotalOutgoingBytes", null)));
|
for (int i = 0; i < streams.size(); i ++) {
|
||||||
} catch (MalformedObjectNameException e) {
|
JsonArray sessions = streams.getJsonObject(i).getJsonArray("sessions");
|
||||||
throw new Error(e);
|
for (int j = 0; j < sessions.size(); j++) {
|
||||||
|
String name = sessions.getJsonObject(j).getString("peer");
|
||||||
|
if (!instances.containsKey(name)) {
|
||||||
|
StreamingMetrics metrics = new StreamingMetrics(InetAddress.getByName(name));
|
||||||
|
instances.put(name, metrics);
|
||||||
|
}
|
||||||
|
all.add(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//removing deleted stream
|
||||||
|
for (String n : instances.keySet()) {
|
||||||
|
if (! all.contains(n)) {
|
||||||
|
instances.remove(n);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignoring exceptions, will retry on the next interval
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
return true;
|
||||||
|
|
||||||
private StreamingMetrics() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isStreamingName(ObjectName n) {
|
private static final class CheckRegistration extends TimerTask {
|
||||||
return TYPE_NAME.equals(n.getKeyProperty("type"));
|
@Override
|
||||||
|
public void run() {
|
||||||
|
checkRegistration();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RegistrationChecker createRegistrationChecker() {
|
|
||||||
return new RegistrationChecker() {
|
|
||||||
@Override
|
|
||||||
protected void doCheck(APIClient client, JmxMBeanServer server, EnumSet<RegistrationMode> mode) throws OperationsException, UnknownHostException {
|
|
||||||
Set<ObjectName> all = new HashSet<ObjectName>(globalNames);
|
|
||||||
JsonArray streams = client.getJsonArray("/stream_manager/");
|
|
||||||
for (int i = 0; i < streams.size(); i++) {
|
|
||||||
JsonArray sessions = streams.getJsonObject(i).getJsonArray("sessions");
|
|
||||||
for (int j = 0; j < sessions.size(); j++) {
|
|
||||||
String peer = sessions.getJsonObject(j).getString("peer");
|
|
||||||
String scope = InetAddress.getByName(peer).getHostAddress().replaceAll(":", ".");
|
|
||||||
all.add(createMetricName(TYPE_NAME, "IncomingBytes", scope));
|
|
||||||
all.add(createMetricName(TYPE_NAME, "OutgoingBytes", scope));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MetricsRegistry registry = new MetricsRegistry(client, server);
|
|
||||||
APIMBean.checkRegistration(server, all, mode, StreamingMetrics::isStreamingName, n -> {
|
|
||||||
String scope = n.getKeyProperty("scope");
|
|
||||||
String name = n.getKeyProperty("name");
|
|
||||||
|
|
||||||
String url = null;
|
|
||||||
if ("ActiveOutboundStreams".equals(name)) {
|
|
||||||
url = "/stream_manager/metrics/outbound";
|
|
||||||
} else if ("IncomingBytes".equals(name) || "TotalIncomingBytes".equals(name)) {
|
|
||||||
url = "/stream_manager/metrics/incoming";
|
|
||||||
} else if ("OutgoingBytes".equals(name) || "TotalOutgoingBytes".equals(name)) {
|
|
||||||
url = "/stream_manager/metrics/outgoing";
|
|
||||||
}
|
|
||||||
if (url == null) {
|
|
||||||
throw new IllegalArgumentException();
|
|
||||||
}
|
|
||||||
if (scope != null) {
|
|
||||||
url = url + "/" + scope;
|
|
||||||
}
|
|
||||||
return registry.counter(url);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,553 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.cassandra.metrics;
|
|
||||||
|
|
||||||
import static com.scylladb.jmx.api.APIClient.getReader;
|
|
||||||
|
|
||||||
import java.io.InvalidObjectException;
|
|
||||||
import java.io.ObjectStreamException;
|
|
||||||
import java.util.Hashtable;
|
|
||||||
import java.util.function.BiFunction;
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import javax.management.MalformedObjectNameException;
|
|
||||||
import javax.management.ObjectName;
|
|
||||||
|
|
||||||
import org.apache.cassandra.db.ColumnFamilyStore;
|
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Metrics for {@link ColumnFamilyStore}.
|
|
||||||
*/
|
|
||||||
public class TableMetrics implements Metrics {
|
|
||||||
private final MetricNameFactory factory;
|
|
||||||
private final MetricNameFactory aliasFactory;
|
|
||||||
private static final MetricNameFactory globalFactory = new AllTableMetricNameFactory("Table");
|
|
||||||
private static final MetricNameFactory globalAliasFactory = new AllTableMetricNameFactory("ColumnFamily");
|
|
||||||
private static final LatencyMetrics globalLatency[] = new LatencyMetrics[] {
|
|
||||||
new LatencyMetrics("Read", compose("read_latency"), globalFactory, globalAliasFactory),
|
|
||||||
new LatencyMetrics("Write", compose("read_latency"), globalFactory, globalAliasFactory),
|
|
||||||
new LatencyMetrics("Range", compose("read_latency"), globalFactory, globalAliasFactory), };
|
|
||||||
|
|
||||||
private final String cfName;
|
|
||||||
private final LatencyMetrics latencyMetrics[];
|
|
||||||
|
|
||||||
public TableMetrics(String keyspace, String columnFamily, boolean isIndex) {
|
|
||||||
this.factory = new TableMetricNameFactory(keyspace, columnFamily, isIndex, "Table");
|
|
||||||
this.aliasFactory = new TableMetricNameFactory(keyspace, columnFamily, isIndex, "ColumnFamily");
|
|
||||||
this.cfName = keyspace + ":" + columnFamily;
|
|
||||||
|
|
||||||
latencyMetrics = new LatencyMetrics[] {
|
|
||||||
new LatencyMetrics("Read", compose("read_latency"), cfName, factory, aliasFactory),
|
|
||||||
new LatencyMetrics("Write", compose("write_latency"), cfName, factory, aliasFactory),
|
|
||||||
new LatencyMetrics("Range", compose("range_latency"), cfName, factory, aliasFactory),
|
|
||||||
|
|
||||||
new LatencyMetrics("CasPrepare", compose("cas_prepare"), cfName, factory, aliasFactory),
|
|
||||||
new LatencyMetrics("CasPropose", compose("cas_propose"), cfName, factory, aliasFactory),
|
|
||||||
new LatencyMetrics("CasCommit", compose("cas_commit"), cfName, factory, aliasFactory), };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(MetricsRegistry registry) throws MalformedObjectNameException {
|
|
||||||
Registry r = new Registry(registry, factory, aliasFactory, cfName);
|
|
||||||
registerCommon(r);
|
|
||||||
registerLocal(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerGlobals(MetricsRegistry registry) throws MalformedObjectNameException {
|
|
||||||
Registry r = new Registry(registry, globalFactory, globalAliasFactory, null);
|
|
||||||
registerCommon(r);
|
|
||||||
for (LatencyMetrics l : globalLatency) {
|
|
||||||
l.register(registry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String compose(String base, String name) {
|
|
||||||
String s = "/column_family/metrics/" + base;
|
|
||||||
return name != null ? s + "/" + name : s;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String compose(String base) {
|
|
||||||
return compose(base, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates metrics for given {@link ColumnFamilyStore}.
|
|
||||||
*
|
|
||||||
* @param cfs
|
|
||||||
* ColumnFamilyStore to measure metrics
|
|
||||||
*/
|
|
||||||
static class Registry extends MetricsRegistry {
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private Function<APIClient, Long> newGauge(final String url) {
|
|
||||||
return newGauge(Long.class, url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> Function<APIClient, T> newGauge(BiFunction<APIClient, String, T> function, String url) {
|
|
||||||
return c -> {
|
|
||||||
return function.apply(c, url);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> Function<APIClient, T> newGauge(Class<T> type, final String url) {
|
|
||||||
return newGauge(getReader(type), url);
|
|
||||||
}
|
|
||||||
|
|
||||||
final MetricNameFactory factory;
|
|
||||||
final MetricNameFactory aliasFactory;
|
|
||||||
final String cfName;
|
|
||||||
final MetricsRegistry other;
|
|
||||||
|
|
||||||
public Registry(MetricsRegistry other, MetricNameFactory factory, MetricNameFactory aliasFactory,
|
|
||||||
String cfName) {
|
|
||||||
super(other);
|
|
||||||
this.other = other;
|
|
||||||
this.cfName = cfName;
|
|
||||||
this.factory = factory;
|
|
||||||
this.aliasFactory = aliasFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(Supplier<MetricMBean> f, ObjectName... objectNames) {
|
|
||||||
other.register(f, objectNames);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableGauge(String name, String uri) throws MalformedObjectNameException {
|
|
||||||
createTableGauge(name, name, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableGauge(String name, String alias, String uri) throws MalformedObjectNameException {
|
|
||||||
createTableGauge(Long.class, name, alias, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void createTableGauge(Class<T> c, String name, String uri) throws MalformedObjectNameException {
|
|
||||||
createTableGauge(c, c, name, name, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void createTableGauge(Class<T> c, String name, String alias, String uri) throws MalformedObjectNameException {
|
|
||||||
createTableGauge(c, name, alias, uri, getReader(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void createTableGauge(Class<T> c, String name, String uri, BiFunction<APIClient, String, T> f)
|
|
||||||
throws MalformedObjectNameException {
|
|
||||||
createTableGauge(c, name, name, uri, f);
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void createTableGauge(Class<T> c, String name, String alias, String uri,
|
|
||||||
BiFunction<APIClient, String, T> f) throws MalformedObjectNameException {
|
|
||||||
register(() -> gauge(newGauge(f, compose(uri, cfName))), factory.createMetricName(name),
|
|
||||||
aliasFactory.createMetricName(alias));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> BiFunction<APIClient, String, T> getDummy(Class<T> type) {
|
|
||||||
if (type == String.class) {
|
|
||||||
return (c, s) -> type.cast("");
|
|
||||||
} else if (type == Integer.class) {
|
|
||||||
return (c, s) -> type.cast(0);
|
|
||||||
} else if (type == Double.class) {
|
|
||||||
return (c, s) -> type.cast(0.0);
|
|
||||||
} else if (type == Long.class) {
|
|
||||||
return (c, s) -> type.cast(0L);
|
|
||||||
}
|
|
||||||
throw new IllegalArgumentException(type.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void createDummyTableGauge(Class<T> c, String name) throws MalformedObjectNameException {
|
|
||||||
register(() -> gauge(newGauge(getDummy(c), null)), factory.createMetricName(name),
|
|
||||||
aliasFactory.createMetricName(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public <L, G> void createTableGauge(Class<L> c1, Class<G> c2, String name, String alias, String uri)
|
|
||||||
throws MalformedObjectNameException {
|
|
||||||
if (cfName != null) {
|
|
||||||
createTableGauge(c1, name, alias, uri, getReader(c1));
|
|
||||||
} else { // global case
|
|
||||||
createTableGauge(c2, name, alias, uri, getReader(c2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableCounter(String name, String uri) throws MalformedObjectNameException {
|
|
||||||
createTableCounter(name, name, uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableCounter(String name, String alias, String uri) throws MalformedObjectNameException {
|
|
||||||
register(() -> counter(compose(uri, cfName)), factory.createMetricName(name),
|
|
||||||
aliasFactory.createMetricName(alias));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createDummyTableCounter(String name) throws MalformedObjectNameException {
|
|
||||||
register(() -> counter(null), factory.createMetricName(name),
|
|
||||||
aliasFactory.createMetricName(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableHistogram(String name, String uri, boolean considerZeros)
|
|
||||||
throws MalformedObjectNameException {
|
|
||||||
createTableHistogram(name, name, uri, considerZeros);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTableHistogram(String name, String alias, String uri, boolean considerZeros)
|
|
||||||
throws MalformedObjectNameException {
|
|
||||||
register(() -> histogram(compose(uri, cfName), considerZeros), factory.createMetricName(name),
|
|
||||||
aliasFactory.createMetricName(alias));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTimer(String name, String uri) throws MalformedObjectNameException {
|
|
||||||
register(() -> timer(compose(uri, cfName)), factory.createMetricName(name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerLocal(Registry registry) throws MalformedObjectNameException {
|
|
||||||
registry.createTableGauge(long[].class, "EstimatedPartitionSizeHistogram", "EstimatedRowSizeHistogram",
|
|
||||||
"estimated_row_size_histogram", APIClient::getEstimatedHistogramAsLongArrValue);
|
|
||||||
registry.createTableGauge("EstimatedPartitionCount", "EstimatedRowCount", "estimated_row_count");
|
|
||||||
|
|
||||||
registry.createTableGauge(long[].class, "EstimatedColumnCountHistogram", "estimated_column_count_histogram",
|
|
||||||
APIClient::getEstimatedHistogramAsLongArrValue);
|
|
||||||
registry.createTableGauge(Double.class, "KeyCacheHitRate", "key_cache_hit_rate");
|
|
||||||
|
|
||||||
registry.createTimer("CoordinatorReadLatency", "coordinator/read");
|
|
||||||
registry.createTimer("CoordinatorScanLatency", "coordinator/scan");
|
|
||||||
registry.createTimer("WaitingOnFreeMemtableSpace", "waiting_on_free_memtable");
|
|
||||||
|
|
||||||
for (LatencyMetrics l : latencyMetrics) {
|
|
||||||
l.register(registry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: implement
|
|
||||||
registry.createDummyTableCounter("DroppedMutations");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void registerCommon(Registry registry) throws MalformedObjectNameException {
|
|
||||||
registry.createTableGauge("MemtableColumnsCount", "memtable_columns_count");
|
|
||||||
registry.createTableGauge("MemtableOnHeapSize", "memtable_on_heap_size");
|
|
||||||
registry.createTableGauge("MemtableOffHeapSize", "memtable_off_heap_size");
|
|
||||||
registry.createTableGauge("MemtableLiveDataSize", "memtable_live_data_size");
|
|
||||||
registry.createTableGauge("AllMemtablesHeapSize", "all_memtables_on_heap_size");
|
|
||||||
registry.createTableGauge("AllMemtablesOffHeapSize", "all_memtables_off_heap_size");
|
|
||||||
registry.createTableGauge("AllMemtablesLiveDataSize", "all_memtables_live_data_size");
|
|
||||||
|
|
||||||
registry.createTableCounter("MemtableSwitchCount", "memtable_switch_count");
|
|
||||||
|
|
||||||
registry.createTableHistogram("SSTablesPerReadHistogram", "sstables_per_read_histogram", true);
|
|
||||||
registry.createTableGauge(Double.class, "CompressionRatio", "compression_ratio");
|
|
||||||
|
|
||||||
registry.createTableCounter("PendingFlushes", "pending_flushes");
|
|
||||||
|
|
||||||
registry.createTableGauge(Integer.class, Long.class, "PendingCompactions", "PendingCompactions",
|
|
||||||
"pending_compactions");
|
|
||||||
registry.createTableGauge(Integer.class, Long.class, "LiveSSTableCount", "LiveSSTableCount",
|
|
||||||
"live_ss_table_count");
|
|
||||||
|
|
||||||
registry.createTableCounter("LiveDiskSpaceUsed", "live_disk_space_used");
|
|
||||||
registry.createTableCounter("TotalDiskSpaceUsed", "total_disk_space_used");
|
|
||||||
registry.createTableGauge("MinPartitionSize", "MinRowSize", "min_row_size");
|
|
||||||
registry.createTableGauge("MaxPartitionSize", "MaxRowSize", "max_row_size");
|
|
||||||
registry.createTableGauge("MeanPartitionSize", "MeanRowSize", "mean_row_size");
|
|
||||||
|
|
||||||
registry.createTableGauge("BloomFilterFalsePositives", "bloom_filter_false_positives");
|
|
||||||
registry.createTableGauge("RecentBloomFilterFalsePositives", "recent_bloom_filter_false_positives");
|
|
||||||
registry.createTableGauge(Double.class, "BloomFilterFalseRatio", "bloom_filter_false_ratio");
|
|
||||||
registry.createTableGauge(Double.class, "RecentBloomFilterFalseRatio", "recent_bloom_filter_false_ratio");
|
|
||||||
|
|
||||||
registry.createTableGauge("BloomFilterDiskSpaceUsed", "bloom_filter_disk_space_used");
|
|
||||||
registry.createTableGauge("BloomFilterOffHeapMemoryUsed", "bloom_filter_off_heap_memory_used");
|
|
||||||
registry.createTableGauge("IndexSummaryOffHeapMemoryUsed", "index_summary_off_heap_memory_used");
|
|
||||||
registry.createTableGauge("CompressionMetadataOffHeapMemoryUsed", "compression_metadata_off_heap_memory_used");
|
|
||||||
registry.createTableGauge("SpeculativeRetries", "speculative_retries");
|
|
||||||
|
|
||||||
registry.createTableHistogram("TombstoneScannedHistogram", "tombstone_scanned_histogram", false);
|
|
||||||
registry.createTableHistogram("LiveScannedHistogram", "live_scanned_histogram", false);
|
|
||||||
registry.createTableHistogram("ColUpdateTimeDeltaHistogram", "col_update_time_delta_histogram", false);
|
|
||||||
|
|
||||||
// We do not want to capture view mutation specific metrics for a view
|
|
||||||
// They only makes sense to capture on the base table
|
|
||||||
// TODO: views
|
|
||||||
// if (!cfs.metadata.isView())
|
|
||||||
// {
|
|
||||||
// viewLockAcquireTime = createTableTimer("ViewLockAcquireTime",
|
|
||||||
// cfs.keyspace.metric.viewLockAcquireTime);
|
|
||||||
// viewReadTime = createTableTimer("ViewReadTime",
|
|
||||||
// cfs.keyspace.metric.viewReadTime);
|
|
||||||
// }
|
|
||||||
|
|
||||||
registry.createTableGauge("SnapshotsSize", "snapshots_size");
|
|
||||||
registry.createTableCounter("RowCacheHitOutOfRange", "row_cache_hit_out_of_range");
|
|
||||||
registry.createTableCounter("RowCacheHit", "row_cache_hit");
|
|
||||||
registry.createTableCounter("RowCacheMiss", "row_cache_miss");
|
|
||||||
|
|
||||||
// TODO: implement
|
|
||||||
registry.createDummyTableGauge(Double.class, "PercentRepaired");
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TableMetricObjectName extends javax.management.ObjectName {
|
|
||||||
private final TableMetricStringNameFactory factory;
|
|
||||||
private final String metricName;
|
|
||||||
|
|
||||||
public TableMetricObjectName(TableMetricStringNameFactory factory, String metricName) throws MalformedObjectNameException {
|
|
||||||
super("");
|
|
||||||
this.factory = factory;
|
|
||||||
this.metricName = metricName;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPropertyValuePattern(String property) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCanonicalName() {
|
|
||||||
return factory.createMetricStringName(metricName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return factory.getDomain();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyProperty(String property) {
|
|
||||||
if (property == "name") {
|
|
||||||
return metricName;
|
|
||||||
}
|
|
||||||
return factory.getKeyProperty(property);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hashtable<String,String> getKeyPropertyList() {
|
|
||||||
Hashtable<String, String> res = factory.getKeyPropertyList();
|
|
||||||
res.put("name", metricName);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyPropertyListString() {
|
|
||||||
return factory.getKeyPropertyListString(metricName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getCanonicalKeyPropertyListString() {
|
|
||||||
return getKeyPropertyListString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return getCanonicalName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
return getCanonicalName().equals(((ObjectName) o).getCanonicalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return getCanonicalName().hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean apply(ObjectName name) {
|
|
||||||
if (name.isDomainPattern() || name.isPropertyListPattern() || name.isPropertyValuePattern()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return getCanonicalName().equals(name.getCanonicalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPattern() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isDomainPattern() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPropertyPattern() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPropertyListPattern() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isPropertyValuePattern() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This type is not really serializable.
|
|
||||||
* Replace it with vanilla objectname.
|
|
||||||
*/
|
|
||||||
private Object writeReplace() throws ObjectStreamException {
|
|
||||||
try {
|
|
||||||
return new ObjectName(getDomain(), getKeyPropertyList());
|
|
||||||
} catch (MalformedObjectNameException e) {
|
|
||||||
throw new InvalidObjectException(toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static interface TableMetricStringNameFactory {
|
|
||||||
String createMetricStringName(String metricName);
|
|
||||||
String getDomain();
|
|
||||||
String getKeyProperty(String property);
|
|
||||||
Hashtable<String,String> getKeyPropertyList();
|
|
||||||
String getKeyPropertyListString(String metricName);
|
|
||||||
}
|
|
||||||
|
|
||||||
static class TableMetricNameFactory implements MetricNameFactory, TableMetricStringNameFactory {
|
|
||||||
private final String keyspaceName;
|
|
||||||
private final String tableName;
|
|
||||||
private final boolean isIndex;
|
|
||||||
private final String type;
|
|
||||||
|
|
||||||
public TableMetricNameFactory(String keyspaceName, String tableName, boolean isIndex, String type) {
|
|
||||||
this.keyspaceName = keyspaceName;
|
|
||||||
this.tableName = tableName;
|
|
||||||
this.isIndex = isIndex;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendKeyPropertyListString(final StringBuilder sb, final String metricName) {
|
|
||||||
String type = isIndex ? "Index" + this.type : this.type;
|
|
||||||
// Order matters here - keys have to be sorted
|
|
||||||
sb.append("keyspace=").append(keyspaceName);
|
|
||||||
sb.append(",name=").append(metricName);
|
|
||||||
sb.append(",scope=").append(tableName);
|
|
||||||
sb.append(",type=").append(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String createMetricStringName(String metricName) {
|
|
||||||
String groupName = TableMetrics.class.getPackage().getName();
|
|
||||||
|
|
||||||
StringBuilder mbeanName = new StringBuilder();
|
|
||||||
mbeanName.append(groupName).append(":");
|
|
||||||
appendKeyPropertyListString(mbeanName, metricName);
|
|
||||||
return mbeanName.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return TableMetrics.class.getPackage().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyProperty(String property) {
|
|
||||||
switch (property) {
|
|
||||||
case "keyspace": return keyspaceName;
|
|
||||||
case "scope": return tableName;
|
|
||||||
case "type": return type;
|
|
||||||
default: return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hashtable<String,String> getKeyPropertyList() {
|
|
||||||
Hashtable<String, String> res = new Hashtable<>();
|
|
||||||
res.put("keyspace", keyspaceName);
|
|
||||||
res.put("scope", tableName);
|
|
||||||
res.put("type", type);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyPropertyListString(String metricName) {
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
appendKeyPropertyListString(sb, metricName);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectName createMetricName(String metricName) throws MalformedObjectNameException {
|
|
||||||
return new TableMetricObjectName(this, metricName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class AllTableMetricNameFactory implements MetricNameFactory, TableMetricStringNameFactory {
|
|
||||||
private final String type;
|
|
||||||
|
|
||||||
public AllTableMetricNameFactory(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void appendKeyPropertyListString(final StringBuilder sb, final String metricName) {
|
|
||||||
// Order matters here - keys have to be sorted
|
|
||||||
sb.append("name=").append(metricName);
|
|
||||||
sb.append(",type=" + type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String createMetricStringName(String metricName) {
|
|
||||||
String groupName = TableMetrics.class.getPackage().getName();
|
|
||||||
StringBuilder mbeanName = new StringBuilder();
|
|
||||||
mbeanName.append(groupName).append(":");
|
|
||||||
appendKeyPropertyListString(mbeanName, metricName);
|
|
||||||
return mbeanName.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getDomain() {
|
|
||||||
return TableMetrics.class.getPackage().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyProperty(String property) {
|
|
||||||
switch (property) {
|
|
||||||
case "type": return type;
|
|
||||||
default: return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Hashtable<String,String> getKeyPropertyList() {
|
|
||||||
Hashtable<String, String> res = new Hashtable<>();
|
|
||||||
res.put("type", type);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getKeyPropertyListString(String metricName) {
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
appendKeyPropertyListString(sb, metricName);
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ObjectName createMetricName(String metricName) throws MalformedObjectNameException {
|
|
||||||
return new TableMetricObjectName(this, metricName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Sampler {
|
|
||||||
READS, WRITES
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,117 +22,157 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cassandra.net;
|
package org.apache.cassandra.net;
|
||||||
|
|
||||||
import static java.util.Collections.emptyMap;
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.net.*;
|
||||||
import jakarta.json.JsonArray;
|
import java.util.*;
|
||||||
import jakarta.json.JsonObject;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import java.util.stream.Collectors;
|
import javax.json.JsonArray;
|
||||||
import java.util.stream.Stream;
|
import javax.json.JsonObject;
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.DroppedMessageMetrics;
|
import org.apache.cassandra.metrics.DroppedMessageMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.MetricsMBean;
|
|
||||||
|
|
||||||
public final class MessagingService extends MetricsMBean implements MessagingServiceMBean {
|
public final class MessagingService implements MessagingServiceMBean {
|
||||||
|
static final int INTERVAL = 1000; // update every 1second
|
||||||
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=MessagingService";
|
public static final String MBEAN_NAME = "org.apache.cassandra.net:type=MessagingService";
|
||||||
private static final Logger logger = Logger.getLogger(MessagingService.class.getName());
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(MessagingService.class.getName());
|
||||||
private Map<String, Long> resentTimeouts = new HashMap<String, Long>();
|
Map<String, DroppedMessageMetrics> dropped;
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
Map<String, Long> resent_timeout = new HashMap<String, Long>();
|
||||||
|
private final ObjectName jmxObjectName;
|
||||||
private long recentTimeoutCount;
|
private long recentTimeoutCount;
|
||||||
|
|
||||||
/* All verb handler identifiers */
|
/* All verb handler identifiers */
|
||||||
public enum Verb {
|
public enum Verb
|
||||||
MUTATION, @Deprecated BINARY, READ_REPAIR, READ, REQUEST_RESPONSE, // client-initiated
|
{
|
||||||
// reads
|
MUTATION,
|
||||||
// and
|
@Deprecated BINARY,
|
||||||
// writes
|
READ_REPAIR,
|
||||||
@Deprecated STREAM_INITIATE, @Deprecated STREAM_INITIATE_DONE, @Deprecated STREAM_REPLY, @Deprecated STREAM_REQUEST, RANGE_SLICE, @Deprecated BOOTSTRAP_TOKEN, @Deprecated TREE_REQUEST, @Deprecated TREE_RESPONSE, @Deprecated JOIN, GOSSIP_DIGEST_SYN, GOSSIP_DIGEST_ACK, GOSSIP_DIGEST_ACK2, @Deprecated DEFINITIONS_ANNOUNCE, DEFINITIONS_UPDATE, TRUNCATE, SCHEMA_CHECK, @Deprecated INDEX_SCAN, REPLICATION_FINISHED, INTERNAL_RESPONSE, // responses
|
READ,
|
||||||
// to
|
REQUEST_RESPONSE, // client-initiated reads and writes
|
||||||
// internal
|
@Deprecated STREAM_INITIATE,
|
||||||
// calls
|
@Deprecated STREAM_INITIATE_DONE,
|
||||||
COUNTER_MUTATION, @Deprecated STREAMING_REPAIR_REQUEST, @Deprecated STREAMING_REPAIR_RESPONSE, SNAPSHOT, // Similar
|
@Deprecated STREAM_REPLY,
|
||||||
// to
|
@Deprecated STREAM_REQUEST,
|
||||||
// nt
|
RANGE_SLICE,
|
||||||
// snapshot
|
@Deprecated BOOTSTRAP_TOKEN,
|
||||||
MIGRATION_REQUEST, GOSSIP_SHUTDOWN, _TRACE, // dummy verb so we can use
|
@Deprecated TREE_REQUEST,
|
||||||
// MS.droppedMessages
|
@Deprecated TREE_RESPONSE,
|
||||||
ECHO, REPAIR_MESSAGE,
|
@Deprecated JOIN,
|
||||||
// use as padding for backwards compatability where a previous version
|
GOSSIP_DIGEST_SYN,
|
||||||
// needs to validate a verb from the future.
|
GOSSIP_DIGEST_ACK,
|
||||||
PAXOS_PREPARE, PAXOS_PROPOSE, PAXOS_COMMIT, PAGED_RANGE,
|
GOSSIP_DIGEST_ACK2,
|
||||||
|
@Deprecated DEFINITIONS_ANNOUNCE,
|
||||||
|
DEFINITIONS_UPDATE,
|
||||||
|
TRUNCATE,
|
||||||
|
SCHEMA_CHECK,
|
||||||
|
@Deprecated INDEX_SCAN,
|
||||||
|
REPLICATION_FINISHED,
|
||||||
|
INTERNAL_RESPONSE, // responses to internal calls
|
||||||
|
COUNTER_MUTATION,
|
||||||
|
@Deprecated STREAMING_REPAIR_REQUEST,
|
||||||
|
@Deprecated STREAMING_REPAIR_RESPONSE,
|
||||||
|
SNAPSHOT, // Similar to nt snapshot
|
||||||
|
MIGRATION_REQUEST,
|
||||||
|
GOSSIP_SHUTDOWN,
|
||||||
|
_TRACE, // dummy verb so we can use MS.droppedMessages
|
||||||
|
ECHO,
|
||||||
|
REPAIR_MESSAGE,
|
||||||
|
// use as padding for backwards compatability where a previous version needs to validate a verb from the future.
|
||||||
|
PAXOS_PREPARE,
|
||||||
|
PAXOS_PROPOSE,
|
||||||
|
PAXOS_COMMIT,
|
||||||
|
PAGED_RANGE,
|
||||||
// remember to add new verbs at the end, since we serialize by ordinal
|
// remember to add new verbs at the end, since we serialize by ordinal
|
||||||
UNUSED_1, UNUSED_2, UNUSED_3,;
|
UNUSED_1,
|
||||||
|
UNUSED_2,
|
||||||
|
UNUSED_3,
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessagingService(APIClient client) {
|
public MessagingService() {
|
||||||
super(MBEAN_NAME, client,
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
Stream.of(Verb.values()).map(v -> new DroppedMessageMetrics(v)).collect(Collectors.toList()));
|
try {
|
||||||
|
jmxObjectName = new ObjectName(MBEAN_NAME);
|
||||||
|
mbs.registerMBean(this, jmxObjectName);
|
||||||
|
dropped = new HashMap<String, DroppedMessageMetrics>();
|
||||||
|
for (Verb v : Verb.values()) {
|
||||||
|
dropped.put(v.name(), new DroppedMessageMetrics(v));
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static MessagingService instance;
|
||||||
|
|
||||||
|
public static MessagingService getInstance() {
|
||||||
|
if (instance == null) {
|
||||||
|
instance = new MessagingService();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pending tasks for Command(Mutations, Read etc) TCP Connections
|
* Pending tasks for Command(Mutations, Read etc) TCP Connections
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getCommandPendingTasks() {
|
public Map<String, Integer> getCommandPendingTasks() {
|
||||||
log(" getCommandPendingTasks()");
|
log(" getCommandPendingTasks()");
|
||||||
return client.getMapStringIntegerValue("/messaging_service/messages/pending");
|
return c.getMapStringIntegerValue("/messaging_service/messages/pending");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completed tasks for Command(Mutations, Read etc) TCP Connections
|
* Completed tasks for Command(Mutations, Read etc) TCP Connections
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Long> getCommandCompletedTasks() {
|
public Map<String, Long> getCommandCompletedTasks() {
|
||||||
log("getCommandCompletedTasks()");
|
log("getCommandCompletedTasks()");
|
||||||
Map<String, Long> res = client.getListMapStringLongValue("/messaging_service/messages/sent");
|
Map<String, Long> res = c
|
||||||
|
.getListMapStringLongValue("/messaging_service/messages/sent");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dropped tasks for Command(Mutations, Read etc) TCP Connections
|
* Dropped tasks for Command(Mutations, Read etc) TCP Connections
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Long> getCommandDroppedTasks() {
|
public Map<String, Long> getCommandDroppedTasks() {
|
||||||
log(" getCommandDroppedTasks()");
|
log(" getCommandDroppedTasks()");
|
||||||
return client.getMapStringLongValue("/messaging_service/messages/dropped");
|
return c.getMapStringLongValue("/messaging_service/messages/dropped");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pending tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
* Pending tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getResponsePendingTasks() {
|
public Map<String, Integer> getResponsePendingTasks() {
|
||||||
log(" getResponsePendingTasks()");
|
log(" getResponsePendingTasks()");
|
||||||
return client.getMapStringIntegerValue("/messaging_service/messages/respond_pending");
|
return c.getMapStringIntegerValue("/messaging_service/messages/respond_pending");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Completed tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
* Completed tasks for Response(GOSSIP & RESPONSE) TCP Connections
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Long> getResponseCompletedTasks() {
|
public Map<String, Long> getResponseCompletedTasks() {
|
||||||
log(" getResponseCompletedTasks()");
|
log(" getResponseCompletedTasks()");
|
||||||
return client.getMapStringLongValue("/messaging_service/messages/respond_completed");
|
return c.getMapStringLongValue("/messaging_service/messages/respond_completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dropped message counts for server lifetime
|
* dropped message counts for server lifetime
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getDroppedMessages() {
|
public Map<String, Integer> getDroppedMessages() {
|
||||||
log(" getDroppedMessages()");
|
log(" getDroppedMessages()");
|
||||||
Map<String, Integer> res = new HashMap<String, Integer>();
|
Map<String, Integer> res = new HashMap<String, Integer>();
|
||||||
JsonArray arr = client.getJsonArray("/messaging_service/messages/dropped_by_ver");
|
JsonArray arr = c.getJsonArray("/messaging_service/messages/dropped_by_ver");
|
||||||
for (int i = 0; i < arr.size(); i++) {
|
for (int i = 0; i < arr.size(); i++) {
|
||||||
JsonObject obj = arr.getJsonObject(i);
|
JsonObject obj = arr.getJsonObject(i);
|
||||||
res.put(obj.getString("verb"), obj.getInt("count"));
|
res.put(obj.getString("verb"), obj.getInt("count"));
|
||||||
@ -140,32 +180,20 @@ public final class MessagingService extends MetricsMBean implements MessagingSer
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Integer> recent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dropped message counts since last called
|
* dropped message counts since last called
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getRecentlyDroppedMessages() {
|
public Map<String, Integer> getRecentlyDroppedMessages() {
|
||||||
log(" getRecentlyDroppedMessages()");
|
log(" getRecentlyDroppedMessages()");
|
||||||
|
Map<String, Integer> map = new HashMap<String, Integer>();
|
||||||
Map<String, Integer> dropped = getDroppedMessages(), result = new HashMap<>(dropped), old = recent;
|
for (Map.Entry<String, DroppedMessageMetrics> entry : dropped.entrySet())
|
||||||
|
map.put(entry.getKey(), entry.getValue().getRecentlyDropped());
|
||||||
recent = dropped;
|
return map;
|
||||||
|
|
||||||
if (old != null) {
|
|
||||||
for (Map.Entry<String, Integer> e : old.entrySet()) {
|
|
||||||
result.put(e.getKey(), result.get(e.getKey()) - e.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Total number of timeouts happened on this node
|
* Total number of timeouts happened on this node
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public long getTotalTimeouts() {
|
public long getTotalTimeouts() {
|
||||||
log(" getTotalTimeouts()");
|
log(" getTotalTimeouts()");
|
||||||
Map<String, Long> timeouts = getTimeoutsPerHost();
|
Map<String, Long> timeouts = getTimeoutsPerHost();
|
||||||
@ -179,16 +207,14 @@ public final class MessagingService extends MetricsMBean implements MessagingSer
|
|||||||
/**
|
/**
|
||||||
* Number of timeouts per host
|
* Number of timeouts per host
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Long> getTimeoutsPerHost() {
|
public Map<String, Long> getTimeoutsPerHost() {
|
||||||
log(" getTimeoutsPerHost()");
|
log(" getTimeoutsPerHost()");
|
||||||
return client.getMapStringLongValue("/messaging_service/messages/timeout");
|
return c.getMapStringLongValue("/messaging_service/messages/timeout");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of timeouts since last check.
|
* Number of timeouts since last check.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public long getRecentTotalTimouts() {
|
public long getRecentTotalTimouts() {
|
||||||
log(" getRecentTotalTimouts()");
|
log(" getRecentTotalTimouts()");
|
||||||
long timeoutCount = getTotalTimeouts();
|
long timeoutCount = getTotalTimeouts();
|
||||||
@ -200,77 +226,25 @@ public final class MessagingService extends MetricsMBean implements MessagingSer
|
|||||||
/**
|
/**
|
||||||
* Number of timeouts since last check per host.
|
* Number of timeouts since last check per host.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public Map<String, Long> getRecentTimeoutsPerHost() {
|
public Map<String, Long> getRecentTimeoutsPerHost() {
|
||||||
log(" getRecentTimeoutsPerHost()");
|
log(" getRecentTimeoutsPerHost()");
|
||||||
Map<String, Long> timeouts = getTimeoutsPerHost();
|
Map<String, Long> timeouts = getTimeoutsPerHost();
|
||||||
Map<String, Long> result = new HashMap<String, Long>();
|
Map<String, Long> result = new HashMap<String, Long>();
|
||||||
for (Entry<String, Long> e : timeouts.entrySet()) {
|
for ( Entry<String, Long> e : timeouts.entrySet()) {
|
||||||
long res = e.getValue().longValue()
|
long res = e.getValue().longValue() -
|
||||||
- ((resentTimeouts.containsKey(e.getKey())) ? (resentTimeouts.get(e.getKey())).longValue() : 0);
|
((resent_timeout.containsKey(e.getKey()))? (resent_timeout.get(e.getKey())).longValue()
|
||||||
resentTimeouts.put(e.getKey(), e.getValue());
|
: 0);
|
||||||
result.put(e.getKey(), res);
|
resent_timeout.put(e.getKey(), e.getValue());
|
||||||
|
result.put(e.getKey(),res);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getVersion(String address) throws UnknownHostException {
|
public int getVersion(String address) throws UnknownHostException {
|
||||||
log(" getVersion(String address) throws UnknownHostException");
|
log(" getVersion(String address) throws UnknownHostException");
|
||||||
return client.getIntValue("");
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
|
queryParams.add("addr", address);
|
||||||
|
return c.getIntValue("/messaging_service/version", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getLargeMessagePendingTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return getCommandPendingTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getLargeMessageCompletedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return getCommandCompletedTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getLargeMessageDroppedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return getCommandDroppedTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getSmallMessagePendingTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return getResponsePendingTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getSmallMessageCompletedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return getResponseCompletedTasks();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getSmallMessageDroppedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Integer> getGossipMessagePendingTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getGossipMessageCompletedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Map<String, Long> getGossipMessageDroppedTasks() {
|
|
||||||
// TODO: implement for realsies
|
|
||||||
return emptyMap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2015 Cloudius Systems
|
|
||||||
*
|
|
||||||
* Modified by Cloudius Systems
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.net;
|
package org.apache.cassandra.net;
|
||||||
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
@ -32,51 +25,6 @@ import java.util.Map;
|
|||||||
* Command/Response - Pending/Completed Tasks
|
* Command/Response - Pending/Completed Tasks
|
||||||
*/
|
*/
|
||||||
public interface MessagingServiceMBean {
|
public interface MessagingServiceMBean {
|
||||||
/**
|
|
||||||
* Pending tasks for large message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Integer> getLargeMessagePendingTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Completed tasks for large message) TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getLargeMessageCompletedTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dropped tasks for large message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getLargeMessageDroppedTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pending tasks for small message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Integer> getSmallMessagePendingTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Completed tasks for small message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getSmallMessageCompletedTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dropped tasks for small message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getSmallMessageDroppedTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pending tasks for gossip message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Integer> getGossipMessagePendingTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Completed tasks for gossip message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getGossipMessageCompletedTasks();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dropped tasks for gossip message TCP Connections
|
|
||||||
*/
|
|
||||||
public Map<String, Long> getGossipMessageDroppedTasks();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pending tasks for Command(Mutations, Read etc) TCP Connections
|
* Pending tasks for Command(Mutations, Read etc) TCP Connections
|
||||||
*/
|
*/
|
||||||
@ -122,20 +70,6 @@ public interface MessagingServiceMBean {
|
|||||||
*/
|
*/
|
||||||
public Map<String, Long> getTimeoutsPerHost();
|
public Map<String, Long> getTimeoutsPerHost();
|
||||||
|
|
||||||
/**
|
|
||||||
* Back-pressure rate limiting per host
|
|
||||||
*/
|
|
||||||
default public Map<String, Double> getBackPressurePerHost() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable/Disable back-pressure
|
|
||||||
*/
|
|
||||||
default public void setBackPressureEnabled(boolean enabled) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of timeouts since last check.
|
* Number of timeouts since last check.
|
||||||
*/
|
*/
|
||||||
|
@ -24,18 +24,22 @@
|
|||||||
|
|
||||||
package org.apache.cassandra.service;
|
package org.apache.cassandra.service;
|
||||||
|
|
||||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
import java.lang.management.ManagementFactory;
|
||||||
import jakarta.ws.rs.core.MultivaluedMap;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
import javax.management.MBeanServer;
|
||||||
|
import javax.management.ObjectName;
|
||||||
|
import javax.ws.rs.core.MultivaluedHashMap;
|
||||||
|
import javax.ws.rs.core.MultivaluedMap;
|
||||||
|
|
||||||
import org.apache.cassandra.metrics.CacheMetrics;
|
import org.apache.cassandra.metrics.CacheMetrics;
|
||||||
|
|
||||||
import com.scylladb.jmx.api.APIClient;
|
import com.scylladb.jmx.api.APIClient;
|
||||||
import com.scylladb.jmx.metrics.MetricsMBean;
|
|
||||||
|
|
||||||
public class CacheService extends MetricsMBean implements CacheServiceMBean {
|
public class CacheService implements CacheServiceMBean {
|
||||||
private static final Logger logger = Logger.getLogger(CacheService.class.getName());
|
private static final java.util.logging.Logger logger = java.util.logging.Logger
|
||||||
|
.getLogger(CacheService.class.getName());
|
||||||
|
private APIClient c = new APIClient();
|
||||||
|
|
||||||
public void log(String str) {
|
public void log(String str) {
|
||||||
logger.finest(str);
|
logger.finest(str);
|
||||||
@ -43,141 +47,141 @@ public class CacheService extends MetricsMBean implements CacheServiceMBean {
|
|||||||
|
|
||||||
public static final String MBEAN_NAME = "org.apache.cassandra.db:type=Caches";
|
public static final String MBEAN_NAME = "org.apache.cassandra.db:type=Caches";
|
||||||
|
|
||||||
public CacheService(APIClient client) {
|
public final CacheMetrics keyCache;
|
||||||
super(MBEAN_NAME, client, new CacheMetrics("KeyCache", "key"), new CacheMetrics("RowCache", "row"),
|
public final CacheMetrics rowCache;
|
||||||
new CacheMetrics("CounterCache", "counter"));
|
public final CacheMetrics counterCache;
|
||||||
|
public final static CacheService instance = new CacheService();
|
||||||
|
|
||||||
|
public static CacheService getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CacheService() {
|
||||||
|
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
mbs.registerMBean(this, new ObjectName(MBEAN_NAME));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
keyCache = new CacheMetrics("KeyCache", null);
|
||||||
|
rowCache = new CacheMetrics("RowCache", "row");
|
||||||
|
counterCache = new CacheMetrics("CounterCache", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRowCacheSavePeriodInSeconds() {
|
public int getRowCacheSavePeriodInSeconds() {
|
||||||
log(" getRowCacheSavePeriodInSeconds()");
|
log(" getRowCacheSavePeriodInSeconds()");
|
||||||
return client.getIntValue("cache_service/row_cache_save_period");
|
return c.getIntValue("cache_service/row_cache_save_period");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRowCacheSavePeriodInSeconds(int rcspis) {
|
public void setRowCacheSavePeriodInSeconds(int rcspis) {
|
||||||
log(" setRowCacheSavePeriodInSeconds(int rcspis)");
|
log(" setRowCacheSavePeriodInSeconds(int rcspis)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("period", Integer.toString(rcspis));
|
queryParams.add("period", Integer.toString(rcspis));
|
||||||
client.post("cache_service/row_cache_save_period", queryParams);
|
c.post("cache_service/row_cache_save_period", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getKeyCacheSavePeriodInSeconds() {
|
public int getKeyCacheSavePeriodInSeconds() {
|
||||||
log(" getKeyCacheSavePeriodInSeconds()");
|
log(" getKeyCacheSavePeriodInSeconds()");
|
||||||
return client.getIntValue("cache_service/key_cache_save_period");
|
return c.getIntValue("cache_service/key_cache_save_period");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setKeyCacheSavePeriodInSeconds(int kcspis) {
|
public void setKeyCacheSavePeriodInSeconds(int kcspis) {
|
||||||
log(" setKeyCacheSavePeriodInSeconds(int kcspis)");
|
log(" setKeyCacheSavePeriodInSeconds(int kcspis)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("period", Integer.toString(kcspis));
|
queryParams.add("period", Integer.toString(kcspis));
|
||||||
client.post("cache_service/key_cache_save_period", queryParams);
|
c.post("cache_service/key_cache_save_period", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCounterCacheSavePeriodInSeconds() {
|
public int getCounterCacheSavePeriodInSeconds() {
|
||||||
log(" getCounterCacheSavePeriodInSeconds()");
|
log(" getCounterCacheSavePeriodInSeconds()");
|
||||||
return client.getIntValue("cache_service/counter_cache_save_period");
|
return c.getIntValue("cache_service/counter_cache_save_period");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCounterCacheSavePeriodInSeconds(int ccspis) {
|
public void setCounterCacheSavePeriodInSeconds(int ccspis) {
|
||||||
log(" setCounterCacheSavePeriodInSeconds(int ccspis)");
|
log(" setCounterCacheSavePeriodInSeconds(int ccspis)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("ccspis", Integer.toString(ccspis));
|
queryParams.add("ccspis", Integer.toString(ccspis));
|
||||||
client.post("cache_service/counter_cache_save_period", queryParams);
|
c.post("cache_service/counter_cache_save_period", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getRowCacheKeysToSave() {
|
public int getRowCacheKeysToSave() {
|
||||||
log(" getRowCacheKeysToSave()");
|
log(" getRowCacheKeysToSave()");
|
||||||
return client.getIntValue("cache_service/row_cache_keys_to_save");
|
return c.getIntValue("cache_service/row_cache_keys_to_save");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRowCacheKeysToSave(int rckts) {
|
public void setRowCacheKeysToSave(int rckts) {
|
||||||
log(" setRowCacheKeysToSave(int rckts)");
|
log(" setRowCacheKeysToSave(int rckts)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("rckts", Integer.toString(rckts));
|
queryParams.add("rckts", Integer.toString(rckts));
|
||||||
client.post("cache_service/row_cache_keys_to_save", queryParams);
|
c.post("cache_service/row_cache_keys_to_save", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getKeyCacheKeysToSave() {
|
public int getKeyCacheKeysToSave() {
|
||||||
log(" getKeyCacheKeysToSave()");
|
log(" getKeyCacheKeysToSave()");
|
||||||
return client.getIntValue("cache_service/key_cache_keys_to_save");
|
return c.getIntValue("cache_service/key_cache_keys_to_save");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setKeyCacheKeysToSave(int kckts) {
|
public void setKeyCacheKeysToSave(int kckts) {
|
||||||
log(" setKeyCacheKeysToSave(int kckts)");
|
log(" setKeyCacheKeysToSave(int kckts)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("kckts", Integer.toString(kckts));
|
queryParams.add("kckts", Integer.toString(kckts));
|
||||||
client.post("cache_service/key_cache_keys_to_save", queryParams);
|
c.post("cache_service/key_cache_keys_to_save", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCounterCacheKeysToSave() {
|
public int getCounterCacheKeysToSave() {
|
||||||
log(" getCounterCacheKeysToSave()");
|
log(" getCounterCacheKeysToSave()");
|
||||||
return client.getIntValue("cache_service/counter_cache_keys_to_save");
|
return c.getIntValue("cache_service/counter_cache_keys_to_save");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCounterCacheKeysToSave(int cckts) {
|
public void setCounterCacheKeysToSave(int cckts) {
|
||||||
log(" setCounterCacheKeysToSave(int cckts)");
|
log(" setCounterCacheKeysToSave(int cckts)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("cckts", Integer.toString(cckts));
|
queryParams.add("cckts", Integer.toString(cckts));
|
||||||
client.post("cache_service/counter_cache_keys_to_save", queryParams);
|
c.post("cache_service/counter_cache_keys_to_save", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invalidate the key cache; for use after invalidating row cache
|
* invalidate the key cache; for use after invalidating row cache
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void invalidateKeyCache() {
|
public void invalidateKeyCache() {
|
||||||
log(" invalidateKeyCache()");
|
log(" invalidateKeyCache()");
|
||||||
client.post("cache_service/invalidate_key_cache");
|
c.post("cache_service/invalidate_key_cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* invalidate the row cache; for use after bulk loading via BinaryMemtable
|
* invalidate the row cache; for use after bulk loading via BinaryMemtable
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void invalidateRowCache() {
|
public void invalidateRowCache() {
|
||||||
log(" invalidateRowCache()");
|
log(" invalidateRowCache()");
|
||||||
client.post("cache_service/invalidate_row_cache");
|
c.post("cache_service/invalidate_row_cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidateCounterCache() {
|
public void invalidateCounterCache() {
|
||||||
log(" invalidateCounterCache()");
|
log(" invalidateCounterCache()");
|
||||||
client.post("cache_service/invalidate_counter_cache");
|
c.post("cache_service/invalidate_counter_cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRowCacheCapacityInMB(long capacity) {
|
public void setRowCacheCapacityInMB(long capacity) {
|
||||||
log(" setRowCacheCapacityInMB(long capacity)");
|
log(" setRowCacheCapacityInMB(long capacity)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("capacity", Long.toString(capacity));
|
queryParams.add("capacity", Long.toString(capacity));
|
||||||
client.post("cache_service/row_cache_capacity", queryParams);
|
c.post("cache_service/row_cache_capacity", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setKeyCacheCapacityInMB(long capacity) {
|
public void setKeyCacheCapacityInMB(long capacity) {
|
||||||
log(" setKeyCacheCapacityInMB(long capacity)");
|
log(" setKeyCacheCapacityInMB(long capacity)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("capacity", Long.toString(capacity));
|
queryParams.add("capacity", Long.toString(capacity));
|
||||||
client.post("cache_service/key_cache_capacity", queryParams);
|
c.post("cache_service/key_cache_capacity", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCounterCacheCapacityInMB(long capacity) {
|
public void setCounterCacheCapacityInMB(long capacity) {
|
||||||
log(" setCounterCacheCapacityInMB(long capacity)");
|
log(" setCounterCacheCapacityInMB(long capacity)");
|
||||||
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<String, String>();
|
||||||
queryParams.add("capacity", Long.toString(capacity));
|
queryParams.add("capacity", Long.toString(capacity));
|
||||||
client.post("cache_service/counter_cache_capacity_in_mb", queryParams);
|
c.post("cache_service/counter_cache_capacity_in_mb", queryParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,9 +195,139 @@ public class CacheService extends MetricsMBean implements CacheServiceMBean {
|
|||||||
* and the thread is interrupted, either before or during the
|
* and the thread is interrupted, either before or during the
|
||||||
* activity.
|
* activity.
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public void saveCaches() throws ExecutionException, InterruptedException {
|
public void saveCaches() throws ExecutionException, InterruptedException {
|
||||||
log(" saveCaches() throws ExecutionException, InterruptedException");
|
log(" saveCaches() throws ExecutionException, InterruptedException");
|
||||||
client.post("cache_service/save_caches");
|
c.post("cache_service/save_caches");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// remaining methods are provided for backwards compatibility; modern
|
||||||
|
// clients should use CacheMetrics instead
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hits
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheHits() {
|
||||||
|
log(" getKeyCacheHits()");
|
||||||
|
return keyCache.hits.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hits
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheHits() {
|
||||||
|
log(" getRowCacheHits()");
|
||||||
|
return rowCache.hits.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#requests
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheRequests() {
|
||||||
|
log(" getKeyCacheRequests()");
|
||||||
|
return keyCache.requests.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#requests
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheRequests() {
|
||||||
|
log(" getRowCacheRequests()");
|
||||||
|
return rowCache.requests.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getKeyCacheRecentHitRate() {
|
||||||
|
log(" getKeyCacheRecentHitRate()");
|
||||||
|
return keyCache.getRecentHitRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRowCacheRecentHitRate() {
|
||||||
|
log(" getRowCacheRecentHitRate()");
|
||||||
|
return rowCache.getRecentHitRate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheCapacityInMB() {
|
||||||
|
log(" getRowCacheCapacityInMB()");
|
||||||
|
return getRowCacheCapacityInBytes() / 1024 / 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheCapacityInBytes() {
|
||||||
|
log(" getRowCacheCapacityInBytes()");
|
||||||
|
return rowCache.capacity.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheCapacityInMB() {
|
||||||
|
log(" getKeyCacheCapacityInMB()");
|
||||||
|
return getKeyCacheCapacityInBytes() / 1024 / 1024;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheCapacityInBytes() {
|
||||||
|
log(" getKeyCacheCapacityInBytes()");
|
||||||
|
return keyCache.capacity.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#size
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheSize() {
|
||||||
|
log(" getRowCacheSize()");
|
||||||
|
return rowCache.size.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#entries
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheEntries() {
|
||||||
|
log(" getRowCacheEntries()");
|
||||||
|
return rowCache.size.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#size
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheSize() {
|
||||||
|
log(" getKeyCacheSize()");
|
||||||
|
return keyCache.size.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#entries
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheEntries() {
|
||||||
|
log(" getKeyCacheEntries()");
|
||||||
|
return keyCache.size.value();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,28 +15,19 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2015 Cloudius Systems
|
|
||||||
*
|
|
||||||
* Modified by Cloudius Systems
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.apache.cassandra.service;
|
package org.apache.cassandra.service;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
public interface CacheServiceMBean {
|
public interface CacheServiceMBean
|
||||||
|
{
|
||||||
public int getRowCacheSavePeriodInSeconds();
|
public int getRowCacheSavePeriodInSeconds();
|
||||||
|
|
||||||
public void setRowCacheSavePeriodInSeconds(int rcspis);
|
public void setRowCacheSavePeriodInSeconds(int rcspis);
|
||||||
|
|
||||||
public int getKeyCacheSavePeriodInSeconds();
|
public int getKeyCacheSavePeriodInSeconds();
|
||||||
|
|
||||||
public void setKeyCacheSavePeriodInSeconds(int kcspis);
|
public void setKeyCacheSavePeriodInSeconds(int kcspis);
|
||||||
|
|
||||||
public int getCounterCacheSavePeriodInSeconds();
|
public int getCounterCacheSavePeriodInSeconds();
|
||||||
|
|
||||||
public void setCounterCacheSavePeriodInSeconds(int ccspis);
|
public void setCounterCacheSavePeriodInSeconds(int ccspis);
|
||||||
|
|
||||||
public int getRowCacheKeysToSave();
|
public int getRowCacheKeysToSave();
|
||||||
@ -44,11 +35,9 @@ public interface CacheServiceMBean {
|
|||||||
public void setRowCacheKeysToSave(int rckts);
|
public void setRowCacheKeysToSave(int rckts);
|
||||||
|
|
||||||
public int getKeyCacheKeysToSave();
|
public int getKeyCacheKeysToSave();
|
||||||
|
|
||||||
public void setKeyCacheKeysToSave(int kckts);
|
public void setKeyCacheKeysToSave(int kckts);
|
||||||
|
|
||||||
public int getCounterCacheKeysToSave();
|
public int getCounterCacheKeysToSave();
|
||||||
|
|
||||||
public void setCounterCacheKeysToSave(int cckts);
|
public void setCounterCacheKeysToSave(int cckts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,13 +61,94 @@ public interface CacheServiceMBean {
|
|||||||
/**
|
/**
|
||||||
* save row and key caches
|
* save row and key caches
|
||||||
*
|
*
|
||||||
* @throws ExecutionException
|
* @throws ExecutionException when attempting to retrieve the result of a task that aborted by throwing an exception
|
||||||
* when attempting to retrieve the result of a task that aborted
|
* @throws InterruptedException when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted, either before or during the activity.
|
||||||
* by throwing an exception
|
|
||||||
* @throws InterruptedException
|
|
||||||
* when a thread is waiting, sleeping, or otherwise occupied,
|
|
||||||
* and the thread is interrupted, either before or during the
|
|
||||||
* activity.
|
|
||||||
*/
|
*/
|
||||||
public void saveCaches() throws ExecutionException, InterruptedException;
|
public void saveCaches() throws ExecutionException, InterruptedException;
|
||||||
|
|
||||||
|
//
|
||||||
|
// remaining methods are provided for backwards compatibility; modern clients should use CacheMetrics instead
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hits
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheHits();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hits
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheHits();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#requests
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheRequests();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#requests
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheRequests();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getKeyCacheRecentHitRate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#hitRate
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public double getRowCacheRecentHitRate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheCapacityInMB();
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheCapacityInBytes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheCapacityInMB();
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#capacity
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheCapacityInBytes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#size
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#entries
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getRowCacheEntries();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#size
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheSize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.apache.cassandra.metrics.CacheMetrics#entries
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public long getKeyCacheEntries();
|
||||||
}
|
}
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user