Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Spectator-cpp

This implements a basic [Spectator](https://github.com/Netflix/spectator) library for instrumenting CPP applications. It
consists of a thin client designed to send metrics through [spectatord](https://github.com/Netflix-Skunkworks/spectatord).
This implements a basic [Spectator](https://github.com/Netflix/spectator) library for instrumenting CPP applications.
It consists of a thin client designed to send metrics through [spectatord](https://github.com/Netflix-Skunkworks/spectatord).

## High-Volume Publishing

Expand Down
11 changes: 7 additions & 4 deletions libs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Spectator-CPP Libraries

This directory contains all the core libraries that make up the Spectator-CPP framework. These modular components work together to build the implementation of the main Spectator Registry interface.
This directory contains all the core libraries that make up the Spectator-CPP framework. These modular components work
together to build the implementation of the main Spectator Registry interface.

## Library Overview

Expand All @@ -10,12 +11,14 @@ This directory contains all the core libraries that make up the Spectator-CPP fr
| `logger` | Logging facilities used throughout the framework |
| `meter` | Core metrics implementations including counters, gauges, timers, and meter identification |
| `utils` | Utility classes and helpers including singleton patterns |
| `writer` | Output writers for metrics data (file, memory, UDP, Unix Domain Socket) |
| `writer` | Output writers for metrics data (Memory, UDP, Unix Domain Socket) |

## Usage

Each library subfolder contains additional documentation describing its specific API and usage examples. See the main project README for complete integration instructions.
Each library subfolder contains additional documentation describing its specific API and usage examples. See the main
project README for complete integration instructions.

## Dependencies

Most libraries have minimal external dependencies, though some writers may require specific system capabilities for networking.
Most libraries have minimal external dependencies, though some writers may require specific system capabilities for
networking.
16 changes: 9 additions & 7 deletions libs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## Overview

The `Config` class serves as the configuration object for the Registry class, which manages how metrics are sent to SpectatorD.
The `Config` constructor takes two parameters. The first parameter is required and is a `WriterConfig` object. This object defines
how metrics will be sent to `SpectatorD`. The second parameter `extraTags` is an unordered map of strings allowing you to provide additional tags to
all of your metrics. Extra tags are additional key-value pairs attached to all metrics and will be merged with environment-derived tags.
The `Config` class serves as the configuration object for the Registry class, which manages how metrics are sent to
SpectatorD. The `Config` constructor takes two parameters. The first parameter is required and is a `WriterConfig`
object. This object defines how metrics will be sent to `SpectatorD`. The second parameter `extraTags` is an
unordered map of strings allowing you to provide additional tags to all of your metrics. Extra tags are additional
key-value pairs attached to all metrics and will be merged with environment-derived tags.

## Usage

Expand All @@ -31,11 +32,12 @@ Config config(WriterConfig(WriterTypes::Memory), tags);

## Environment Variables

If the following environment variables are set and not empty, there key and value will also be read and applied to your tags
If the following environment variables are set and not empty, there key and value will also be read and applied to
your tags
- `TITUS_CONTAINER_NAME`: Set the `nf.container` tag automatically
- `TITUS_PROCESS_NAME`: Set the `nf.process` tag automatically

### Warning

If the environment variable `SPECTATOR_OUTPUT_LOCATION` is set this will override the value specified in the `WriterConfig`
read the `WriterConfig` readme.md for more details.
If the environment variable `SPECTATOR_OUTPUT_LOCATION` is set this will override the value specified in the
`WriterConfig` read the `WriterConfig` readme.md for more details.
2 changes: 1 addition & 1 deletion libs/meter/meter_types/include/age_gauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AgeGauge final : public Meter
Writer::GetInstance().Write(line);
}

void Set(const int& seconds) const
void Set(const double& seconds) const
{
auto line = this->ConstructLine(seconds);
Writer::GetInstance().Write(line);
Expand Down
2 changes: 1 addition & 1 deletion libs/meter/meter_types/include/dist_summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DistributionSummary final : public Meter
public:
explicit DistributionSummary(const MeterId& meter_id) : Meter(meter_id, DisTRIBUTION_SUMMARY_TYPE_SYMBOL) {}

void Record(const int& amount) const
void Record(const double& amount) const
{
if (amount >= 0)
{
Expand Down
3 changes: 2 additions & 1 deletion libs/meter/meter_types/include/percentile_dist_summary.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <meter_id.h>
#include <writer.h>

#include <cstdint>
#include <string>

static constexpr auto PERCENTILE_DISTRIBUTION_SUMMARY_TYPE_SYMBOL = "D";
Expand All @@ -16,7 +17,7 @@ class PercentileDistributionSummary final : public Meter
{
}

void Record(const int& amount) const
void Record(const int64_t& amount) const
{
if (amount >= 0)
{
Expand Down
2 changes: 1 addition & 1 deletion libs/meter/meter_types/test/test_age_gauge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ TEST_F(AgeGaugeTest, Set)
AgeGauge g(tid);
EXPECT_TRUE(writer->IsEmpty());
g.Set(10);
EXPECT_EQ("A:age_gauge:10\n", writer->LastLine());
EXPECT_EQ("A:age_gauge:10.000000\n", writer->LastLine());
}
4 changes: 2 additions & 2 deletions libs/meter/meter_types/test/test_dist_summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ TEST_F(DistSummaryTest, record)
EXPECT_TRUE(writer->IsEmpty());

ds.Record(42);
EXPECT_EQ("d:dist_summary:42\n", writer->LastLine());
EXPECT_EQ("d:dist_summary:42.000000\n", writer->LastLine());
}

TEST_F(DistSummaryTest, recordNegative)
Expand All @@ -39,5 +39,5 @@ TEST_F(DistSummaryTest, recordZero)
EXPECT_TRUE(writer->IsEmpty());

ds.Record(0);
EXPECT_EQ("d:dist_summary:0\n", writer->LastLine());
EXPECT_EQ("d:dist_summary:0.000000\n", writer->LastLine());
}
9 changes: 6 additions & 3 deletions libs/writer/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Writer Module

The Writer module provides a flexible system for metric data output in the Spectator C++ library. It consists of several components that handle different aspects of data writing.
The Writer module provides a flexible system for metric data output in the Spectator C++ library. It consists of
several components that handle different aspects of data writing.

## Components

Expand Down Expand Up @@ -36,7 +37,8 @@ This component handles configuration of writers:
WriterConfig config(WriterTypes::UDP);

// Or with a URL-style location
WriterConfig config("udp://192.168.1.100:8125");
const std::string unixUrl = std::string(WriterTypes::UnixURL) + "/var/run/custom/socket.sock";
const WriterConfig config(unixUrl);

// Environment variable overrides any provided value
// SPECTATOR_OUTPUT_LOCATION=unix:///custom/path/socket.sock
Expand Down Expand Up @@ -72,7 +74,8 @@ These components work together to provide a flexible metric output system:

```cpp
// Create a configuration
WriterConfig writerConfig("udp://localhost:8125");
const std::string udpUrl = std::string(WriterTypes::UDPURL) + "192.168.1.100:8125";
const WriterConfig writerConfig(udpUrl);

// Create a configuration object with the writer config
Config config(writerConfig);
Expand Down
10 changes: 5 additions & 5 deletions spectator/test_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ TEST(RegistryTest, AgeGauge)
EXPECT_TRUE(memoryWriter->IsEmpty());

g1.Set(1);
EXPECT_EQ("A:age_gauge:1\n", memoryWriter->LastLine());
EXPECT_EQ("A:age_gauge:1.000000\n", memoryWriter->LastLine());

g2.Set(2);
EXPECT_EQ("A:age_gauge,my-tags=bar:2\n", memoryWriter->LastLine());
EXPECT_EQ("A:age_gauge,my-tags=bar:2.000000\n", memoryWriter->LastLine());
}

TEST(RegistryTest, AgeGaugeWithId)
Expand All @@ -47,7 +47,7 @@ TEST(RegistryTest, AgeGaugeWithId)
EXPECT_TRUE(memoryWriter->IsEmpty());

g.Set(0);
EXPECT_EQ("A:age_gauge,extra-tags=foo,my-tags=bar:0\n",
EXPECT_EQ("A:age_gauge,extra-tags=foo,my-tags=bar:0.000000\n",
ParseProtocolLine(memoryWriter->LastLine()).value().to_string());
}

Expand Down Expand Up @@ -109,7 +109,7 @@ TEST(RegistryTest, DistributionSummary)
EXPECT_TRUE(memoryWriter->IsEmpty());

d.Record(42);
EXPECT_EQ("d:distribution_summary:42\n", memoryWriter->LastLine());
EXPECT_EQ("d:distribution_summary:42.000000\n", memoryWriter->LastLine());
}

TEST(RegistryTest, DistributionSummaryWithId)
Expand All @@ -122,7 +122,7 @@ TEST(RegistryTest, DistributionSummaryWithId)
EXPECT_TRUE(memoryWriter->IsEmpty());

d.Record(42);
EXPECT_EQ("d:distribution_summary,extra-tags=foo,my-tags=bar:42\n",
EXPECT_EQ("d:distribution_summary,extra-tags=foo,my-tags=bar:42.000000\n",
ParseProtocolLine(memoryWriter->LastLine()).value().to_string());
}

Expand Down