Dropwizard doesn't report metrics to ganglia - dropwizard

I am trying to monitor my dropwizard web service using ganglia. I ran gmond and gmetad on my local machine. And I was able to see basic metrics(eg.cpu,memory usage) on ganglia-web.
I also added ganglia reporter in my service according to this. But nothing shows up on my ganglia-web.
private static final MetricRegistry metrics = new MetricRegistry();
private final Timer ingest = metrics.timer("MyApp");
try {
final GMetric ganglia = new GMetric("localhost", 8649, GMetric.UDPAddressingMode.MULTICAST, 1);
final GangliaReporter gangliaReporter = GangliaReporter.forRegistry(metrics)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.build(ganglia);
gangliaReporter.start(1, TimeUnit.MINUTES);
} catch (Exception e) {
LOGGER.error("Can not initiate GangliaReporter",e);
}

It looks to me that you entered a normal network address but tell GMetric to expect a multicast address. Here is what I used (and works):
GMetric ganglia = new GMetric("192.168.0.40", 8649, UDPAddressingMode.UNICAST, 1);
If this does not help you, please show your gmond.conf (udp channel config)

Related

How can I activate JMX for Caffeine cache

I was looking at this SO question, but here I only want Caffeine to start reporting to JMX.
I have added an application.conf file as such and referenced it via -Dconfig.file:
caffeine.jcache {
# A named cache is configured by nesting a new definition under the caffeine.jcache namespace. The
# per-cache configuration is overlaid on top of the default configuration.
default {
# The monitoring configuration
monitoring {
# If JCache statistics should be recorded and externalized via JMX
statistics = true
# If the configuration should be externalized via JMX
management = true
}
}
It is not working, but I suspect it might be related to jcache, but not sure what is the expected way to implement this basic monitoring.
The cache instance is registered with the MBean server when it is instantiated by the CacheManager. The following test uses the programmatic api for test simplicity.
public final class JmxTest {
#Test
public void jmx() throws MalformedObjectNameException {
var config = new CaffeineConfiguration<>();
config.setManagementEnabled(true);
config.setStatisticsEnabled(true);
var manager = Caching.getCachingProvider().getCacheManager();
var cache = manager.createCache("jmx", config);
cache.put(1, 2);
var server = ManagementFactory.getPlatformMBeanServer();
String name = String.format("javax.cache:type=%s,CacheManager=%s,Cache=%s",
"CacheStatistics", manager.getURI().toString(), cache.getName());
var stats = JMX.newMBeanProxy(server, new ObjectName(name), CacheStatisticsMXBean.class);
assertThat(stats.getCachePuts()).isEqualTo(1);
}
}
If you do not need JCache for an integration then you will likely prefer to use the native APIs and metrics library. It is supported by Micrometer, Dropwizard Metrics, and the Prometheus client. While JCache is great for framework integrations, its api is rigid and cause surprising performance issues.

kubernetes deployment notification to slack channel using webhook

I have set up the notification for cloud build CI/CD which is pushing notification to a respective slack channel.
After a successful build that image push to kubernetes cluster and rolling update strategy followed by deployment.
So I want to push notification when new pod become ready and old pod terminated so that time gets an idea about new changes applied to deployment.
Note : I am using GKE cluster but not installed Prometheus due to resource limits.
There are multiple ways of doing this, I can think of two ways right now:
Use Prometheus + Alert manager to send you a slack notification when pods became ready.
Use CI/CD pipeline to continuously check for the status of the pods, once they are updated successfully, send a notification.
Hope this answers your question.
EDIT:
If you would like to stick to using stackdriver, then there is a solution for it as well: https://kubernetes.io/docs/tasks/debug-application-cluster/events-stackdriver/
If you cannot afford to Prometheus stack due to resources limitation check kubewatch it has slack support build-in so it should be suitable for your needs.
Using kubernetes api watch can be implemented
https://github.com/kubernetes-client/csharp/tree/master/examples/watch
Basically it will check the not running pod and notify using Microsoft Teams web-hook. It will also notify pod which was initially not running and came back to running status again(recovered pod)
C# code snippet below with Main and Notify function.
You can replace the deployment over pod
static async Task Main(string[] args)
{
// Load from the default kubeconfig on the machine.
var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
// Use the config object to create a client.
var client = new Kubernetes(config);
try
{
var podlistResp = await client.ListNamespacedPodWithHttpMessagesAsync(Namespace, watch: true);
using (podlistResp.Watch<V1Pod, V1PodList>(async (type, item) =>
{
Console.WriteLine(type);
Console.WriteLine("==on watch event==");
var message = $"Namespace: {Namespace} Pod: {item.Metadata.Name} Type: {type} Phase:{item.Status.Phase}";
var remessage = $"Namespace: {Namespace} Pod: {item.Metadata.Name} Type: {type} back to Phase:{item.Status.Phase}";
Console.WriteLine(message);
if (!item.Status.Phase.Equals("Running") && !item.Status.Phase.Equals("Succeeded"))
{ Console.WriteLine("==on watch event==");
await Notify(message);
Console.WriteLine("==on watch event==");
}
if ( type== WatchEventType.Modified && item.Status.Phase.Equals("Running") )
{ Console.WriteLine("==on watch event==");
await Notify(remessage);
Console.WriteLine("==on watch event==");
}
}))
{
Console.WriteLine("press ctrl + c to stop watching");
var ctrlc = new ManualResetEventSlim(false);
Console.CancelKeyPress += (sender, eventArgs) => ctrlc.Set();
ctrlc.Wait();
}
}
catch (System.Exception ex)
{
Console.Error.WriteLine($"An error happened Message: {ex.Message}", ex);
}
}
private static async Task Notify(string message)
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://outlook.office.com");
var body = new { text = message };
var content = new StringContent(JsonConvert.SerializeObject(body));
var result = await client.PostAsync("https://outlook.office.com/webhook/xxxx/IncomingWebhook/xxx", content);
result.EnsureSuccessStatusCode();
}
}
For anyone looking for such tool, do try BotKube. It is built to send
Kubernetes events to messengers like Slack, Mattermost and Microsoft Teams. It also has features like custom filters

tcpListener on Win 10 iOT not working

I have a UWA on RPi 3 with Win 10 version 10.0.14393.0 and VS 2015 Update 3. I'm trying to run a TCPListener on my RPi, code runs with no exception but never can connect it, seems that some things block my connection. there is no hardware or software Firewall in path. I tried both background and foreground app but no result.
My code is as below :
namespace TestBackPort
{
public sealed class StartupTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
TcpListener tcpListener = null;
tcpListener = new TcpListener(IPAddress.Parse("192.168.1.9"), 1100);
tcpListener.Start();
var task = HandleConnectionsAsync(tcpListener);
task.Wait();
}
int connectionNumber = 0;
async Task HandleConnectionsAsync(TcpListener listener)
{
while (true)
{
var client = await listener.AcceptTcpClientAsync();
// Console.WriteLine("OK #" + connectionNumber);
connectionNumber++;
}
}
}
}
First of all, check your network state using "netstat" utility.
Connect to your raspberry pi using putty or powershell
Do "netstate -a" to verify that the TCP server is actually listening on that port.
When you have your server running, you should see something similar to below
Secondly, make sure you have the Internet Server capability enabled in the project manifest file. It could be either the Internet or the Private Networks, like below.

How to authenticate when receiving idocs with ERPConnect (Theobald)?

I'm a little lost. I followed the documentation of ERPConnect (Theobald) to setup an rfc server:
static void Main(string[] args)
{
// define server object and start
RFCServer s = new RFCServer();
s.Logging = true;
s.GatewayHost = "hamlet";
s.GatewayService = "sapgw11";
s.ProgramID = "ERPTEST";
s.CanReceiveIdocs = true;
s.IncomingIdoc+= new ERPConnect.RFCServer.OnIncomingIdoc(s_IncomingIdoc);
s.InternalException+= new ERPConnect.RFCServer.OnInternalException (s_InternalException);
s.Start();
Console.WriteLine("Server is running. Press any key to exit.");
Console.ReadLine();
s.Stop();
}
The only problem is, that I can't figure out, how to send my password credentials to the SAP server. As a result I get internal exceptions, that I am not authorized to receive idocs.
there is no need for any credentials if you want to receive Idocs. Setting up an RFC Server to receive Idocs needs only this 3 SAP Properties: GatewayHost (usually your SAP Server), Gateway Service(usually sapgw + Instancenumber of the SAP System) and ProgramID. You can find a tutorial how to setup the ProgramID following this link:
http://help.theobald-software.com/ERPConnect-EN/default.aspx?pageid=setting-up-an-environment-for-sending-test-idocs
More Details how to receive an Idoc :
http://help.theobald-software.com/ERPConnect-EN/default.aspx?pageid=example-receiving-an-idoc
Best
Ali

How to make HttpClient relay traffic show up in Fidder or Charles?

I have a simple web api project based on this example:
http://aspnet.codeplex.com/sourcecontrol/latest#Samples/WebApi/RelaySample/Program.cs
However, in the above sample the relay is working with a local server, in my project the relay is working with an external web server with a real address; companyX.com
I am using the relay service (or, web proxy service) through a browser, for example, in the browser request relayService.com/companyX. The relay service responds with data from the external companyX.com site.
The relay works great, however some headers are not correct and I need to see what the HttpClient is sending to the remote companyX.com server.
In fiddler or Charles, only the request/response from my browser to relayService.com is listed, the request/response from the HttpClient to relayService.com never shows up.
The relayService.com is running locally on my machine, in IIS7, I'm using the hosts file to direct traffic to relayService.com.
I have tried several variation of the following when creating the HttpClient:
var clientHandler = new HttpClientHandler
{
CookieContainer = cookies,
UseCookies = true,
UseDefaultCredentials = false,
Proxy = new WebProxy("http://localhost:8888"),
UseProxy = true,
AutomaticDecompression = DecompressionMethods.GZip,
AllowAutoRedirect = false,
ClientCertificateOptions = ClientCertificateOption.Automatic
};
HttpClient client = new HttpClient(clientHandler);
UPDATE
If I change UseProxy = false The service continues to work, when Fiddler is open or closed.
With UseProxy = true then the service will fail, if fiddler is open, I get the following error:
Object reference not set to an instance of an object.
at System.DomainNameHelper.IdnEquivalent(String hostname) at System.Net.HttpWebRequest.GetSafeHostAndPort(Uri sourceUri, Boolean addDefaultPort, Boolean forcePunycode) at System.Net.HttpWebRequest.GenerateProxyRequestLine(Int32 headersSize) at System.Net.HttpWebRequest.SerializeHeaders() at System.Net.HttpWebRequest.EndSubmitRequest() at System.Net.Connection.CompleteConnection(Boolean async, HttpWebRequest request)
With UseProxy = true and fiddler is CLOSED, I get the following (obvious) error:
No connection could be made because the target machine actively refused it 127.0.0.1:8888
In the same solution I am using HttpWebRequest to download data from the web and that does show up in Fiddler, so it seems to be an issue with the HttpClient.GetAsync()
I have tried this on two machines with identical results.
I have been struggling with this all day, any help would be much appreciated.
Just to recap:
* relayService.com is running locally on my machine, in IIS7
hosts file has "127.0.0.1 relayService.com"
relayService.com is an MVC Web API site that uses HttpClient.GetAsync() to download content from the live web
Fiddler/Charles is running locally on same machine
browser traffic to the local relayService.com appears in Fiddler/Charles
HttpClient.GetAsync() to live web traffic does not appear in Fiddler/Charles
Fiddler/Charles are both up to date versions.
Thanks again
You don't need anything in your HOSTS file if you're using Fiddler; you can use Fiddler's Tools > HOSTS to redirect traffic anywhere you'd like.
When trying to capture traffic from a service account (e.g. the ASP.NET acccount) you typically want to configure that account to use the proxy; see http://fiddler2.com/blog/blog/2013/01/08/capturing-traffic-from-.net-services-with-fiddler for details on that. If you do that, you shouldn't need to configure the proxy object directly in code.
The exception you've shown suggests that here's a bug in the GenerateProxyRequestLine function. Is there any change if you update this: new WebProxy("http://localhost:8888"); to new WebProxy("127.0.0.1", 8888); ?
Generally speaking, .NET applications will bypass the proxy for URLs pointed at //localhost or //127.0.0.1, so when debugging with Fiddler it's common to use a service URL of //localhost.fiddler so that the traffic is always sent to the proxy.
I fixed the problem by making the HttpClient static.
This works fine (for the program functionality) but has the problem with fiddler described above, where trying to use the proxy throws an error:
private HttpClient _client()
{
var clientHandler = new HttpClientHandler
{
UseCookies = true,
UseDefaultCredentials = false,
Proxy = new WebProxy("http://localhost:8888"),
UseProxy = true,
AutomaticDecompression = DecompressionMethods.GZip,
AllowAutoRedirect = true,
ClientCertificateOptions = ClientCertificateOption.Automatic
};
HttpClient client = new HttpClient(clientHandler);
client.Timeout = TimeSpan.FromMinutes(20);
return client;
}
The client was created with:
using (HttpResponseMessage serviceResponse = await _client().GetAsync(getURL(), HttpCompletionOption.ResponseHeadersRead))
{
// Return response
}
However, the below also works and all traffic shows up in Fiddler!
private static readonly HttpClientHandler _clientHandler = new HttpClientHandler()
{
//CookieContainer = cookies,
UseCookies = true,
UseDefaultCredentials = false,
Proxy = new WebProxy("http://localhost:8888"),
UseProxy = false,
AutomaticDecompression = DecompressionMethods.GZip,
AllowAutoRedirect = false,
ClientCertificateOptions = ClientCertificateOption.Automatic,
};
//Create a shared instance of HttpClient and set the request timeout
private static readonly HttpClient _client = new HttpClient(_clientHandler)
{
Timeout = TimeSpan.FromMinutes(20)
};
The client was created with (only difference is removing the '()' after _client above):
using (HttpResponseMessage serviceResponse = await _client.GetAsync(getURL(), HttpCompletionOption.ResponseHeadersRead))
{
// Return response
}
I have no clue why this works. Any insight would be appreciated.
Thanks,

Resources