Skip to content

Commit

Permalink
Small improvements for release (#56)
Browse files Browse the repository at this point in the history
* improve --help output
* improve --version output with influxdb/prometheus support
* fix COPR last-commit-hash feature
  • Loading branch information
f18m authored Aug 28, 2022
1 parent 29b6bec commit 34c19c1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .copr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ $(info Launching COPR build from directory: $(COPR_CURRENT_SUBDIRECTORY))
srpm:
@echo "Env variables in this COPR build:"
@export
@echo "Installing git client:"
@echo "Installing git client (required later on to embed commit hash into RPM binaries):"
dnf -y install git
git config --global --add safe.directory $(shell readlink -f ..)
@echo "Running srpm target from .copr/Makefile"
mkdir -p $(RPM_TMP_DIR)/ $(RPM_TARBALL_DIR)/
rm -rf $(RPM_TMP_DIR)/* $(RPM_TARBALL_DIR)/*
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ yum install -y cmonitor-collector cmonitor-tools
Note that the RPM `cmonitor-collector` has no dependencies from Python and has very small set of dependencies (GNU libc and few others)
so can be installed easily everywhere. The RPM `cmonitor-tools` instead requires Python3.

Finally note that Fedora COPR infrastructure will retain only the very **latest** version of cmonitor RPMs.
If your CI/CD relies on a particular version of cmonitor, the suggestion is to download and store the RPM version you need.


### Debian package (for Debian, Ubuntu, etc)

Expand Down Expand Up @@ -528,13 +531,11 @@ Options to save data locally
-P, --output-pretty Generate a pretty-printed JSON file instead of a machine-friendly JSON (the default).
Options to stream data remotely
-r, --remote=<REQ ARG> Set the type of remote target: 'influxdb' or 'prometheus'.
-r, --remote=<REQ ARG> Set the type of remote target: 'none' (default), 'influxdb' or 'prometheus'.
-i, --remote-ip=<REQ ARG> When remote is InfluxDB: IP address or hostname of the InfluxDB instance to send measurements to;
cmonitor_collector will use a database named 'cmonitor' to store them.
When remote is Prometheus: listen address, typically 127.0.0.1 (to accept connections from localhost only)
or 0.0.0.0 (to accept connections from all).
When remote is Prometheus: listen address, defaults to 0.0.0.0 (to accept connections from all).
-p, --remote-port=<REQ ARG> When remote is InfluxDB: port of server;
When remote is Prometheus: listen port, typically 8080.
When remote is Prometheus: listen port, defaults to 8080.
-X, --remote-secret=<REQ ARG> InfluxDB only: set the collector secret (by default use environment variable CMONITOR_SECRET).
-D, --remote-dbname=<REQ ARG> InfluxDB only: set the InfluxDB database name (default is 'cmonitor').
Expand All @@ -546,18 +547,21 @@ Other options
Examples:
1) Collect data from OS every 5 mins all day:
cmonitor_collector -s 300 -c 288 -m /home/perf
2) Collect data from a docker container:
2) Use the defaults (-s 60, collect forever), saving to custom file in background:
cmonitor_collector --output-filename=my_server_today
3) Collect data from a docker container:
DOCKER_NAME=your_docker_name
DOCKER_ID=$(docker ps -aq --no-trunc -f "name=$DOCKER_NAME")
cmonitor_collector --allow-multiple-instances --num-samples=until-cgroup-alive
--cgroup-name=docker/$DOCKER_ID --custom-metadata='cmonitor_chart_name:$DOCKER_NAME'
--custom-metadata='additional_metadata:some-data'
3) Use the defaults (-s 60, collect forever), saving to custom file in background:
cmonitor_collector --output-filename=my_server_today
4) Crontab entry:
0 4 * * * /usr/bin/cmonitor_collector -s 300 -c 288 -m /home/perf
5) Crontab entry for pumping data to an InfluxDB:
* 0 * * * /usr/bin/cmonitor_collector -s 300 -c 288 -i admin.acme.com -p 8086
4) Monitor a docker container sending data to an InfluxDB (only, no JSON output):
cmonitor_collector --num-samples=until-cgroup-alive --cgroup-name=docker/$DOCKER_ID
--output-filename=none --remote=influxdb --remote-ip myinfluxdb.foobar.com --remote-port 8086
5) Monitor a docker container and expose HTTP endpoint for Prometheus scraping (no JSON output):
cmonitor_collector -s 5 --num-samples=until-cgroup-alive --cgroup-name=docker/$DOCKER_ID
--output-filename=none --remote=prometheus --collect=all_cgroup --score-threshold=0
curl http://localhost:8080/metrics # test scraping
6) Pipe into 'myprog' half-a-day of sampled performance data:
cmonitor_collector --sampling-interval=30 --num-samples=1440 --output-filename=stdout --foreground | myprog
Expand Down
1 change: 1 addition & 0 deletions collector/spec/collector.spec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ perfect for ephemeral containers (e.g. containers used for DevOps automatic test
Can also be used with InfluxDB and Grafana.

%prep
echo "[Inside RPM prep] running setup"
%setup

%build
Expand Down
41 changes: 28 additions & 13 deletions collector/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@
*/
#define MIN_SAMPLING_TIME_SEC (0.01)

#define CMONITOR_DEFAULT_PROMETHEUS_PORT 8080
#define CMONITOR_DEFAULT_PROMETHEUS_PORT_STR "8080"

#ifdef PROMETHEUS_SUPPORT
#define VERSION_STRING_SUPPORTED_REMOTES "with Prometheus, InfluxDB support"
#else
#define VERSION_STRING_SUPPORTED_REMOTES "with InfluxDB support"
#endif

//------------------------------------------------------------------------------
// Globals
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -224,12 +233,10 @@ struct option_extended {
"Set the type of remote target: 'none' (default), 'influxdb' or 'prometheus'." },
{ "Options to stream data remotely", &g_long_opts[13],
"When remote is InfluxDB: IP address or hostname of the InfluxDB instance to send measurements to;\n"
"cmonitor_collector will use a database named 'cmonitor' to store them.\n"
"When remote is Prometheus: listen address, typically 127.0.0.1 (to accept connections from localhost only)\n"
"or 0.0.0.0 (to accept connections from all)." },
"When remote is Prometheus: listen address, defaults to 0.0.0.0 (to accept connections from all)." },
{ "Options to stream data remotely", &g_long_opts[14],
"When remote is InfluxDB: port of server;\n"
"When remote is Prometheus: listen port, typically 8080." },
"When remote is Prometheus: listen port, defaults to " CMONITOR_DEFAULT_PROMETHEUS_PORT_STR "." },
{ "Options to stream data remotely", &g_long_opts[15],
"InfluxDB only: set the collector secret (by default use environment variable CMONITOR_SECRET)." },
{ "Options to stream data remotely", &g_long_opts[16],
Expand Down Expand Up @@ -420,19 +427,26 @@ void CMonitorCollectorApp::print_help()
std::cerr << "Examples:" << std::endl;
std::cerr << " 1) Collect data from OS every 5 mins all day:" << std::endl;
std::cerr << "\tcmonitor_collector -s 300 -c 288 -m /home/perf" << std::endl;
std::cerr << " 2) Collect data from a docker container:" << std::endl;
std::cerr << " 2) Use the defaults (-s 60, collect forever), saving to custom file in background:" << std::endl;
std::cerr << "\tcmonitor_collector --output-filename=my_server_today" << std::endl;
std::cerr << " 3) Collect data from a docker container:" << std::endl;
std::cerr << "\tDOCKER_NAME=your_docker_name" << std::endl;
std::cerr << "\tDOCKER_ID=$(docker ps -aq --no-trunc -f \"name=$DOCKER_NAME\")" << std::endl;
std::cerr << "\tcmonitor_collector --allow-multiple-instances --num-samples=until-cgroup-alive " << std::endl;
std::cerr << "\t\t\t--cgroup-name=docker/$DOCKER_ID --custom-metadata='cmonitor_chart_name:$DOCKER_NAME'"
<< std::endl;
std::cerr << "\t\t\t--custom-metadata='additional_metadata:some-data'" << std::endl;
std::cerr << " 3) Use the defaults (-s 60, collect forever), saving to custom file in background:" << std::endl;
std::cerr << "\tcmonitor_collector --output-filename=my_server_today" << std::endl;
std::cerr << " 4) Crontab entry:" << std::endl;
std::cerr << "\t0 4 * * * /usr/bin/cmonitor_collector -s 300 -c 288 -m /home/perf" << std::endl;
std::cerr << " 5) Crontab entry for pumping data to an InfluxDB:" << std::endl;
std::cerr << "\t* 0 * * * /usr/bin/cmonitor_collector -s 300 -c 288 -i admin.acme.com -p 8086" << std::endl;
std::cerr << " 4) Monitor a docker container sending data to an InfluxDB (only, no JSON output):" << std::endl;
std::cerr << "\tcmonitor_collector --num-samples=until-cgroup-alive --cgroup-name=docker/$DOCKER_ID " << std::endl;
std::cerr << "\t\t\t--output-filename=none --remote=influxdb --remote-ip myinfluxdb.foobar.com --remote-port 8086"
<< std::endl;
std::cerr << " 5) Monitor a docker container and expose HTTP endpoint for Prometheus scraping (no JSON output):"
<< std::endl;
std::cerr << "\tcmonitor_collector -s 5 --num-samples=until-cgroup-alive --cgroup-name=docker/$DOCKER_ID "
<< std::endl;
std::cerr << "\t\t\t--output-filename=none --remote=prometheus --collect=all_cgroup --score-threshold=0"
<< std::endl;
std::cerr << "\tcurl http://localhost:8080/metrics # test scraping" << std::endl;
std::cerr << " 6) Pipe into 'myprog' half-a-day of sampled performance data:" << std::endl;
std::cerr << "\tcmonitor_collector --sampling-interval=30 --num-samples=1440 --output-filename=stdout --foreground "
"| myprog"
Expand Down Expand Up @@ -591,7 +605,8 @@ void CMonitorCollectorApp::parse_args(int argc, char** argv)

// help
case 'v':
printf("%s (commit %s)\n", VERSION_STRING, CMONITOR_LAST_COMMIT_HASH);
printf("%s (commit %s, %s)\n", VERSION_STRING, CMONITOR_LAST_COMMIT_HASH,
VERSION_STRING_SUPPORTED_REMOTES);
exit(0);
break;
case 'd':
Expand Down Expand Up @@ -671,7 +686,7 @@ void CMonitorCollectorApp::fill_with_defaults()

if (m_cfg.m_nRemote == REMOTE_PROMETHEUS && m_cfg.m_nRemotePort == 0)
// provide a good default port:
m_cfg.m_nRemotePort = 8080;
m_cfg.m_nRemotePort = CMONITOR_DEFAULT_PROMETHEUS_PORT;
if (m_cfg.m_nRemote == REMOTE_PROMETHEUS && m_cfg.m_strRemoteAddress == "")
// provide a good default listen address:
m_cfg.m_strRemoteAddress = "0.0.0.0";
Expand Down
3 changes: 1 addition & 2 deletions collector/src/output_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ void CMonitorOutputFrontend::init_prometheus_connection(
CMonitorLogger::instance()->LogDebug("init_prometheus_connection() initialized Prometheus port to %s", url.c_str());
printf("Initialized Prometheus HTTP server listening at http://%s/metrics\n", url.c_str());

m_default_labels = { { "function", "cmonitor" } };
// store the metadata from command line.
// store the metadata provided from command line as Prometheus labels associated with EACH metric
if (!metaData.empty()) {
for (const auto& entry : metaData) {
m_default_labels.insert(std::make_pair(entry.first, entry.second));
Expand Down

0 comments on commit 34c19c1

Please sign in to comment.